/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. package org.mobicents.protocols.ss7.m3ua.impl.parameter;
  23. import java.io.ByteArrayInputStream;
  24. import java.io.ByteArrayOutputStream;
  25. import java.io.IOException;
  26. import java.nio.ByteBuffer;
  27. import java.util.Arrays;
  28. import javolution.xml.XMLObjectReader;
  29. import javolution.xml.XMLObjectWriter;
  30. import javolution.xml.stream.XMLStreamException;
  31. import org.testng.annotations.*;
  32. import static org.testng.Assert.*;
  33. import org.mobicents.protocols.ss7.m3ua.parameter.CongestedIndication.CongestionLevel;
  34. import org.mobicents.protocols.ss7.m3ua.parameter.DeregistrationStatus;
  35. import org.mobicents.protocols.ss7.m3ua.parameter.DestinationPointCode;
  36. import org.mobicents.protocols.ss7.m3ua.parameter.LocalRKIdentifier;
  37. import org.mobicents.protocols.ss7.m3ua.parameter.NetworkAppearance;
  38. import org.mobicents.protocols.ss7.m3ua.parameter.OPCList;
  39. import org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
  40. import org.mobicents.protocols.ss7.m3ua.parameter.RegistrationStatus;
  41. import org.mobicents.protocols.ss7.m3ua.parameter.RoutingContext;
  42. import org.mobicents.protocols.ss7.m3ua.parameter.ServiceIndicators;
  43. import org.mobicents.protocols.ss7.m3ua.parameter.Status;
  44. import org.mobicents.protocols.ss7.m3ua.parameter.TrafficModeType;
  45. /**
  46. * @author amit bhayani
  47. * @author kulikov
  48. */
  49. public class ParameterTest {
  50. private ParameterFactoryImpl factory = new ParameterFactoryImpl();
  51. private ByteBuffer out = null;
  52. public ParameterTest() {
  53. }
  54. @BeforeClass
  55. public static void setUpClass() throws Exception {
  56. }
  57. @AfterClass
  58. public static void tearDownClass() throws Exception {
  59. }
  60. @BeforeMethod
  61. public void setUp() {
  62. out = ByteBuffer.allocate(8192);
  63. }
  64. @AfterMethod
  65. public void tearDown() {
  66. }
  67. private short getTag(byte[] data) {
  68. return (short) ((data[0] & 0xff) << 8 | (data[1] & 0xff));
  69. }
  70. private short getLen(byte[] data) {
  71. return (short) ((data[2] & 0xff) << 8 | (data[3] & 0xff));
  72. }
  73. private byte[] getValue(byte[] data) {
  74. // reduce 4 for Tag + length bytes
  75. short length = (short) (getLen(data) - 4);
  76. byte[] value = new byte[length];
  77. System.arraycopy(data, 4, value, 0, length);
  78. return value;
  79. }
  80. @Test
  81. public void testProtocolData() throws IOException {
  82. // Trace from wireshark
  83. byte[] userData = new byte[] { 0x09, (byte) 0x80, 0x03, 0x0c, 0x15, 0x09, 0x12, 0x05, 0x00, 0x12, 0x04, 0x55,
  84. 0x16, 0x09, (byte) 0x90, 0x09, 0x12, 0x07, 0x00, 0x12, 0x04, 0x55, 0x16, 0x09, 0x00, 0x5f, 0x62, 0x5d,
  85. 0x48, 0x04, 0x3a, (byte) 0x8c, 0x10, 0x04, 0x6b, 0x3f, 0x28, 0x3d, 0x06, 0x07, 0x00, 0x11, (byte) 0x86,
  86. 0x05, 0x01, 0x01, 0x01, (byte) 0xa0, 0x32, 0x60, 0x30, (byte) 0x80, 0x02, 0x07, (byte) 0x80,
  87. (byte) 0xa1, 0x09, 0x06, 0x07, 0x04, 0x00, 0x00, 0x01, 0x00, 0x13, 0x02, (byte) 0xbe, 0x1f, 0x28, 0x1d,
  88. 0x06, 0x07, 0x04, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, (byte) 0xa0, 0x12, (byte) 0xa0, 0x10,
  89. (byte) 0x80, 0x07, (byte) 0x91, 0x55, 0x16, 0x28, (byte) 0x81, 0x00, 0x70, (byte) 0x81, 0x05,
  90. (byte) 0x91, 0x55, 0x16, 0x09, 0x00, 0x6c, 0x14, (byte) 0xa1, 0x12, 0x02, 0x01, 0x00, 0x02, 0x01, 0x3b,
  91. 0x30, 0x0a, 0x04, 0x01, 0x0f, 0x04, 0x05, 0x2a, (byte) 0xd9, (byte) 0x8c, 0x36, 0x02 };
  92. byte[] protocolData = new byte[userData.length + 12];
  93. System.arraycopy(userData, 0, protocolData, 12, userData.length);
  94. protocolData[0] = 0x00;
  95. protocolData[1] = 0x00;
  96. protocolData[2] = 0x1e;
  97. protocolData[3] = (byte) 0xd4;
  98. protocolData[4] = 0x00;
  99. protocolData[5] = 0x00;
  100. protocolData[6] = 0x08;
  101. protocolData[7] = (byte) 0x98;
  102. protocolData[8] = 0x03;
  103. protocolData[9] = 0x03;
  104. protocolData[10] = 0x00;
  105. protocolData[11] = 0x0f;
  106. int si = 3;
  107. int mp = 0;
  108. int ni = 3;
  109. int dpc = 2200;
  110. int opc = 7892;
  111. int sls = 15;
  112. ProtocolDataImpl p1 = (ProtocolDataImpl) factory.createProtocolData(opc, dpc, si, ni, mp, sls, userData);
  113. assertTrue(Arrays.equals(protocolData, p1.getValue()));
  114. ProtocolDataImpl p2 = (ProtocolDataImpl) factory.createProtocolData(protocolData);
  115. assertEquals(p1.getTag(), p2.getTag());
  116. assertEquals(p1.getOpc(), p2.getOpc());
  117. assertEquals(p1.getDpc(), p2.getDpc());
  118. assertEquals(p2.getSI(), p2.getSI());
  119. assertEquals(p2.getNI(), p2.getNI());
  120. assertEquals(p2.getMP(), p2.getMP());
  121. assertEquals(p2.getSLS(), p2.getSLS());
  122. boolean isDataCorrect = Arrays.equals(p2.getData(), p2.getData());
  123. assertTrue(isDataCorrect, "Data mismatch");
  124. }
  125. /**
  126. * Test of getOpc method, of class ProtocolDataImpl.
  127. */
  128. @Test
  129. public void testProtocolData1() throws IOException {
  130. ProtocolDataImpl p1 = (ProtocolDataImpl) factory.createProtocolData(1408, 14150, 1, 1, 0, 1, new byte[] { 1, 2,
  131. 3, 4 });
  132. p1.write(out);
  133. byte[] data = out.array();
  134. ProtocolDataImpl p2 = (ProtocolDataImpl) factory.createParameter(getTag(data), getValue(data));
  135. assertEquals(p1.getTag(), p2.getTag());
  136. assertEquals(p1.getOpc(), p2.getOpc());
  137. assertEquals(p1.getDpc(), p2.getDpc());
  138. assertEquals(p1.getSI(), p2.getSI());
  139. assertEquals(p1.getNI(), p2.getNI());
  140. assertEquals(p1.getMP(), p2.getMP());
  141. assertEquals(p1.getSLS(), p2.getSLS());
  142. boolean isDataCorrect = Arrays.equals(p1.getData(), p2.getData());
  143. assertTrue(isDataCorrect, "Data mismatch");
  144. }
  145. @Test
  146. public void testNetworkAppearance() throws IOException, XMLStreamException {
  147. NetworkAppearanceImpl np = (NetworkAppearanceImpl) factory.createNetworkAppearance(123);
  148. np.write(out);
  149. byte[] data = out.array();
  150. NetworkAppearanceImpl np2 = (NetworkAppearanceImpl) factory.createParameter(getTag(data), getValue(data));
  151. assertEquals(123, (int) np2.getNetApp());
  152. // Test Serialization
  153. ByteArrayOutputStream output = new ByteArrayOutputStream();
  154. XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
  155. writer.setIndentation("\t");
  156. writer.write(np, "NetworkAppearanceImpl", NetworkAppearanceImpl.class);
  157. writer.close();
  158. System.out.println(output.toString());
  159. ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
  160. XMLObjectReader reader = XMLObjectReader.newInstance(input);
  161. NetworkAppearanceImpl np3 = reader.read("NetworkAppearanceImpl", NetworkAppearanceImpl.class);
  162. assertEquals(123, (int) np3.getNetApp());
  163. assertEquals(Parameter.Network_Appearance, np3.getTag());
  164. }
  165. @Test
  166. public void testRoutingContext() throws IOException, XMLStreamException {
  167. RoutingContextImpl rc = (RoutingContextImpl) factory.createRoutingContext(new long[] { 4294967295l });
  168. rc.write(out);
  169. byte[] data = out.array();
  170. RoutingContextImpl rc2 = (RoutingContextImpl) factory.createParameter(getTag(data), getValue(data));
  171. assertTrue(Arrays.equals(new long[] { 4294967295l }, rc2.getRoutingContexts()));
  172. // Test Serialization
  173. ByteArrayOutputStream output = new ByteArrayOutputStream();
  174. XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
  175. writer.setIndentation("\t");
  176. writer.write(rc, "RoutingContextImpl", RoutingContextImpl.class);
  177. writer.close();
  178. System.out.println(output.toString());
  179. ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
  180. XMLObjectReader reader = XMLObjectReader.newInstance(input);
  181. RoutingContextImpl rc3 = reader.read("RoutingContextImpl", RoutingContextImpl.class);
  182. assertTrue(Arrays.equals(new long[] { 4294967295l }, rc3.getRoutingContexts()));
  183. assertEquals(Parameter.Routing_Context, rc3.getTag());
  184. }
  185. @Test
  186. public void testRoutingContexts() throws IOException, XMLStreamException {
  187. RoutingContextImpl rc = (RoutingContextImpl) factory.createRoutingContext(new long[] { 123l, 4294967295l });
  188. rc.write(out);
  189. byte[] data = out.array();
  190. RoutingContextImpl rc2 = (RoutingContextImpl) factory.createParameter(getTag(data), getValue(data));
  191. assertTrue(Arrays.equals(new long[] { 123l, 4294967295l }, rc2.getRoutingContexts()));
  192. // Test Serialization
  193. ByteArrayOutputStream output = new ByteArrayOutputStream();
  194. XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
  195. writer.setIndentation("\t");
  196. writer.write(rc, "RoutingContextImpl", RoutingContextImpl.class);
  197. writer.close();
  198. System.out.println(output.toString());
  199. ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
  200. XMLObjectReader reader = XMLObjectReader.newInstance(input);
  201. RoutingContextImpl rc3 = reader.read("RoutingContextImpl", RoutingContextImpl.class);
  202. assertTrue(Arrays.equals(new long[] { 123l, 4294967295l }, rc3.getRoutingContexts()));
  203. assertEquals(Parameter.Routing_Context, rc3.getTag());
  204. }
  205. @Test
  206. public void testCorrelationId() throws IOException {
  207. CorrelationIdImpl crrId = (CorrelationIdImpl) factory.createCorrelationId(4294967295l);
  208. crrId.write(out);
  209. byte[] data = out.array();
  210. CorrelationIdImpl crrId2 = (CorrelationIdImpl) factory.createParameter(getTag(data), getValue(data));
  211. assertEquals(4294967295l, crrId2.getCorrelationId());
  212. }
  213. @Test
  214. public void testAffectedPointCode() throws IOException {
  215. AffectedPointCodeImpl affectedPc = (AffectedPointCodeImpl) factory.createAffectedPointCode(new int[] { 123 },
  216. new short[] { 0 });
  217. affectedPc.write(out);
  218. byte[] data = out.array();
  219. AffectedPointCodeImpl affectedPc2 = (AffectedPointCodeImpl) factory.createParameter(getTag(data),
  220. getValue(data));
  221. assertTrue(Arrays.equals(new int[] { 123 }, affectedPc2.getPointCodes()));
  222. assertTrue(Arrays.equals(new short[] { 0 }, affectedPc2.getMasks()));
  223. }
  224. @Test
  225. public void testAffectedPointCodes() throws IOException {
  226. AffectedPointCodeImpl affectedPc = (AffectedPointCodeImpl) factory.createAffectedPointCode(
  227. new int[] { 123, 456 }, new short[] { 0, 1 });
  228. affectedPc.write(out);
  229. byte[] data = out.array();
  230. AffectedPointCodeImpl affectedPc2 = (AffectedPointCodeImpl) factory.createParameter(getTag(data),
  231. getValue(data));
  232. assertTrue(Arrays.equals(new int[] { 123, 456 }, affectedPc2.getPointCodes()));
  233. assertTrue(Arrays.equals(new short[] { 0, 1 }, affectedPc2.getMasks()));
  234. }
  235. @Test
  236. public void testInfoString() throws IOException {
  237. InfoStringImpl infoStr = (InfoStringImpl) factory.createInfoString("Hello World");
  238. infoStr.write(out);
  239. byte[] data = out.array();
  240. InfoStringImpl infoStr2 = (InfoStringImpl) factory.createParameter(getTag(data), getValue(data));
  241. assertEquals("Hello World", infoStr2.getString());
  242. }
  243. @Test
  244. public void testConcernedDPC() throws IOException {
  245. ConcernedDPCImpl concernedDPC = (ConcernedDPCImpl) factory.createConcernedDPC(123);
  246. concernedDPC.write(out);
  247. byte[] data = out.array();
  248. ConcernedDPCImpl concernedDPC2 = (ConcernedDPCImpl) factory.createParameter(getTag(data), getValue(data));
  249. assertEquals(concernedDPC.getPointCode(), concernedDPC2.getPointCode());
  250. }
  251. @Test
  252. public void testCongestedIndication() throws IOException {
  253. CongestedIndicationImpl congIndImpl = (CongestedIndicationImpl) factory
  254. .createCongestedIndication(CongestionLevel.LEVEL2);
  255. congIndImpl.write(out);
  256. byte[] data = out.array();
  257. CongestedIndicationImpl congIndImpl2 = (CongestedIndicationImpl) factory.createParameter(getTag(data),
  258. getValue(data));
  259. assertEquals(congIndImpl.getCongestionLevel(), congIndImpl2.getCongestionLevel());
  260. }
  261. @Test
  262. public void testUserCause() throws IOException {
  263. UserCauseImpl usrCa = (UserCauseImpl) factory.createUserCause(5, 0);
  264. usrCa.write(out);
  265. byte[] data = out.array();
  266. UserCauseImpl usrCa2 = (UserCauseImpl) factory.createParameter(getTag(data), getValue(data));
  267. assertEquals(usrCa.getUser(), usrCa2.getUser());
  268. assertEquals(usrCa.getCause(), usrCa2.getCause());
  269. }
  270. @Test
  271. public void testASPIdentifier() throws IOException {
  272. ASPIdentifierImpl rc = (ASPIdentifierImpl) factory.createASPIdentifier(12234445);
  273. rc.write(out);
  274. byte[] data = out.array();
  275. ASPIdentifierImpl rc2 = (ASPIdentifierImpl) factory.createParameter(getTag(data), getValue(data));
  276. assertEquals(12234445l, rc2.getAspId());
  277. }
  278. @Test
  279. public void testDestinationPointCode() throws IOException, XMLStreamException {
  280. DestinationPointCodeImpl affectedPc = (DestinationPointCodeImpl) factory.createDestinationPointCode(123,
  281. (short) 0);
  282. affectedPc.write(out);
  283. byte[] data = out.array();
  284. DestinationPointCodeImpl affectedPc2 = (DestinationPointCodeImpl) factory.createParameter(getTag(data),
  285. getValue(data));
  286. assertEquals(123, affectedPc2.getPointCode());
  287. assertEquals((short) 0, affectedPc2.getMask());
  288. // Test Serialization
  289. ByteArrayOutputStream output = new ByteArrayOutputStream();
  290. XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
  291. writer.setIndentation("\t");
  292. writer.write(affectedPc, "DestinationPointCodeImpl", DestinationPointCodeImpl.class);
  293. writer.close();
  294. System.out.println(output.toString());
  295. ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
  296. XMLObjectReader reader = XMLObjectReader.newInstance(input);
  297. DestinationPointCodeImpl affectedPc3 = reader.read("DestinationPointCodeImpl", DestinationPointCodeImpl.class);
  298. assertEquals(123, affectedPc3.getPointCode());
  299. assertEquals((short) 0, affectedPc3.getMask());
  300. assertEquals(Parameter.Destination_Point_Code, affectedPc3.getTag());
  301. }
  302. @Test
  303. public void testLocalRKIdentifier() throws IOException, XMLStreamException {
  304. LocalRKIdentifierImpl crrId = (LocalRKIdentifierImpl) factory.createLocalRKIdentifier(4294967295l);
  305. crrId.write(out);
  306. byte[] data = out.array();
  307. LocalRKIdentifierImpl crrId2 = (LocalRKIdentifierImpl) factory.createParameter(getTag(data), getValue(data));
  308. assertEquals(4294967295l, crrId2.getId());
  309. // Test Serialization
  310. ByteArrayOutputStream output = new ByteArrayOutputStream();
  311. XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
  312. writer.setIndentation("\t");
  313. writer.write(crrId, "LocalRKIdentifierImpl", LocalRKIdentifierImpl.class);
  314. writer.close();
  315. System.out.println(output.toString());
  316. ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
  317. XMLObjectReader reader = XMLObjectReader.newInstance(input);
  318. LocalRKIdentifierImpl crrId3 = reader.read("LocalRKIdentifierImpl", LocalRKIdentifierImpl.class);
  319. assertEquals(4294967295l, crrId3.getId());
  320. assertEquals(Parameter.Local_Routing_Key_Identifier, crrId3.getTag());
  321. }
  322. @Test
  323. public void testOPCList() throws IOException, XMLStreamException {
  324. OPCListImpl opcList = (OPCListImpl) factory.createOPCList(new int[] { 123, 456 }, new short[] { 0, 1 });
  325. opcList.write(out);
  326. byte[] data = out.array();
  327. OPCListImpl opcList1 = (OPCListImpl) factory.createParameter(getTag(data), getValue(data));
  328. assertTrue(Arrays.equals(new int[] { 123, 456 }, opcList1.getPointCodes()));
  329. assertTrue(Arrays.equals(new short[] { 0, 1 }, opcList1.getMasks()));
  330. // Test Serialization
  331. ByteArrayOutputStream output = new ByteArrayOutputStream();
  332. XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
  333. writer.setIndentation("\t");
  334. writer.write(opcList, "OPCListImpl", OPCListImpl.class);
  335. writer.close();
  336. System.out.println(output.toString());
  337. ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
  338. XMLObjectReader reader = XMLObjectReader.newInstance(input);
  339. OPCListImpl opcList3 = reader.read("OPCListImpl", OPCListImpl.class);
  340. assertTrue(Arrays.equals(new int[] { 123, 456 }, opcList3.getPointCodes()));
  341. assertTrue(Arrays.equals(new short[] { 0, 1 }, opcList3.getMasks()));
  342. assertEquals(Parameter.Originating_Point_Code_List, opcList3.getTag());
  343. }
  344. @Test
  345. public void testServiceIndicators() throws IOException, XMLStreamException {
  346. ServiceIndicatorsImpl siList = (ServiceIndicatorsImpl) factory
  347. .createServiceIndicators(new short[] { 1, 2, 3, 4 });
  348. siList.write(out);
  349. byte[] data = out.array();
  350. ServiceIndicatorsImpl siList1 = (ServiceIndicatorsImpl) factory.createParameter(getTag(data), getValue(data));
  351. assertTrue(Arrays.equals(new short[] { 1, 2, 3, 4 }, siList1.getIndicators()));
  352. // Test Serialization
  353. ByteArrayOutputStream output = new ByteArrayOutputStream();
  354. XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
  355. writer.setIndentation("\t");
  356. writer.write(siList, "ServiceIndicatorsImpl", ServiceIndicatorsImpl.class);
  357. writer.close();
  358. System.out.println(output.toString());
  359. ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
  360. XMLObjectReader reader = XMLObjectReader.newInstance(input);
  361. ServiceIndicatorsImpl siList3 = reader.read("ServiceIndicatorsImpl", ServiceIndicatorsImpl.class);
  362. assertTrue(Arrays.equals(new short[] { 1, 2, 3, 4 }, siList3.getIndicators()));
  363. assertEquals(Parameter.Service_Indicators, siList3.getTag());
  364. }
  365. @Test
  366. public void testTrafficModeType() throws IOException, XMLStreamException {
  367. TrafficModeTypeImpl rc = (TrafficModeTypeImpl) factory.createTrafficModeType(1);
  368. rc.write(out);
  369. byte[] data = out.array();
  370. TrafficModeTypeImpl rc2 = (TrafficModeTypeImpl) factory.createParameter(getTag(data), getValue(data));
  371. assertEquals(1, rc2.getMode());
  372. // Test Serialization
  373. ByteArrayOutputStream output = new ByteArrayOutputStream();
  374. XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
  375. writer.setIndentation("\t");
  376. writer.write(rc, "TrafficModeTypeImpl", TrafficModeTypeImpl.class);
  377. writer.close();
  378. System.out.println(output.toString());
  379. ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
  380. XMLObjectReader reader = XMLObjectReader.newInstance(input);
  381. TrafficModeTypeImpl crrId3 = reader.read("TrafficModeTypeImpl", TrafficModeTypeImpl.class);
  382. assertEquals(1, crrId3.getMode());
  383. assertEquals(Parameter.Traffic_Mode_Type, crrId3.getTag());
  384. }
  385. @Test
  386. public void testRoutingKey() throws IOException, XMLStreamException {
  387. LocalRKIdentifier localRkId = factory.createLocalRKIdentifier(12);
  388. RoutingContext rc = factory.createRoutingContext(new long[] { 1 });
  389. TrafficModeType trafMdTy = factory.createTrafficModeType(1);
  390. NetworkAppearance netApp = factory.createNetworkAppearance(1);
  391. DestinationPointCode[] dpc = new DestinationPointCode[] { factory.createDestinationPointCode(123, (short) 0),
  392. factory.createDestinationPointCode(456, (short) 1) };
  393. ServiceIndicators[] servInds = new ServiceIndicators[] { factory.createServiceIndicators(new short[] { 1, 2 }),
  394. factory.createServiceIndicators(new short[] { 1, 2 }) };
  395. OPCList[] opcList = new OPCList[] { factory.createOPCList(new int[] { 1, 2, 3 }, new short[] { 0, 0, 0 }),
  396. factory.createOPCList(new int[] { 4, 5, 6 }, new short[] { 0, 0, 0 }) };
  397. RoutingKeyImpl routKey = (RoutingKeyImpl) factory.createRoutingKey(localRkId, rc, trafMdTy, netApp, dpc,
  398. servInds, opcList);
  399. routKey.write(out);
  400. byte[] data = out.array();
  401. RoutingKeyImpl routeKey2 = (RoutingKeyImpl) factory.createParameter(getTag(data), getValue(data));
  402. assertEquals(localRkId.getId(), routeKey2.getLocalRKIdentifier().getId());
  403. assertTrue(Arrays.equals(routKey.getRoutingContext().getRoutingContexts(), routeKey2.getRoutingContext()
  404. .getRoutingContexts()));
  405. // Test Serialization
  406. ByteArrayOutputStream output = new ByteArrayOutputStream();
  407. XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
  408. writer.setIndentation("\t");
  409. writer.write(routKey, "RoutingKeyImpl", RoutingKeyImpl.class);
  410. writer.close();
  411. System.out.println(output.toString());
  412. ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
  413. XMLObjectReader reader = XMLObjectReader.newInstance(input);
  414. RoutingKeyImpl routeKey3 = reader.read("RoutingKeyImpl", RoutingKeyImpl.class);
  415. assertEquals(localRkId.getId(), routeKey3.getLocalRKIdentifier().getId());
  416. assertTrue(Arrays.equals(routKey.getRoutingContext().getRoutingContexts(), routeKey3.getRoutingContext()
  417. .getRoutingContexts()));
  418. assertEquals(Parameter.Routing_Key, routeKey3.getTag());
  419. }
  420. @Test
  421. public void testRoutingKeySerialization1() throws IOException, XMLStreamException {
  422. LocalRKIdentifier localRkId = factory.createLocalRKIdentifier(12);
  423. RoutingContext rc = factory.createRoutingContext(new long[] { 1 });
  424. TrafficModeType trafMdTy = factory.createTrafficModeType(1);
  425. NetworkAppearance netApp = factory.createNetworkAppearance(1);
  426. DestinationPointCode[] dpc = new DestinationPointCode[] { factory.createDestinationPointCode(123, (short) 0),
  427. factory.createDestinationPointCode(456, (short) 1) };
  428. ServiceIndicators[] servInds = new ServiceIndicators[] { factory.createServiceIndicators(new short[] { 1, 2 }),
  429. factory.createServiceIndicators(new short[] { 1, 2 }) };
  430. OPCList[] opcList = new OPCList[] { factory.createOPCList(new int[] { 1, 2, 3 }, new short[] { 0, 0, 0 }),
  431. factory.createOPCList(new int[] { 4, 5, 6 }, new short[] { 0, 0, 0 }) };
  432. RoutingKeyImpl routKey = (RoutingKeyImpl) factory.createRoutingKey(null, rc, trafMdTy, null, dpc, null, null);
  433. routKey.write(out);
  434. byte[] data = out.array();
  435. RoutingKeyImpl routeKey2 = (RoutingKeyImpl) factory.createParameter(getTag(data), getValue(data));
  436. assertNull(routeKey2.getLocalRKIdentifier());
  437. assertTrue(Arrays.equals(routKey.getRoutingContext().getRoutingContexts(), routeKey2.getRoutingContext()
  438. .getRoutingContexts()));
  439. // Test Serialization
  440. ByteArrayOutputStream output = new ByteArrayOutputStream();
  441. XMLObjectWriter writer = XMLObjectWriter.newInstance(output);
  442. writer.setIndentation("\t");
  443. writer.write(routKey, "RoutingKeyImpl", RoutingKeyImpl.class);
  444. writer.close();
  445. System.out.println(output.toString());
  446. ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
  447. XMLObjectReader reader = XMLObjectReader.newInstance(input);
  448. RoutingKeyImpl routeKey3 = reader.read("RoutingKeyImpl", RoutingKeyImpl.class);
  449. assertNull(routeKey3.getLocalRKIdentifier());
  450. assertTrue(Arrays.equals(routKey.getRoutingContext().getRoutingContexts(), routeKey3.getRoutingContext()
  451. .getRoutingContexts()));
  452. assertEquals(Parameter.Routing_Key, routeKey3.getTag());
  453. }
  454. @Test
  455. public void testRegistrationStatus() throws IOException {
  456. RegistrationStatusImpl crrId = (RegistrationStatusImpl) factory.createRegistrationStatus(11);
  457. crrId.write(out);
  458. byte[] data = out.array();
  459. RegistrationStatusImpl crrId2 = (RegistrationStatusImpl) factory.createParameter(getTag(data), getValue(data));
  460. assertEquals(11, crrId2.getStatus());
  461. }
  462. @Test
  463. public void testRegistrationResult() throws IOException {
  464. LocalRKIdentifier localRkId = factory.createLocalRKIdentifier(12);
  465. RoutingContext rc = factory.createRoutingContext(new long[] { 1 });
  466. RegistrationStatus status = factory.createRegistrationStatus(0);
  467. RegistrationResultImpl routKey = (RegistrationResultImpl) factory.createRegistrationResult(localRkId, status,
  468. rc);
  469. routKey.write(out);
  470. byte[] data = out.array();
  471. RegistrationResultImpl rc2 = (RegistrationResultImpl) factory.createParameter(getTag(data), getValue(data));
  472. assertEquals(localRkId.getId(), rc2.getLocalRKIdentifier().getId());
  473. assertTrue(Arrays.equals(routKey.getRoutingContext().getRoutingContexts(), rc2.getRoutingContext()
  474. .getRoutingContexts()));
  475. assertEquals(status.getStatus(), rc2.getRegistrationStatus().getStatus());
  476. }
  477. @Test
  478. public void testDeregistrationStatus() throws IOException {
  479. DeregistrationStatusImpl crrId = (DeregistrationStatusImpl) factory.createDeregistrationStatus(5);
  480. crrId.write(out);
  481. byte[] data = out.array();
  482. DeregistrationStatusImpl crrId2 = (DeregistrationStatusImpl) factory.createParameter(getTag(data),
  483. getValue(data));
  484. assertEquals(5, crrId2.getStatus());
  485. }
  486. @Test
  487. public void testDeregistrationResult() throws IOException {
  488. RoutingContext rc = factory.createRoutingContext(new long[] { 1 });
  489. DeregistrationStatus status = factory.createDeregistrationStatus(0);
  490. DeregistrationResultImpl routKey = (DeregistrationResultImpl) factory.createDeregistrationResult(rc, status);
  491. routKey.write(out);
  492. byte[] data = out.array();
  493. DeregistrationResultImpl rc2 = (DeregistrationResultImpl) factory.createParameter(getTag(data), getValue(data));
  494. assertTrue(Arrays.equals(routKey.getRoutingContext().getRoutingContexts(), rc2.getRoutingContext()
  495. .getRoutingContexts()));
  496. assertEquals(status.getStatus(), rc2.getDeregistrationStatus().getStatus());
  497. }
  498. @Test
  499. public void testStatus() throws IOException {
  500. Status routKey = (Status) factory.createStatus(1, 4);
  501. ((StatusImpl) routKey).write(out);
  502. byte[] data = out.array();
  503. StatusImpl rc2 = (StatusImpl) factory.createParameter(getTag(data), getValue(data));
  504. assertEquals(routKey.getType(), rc2.getType());
  505. assertEquals(routKey.getInfo(), rc2.getInfo());
  506. }
  507. }