001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Alexander V. Esin
020: * @version $Revision$
021: */package org.ietf.jgss;
022:
023: import java.net.InetAddress;
024: import java.util.Arrays;
025:
026: import junit.framework.TestCase;
027:
028: /**
029: * Tests ChannelBinding class
030: */
031: public class ChannelBindingTest extends TestCase {
032:
033: public void testGetApplicationData() {
034: byte data[] = { 0, 1, 2, 10, 20 };
035: ChannelBinding cb = new ChannelBinding(data);
036: assertTrue(Arrays.equals(new byte[] { 0, 1, 2, 10, 20 }, cb
037: .getApplicationData()));
038: }
039:
040: public void testGetApplicationData_0() throws Exception {
041: byte data[] = { 0, 10, 20, 40, 50 };
042: InetAddress addr1 = InetAddress.getByAddress(new byte[] { 127,
043: 0, 0, 1 });
044: InetAddress addr2 = InetAddress.getByAddress(new byte[] { 127,
045: 0, 0, 2 });
046: ChannelBinding cb = new ChannelBinding(addr1, addr2, data);
047: assertTrue(Arrays.equals(new byte[] { 0, 10, 20, 40, 50 }, cb
048: .getApplicationData()));
049: }
050:
051: public void testGetApplicationData_1() {
052: ChannelBinding cb = new ChannelBinding(null);
053: assertNull(cb.getApplicationData());
054: }
055:
056: public void testGetInitiatorAddress() throws Exception {
057: InetAddress addr = InetAddress.getByAddress(new byte[] { 127,
058: 0, 0, 1 });
059: ChannelBinding cb = new ChannelBinding(addr, null, null);
060: assertEquals(InetAddress
061: .getByAddress(new byte[] { 127, 0, 0, 1 }), cb
062: .getInitiatorAddress());
063: }
064:
065: public void testGetInitiatorAddress_0() throws Exception {
066: byte data[] = { 0, 10, 20, 40, 50 };
067: InetAddress addr1 = InetAddress.getByAddress(new byte[] { 127,
068: 0, 0, 1 });
069: InetAddress addr2 = InetAddress.getByAddress(new byte[] { 127,
070: 0, 0, 2 });
071: ChannelBinding cb = new ChannelBinding(addr1, addr2, data);
072: assertEquals(InetAddress
073: .getByAddress(new byte[] { 127, 0, 0, 1 }), cb
074: .getInitiatorAddress());
075: }
076:
077: public void testGetInitiatorAddress_1() {
078: ChannelBinding cb = new ChannelBinding(null);
079: assertNull(cb.getInitiatorAddress());
080: }
081:
082: public void testGetAcceptorAddress() throws Exception {
083: InetAddress addr = InetAddress.getByAddress(new byte[] { 127,
084: 0, 0, 1 });
085: ChannelBinding cb = new ChannelBinding(null, addr, null);
086: assertEquals(InetAddress
087: .getByAddress(new byte[] { 127, 0, 0, 1 }), cb
088: .getAcceptorAddress());
089: }
090:
091: public void testGetAcceptorAddress_0() throws Exception {
092: byte data[] = { 0, 10, 20, 40, 50 };
093: InetAddress addr1 = InetAddress.getByAddress(new byte[] { 127,
094: 0, 0, 1 });
095: InetAddress addr2 = InetAddress.getByAddress(new byte[] { 127,
096: 0, 0, 2 });
097: ChannelBinding cb = new ChannelBinding(addr1, addr2, data);
098: assertEquals(InetAddress
099: .getByAddress(new byte[] { 127, 0, 0, 2 }), cb
100: .getAcceptorAddress());
101: }
102:
103: public void testGetAcceptorAddress_1() {
104: ChannelBinding cb = new ChannelBinding(null);
105: assertNull(cb.getAcceptorAddress());
106: }
107:
108: public void testEquals() {
109: ChannelBinding cb = new ChannelBinding(null);
110: assertTrue((new ChannelBinding(null, null, null).equals(cb)));
111: }
112:
113: public void testEquals_0_0_0() {
114: ChannelBinding cb = new ChannelBinding(new byte[] { 0, 10, 20,
115: 40, 50 });
116: assertTrue(cb.equals(cb));
117: }
118:
119: public void testEquals_0() throws Exception {
120: byte data[] = { 0, 10, 20, 40, 50 };
121: InetAddress addr1 = InetAddress.getByAddress(new byte[] { 127,
122: 0, 0, 1 });
123: InetAddress addr2 = InetAddress.getByAddress(new byte[] { 127,
124: 0, 0, 2 });
125: ChannelBinding cb = new ChannelBinding(addr1, addr2, data);
126:
127: assertTrue((new ChannelBinding(InetAddress
128: .getByAddress(new byte[] { 127, 0, 0, 1 }), InetAddress
129: .getByAddress(new byte[] { 127, 0, 0, 2 }), new byte[] {
130: 0, 10, 20, 40, 50 })).equals(cb));
131: }
132:
133: public void testEquals_0_0() throws Exception {
134: byte data[] = { 0, 10, 20, 40, 50 };
135: InetAddress addr1 = InetAddress.getByAddress(new byte[] { 127,
136: 0, 0, 1 });
137: InetAddress addr2 = InetAddress.getByAddress(new byte[] { 127,
138: 0, 0, 2 });
139: ChannelBinding cb = new ChannelBinding(addr1, addr2, data);
140:
141: assertTrue((new ChannelBinding(addr1, addr2, new byte[] { 0,
142: 10, 20, 40, 50 })).equals(cb));
143: }
144:
145: public void testEquals_1() throws Exception {
146: byte data[] = { 0, 10, 20, 40, 5 };
147: ChannelBinding cb = new ChannelBinding(data);
148: assertTrue((new ChannelBinding(new byte[] { 0, 10, 20, 40, 5 }))
149: .equals(cb));
150: }
151:
152: public void testEquals_2() throws Exception {
153: byte data[] = null;
154: InetAddress addr1 = InetAddress.getByAddress(new byte[] { 127,
155: 0, 0, 1 });
156: InetAddress addr2 = InetAddress.getByAddress(new byte[] { 127,
157: 0, 0, 2 });
158: ChannelBinding cb = new ChannelBinding(addr1, addr2, data);
159:
160: assertTrue((new ChannelBinding(InetAddress
161: .getByAddress(new byte[] { 127, 0, 0, 1 }), InetAddress
162: .getByAddress(new byte[] { 127, 0, 0, 2 }), null))
163: .equals(cb));
164: }
165:
166: public void testEquals_2_0() throws Exception {
167: byte data[] = null;
168: InetAddress addr1 = null;
169: InetAddress addr2 = InetAddress.getByAddress(new byte[] { 127,
170: 0, 0, 2 });
171: ChannelBinding cb = new ChannelBinding(addr1, addr2, data);
172:
173: assertTrue((new ChannelBinding(null, InetAddress
174: .getByAddress(new byte[] { 127, 0, 0, 2 }), null))
175: .equals(cb));
176: }
177:
178: //Negative
179: public void testEquals_Negative() throws Exception {
180: byte data[] = { 0, 10, 20 };
181: ChannelBinding cb = new ChannelBinding(data);
182: assertTrue(!(new ChannelBinding(null)).equals(cb));
183: }
184:
185: public void testEquals_Negative_0() throws Exception {
186: byte data[] = { 0, 10, 20 };
187: ChannelBinding cb = new ChannelBinding(null);
188: assertTrue(!(new ChannelBinding(data)).equals(cb));
189: }
190:
191: public void testEquals_Negative_0_0() throws Exception {
192: byte data[] = { 0, 10, 20 };
193: ChannelBinding cb = new ChannelBinding(data);
194: assertTrue(!cb.equals(new Object()));
195: }
196:
197: public void testEquals_Negative_1() throws Exception {
198: byte data[] = { 0, 10, 20 };
199: ChannelBinding cb = new ChannelBinding(data);
200: assertTrue(!(new ChannelBinding(
201: new byte[] { 0, 10, 20, 30, 40 })).equals(cb));
202: }
203:
204: public void testEquals_Negative_2() throws Exception {
205: byte data[] = { 0, 10, 20 };
206: InetAddress addr1 = InetAddress.getByAddress(new byte[] { 127,
207: 0, 0, 1 });
208: InetAddress addr2 = InetAddress.getByAddress(new byte[] { 127,
209: 0, 0, 2 });
210: ChannelBinding cb = new ChannelBinding(addr1, addr2, data);
211: assertTrue(!(new ChannelBinding(new byte[] { 0, 10, 20 }))
212: .equals(cb));
213: }
214:
215: public void testEquals_Negative_3() throws Exception {
216: byte data[] = { 0, 10, 20, 30 };
217: InetAddress addr1 = InetAddress.getByAddress(new byte[] { 127,
218: 0, 0, 1 });
219: InetAddress addr2 = InetAddress.getByAddress(new byte[] { 127,
220: 0, 0, 2 });
221: ChannelBinding cb = new ChannelBinding(addr1, addr2, data);
222: assertTrue(!(new ChannelBinding(addr1, addr2, new byte[] { 0,
223: 10, 20 })).equals(cb));
224: }
225:
226: public void testEquals_Negative_3_0() throws Exception {
227: byte data[] = { 0, 10, 20, 30 };
228: InetAddress addr1 = InetAddress.getByAddress(new byte[] { 127,
229: 0, 0, 1 });
230: InetAddress addr2 = InetAddress.getByAddress(new byte[] { 127,
231: 0, 0, 2 });
232: ChannelBinding cb = new ChannelBinding(addr1, addr2, data);
233: assertTrue(!(new ChannelBinding(InetAddress
234: .getByAddress(new byte[] { 127, 0, 0, 1 }), InetAddress
235: .getByAddress(new byte[] { 127, 0, 0, 2 }), new byte[] {
236: 0, 10, 20 })).equals(cb));
237: }
238:
239: public void testEquals_Negative_4() throws Exception {
240: byte data[] = { 0, 10, 20 };
241: InetAddress addr1 = InetAddress.getByAddress(new byte[] { 127,
242: 0, 0, 1 });
243: InetAddress addr2 = InetAddress.getByAddress(new byte[] { 127,
244: 0, 0, 2 });
245: ChannelBinding cb = new ChannelBinding(addr1, addr2, data);
246: assertTrue(!(new ChannelBinding(InetAddress
247: .getByAddress(new byte[] { 127, 0, 0, 1 }), InetAddress
248: .getByAddress(new byte[] { 127, 0, 0, 1 }), new byte[] {
249: 0, 10, 20 })).equals(cb));
250: }
251:
252: public void testEquals_Negative_5() throws Exception {
253: byte data[] = { 0, 10, 20 };
254: InetAddress addr1 = InetAddress.getByAddress(new byte[] { 127,
255: 0, 0, 2 });
256: InetAddress addr2 = InetAddress.getByAddress(new byte[] { 127,
257: 0, 0, 1 });
258: ChannelBinding cb = new ChannelBinding(addr1, addr2, data);
259: assertTrue(!(new ChannelBinding(InetAddress
260: .getByAddress(new byte[] { 127, 0, 0, 1 }), InetAddress
261: .getByAddress(new byte[] { 127, 0, 0, 1 }), new byte[] {
262: 0, 10, 20 })).equals(cb));
263: }
264:
265: public void testEquals_Negative_6() throws Exception {
266: byte data[] = { 0, 10, 20 };
267: InetAddress addr1 = InetAddress.getByAddress(new byte[] { 127,
268: 0, 0, 2 });
269: InetAddress addr2 = InetAddress.getByAddress(new byte[] { 127,
270: 0, 0, 1 });
271: ChannelBinding cb = new ChannelBinding(addr1, addr2, data);
272: assertTrue(!(new ChannelBinding(null, InetAddress
273: .getByAddress(new byte[] { 127, 0, 0, 1 }), new byte[] {
274: 0, 10, 20 })).equals(cb));
275: }
276:
277: public void testHashCode() throws Exception {
278: byte data[] = { 0, 10, 20, 40, 50 };
279: InetAddress addr1 = InetAddress.getByAddress(new byte[] { 127,
280: 0, 0, 1 });
281: InetAddress addr2 = InetAddress.getByAddress(new byte[] { 127,
282: 0, 0, 2 });
283: ChannelBinding cb = new ChannelBinding(addr1, addr2, data);
284: assertEquals(addr1.hashCode(), cb.hashCode());
285: }
286:
287: public void testHashCode_0() throws Exception {
288: byte data[] = { 0, 10, 20, 40, 50 };
289: InetAddress addr = InetAddress.getByAddress(new byte[] { 127,
290: 0, 0, 1 });
291: ChannelBinding cb = new ChannelBinding(null, addr, data);
292: assertEquals(addr.hashCode(), cb.hashCode());
293: }
294:
295: public void testHashCode_1() throws Exception {
296: byte data[] = { 1, 2 };
297: ChannelBinding cb = new ChannelBinding(null, null, data);
298: assertEquals(33, cb.hashCode());
299: }
300:
301: public void testHashCode_2() throws Exception {
302: byte data[] = { 10, 2 };
303: ChannelBinding cb = new ChannelBinding(null, null, data);
304: assertEquals(312, cb.hashCode());
305: }
306: }
|