1 18 package org.apache.activemq.ra; 19 20 import org.apache.activemq.ra.ActiveMQResourceAdapter; 21 22 import junit.framework.TestCase; 23 24 27 public class ActiveMQResourceAdapterJavaBeanEqualityTest extends TestCase { 28 29 private ActiveMQResourceAdapter raOne; 30 private ActiveMQResourceAdapter raTwo; 31 32 public ActiveMQResourceAdapterJavaBeanEqualityTest(String name) { 33 super(name); 34 } 35 36 protected void setUp() throws Exception { 37 super.setUp(); 38 raOne = new ActiveMQResourceAdapter(); 39 raTwo = new ActiveMQResourceAdapter(); 40 } 41 42 public void testSelfEquality() { 43 assertEquality(raOne, raOne); 44 } 45 46 public void testEmptyEquality() { 47 assertEquality(raOne, raTwo); 48 } 49 50 public void testNullEqualityFailure() { 51 assertFalse(raOne.equals(null)); 52 } 53 54 public void testServerUrlEquality() { 55 raOne.setServerUrl("one"); 56 raTwo.setServerUrl("one"); 57 assertEquality(raOne,raTwo); 58 } 59 60 public void testServerUrlInequality() { 61 raOne.setServerUrl("one"); 62 raTwo.setServerUrl("two"); 63 assertNonEquality(raOne,raTwo); 64 } 65 66 public void testServerUrlInequalityDifferentCase() { 67 raOne.setServerUrl("one"); 68 raTwo.setServerUrl("ONE"); 69 assertNonEquality(raOne, raTwo); 70 } 71 72 public void testNullServerUrlInequality() { 73 raOne.setServerUrl("one"); 74 raTwo.setServerUrl(null); 75 assertNonEquality(raOne, raTwo); 76 } 77 78 public void testBrokerXMLConfigEquality() { 79 raOne.setBrokerXmlConfig("one"); 80 raTwo.setBrokerXmlConfig("one"); 81 assertEquality(raOne, raTwo); 82 } 83 84 public void testBrokerXMLConfigInequality() { 85 raOne.setBrokerXmlConfig("one"); 86 raTwo.setBrokerXmlConfig("two"); 87 assertNonEquality(raOne, raTwo); 88 } 89 90 public void testBrokerXMLConfigInequalityDifferentCase() { 91 raOne.setBrokerXmlConfig("one"); 92 raTwo.setBrokerXmlConfig("ONE"); 93 assertNonEquality(raOne, raTwo); 94 } 95 96 public void testNullBrokerXMLConfigInequality() { 97 raOne.setBrokerXmlConfig("one"); 98 raTwo.setBrokerXmlConfig(null); 99 assertNonEquality(raOne, raTwo); 100 } 101 102 public void testPasswordNotPartOfEquality() { 103 raOne.setClientid("one"); 104 raTwo.setClientid("one"); 105 raOne.setPassword("foo"); 106 raTwo.setPassword("bar"); 107 assertEquality(raOne, raTwo); 108 } 109 110 private void assertEquality(ActiveMQResourceAdapter leftRa, ActiveMQResourceAdapter rightRa) { 111 assertTrue("ActiveMQResourceAdapters are not equal", leftRa.equals(rightRa)); 112 assertTrue("ActiveMQResourceAdapters are not equal", rightRa.equals(leftRa)); 113 assertTrue("HashCodes are not equal", leftRa.hashCode() == rightRa.hashCode()); 114 } 115 116 private void assertNonEquality(ActiveMQResourceAdapter leftRa, ActiveMQResourceAdapter rightRa) { 117 assertFalse("ActiveMQResourceAdapters are equal", leftRa.equals(rightRa)); 118 assertFalse("ActiveMQResourceAdapters are equal", rightRa.equals(leftRa)); 119 assertFalse("HashCodes are equal", leftRa.hashCode() == rightRa.hashCode()); 120 } 121 122 123 } 124 | Popular Tags |