PageRenderTime 71ms CodeModel.GetById 12ms app.highlight 52ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/m3ua/impl/src/test/java/org/mobicents/protocols/ss7/m3ua/impl/parameter/ParameterTest.java

http://mobicents.googlecode.com/
Java | 682 lines | 467 code | 175 blank | 40 comment | 0 complexity | 565a7e49b93416b6678137b410ef1c16 MD5 | raw file
  1/*
  2 * JBoss, Home of Professional Open Source
  3 * Copyright 2011, Red Hat, Inc. and individual contributors
  4 * by the @authors tag. See the copyright.txt in the distribution for a
  5 * full listing of individual contributors.
  6 *
  7 * This is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU Lesser General Public License as
  9 * published by the Free Software Foundation; either version 2.1 of
 10 * the License, or (at your option) any later version.
 11 *
 12 * This software is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15 * Lesser General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU Lesser General Public
 18 * License along with this software; if not, write to the Free
 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21 */
 22
 23package org.mobicents.protocols.ss7.m3ua.impl.parameter;
 24
 25
 26import java.io.ByteArrayInputStream;
 27import java.io.ByteArrayOutputStream;
 28import java.io.IOException;
 29import java.nio.ByteBuffer;
 30import java.util.Arrays;
 31
 32import javolution.xml.XMLObjectReader;
 33import javolution.xml.XMLObjectWriter;
 34import javolution.xml.stream.XMLStreamException;
 35
 36import org.testng.annotations.*;
 37import static org.testng.Assert.*;
 38
 39import org.mobicents.protocols.ss7.m3ua.parameter.CongestedIndication.CongestionLevel;
 40import org.mobicents.protocols.ss7.m3ua.parameter.DeregistrationStatus;
 41import org.mobicents.protocols.ss7.m3ua.parameter.DestinationPointCode;
 42import org.mobicents.protocols.ss7.m3ua.parameter.LocalRKIdentifier;
 43import org.mobicents.protocols.ss7.m3ua.parameter.NetworkAppearance;
 44import org.mobicents.protocols.ss7.m3ua.parameter.OPCList;
 45import org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
 46import org.mobicents.protocols.ss7.m3ua.parameter.RegistrationStatus;
 47import org.mobicents.protocols.ss7.m3ua.parameter.RoutingContext;
 48import org.mobicents.protocols.ss7.m3ua.parameter.ServiceIndicators;
 49import org.mobicents.protocols.ss7.m3ua.parameter.Status;
 50import org.mobicents.protocols.ss7.m3ua.parameter.TrafficModeType;
 51
 52/**
 53 * @author amit bhayani
 54 * @author kulikov
 55 */
 56public class ParameterTest {
 57
 58	private ParameterFactoryImpl factory = new ParameterFactoryImpl();
 59	private ByteBuffer out = null;
 60
 61	public ParameterTest() {
 62	}
 63
 64	@BeforeClass
 65	public static void setUpClass() throws Exception {
 66	}
 67
 68	@AfterClass
 69	public static void tearDownClass() throws Exception {
 70	}
 71
 72	@BeforeMethod
 73	public void setUp() {
 74		out = ByteBuffer.allocate(8192);
 75	}
 76
 77	@AfterMethod
 78	public void tearDown() {
 79	}
 80
 81	private short getTag(byte[] data) {
 82		return (short) ((data[0] & 0xff) << 8 | (data[1] & 0xff));
 83	}
 84
 85	private short getLen(byte[] data) {
 86		return (short) ((data[2] & 0xff) << 8 | (data[3] & 0xff));
 87	}
 88
 89	private byte[] getValue(byte[] data) {
 90		// reduce 4 for Tag + length bytes
 91		short length = (short) (getLen(data) - 4);
 92		byte[] value = new byte[length];
 93		System.arraycopy(data, 4, value, 0, length);
 94		return value;
 95	}
 96
 97	@Test
 98	public void testProtocolData() throws IOException {
 99
100		// Trace from wireshark
101		byte[] userData = new byte[] { 0x09, (byte) 0x80, 0x03, 0x0c, 0x15, 0x09, 0x12, 0x05, 0x00, 0x12, 0x04, 0x55,
102				0x16, 0x09, (byte) 0x90, 0x09, 0x12, 0x07, 0x00, 0x12, 0x04, 0x55, 0x16, 0x09, 0x00, 0x5f, 0x62, 0x5d,
103				0x48, 0x04, 0x3a, (byte) 0x8c, 0x10, 0x04, 0x6b, 0x3f, 0x28, 0x3d, 0x06, 0x07, 0x00, 0x11, (byte) 0x86,
104				0x05, 0x01, 0x01, 0x01, (byte) 0xa0, 0x32, 0x60, 0x30, (byte) 0x80, 0x02, 0x07, (byte) 0x80,
105				(byte) 0xa1, 0x09, 0x06, 0x07, 0x04, 0x00, 0x00, 0x01, 0x00, 0x13, 0x02, (byte) 0xbe, 0x1f, 0x28, 0x1d,
106				0x06, 0x07, 0x04, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, (byte) 0xa0, 0x12, (byte) 0xa0, 0x10,
107				(byte) 0x80, 0x07, (byte) 0x91, 0x55, 0x16, 0x28, (byte) 0x81, 0x00, 0x70, (byte) 0x81, 0x05,
108				(byte) 0x91, 0x55, 0x16, 0x09, 0x00, 0x6c, 0x14, (byte) 0xa1, 0x12, 0x02, 0x01, 0x00, 0x02, 0x01, 0x3b,
109				0x30, 0x0a, 0x04, 0x01, 0x0f, 0x04, 0x05, 0x2a, (byte) 0xd9, (byte) 0x8c, 0x36, 0x02 };
110
111		byte[] protocolData = new byte[userData.length + 12];
112
113		System.arraycopy(userData, 0, protocolData, 12, userData.length);
114		protocolData[0] = 0x00;
115		protocolData[1] = 0x00;
116		protocolData[2] = 0x1e;
117		protocolData[3] = (byte) 0xd4;
118		protocolData[4] = 0x00;
119		protocolData[5] = 0x00;
120		protocolData[6] = 0x08;
121		protocolData[7] = (byte) 0x98;
122		protocolData[8] = 0x03;
123		protocolData[9] = 0x03;
124		protocolData[10] = 0x00;
125		protocolData[11] = 0x0f;
126
127		int si = 3;
128		int mp = 0;
129		int ni = 3;
130		int dpc = 2200;
131		int opc = 7892;
132		int sls = 15;
133		ProtocolDataImpl p1 = (ProtocolDataImpl) factory.createProtocolData(opc, dpc, si, ni, mp, sls, userData);
134
135		assertTrue(Arrays.equals(protocolData, p1.getValue()));
136
137		ProtocolDataImpl p2 = (ProtocolDataImpl) factory.createProtocolData(protocolData);
138
139		assertEquals(p1.getTag(), p2.getTag());
140		assertEquals(p1.getOpc(), p2.getOpc());
141		assertEquals(p1.getDpc(), p2.getDpc());
142		assertEquals(p2.getSI(), p2.getSI());
143		assertEquals(p2.getNI(), p2.getNI());
144		assertEquals(p2.getMP(), p2.getMP());
145		assertEquals(p2.getSLS(), p2.getSLS());
146
147		boolean isDataCorrect = Arrays.equals(p2.getData(), p2.getData());
148		assertTrue(isDataCorrect, "Data mismatch");
149	}
150
151	/**
152	 * Test of getOpc method, of class ProtocolDataImpl.
153	 */
154	@Test
155	public void testProtocolData1() throws IOException {
156		ProtocolDataImpl p1 = (ProtocolDataImpl) factory.createProtocolData(1408, 14150, 1, 1, 0, 1, new byte[] { 1, 2,
157				3, 4 });
158		p1.write(out);
159
160		byte[] data = out.array();
161
162		ProtocolDataImpl p2 = (ProtocolDataImpl) factory.createParameter(getTag(data), getValue(data));
163
164		assertEquals(p1.getTag(), p2.getTag());
165		assertEquals(p1.getOpc(), p2.getOpc());
166		assertEquals(p1.getDpc(), p2.getDpc());
167		assertEquals(p1.getSI(), p2.getSI());
168		assertEquals(p1.getNI(), p2.getNI());
169		assertEquals(p1.getMP(), p2.getMP());
170		assertEquals(p1.getSLS(), p2.getSLS());
171
172		boolean isDataCorrect = Arrays.equals(p1.getData(), p2.getData());
173		assertTrue(isDataCorrect, "Data mismatch");
174	}
175
176	@Test
177	public void testNetworkAppearance() throws IOException, XMLStreamException {
178
179		NetworkAppearanceImpl np = (NetworkAppearanceImpl) factory.createNetworkAppearance(123);
180		np.write(out);
181
182		byte[] data = out.array();
183
184		NetworkAppearanceImpl np2 = (NetworkAppearanceImpl) factory.createParameter(getTag(data), getValue(data));
185
186		assertEquals(123, (int) np2.getNetApp());
187
188		// Test Serialization
189		ByteArrayOutputStream output = new ByteArrayOutputStream();
190		XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
191		writer.setIndentation("\t");
192		writer.write(np, "NetworkAppearanceImpl", NetworkAppearanceImpl.class);
193		writer.close();
194
195		System.out.println(output.toString());
196
197		ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
198		XMLObjectReader reader = XMLObjectReader.newInstance(input);
199		NetworkAppearanceImpl np3 = reader.read("NetworkAppearanceImpl", NetworkAppearanceImpl.class);
200
201		assertEquals(123, (int) np3.getNetApp());
202		assertEquals(Parameter.Network_Appearance, np3.getTag());
203	}
204
205	@Test
206	public void testRoutingContext() throws IOException, XMLStreamException {
207		RoutingContextImpl rc = (RoutingContextImpl) factory.createRoutingContext(new long[] { 4294967295l });
208		rc.write(out);
209
210		byte[] data = out.array();
211
212		RoutingContextImpl rc2 = (RoutingContextImpl) factory.createParameter(getTag(data), getValue(data));
213
214		assertTrue(Arrays.equals(new long[] { 4294967295l }, rc2.getRoutingContexts()));
215
216		// Test Serialization
217		ByteArrayOutputStream output = new ByteArrayOutputStream();
218		XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
219		writer.setIndentation("\t");
220		writer.write(rc, "RoutingContextImpl", RoutingContextImpl.class);
221		writer.close();
222
223		System.out.println(output.toString());
224
225		ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
226		XMLObjectReader reader = XMLObjectReader.newInstance(input);
227		RoutingContextImpl rc3 = reader.read("RoutingContextImpl", RoutingContextImpl.class);
228
229		assertTrue(Arrays.equals(new long[] { 4294967295l }, rc3.getRoutingContexts()));
230		assertEquals(Parameter.Routing_Context, rc3.getTag());
231	}
232
233	@Test
234	public void testRoutingContexts() throws IOException, XMLStreamException {
235		RoutingContextImpl rc = (RoutingContextImpl) factory.createRoutingContext(new long[] { 123l, 4294967295l });
236		rc.write(out);
237
238		byte[] data = out.array();
239
240		RoutingContextImpl rc2 = (RoutingContextImpl) factory.createParameter(getTag(data), getValue(data));
241
242		assertTrue(Arrays.equals(new long[] { 123l, 4294967295l }, rc2.getRoutingContexts()));
243
244		// Test Serialization
245		ByteArrayOutputStream output = new ByteArrayOutputStream();
246		XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
247		writer.setIndentation("\t");
248		writer.write(rc, "RoutingContextImpl", RoutingContextImpl.class);
249		writer.close();
250
251		System.out.println(output.toString());
252
253		ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
254		XMLObjectReader reader = XMLObjectReader.newInstance(input);
255		RoutingContextImpl rc3 = reader.read("RoutingContextImpl", RoutingContextImpl.class);
256
257		assertTrue(Arrays.equals(new long[] { 123l, 4294967295l }, rc3.getRoutingContexts()));
258		assertEquals(Parameter.Routing_Context, rc3.getTag());
259	}
260
261	@Test
262	public void testCorrelationId() throws IOException {
263		CorrelationIdImpl crrId = (CorrelationIdImpl) factory.createCorrelationId(4294967295l);
264		crrId.write(out);
265
266		byte[] data = out.array();
267
268		CorrelationIdImpl crrId2 = (CorrelationIdImpl) factory.createParameter(getTag(data), getValue(data));
269
270		assertEquals(4294967295l, crrId2.getCorrelationId());
271	}
272
273	@Test
274	public void testAffectedPointCode() throws IOException {
275
276		AffectedPointCodeImpl affectedPc = (AffectedPointCodeImpl) factory.createAffectedPointCode(new int[] { 123 },
277				new short[] { 0 });
278		affectedPc.write(out);
279
280		byte[] data = out.array();
281
282		AffectedPointCodeImpl affectedPc2 = (AffectedPointCodeImpl) factory.createParameter(getTag(data),
283				getValue(data));
284
285		assertTrue(Arrays.equals(new int[] { 123 }, affectedPc2.getPointCodes()));
286		assertTrue(Arrays.equals(new short[] { 0 }, affectedPc2.getMasks()));
287	}
288
289	@Test
290	public void testAffectedPointCodes() throws IOException {
291		AffectedPointCodeImpl affectedPc = (AffectedPointCodeImpl) factory.createAffectedPointCode(
292				new int[] { 123, 456 }, new short[] { 0, 1 });
293		affectedPc.write(out);
294
295		byte[] data = out.array();
296
297		AffectedPointCodeImpl affectedPc2 = (AffectedPointCodeImpl) factory.createParameter(getTag(data),
298				getValue(data));
299
300		assertTrue(Arrays.equals(new int[] { 123, 456 }, affectedPc2.getPointCodes()));
301		assertTrue(Arrays.equals(new short[] { 0, 1 }, affectedPc2.getMasks()));
302	}
303
304	@Test
305	public void testInfoString() throws IOException {
306		InfoStringImpl infoStr = (InfoStringImpl) factory.createInfoString("Hello World");
307		infoStr.write(out);
308
309		byte[] data = out.array();
310
311		InfoStringImpl infoStr2 = (InfoStringImpl) factory.createParameter(getTag(data), getValue(data));
312
313		assertEquals("Hello World", infoStr2.getString());
314
315	}
316
317	@Test
318	public void testConcernedDPC() throws IOException {
319		ConcernedDPCImpl concernedDPC = (ConcernedDPCImpl) factory.createConcernedDPC(123);
320		concernedDPC.write(out);
321
322		byte[] data = out.array();
323
324		ConcernedDPCImpl concernedDPC2 = (ConcernedDPCImpl) factory.createParameter(getTag(data), getValue(data));
325
326		assertEquals(concernedDPC.getPointCode(), concernedDPC2.getPointCode());
327
328	}
329
330	@Test
331	public void testCongestedIndication() throws IOException {
332		CongestedIndicationImpl congIndImpl = (CongestedIndicationImpl) factory
333				.createCongestedIndication(CongestionLevel.LEVEL2);
334		congIndImpl.write(out);
335
336		byte[] data = out.array();
337
338		CongestedIndicationImpl congIndImpl2 = (CongestedIndicationImpl) factory.createParameter(getTag(data),
339				getValue(data));
340
341		assertEquals(congIndImpl.getCongestionLevel(), congIndImpl2.getCongestionLevel());
342
343	}
344
345	@Test
346	public void testUserCause() throws IOException {
347		UserCauseImpl usrCa = (UserCauseImpl) factory.createUserCause(5, 0);
348		usrCa.write(out);
349
350		byte[] data = out.array();
351
352		UserCauseImpl usrCa2 = (UserCauseImpl) factory.createParameter(getTag(data), getValue(data));
353
354		assertEquals(usrCa.getUser(), usrCa2.getUser());
355
356		assertEquals(usrCa.getCause(), usrCa2.getCause());
357
358	}
359
360	@Test
361	public void testASPIdentifier() throws IOException {
362		ASPIdentifierImpl rc = (ASPIdentifierImpl) factory.createASPIdentifier(12234445);
363		rc.write(out);
364
365		byte[] data = out.array();
366
367		ASPIdentifierImpl rc2 = (ASPIdentifierImpl) factory.createParameter(getTag(data), getValue(data));
368
369		assertEquals(12234445l, rc2.getAspId());
370	}
371
372	@Test
373	public void testDestinationPointCode() throws IOException, XMLStreamException {
374
375		DestinationPointCodeImpl affectedPc = (DestinationPointCodeImpl) factory.createDestinationPointCode(123,
376				(short) 0);
377		affectedPc.write(out);
378
379		byte[] data = out.array();
380
381		DestinationPointCodeImpl affectedPc2 = (DestinationPointCodeImpl) factory.createParameter(getTag(data),
382				getValue(data));
383
384		assertEquals(123, affectedPc2.getPointCode());
385		assertEquals((short) 0, affectedPc2.getMask());
386
387		// Test Serialization
388		ByteArrayOutputStream output = new ByteArrayOutputStream();
389		XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
390		writer.setIndentation("\t");
391		writer.write(affectedPc, "DestinationPointCodeImpl", DestinationPointCodeImpl.class);
392		writer.close();
393
394		System.out.println(output.toString());
395
396		ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
397		XMLObjectReader reader = XMLObjectReader.newInstance(input);
398		DestinationPointCodeImpl affectedPc3 = reader.read("DestinationPointCodeImpl", DestinationPointCodeImpl.class);
399
400		assertEquals(123, affectedPc3.getPointCode());
401		assertEquals((short) 0, affectedPc3.getMask());
402		assertEquals(Parameter.Destination_Point_Code, affectedPc3.getTag());
403	}
404
405	@Test
406	public void testLocalRKIdentifier() throws IOException, XMLStreamException {
407		LocalRKIdentifierImpl crrId = (LocalRKIdentifierImpl) factory.createLocalRKIdentifier(4294967295l);
408		crrId.write(out);
409
410		byte[] data = out.array();
411
412		LocalRKIdentifierImpl crrId2 = (LocalRKIdentifierImpl) factory.createParameter(getTag(data), getValue(data));
413
414		assertEquals(4294967295l, crrId2.getId());
415
416		// Test Serialization
417		ByteArrayOutputStream output = new ByteArrayOutputStream();
418		XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
419		writer.setIndentation("\t");
420		writer.write(crrId, "LocalRKIdentifierImpl", LocalRKIdentifierImpl.class);
421		writer.close();
422
423		System.out.println(output.toString());
424
425		ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
426		XMLObjectReader reader = XMLObjectReader.newInstance(input);
427		LocalRKIdentifierImpl crrId3 = reader.read("LocalRKIdentifierImpl", LocalRKIdentifierImpl.class);
428
429		assertEquals(4294967295l, crrId3.getId());
430		assertEquals(Parameter.Local_Routing_Key_Identifier, crrId3.getTag());
431	}
432
433	@Test
434	public void testOPCList() throws IOException, XMLStreamException {
435		OPCListImpl opcList = (OPCListImpl) factory.createOPCList(new int[] { 123, 456 }, new short[] { 0, 1 });
436		opcList.write(out);
437
438		byte[] data = out.array();
439
440		OPCListImpl opcList1 = (OPCListImpl) factory.createParameter(getTag(data), getValue(data));
441
442		assertTrue(Arrays.equals(new int[] { 123, 456 }, opcList1.getPointCodes()));
443		assertTrue(Arrays.equals(new short[] { 0, 1 }, opcList1.getMasks()));
444
445		// Test Serialization
446		ByteArrayOutputStream output = new ByteArrayOutputStream();
447		XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
448		writer.setIndentation("\t");
449		writer.write(opcList, "OPCListImpl", OPCListImpl.class);
450		writer.close();
451
452		System.out.println(output.toString());
453
454		ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
455		XMLObjectReader reader = XMLObjectReader.newInstance(input);
456		OPCListImpl opcList3 = reader.read("OPCListImpl", OPCListImpl.class);
457
458		assertTrue(Arrays.equals(new int[] { 123, 456 }, opcList3.getPointCodes()));
459		assertTrue(Arrays.equals(new short[] { 0, 1 }, opcList3.getMasks()));
460		assertEquals(Parameter.Originating_Point_Code_List, opcList3.getTag());
461	}
462
463	@Test
464	public void testServiceIndicators() throws IOException, XMLStreamException {
465		ServiceIndicatorsImpl siList = (ServiceIndicatorsImpl) factory
466				.createServiceIndicators(new short[] { 1, 2, 3, 4 });
467		siList.write(out);
468
469		byte[] data = out.array();
470
471		ServiceIndicatorsImpl siList1 = (ServiceIndicatorsImpl) factory.createParameter(getTag(data), getValue(data));
472
473		assertTrue(Arrays.equals(new short[] { 1, 2, 3, 4 }, siList1.getIndicators()));
474
475		// Test Serialization
476		ByteArrayOutputStream output = new ByteArrayOutputStream();
477		XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
478		writer.setIndentation("\t");
479		writer.write(siList, "ServiceIndicatorsImpl", ServiceIndicatorsImpl.class);
480		writer.close();
481
482		System.out.println(output.toString());
483
484		ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
485		XMLObjectReader reader = XMLObjectReader.newInstance(input);
486		ServiceIndicatorsImpl siList3 = reader.read("ServiceIndicatorsImpl", ServiceIndicatorsImpl.class);
487
488		assertTrue(Arrays.equals(new short[] { 1, 2, 3, 4 }, siList3.getIndicators()));
489		assertEquals(Parameter.Service_Indicators, siList3.getTag());
490	}
491
492	@Test
493	public void testTrafficModeType() throws IOException, XMLStreamException {
494		TrafficModeTypeImpl rc = (TrafficModeTypeImpl) factory.createTrafficModeType(1);
495		rc.write(out);
496
497		byte[] data = out.array();
498
499		TrafficModeTypeImpl rc2 = (TrafficModeTypeImpl) factory.createParameter(getTag(data), getValue(data));
500
501		assertEquals(1, rc2.getMode());
502
503		// Test Serialization
504		ByteArrayOutputStream output = new ByteArrayOutputStream();
505		XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
506		writer.setIndentation("\t");
507		writer.write(rc, "TrafficModeTypeImpl", TrafficModeTypeImpl.class);
508		writer.close();
509
510		System.out.println(output.toString());
511
512		ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
513		XMLObjectReader reader = XMLObjectReader.newInstance(input);
514		TrafficModeTypeImpl crrId3 = reader.read("TrafficModeTypeImpl", TrafficModeTypeImpl.class);
515
516		assertEquals(1, crrId3.getMode());
517		assertEquals(Parameter.Traffic_Mode_Type, crrId3.getTag());
518	}
519
520	@Test
521	public void testRoutingKey() throws IOException, XMLStreamException {
522		LocalRKIdentifier localRkId = factory.createLocalRKIdentifier(12);
523		RoutingContext rc = factory.createRoutingContext(new long[] { 1 });
524		TrafficModeType trafMdTy = factory.createTrafficModeType(1);
525		NetworkAppearance netApp = factory.createNetworkAppearance(1);
526		DestinationPointCode[] dpc = new DestinationPointCode[] { factory.createDestinationPointCode(123, (short) 0),
527				factory.createDestinationPointCode(456, (short) 1) };
528		ServiceIndicators[] servInds = new ServiceIndicators[] { factory.createServiceIndicators(new short[] { 1, 2 }),
529				factory.createServiceIndicators(new short[] { 1, 2 }) };
530		OPCList[] opcList = new OPCList[] { factory.createOPCList(new int[] { 1, 2, 3 }, new short[] { 0, 0, 0 }),
531				factory.createOPCList(new int[] { 4, 5, 6 }, new short[] { 0, 0, 0 }) };
532
533		RoutingKeyImpl routKey = (RoutingKeyImpl) factory.createRoutingKey(localRkId, rc, trafMdTy, netApp, dpc,
534				servInds, opcList);
535		routKey.write(out);
536
537		byte[] data = out.array();
538
539		RoutingKeyImpl routeKey2 = (RoutingKeyImpl) factory.createParameter(getTag(data), getValue(data));
540
541		assertEquals(localRkId.getId(), routeKey2.getLocalRKIdentifier().getId());
542		assertTrue(Arrays.equals(routKey.getRoutingContext().getRoutingContexts(), routeKey2.getRoutingContext()
543				.getRoutingContexts()));
544
545		// Test Serialization
546		ByteArrayOutputStream output = new ByteArrayOutputStream();
547		XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
548		writer.setIndentation("\t");
549		writer.write(routKey, "RoutingKeyImpl", RoutingKeyImpl.class);
550		writer.close();
551
552		System.out.println(output.toString());
553
554		ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
555		XMLObjectReader reader = XMLObjectReader.newInstance(input);
556		RoutingKeyImpl routeKey3 = reader.read("RoutingKeyImpl", RoutingKeyImpl.class);
557
558		assertEquals(localRkId.getId(), routeKey3.getLocalRKIdentifier().getId());
559		assertTrue(Arrays.equals(routKey.getRoutingContext().getRoutingContexts(), routeKey3.getRoutingContext()
560				.getRoutingContexts()));
561		assertEquals(Parameter.Routing_Key, routeKey3.getTag());
562	}
563
564	@Test
565	public void testRoutingKeySerialization1() throws IOException, XMLStreamException {
566		LocalRKIdentifier localRkId = factory.createLocalRKIdentifier(12);
567		RoutingContext rc = factory.createRoutingContext(new long[] { 1 });
568		TrafficModeType trafMdTy = factory.createTrafficModeType(1);
569		NetworkAppearance netApp = factory.createNetworkAppearance(1);
570		DestinationPointCode[] dpc = new DestinationPointCode[] { factory.createDestinationPointCode(123, (short) 0),
571				factory.createDestinationPointCode(456, (short) 1) };
572		ServiceIndicators[] servInds = new ServiceIndicators[] { factory.createServiceIndicators(new short[] { 1, 2 }),
573				factory.createServiceIndicators(new short[] { 1, 2 }) };
574		OPCList[] opcList = new OPCList[] { factory.createOPCList(new int[] { 1, 2, 3 }, new short[] { 0, 0, 0 }),
575				factory.createOPCList(new int[] { 4, 5, 6 }, new short[] { 0, 0, 0 }) };
576
577		RoutingKeyImpl routKey = (RoutingKeyImpl) factory.createRoutingKey(null, rc, trafMdTy, null, dpc, null, null);
578		routKey.write(out);
579
580		byte[] data = out.array();
581
582		RoutingKeyImpl routeKey2 = (RoutingKeyImpl) factory.createParameter(getTag(data), getValue(data));
583
584		assertNull(routeKey2.getLocalRKIdentifier());
585		assertTrue(Arrays.equals(routKey.getRoutingContext().getRoutingContexts(), routeKey2.getRoutingContext()
586				.getRoutingContexts()));
587
588		// Test Serialization
589		ByteArrayOutputStream output = new ByteArrayOutputStream();
590		XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
591		writer.setIndentation("\t");
592		writer.write(routKey, "RoutingKeyImpl", RoutingKeyImpl.class);
593		writer.close();
594
595		System.out.println(output.toString());
596
597		ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
598		XMLObjectReader reader = XMLObjectReader.newInstance(input);
599		RoutingKeyImpl routeKey3 = reader.read("RoutingKeyImpl", RoutingKeyImpl.class);
600
601		assertNull(routeKey3.getLocalRKIdentifier());
602		assertTrue(Arrays.equals(routKey.getRoutingContext().getRoutingContexts(), routeKey3.getRoutingContext()
603				.getRoutingContexts()));
604		assertEquals(Parameter.Routing_Key, routeKey3.getTag());
605	}
606
607	@Test
608	public void testRegistrationStatus() throws IOException {
609		RegistrationStatusImpl crrId = (RegistrationStatusImpl) factory.createRegistrationStatus(11);
610		crrId.write(out);
611
612		byte[] data = out.array();
613
614		RegistrationStatusImpl crrId2 = (RegistrationStatusImpl) factory.createParameter(getTag(data), getValue(data));
615
616		assertEquals(11, crrId2.getStatus());
617	}
618
619	@Test
620	public void testRegistrationResult() throws IOException {
621		LocalRKIdentifier localRkId = factory.createLocalRKIdentifier(12);
622		RoutingContext rc = factory.createRoutingContext(new long[] { 1 });
623		RegistrationStatus status = factory.createRegistrationStatus(0);
624
625		RegistrationResultImpl routKey = (RegistrationResultImpl) factory.createRegistrationResult(localRkId, status,
626				rc);
627		routKey.write(out);
628
629		byte[] data = out.array();
630
631		RegistrationResultImpl rc2 = (RegistrationResultImpl) factory.createParameter(getTag(data), getValue(data));
632
633		assertEquals(localRkId.getId(), rc2.getLocalRKIdentifier().getId());
634		assertTrue(Arrays.equals(routKey.getRoutingContext().getRoutingContexts(), rc2.getRoutingContext()
635				.getRoutingContexts()));
636		assertEquals(status.getStatus(), rc2.getRegistrationStatus().getStatus());
637	}
638
639	@Test
640	public void testDeregistrationStatus() throws IOException {
641		DeregistrationStatusImpl crrId = (DeregistrationStatusImpl) factory.createDeregistrationStatus(5);
642		crrId.write(out);
643
644		byte[] data = out.array();
645
646		DeregistrationStatusImpl crrId2 = (DeregistrationStatusImpl) factory.createParameter(getTag(data),
647				getValue(data));
648
649		assertEquals(5, crrId2.getStatus());
650	}
651
652	@Test
653	public void testDeregistrationResult() throws IOException {
654		RoutingContext rc = factory.createRoutingContext(new long[] { 1 });
655		DeregistrationStatus status = factory.createDeregistrationStatus(0);
656
657		DeregistrationResultImpl routKey = (DeregistrationResultImpl) factory.createDeregistrationResult(rc, status);
658		routKey.write(out);
659
660		byte[] data = out.array();
661
662		DeregistrationResultImpl rc2 = (DeregistrationResultImpl) factory.createParameter(getTag(data), getValue(data));
663
664		assertTrue(Arrays.equals(routKey.getRoutingContext().getRoutingContexts(), rc2.getRoutingContext()
665				.getRoutingContexts()));
666		assertEquals(status.getStatus(), rc2.getDeregistrationStatus().getStatus());
667	}
668
669	@Test
670	public void testStatus() throws IOException {
671
672		Status routKey = (Status) factory.createStatus(1, 4);
673		((StatusImpl) routKey).write(out);
674
675		byte[] data = out.array();
676
677		StatusImpl rc2 = (StatusImpl) factory.createParameter(getTag(data), getValue(data));
678
679		assertEquals(routKey.getType(), rc2.getType());
680		assertEquals(routKey.getInfo(), rc2.getInfo());
681	}
682}