/protocols/ss7/m3ua/impl/src/test/java/org/mobicents/protocols/ss7/m3ua/impl/message/MessageTest.java

http://mobicents.googlecode.com/ · Java · 823 lines · 573 code · 217 blank · 33 comment · 0 complexity · 7c86bb93d7053b49f311b1cb6e95e8e0 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.message;
  23. import org.testng.annotations.*;
  24. import static org.testng.Assert.*;
  25. import java.io.IOException;
  26. import java.nio.ByteBuffer;
  27. import java.util.Arrays;
  28. import org.mobicents.protocols.ss7.m3ua.impl.message.aspsm.ASPDownAckImpl;
  29. import org.mobicents.protocols.ss7.m3ua.impl.message.aspsm.ASPDownImpl;
  30. import org.mobicents.protocols.ss7.m3ua.impl.message.aspsm.ASPUpAckImpl;
  31. import org.mobicents.protocols.ss7.m3ua.impl.message.aspsm.ASPUpImpl;
  32. import org.mobicents.protocols.ss7.m3ua.impl.message.aspsm.HeartbeatAckImpl;
  33. import org.mobicents.protocols.ss7.m3ua.impl.message.aspsm.HeartbeatImpl;
  34. import org.mobicents.protocols.ss7.m3ua.impl.message.asptm.ASPActiveAckImpl;
  35. import org.mobicents.protocols.ss7.m3ua.impl.message.asptm.ASPActiveImpl;
  36. import org.mobicents.protocols.ss7.m3ua.impl.message.asptm.ASPInactiveAckImpl;
  37. import org.mobicents.protocols.ss7.m3ua.impl.message.asptm.ASPInactiveImpl;
  38. import org.mobicents.protocols.ss7.m3ua.impl.message.mgmt.ErrorImpl;
  39. import org.mobicents.protocols.ss7.m3ua.impl.message.mgmt.NotifyImpl;
  40. import org.mobicents.protocols.ss7.m3ua.impl.message.rkm.DeregistrationRequestImpl;
  41. import org.mobicents.protocols.ss7.m3ua.impl.message.rkm.DeregistrationResponseImpl;
  42. import org.mobicents.protocols.ss7.m3ua.impl.message.rkm.RegistrationRequestImpl;
  43. import org.mobicents.protocols.ss7.m3ua.impl.message.rkm.RegistrationResponseImpl;
  44. import org.mobicents.protocols.ss7.m3ua.impl.message.ssnm.DestinationAvailableImpl;
  45. import org.mobicents.protocols.ss7.m3ua.impl.message.ssnm.DestinationUPUnavailableImpl;
  46. import org.mobicents.protocols.ss7.m3ua.impl.message.ssnm.DestinationUnavailableImpl;
  47. import org.mobicents.protocols.ss7.m3ua.impl.message.ssnm.SignallingCongestionImpl;
  48. import org.mobicents.protocols.ss7.m3ua.impl.message.transfer.PayloadDataImpl;
  49. import org.mobicents.protocols.ss7.m3ua.impl.parameter.ParameterFactoryImpl;
  50. import org.mobicents.protocols.ss7.m3ua.impl.parameter.ProtocolDataImpl;
  51. import org.mobicents.protocols.ss7.m3ua.impl.parameter.RoutingKeyImpl;
  52. import org.mobicents.protocols.ss7.m3ua.message.MessageClass;
  53. import org.mobicents.protocols.ss7.m3ua.message.MessageType;
  54. import org.mobicents.protocols.ss7.m3ua.message.aspsm.Heartbeat;
  55. import org.mobicents.protocols.ss7.m3ua.message.aspsm.HeartbeatAck;
  56. import org.mobicents.protocols.ss7.m3ua.message.ssnm.SignallingCongestion;
  57. import org.mobicents.protocols.ss7.m3ua.parameter.ASPIdentifier;
  58. import org.mobicents.protocols.ss7.m3ua.parameter.AffectedPointCode;
  59. import org.mobicents.protocols.ss7.m3ua.parameter.ConcernedDPC;
  60. import org.mobicents.protocols.ss7.m3ua.parameter.CongestedIndication;
  61. import org.mobicents.protocols.ss7.m3ua.parameter.CongestedIndication.CongestionLevel;
  62. import org.mobicents.protocols.ss7.m3ua.parameter.DeregistrationResult;
  63. import org.mobicents.protocols.ss7.m3ua.parameter.DeregistrationStatus;
  64. import org.mobicents.protocols.ss7.m3ua.parameter.DestinationPointCode;
  65. import org.mobicents.protocols.ss7.m3ua.parameter.DiagnosticInfo;
  66. import org.mobicents.protocols.ss7.m3ua.parameter.ErrorCode;
  67. import org.mobicents.protocols.ss7.m3ua.parameter.HeartbeatData;
  68. import org.mobicents.protocols.ss7.m3ua.parameter.InfoString;
  69. import org.mobicents.protocols.ss7.m3ua.parameter.LocalRKIdentifier;
  70. import org.mobicents.protocols.ss7.m3ua.parameter.NetworkAppearance;
  71. import org.mobicents.protocols.ss7.m3ua.parameter.OPCList;
  72. import org.mobicents.protocols.ss7.m3ua.parameter.RegistrationResult;
  73. import org.mobicents.protocols.ss7.m3ua.parameter.RegistrationStatus;
  74. import org.mobicents.protocols.ss7.m3ua.parameter.RoutingContext;
  75. import org.mobicents.protocols.ss7.m3ua.parameter.ServiceIndicators;
  76. import org.mobicents.protocols.ss7.m3ua.parameter.Status;
  77. import org.mobicents.protocols.ss7.m3ua.parameter.TrafficModeType;
  78. import org.mobicents.protocols.ss7.m3ua.parameter.UserCause;
  79. /**
  80. *
  81. * @author kulikov
  82. */
  83. public class MessageTest {
  84. private ParameterFactoryImpl parmFactory = new ParameterFactoryImpl();
  85. private MessageFactoryImpl messageFactory = new MessageFactoryImpl();
  86. public MessageTest() {
  87. }
  88. @BeforeClass
  89. public static void setUpClass() throws Exception {
  90. }
  91. @AfterClass
  92. public static void tearDownClass() throws Exception {
  93. }
  94. @BeforeMethod
  95. public void setUp() {
  96. }
  97. @AfterMethod
  98. public void tearDown() {
  99. }
  100. /**
  101. * Test of getOpc method, of class ProtocolDataImpl.
  102. */
  103. @Test
  104. public void testPayloadData() throws IOException {
  105. ByteBuffer buffer = ByteBuffer.allocate(8192);
  106. PayloadDataImpl msg = (PayloadDataImpl) messageFactory.createMessage(
  107. MessageClass.TRANSFER_MESSAGES, MessageType.PAYLOAD);
  108. ProtocolDataImpl p1 = (ProtocolDataImpl) parmFactory
  109. .createProtocolData(1408, 14150, 1, 1, 0, 0, new byte[] { 1, 2,
  110. 3, 4 });
  111. msg.setData(p1);
  112. msg.encode(buffer);
  113. buffer.flip();
  114. PayloadDataImpl msg1 = (PayloadDataImpl) messageFactory
  115. .createMessage(buffer);
  116. ProtocolDataImpl p2 = (ProtocolDataImpl) msg1.getData();
  117. assertEquals(p1.getTag(), p2.getTag());
  118. assertEquals(p1.getOpc(), p2.getOpc());
  119. assertEquals(p1.getDpc(), p2.getDpc());
  120. assertEquals(p1.getSI(), p2.getSI());
  121. assertEquals(p1.getNI(), p2.getNI());
  122. assertEquals(p1.getMP(), p2.getMP());
  123. assertEquals(p1.getSLS(), p2.getSLS());
  124. }
  125. @Test
  126. public void testDestinationUnavailable() throws IOException {
  127. ByteBuffer buffer = ByteBuffer.allocate(8192);
  128. DestinationUnavailableImpl msg = (DestinationUnavailableImpl) messageFactory
  129. .createMessage(MessageClass.SIGNALING_NETWORK_MANAGEMENT,
  130. MessageType.DESTINATION_UNAVAILABLE);
  131. NetworkAppearance netApp = parmFactory.createNetworkAppearance(1233);
  132. msg.setNetworkAppearance(netApp);
  133. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 12 });
  134. msg.setRoutingContexts(rc);
  135. AffectedPointCode afpc = parmFactory.createAffectedPointCode(
  136. new int[] { 123 }, new short[] { 0 });
  137. msg.setAffectedPointCodes(afpc);
  138. msg.encode(buffer);
  139. buffer.flip();
  140. DestinationUnavailableImpl msg1 = (DestinationUnavailableImpl) messageFactory
  141. .createMessage(buffer);
  142. NetworkAppearance netApp1 = (NetworkAppearance) msg1
  143. .getNetworkAppearance();
  144. assertEquals(netApp.getNetApp(), netApp1.getNetApp());
  145. }
  146. @Test
  147. public void testDestinationAvailable() throws IOException {
  148. ByteBuffer buffer = ByteBuffer.allocate(8192);
  149. DestinationAvailableImpl msg = (DestinationAvailableImpl) messageFactory
  150. .createMessage(MessageClass.SIGNALING_NETWORK_MANAGEMENT,
  151. MessageType.DESTINATION_AVAILABLE);
  152. NetworkAppearance netApp = parmFactory.createNetworkAppearance(11233);
  153. msg.setNetworkAppearance(netApp);
  154. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 12,
  155. 13 });
  156. msg.setRoutingContexts(rc);
  157. AffectedPointCode afpc = parmFactory.createAffectedPointCode(new int[] {
  158. 123, 456 }, new short[] { 0, 1 });
  159. msg.setAffectedPointCodes(afpc);
  160. InfoString str = parmFactory.createInfoString("Some debug message");
  161. msg.setInfoString(str);
  162. msg.encode(buffer);
  163. buffer.flip();
  164. DestinationAvailableImpl msg1 = (DestinationAvailableImpl) messageFactory
  165. .createMessage(buffer);
  166. NetworkAppearance netApp1 = (NetworkAppearance) msg1
  167. .getNetworkAppearance();
  168. assertEquals(netApp.getNetApp(), netApp1.getNetApp());
  169. RoutingContext rc1 = msg1.getRoutingContexts();
  170. assertTrue(Arrays.equals(rc.getRoutingContexts(),
  171. rc1.getRoutingContexts()));
  172. }
  173. @Test
  174. public void testSignallingCongestion() throws IOException {
  175. ByteBuffer buffer = ByteBuffer.allocate(8192);
  176. SignallingCongestion msg = (SignallingCongestion) messageFactory
  177. .createMessage(MessageClass.SIGNALING_NETWORK_MANAGEMENT,
  178. MessageType.SIGNALING_CONGESTION);
  179. NetworkAppearance netApp = parmFactory.createNetworkAppearance(11233);
  180. msg.setNetworkAppearance(netApp);
  181. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 12,
  182. 13 });
  183. msg.setRoutingContexts(rc);
  184. AffectedPointCode afpc = parmFactory.createAffectedPointCode(new int[] {
  185. 123, 456 }, new short[] { 0, 1 });
  186. msg.setAffectedPointCodes(afpc);
  187. InfoString str = parmFactory.createInfoString("Some debug message");
  188. msg.setInfoString(str);
  189. ConcernedDPC pointCode = parmFactory.createConcernedDPC(234567);
  190. msg.setConcernedDPC(pointCode);
  191. CongestedIndication congInd = parmFactory
  192. .createCongestedIndication(CongestionLevel.LEVEL1);
  193. msg.setCongestedIndication(congInd);
  194. ((SignallingCongestionImpl) msg).encode(buffer);
  195. buffer.flip();
  196. SignallingCongestion msg1 = (SignallingCongestion) messageFactory
  197. .createMessage(buffer);
  198. NetworkAppearance netApp1 = (NetworkAppearance) msg1
  199. .getNetworkAppearance();
  200. assertEquals(netApp.getNetApp(), netApp1.getNetApp());
  201. RoutingContext rc1 = msg1.getRoutingContexts();
  202. assertTrue(Arrays.equals(rc.getRoutingContexts(),
  203. rc1.getRoutingContexts()));
  204. assertEquals(msg.getConcernedDPC().getPointCode(), msg1
  205. .getConcernedDPC().getPointCode());
  206. assertEquals(msg.getCongestedIndication().getCongestionLevel(), msg1
  207. .getCongestedIndication().getCongestionLevel());
  208. }
  209. @Test
  210. public void testDestinationUPUnavailable() throws IOException {
  211. ByteBuffer buffer = ByteBuffer.allocate(8192);
  212. DestinationUPUnavailableImpl msg = (DestinationUPUnavailableImpl) messageFactory
  213. .createMessage(MessageClass.SIGNALING_NETWORK_MANAGEMENT,
  214. MessageType.DESTINATION_USER_PART_UNAVAILABLE);
  215. NetworkAppearance netApp = parmFactory.createNetworkAppearance(1233);
  216. msg.setNetworkAppearance(netApp);
  217. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 12 });
  218. msg.setRoutingContext(rc);
  219. AffectedPointCode afpc = parmFactory.createAffectedPointCode(
  220. new int[] { 123 }, new short[] { 0 });
  221. msg.setAffectedPointCode(afpc);
  222. UserCause usrCau = parmFactory.createUserCause(5, 0);
  223. msg.setUserCause(usrCau);
  224. msg.encode(buffer);
  225. buffer.flip();
  226. DestinationUPUnavailableImpl msg1 = (DestinationUPUnavailableImpl) messageFactory
  227. .createMessage(buffer);
  228. NetworkAppearance netApp1 = (NetworkAppearance) msg1
  229. .getNetworkAppearance();
  230. assertEquals(netApp.getNetApp(), netApp1.getNetApp());
  231. assertEquals(msg.getUserCause().getUser(), msg1.getUserCause()
  232. .getUser());
  233. assertEquals(msg.getUserCause().getCause(), msg1.getUserCause()
  234. .getCause());
  235. }
  236. @Test
  237. public void testASPUp() throws IOException {
  238. ByteBuffer buffer = ByteBuffer.allocate(8192);
  239. ASPUpImpl msg = (ASPUpImpl) messageFactory.createMessage(
  240. MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP);
  241. ASPIdentifier aspId = parmFactory.createASPIdentifier(1234);
  242. msg.setASPIdentifier(aspId);
  243. msg.encode(buffer);
  244. buffer.flip();
  245. ASPUpImpl msg1 = (ASPUpImpl) messageFactory.createMessage(buffer);
  246. assertEquals(msg.getASPIdentifier().getAspId(), msg1.getASPIdentifier()
  247. .getAspId());
  248. }
  249. @Test
  250. public void testASPUpAck() throws IOException {
  251. ByteBuffer buffer = ByteBuffer.allocate(8192);
  252. ASPUpAckImpl msg = (ASPUpAckImpl) messageFactory.createMessage(
  253. MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP_ACK);
  254. ASPIdentifier aspId = parmFactory.createASPIdentifier(1234);
  255. msg.setASPIdentifier(aspId);
  256. InfoString infStr = parmFactory.createInfoString("Hello World");
  257. msg.setInfoString(infStr);
  258. msg.encode(buffer);
  259. buffer.flip();
  260. ASPUpAckImpl msg1 = (ASPUpAckImpl) messageFactory.createMessage(buffer);
  261. assertEquals(msg.getASPIdentifier().getAspId(), msg1.getASPIdentifier()
  262. .getAspId());
  263. assertEquals(msg.getInfoString().getString(), msg1.getInfoString()
  264. .getString());
  265. }
  266. @Test
  267. public void testASPDown() throws IOException {
  268. ByteBuffer buffer = ByteBuffer.allocate(8192);
  269. ASPDownImpl msg = (ASPDownImpl) messageFactory.createMessage(
  270. MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_DOWN);
  271. msg.encode(buffer);
  272. buffer.flip();
  273. ASPDownImpl msg1 = (ASPDownImpl) messageFactory.createMessage(buffer);
  274. assertNotNull(msg1);
  275. }
  276. @Test
  277. public void testASPDownAck() throws IOException {
  278. ByteBuffer buffer = ByteBuffer.allocate(8192);
  279. ASPDownAckImpl msg = (ASPDownAckImpl) messageFactory.createMessage(
  280. MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_DOWN_ACK);
  281. msg.encode(buffer);
  282. buffer.flip();
  283. ASPDownAckImpl msg1 = (ASPDownAckImpl) messageFactory
  284. .createMessage(buffer);
  285. assertNotNull(msg1);
  286. }
  287. @Test
  288. public void testRegistrationRequest() throws IOException {
  289. ByteBuffer buffer = ByteBuffer.allocate(8192);
  290. RegistrationRequestImpl msg = (RegistrationRequestImpl) messageFactory
  291. .createMessage(MessageClass.ROUTING_KEY_MANAGEMENT,
  292. MessageType.REG_REQUEST);
  293. ASPIdentifier aspId = parmFactory.createASPIdentifier(1234);
  294. LocalRKIdentifier localRkId = parmFactory.createLocalRKIdentifier(12);
  295. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
  296. TrafficModeType trafMdTy = parmFactory.createTrafficModeType(1);
  297. NetworkAppearance netApp = parmFactory.createNetworkAppearance(1);
  298. DestinationPointCode[] dpc = new DestinationPointCode[] {
  299. parmFactory.createDestinationPointCode(123, (short) 0),
  300. parmFactory.createDestinationPointCode(456, (short) 1) };
  301. ServiceIndicators[] servInds = new ServiceIndicators[] {
  302. parmFactory.createServiceIndicators(new short[] { 1, 2 }),
  303. parmFactory.createServiceIndicators(new short[] { 1, 2 }) };
  304. OPCList[] opcList = new OPCList[] {
  305. parmFactory.createOPCList(new int[] { 1, 2, 3 }, new short[] {
  306. 0, 0, 0 }),
  307. parmFactory.createOPCList(new int[] { 4, 5, 6 }, new short[] {
  308. 0, 0, 0 }) };
  309. RoutingKeyImpl routKey = (RoutingKeyImpl) parmFactory.createRoutingKey(
  310. localRkId, rc, trafMdTy, netApp, dpc, servInds, opcList);
  311. msg.setRoutingKey(routKey);
  312. msg.encode(buffer);
  313. buffer.flip();
  314. RegistrationRequestImpl msg1 = (RegistrationRequestImpl) messageFactory
  315. .createMessage(buffer);
  316. assertEquals(msg.getRoutingKey().getLocalRKIdentifier().getId(), msg1
  317. .getRoutingKey().getLocalRKIdentifier().getId());
  318. }
  319. @Test
  320. public void testRegistrationResponse() throws IOException {
  321. ByteBuffer buffer = ByteBuffer.allocate(8192);
  322. RegistrationResponseImpl msg = (RegistrationResponseImpl) messageFactory
  323. .createMessage(MessageClass.ROUTING_KEY_MANAGEMENT,
  324. MessageType.REG_RESPONSE);
  325. LocalRKIdentifier localRkId = parmFactory.createLocalRKIdentifier(12);
  326. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
  327. RegistrationStatus status = parmFactory.createRegistrationStatus(0);
  328. RegistrationResult result = (RegistrationResult) parmFactory
  329. .createRegistrationResult(localRkId, status, rc);
  330. msg.setRegistrationResult(result);
  331. msg.encode(buffer);
  332. buffer.flip();
  333. RegistrationResponseImpl msg1 = (RegistrationResponseImpl) messageFactory
  334. .createMessage(buffer);
  335. assertEquals(
  336. msg.getRegistrationResult().getLocalRKIdentifier().getId(),
  337. msg1.getRegistrationResult().getLocalRKIdentifier().getId());
  338. }
  339. @Test
  340. public void testDeregistrationRequest() throws IOException {
  341. ByteBuffer buffer = ByteBuffer.allocate(8192);
  342. DeregistrationRequestImpl msg = (DeregistrationRequestImpl) messageFactory
  343. .createMessage(MessageClass.ROUTING_KEY_MANAGEMENT,
  344. MessageType.DEREG_REQUEST);
  345. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
  346. msg.setRoutingContext(rc);
  347. msg.encode(buffer);
  348. buffer.flip();
  349. DeregistrationRequestImpl msg1 = (DeregistrationRequestImpl) messageFactory
  350. .createMessage(buffer);
  351. assertTrue(Arrays.equals(msg.getRoutingContext().getRoutingContexts(),
  352. msg1.getRoutingContext().getRoutingContexts()));
  353. }
  354. @Test
  355. public void testDeregistrationResponse() throws IOException {
  356. ByteBuffer buffer = ByteBuffer.allocate(8192);
  357. DeregistrationResponseImpl msg = (DeregistrationResponseImpl) messageFactory
  358. .createMessage(MessageClass.ROUTING_KEY_MANAGEMENT,
  359. MessageType.DEREG_RESPONSE);
  360. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
  361. DeregistrationStatus status = parmFactory.createDeregistrationStatus(0);
  362. DeregistrationResult result = (DeregistrationResult) parmFactory
  363. .createDeregistrationResult(rc, status);
  364. msg.setDeregistrationResult(result);
  365. msg.encode(buffer);
  366. buffer.flip();
  367. DeregistrationResponseImpl msg1 = (DeregistrationResponseImpl) messageFactory
  368. .createMessage(buffer);
  369. assertEquals(msg.getDeregistrationResult().getDeregistrationStatus()
  370. .getStatus(), msg1.getDeregistrationResult()
  371. .getDeregistrationStatus().getStatus());
  372. }
  373. @Test
  374. public void testASPActive() throws IOException {
  375. ByteBuffer buffer = ByteBuffer.allocate(8192);
  376. ASPActiveImpl msg = (ASPActiveImpl) messageFactory.createMessage(
  377. MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE);
  378. TrafficModeType mode = parmFactory.createTrafficModeType(1);
  379. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
  380. InfoString str = parmFactory.createInfoString("There it is");
  381. msg.setTrafficModeType(mode);
  382. msg.setRoutingContext(rc);
  383. msg.setInfoString(str);
  384. msg.encode(buffer);
  385. buffer.flip();
  386. ASPActiveImpl msg1 = (ASPActiveImpl) messageFactory
  387. .createMessage(buffer);
  388. assertEquals(msg.getTrafficModeType().getMode(), msg1
  389. .getTrafficModeType().getMode());
  390. assertEquals(msg.getInfoString().getString(), msg1.getInfoString()
  391. .getString());
  392. }
  393. @Test
  394. public void testASPActiveAck() throws IOException {
  395. ByteBuffer buffer = ByteBuffer.allocate(8192);
  396. ASPActiveAckImpl msg = (ASPActiveAckImpl) messageFactory.createMessage(
  397. MessageClass.ASP_TRAFFIC_MAINTENANCE,
  398. MessageType.ASP_ACTIVE_ACK);
  399. TrafficModeType mode = parmFactory.createTrafficModeType(1);
  400. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
  401. InfoString str = parmFactory.createInfoString("There it is");
  402. msg.setTrafficModeType(mode);
  403. msg.setRoutingContext(rc);
  404. msg.setInfoString(str);
  405. msg.encode(buffer);
  406. buffer.flip();
  407. ASPActiveAckImpl msg1 = (ASPActiveAckImpl) messageFactory
  408. .createMessage(buffer);
  409. assertEquals(msg.getTrafficModeType().getMode(), msg1
  410. .getTrafficModeType().getMode());
  411. assertEquals(msg.getInfoString().getString(), msg1.getInfoString()
  412. .getString());
  413. assertTrue(Arrays.equals(msg.getRoutingContext().getRoutingContexts(),
  414. msg1.getRoutingContext().getRoutingContexts()));
  415. }
  416. @Test
  417. public void testASPInactive() throws IOException {
  418. ByteBuffer buffer = ByteBuffer.allocate(8192);
  419. ASPInactiveImpl msg = (ASPInactiveImpl) messageFactory.createMessage(
  420. MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_INACTIVE);
  421. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
  422. InfoString str = parmFactory.createInfoString("There it is");
  423. msg.setRoutingContext(rc);
  424. msg.setInfoString(str);
  425. msg.encode(buffer);
  426. buffer.flip();
  427. ASPInactiveImpl msg1 = (ASPInactiveImpl) messageFactory
  428. .createMessage(buffer);
  429. assertEquals(msg.getInfoString().getString(), msg1.getInfoString()
  430. .getString());
  431. assertTrue(Arrays.equals(msg.getRoutingContext().getRoutingContexts(),
  432. msg1.getRoutingContext().getRoutingContexts()));
  433. }
  434. @Test
  435. public void testASPInactiveAck() throws IOException {
  436. ByteBuffer buffer = ByteBuffer.allocate(8192);
  437. ASPInactiveAckImpl msg = (ASPInactiveAckImpl) messageFactory
  438. .createMessage(MessageClass.ASP_TRAFFIC_MAINTENANCE,
  439. MessageType.ASP_INACTIVE_ACK);
  440. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
  441. InfoString str = parmFactory.createInfoString("There it is");
  442. msg.setRoutingContext(rc);
  443. msg.setInfoString(str);
  444. msg.encode(buffer);
  445. buffer.flip();
  446. ASPInactiveAckImpl msg1 = (ASPInactiveAckImpl) messageFactory
  447. .createMessage(buffer);
  448. assertEquals(msg.getInfoString().getString(), msg1.getInfoString()
  449. .getString());
  450. assertTrue(Arrays.equals(msg.getRoutingContext().getRoutingContexts(),
  451. msg1.getRoutingContext().getRoutingContexts()));
  452. }
  453. @Test
  454. public void testError() throws IOException {
  455. ByteBuffer buffer = ByteBuffer.allocate(8192);
  456. ErrorImpl msg = (ErrorImpl) messageFactory.createMessage(
  457. MessageClass.MANAGEMENT, MessageType.ERROR);
  458. ErrorCode code = parmFactory.createErrorCode(0x08);
  459. msg.setErrorCode(code);
  460. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
  461. msg.setRoutingContext(rc);
  462. AffectedPointCode affPc = parmFactory.createAffectedPointCode(
  463. new int[] { 1, 2 }, new short[] { 0, 0 });
  464. msg.setAffectedPointCode(affPc);
  465. NetworkAppearance netApp = parmFactory.createNetworkAppearance(12345l);
  466. msg.setNetworkAppearance(netApp);
  467. DiagnosticInfo str = parmFactory.createDiagnosticInfo("There it is");
  468. msg.setDiagnosticInfo(str);
  469. msg.encode(buffer);
  470. buffer.flip();
  471. ErrorImpl msg1 = (ErrorImpl) messageFactory.createMessage(buffer);
  472. assertEquals(msg.getErrorCode().getCode(), msg1.getErrorCode()
  473. .getCode());
  474. assertTrue(Arrays.equals(msg.getRoutingContext().getRoutingContexts(),
  475. msg1.getRoutingContext().getRoutingContexts()));
  476. assertTrue(Arrays.equals(msg.getAffectedPointCode().getPointCodes(),
  477. msg1.getAffectedPointCode().getPointCodes()));
  478. assertTrue(Arrays.equals(msg.getAffectedPointCode().getMasks(), msg1
  479. .getAffectedPointCode().getMasks()));
  480. assertEquals(msg.getNetworkAppearance().getNetApp(), msg1
  481. .getNetworkAppearance().getNetApp());
  482. assertEquals(msg.getDiagnosticInfo().getInfo(), msg1
  483. .getDiagnosticInfo().getInfo());
  484. }
  485. @Test
  486. public void testNotify() throws IOException {
  487. ByteBuffer buffer = ByteBuffer.allocate(8192);
  488. NotifyImpl msg = (NotifyImpl) messageFactory.createMessage(
  489. MessageClass.MANAGEMENT, MessageType.NOTIFY);
  490. Status status = parmFactory.createStatus(1, 4);
  491. msg.setStatus(status);
  492. ASPIdentifier aspId = parmFactory.createASPIdentifier(123);
  493. msg.setASPIdentifier(aspId);
  494. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
  495. msg.setRoutingContext(rc);
  496. msg.encode(buffer);
  497. buffer.flip();
  498. NotifyImpl msg1 = (NotifyImpl) messageFactory.createMessage(buffer);
  499. assertEquals(msg.getStatus().getType(), msg1.getStatus().getType());
  500. assertEquals(msg.getStatus().getInfo(), msg1.getStatus().getInfo());
  501. assertEquals(msg.getASPIdentifier().getAspId(), msg1.getASPIdentifier()
  502. .getAspId());
  503. assertTrue(Arrays.equals(msg.getRoutingContext().getRoutingContexts(),
  504. msg1.getRoutingContext().getRoutingContexts()));
  505. }
  506. @Test
  507. public void encodeTwoMessages() throws IOException {
  508. ByteBuffer buffer = ByteBuffer.allocate(8192);
  509. PayloadDataImpl payloadMsg = (PayloadDataImpl) messageFactory
  510. .createMessage(MessageClass.TRANSFER_MESSAGES,
  511. MessageType.PAYLOAD);
  512. ProtocolDataImpl p1 = (ProtocolDataImpl) parmFactory
  513. .createProtocolData(1408, 14150, 1, 1, 0, 0, new byte[] { 1, 2,
  514. 3, 4 });
  515. payloadMsg.setData(p1);
  516. payloadMsg.encode(buffer);
  517. DestinationUnavailableImpl dunaMsg = (DestinationUnavailableImpl) messageFactory
  518. .createMessage(MessageClass.SIGNALING_NETWORK_MANAGEMENT,
  519. MessageType.DESTINATION_UNAVAILABLE);
  520. NetworkAppearance netApp = parmFactory.createNetworkAppearance(1233);
  521. dunaMsg.setNetworkAppearance(netApp);
  522. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 12 });
  523. dunaMsg.setRoutingContexts(rc);
  524. AffectedPointCode afpc = parmFactory.createAffectedPointCode(
  525. new int[] { 123 }, new short[] { 0 });
  526. dunaMsg.setAffectedPointCodes(afpc);
  527. dunaMsg.encode(buffer);
  528. buffer.flip();
  529. // Paylod decode
  530. PayloadDataImpl payloadMsg1 = (PayloadDataImpl) messageFactory
  531. .createMessage(buffer);
  532. ProtocolDataImpl p2 = (ProtocolDataImpl) payloadMsg1.getData();
  533. assertEquals(p1.getTag(), p2.getTag());
  534. assertEquals(p1.getOpc(), p2.getOpc());
  535. assertEquals(p1.getDpc(), p2.getDpc());
  536. assertEquals(p1.getSI(), p2.getSI());
  537. assertEquals(p1.getNI(), p2.getNI());
  538. assertEquals(p1.getMP(), p2.getMP());
  539. assertEquals(p1.getSLS(), p2.getSLS());
  540. assertTrue(buffer.hasRemaining());
  541. DestinationUnavailableImpl dunaMsg1 = (DestinationUnavailableImpl) messageFactory
  542. .createMessage(buffer);
  543. NetworkAppearance netApp1 = (NetworkAppearance) dunaMsg1
  544. .getNetworkAppearance();
  545. assertEquals(netApp.getNetApp(), netApp1.getNetApp());
  546. }
  547. @Test
  548. public void testHeartBeat() throws IOException {
  549. // Test encode
  550. ByteBuffer buffer = ByteBuffer.allocate(8192);
  551. byte[] data = new byte[] { 0x01, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00,
  552. 0x1c, 0x00, 0x09, 0x00, 0x14, 0x00, 0x02, 0x00, 0x00, 0x00,
  553. 0x07, (byte) 0xaf, 0x3e, 0x75, 0x40, 0x03, 0x13, 0x05, 0x07,
  554. 0x11, 0x20 };
  555. byte[] heratbeatData = new byte[] { 0x00, 0x02, 0x00, 0x00, 0x00, 0x07,
  556. (byte) 0xaf, 0x3e, 0x75, 0x40, 0x03, 0x13, 0x05, 0x07, 0x11,
  557. 0x20 };
  558. Heartbeat heartbeat = (Heartbeat) messageFactory.createMessage(
  559. MessageClass.ASP_STATE_MAINTENANCE, MessageType.HEARTBEAT);
  560. HeartbeatData hrBtData = parmFactory.createHeartbeatData(heratbeatData);
  561. heartbeat.setHeartbeatData(hrBtData);
  562. ((HeartbeatImpl) heartbeat).encode(buffer);
  563. buffer.flip();
  564. byte[] rawData = new byte[buffer.limit()];
  565. buffer.get(rawData);
  566. assertTrue(Arrays.equals(data, rawData));
  567. // Test Decode
  568. M3UAMessageImpl m3uaMessageImpl = messageFactory
  569. .createSctpMessage(data);
  570. assertTrue((m3uaMessageImpl instanceof HeartbeatImpl));
  571. assertNotNull(((HeartbeatImpl) m3uaMessageImpl).getHeartbeatData());
  572. assertTrue(Arrays.equals(heratbeatData,
  573. ((HeartbeatImpl) m3uaMessageImpl).getHeartbeatData().getData()));
  574. }
  575. @Test
  576. public void testHeartBeatAck() throws IOException {
  577. // Test encode
  578. ByteBuffer buffer = ByteBuffer.allocate(8192);
  579. byte[] data = new byte[] { 0x01, 0x00, 0x03, 0x06, 0x00, 0x00, 0x00,
  580. 0x1c, 0x00, 0x09, 0x00, 0x14, 0x00, 0x02, 0x00, 0x00, 0x00,
  581. 0x07, (byte) 0xaf, 0x3e, 0x75, 0x40, 0x03, 0x13, 0x05, 0x07,
  582. 0x11, 0x20 };
  583. byte[] heratbeatAckData = new byte[] { 0x00, 0x02, 0x00, 0x00, 0x00,
  584. 0x07, (byte) 0xaf, 0x3e, 0x75, 0x40, 0x03, 0x13, 0x05, 0x07,
  585. 0x11, 0x20 };
  586. HeartbeatAck heartbeatAck = (HeartbeatAck) messageFactory
  587. .createMessage(MessageClass.ASP_STATE_MAINTENANCE,
  588. MessageType.HEARTBEAT_ACK);
  589. HeartbeatData hrBtData = parmFactory
  590. .createHeartbeatData(heratbeatAckData);
  591. heartbeatAck.setHeartbeatData(hrBtData);
  592. ((HeartbeatAckImpl) heartbeatAck).encode(buffer);
  593. buffer.flip();
  594. byte[] rawData = new byte[buffer.limit()];
  595. buffer.get(rawData);
  596. assertTrue(Arrays.equals(data, rawData));
  597. // Test Decode
  598. M3UAMessageImpl m3uaMessageImpl = messageFactory
  599. .createSctpMessage(data);
  600. assertTrue((m3uaMessageImpl instanceof HeartbeatAckImpl));
  601. assertNotNull(((HeartbeatAckImpl) m3uaMessageImpl).getHeartbeatData());
  602. assertTrue(Arrays.equals(heratbeatAckData,
  603. ((HeartbeatAckImpl) m3uaMessageImpl).getHeartbeatData()
  604. .getData()));
  605. }
  606. }