KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > ra > ActiveMQResourceAdapterJavaBeanEqualityTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.ra;
19
20 import org.apache.activemq.ra.ActiveMQResourceAdapter;
21
22 import junit.framework.TestCase;
23
24 /**
25  * @version $Revision$
26  */

27 public class ActiveMQResourceAdapterJavaBeanEqualityTest extends TestCase {
28
29     private ActiveMQResourceAdapter raOne;
30     private ActiveMQResourceAdapter raTwo;
31
32     public ActiveMQResourceAdapterJavaBeanEqualityTest(String JavaDoc name) {
33         super(name);
34     }
35
36     protected void setUp() throws Exception JavaDoc {
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