PageRenderTime 58ms CodeModel.GetById 2ms app.highlight 50ms RepoModel.GetById 1ms app.codeStats 1ms

/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
 23package org.mobicents.protocols.ss7.m3ua.impl.message;
 24import org.testng.annotations.*;
 25import static org.testng.Assert.*;
 26
 27
 28import java.io.IOException;
 29import java.nio.ByteBuffer;
 30import java.util.Arrays;
 31
 32
 33import org.mobicents.protocols.ss7.m3ua.impl.message.aspsm.ASPDownAckImpl;
 34import org.mobicents.protocols.ss7.m3ua.impl.message.aspsm.ASPDownImpl;
 35import org.mobicents.protocols.ss7.m3ua.impl.message.aspsm.ASPUpAckImpl;
 36import org.mobicents.protocols.ss7.m3ua.impl.message.aspsm.ASPUpImpl;
 37import org.mobicents.protocols.ss7.m3ua.impl.message.aspsm.HeartbeatAckImpl;
 38import org.mobicents.protocols.ss7.m3ua.impl.message.aspsm.HeartbeatImpl;
 39import org.mobicents.protocols.ss7.m3ua.impl.message.asptm.ASPActiveAckImpl;
 40import org.mobicents.protocols.ss7.m3ua.impl.message.asptm.ASPActiveImpl;
 41import org.mobicents.protocols.ss7.m3ua.impl.message.asptm.ASPInactiveAckImpl;
 42import org.mobicents.protocols.ss7.m3ua.impl.message.asptm.ASPInactiveImpl;
 43import org.mobicents.protocols.ss7.m3ua.impl.message.mgmt.ErrorImpl;
 44import org.mobicents.protocols.ss7.m3ua.impl.message.mgmt.NotifyImpl;
 45import org.mobicents.protocols.ss7.m3ua.impl.message.rkm.DeregistrationRequestImpl;
 46import org.mobicents.protocols.ss7.m3ua.impl.message.rkm.DeregistrationResponseImpl;
 47import org.mobicents.protocols.ss7.m3ua.impl.message.rkm.RegistrationRequestImpl;
 48import org.mobicents.protocols.ss7.m3ua.impl.message.rkm.RegistrationResponseImpl;
 49import org.mobicents.protocols.ss7.m3ua.impl.message.ssnm.DestinationAvailableImpl;
 50import org.mobicents.protocols.ss7.m3ua.impl.message.ssnm.DestinationUPUnavailableImpl;
 51import org.mobicents.protocols.ss7.m3ua.impl.message.ssnm.DestinationUnavailableImpl;
 52import org.mobicents.protocols.ss7.m3ua.impl.message.ssnm.SignallingCongestionImpl;
 53import org.mobicents.protocols.ss7.m3ua.impl.message.transfer.PayloadDataImpl;
 54import org.mobicents.protocols.ss7.m3ua.impl.parameter.ParameterFactoryImpl;
 55import org.mobicents.protocols.ss7.m3ua.impl.parameter.ProtocolDataImpl;
 56import org.mobicents.protocols.ss7.m3ua.impl.parameter.RoutingKeyImpl;
 57import org.mobicents.protocols.ss7.m3ua.message.MessageClass;
 58import org.mobicents.protocols.ss7.m3ua.message.MessageType;
 59import org.mobicents.protocols.ss7.m3ua.message.aspsm.Heartbeat;
 60import org.mobicents.protocols.ss7.m3ua.message.aspsm.HeartbeatAck;
 61import org.mobicents.protocols.ss7.m3ua.message.ssnm.SignallingCongestion;
 62import org.mobicents.protocols.ss7.m3ua.parameter.ASPIdentifier;
 63import org.mobicents.protocols.ss7.m3ua.parameter.AffectedPointCode;
 64import org.mobicents.protocols.ss7.m3ua.parameter.ConcernedDPC;
 65import org.mobicents.protocols.ss7.m3ua.parameter.CongestedIndication;
 66import org.mobicents.protocols.ss7.m3ua.parameter.CongestedIndication.CongestionLevel;
 67import org.mobicents.protocols.ss7.m3ua.parameter.DeregistrationResult;
 68import org.mobicents.protocols.ss7.m3ua.parameter.DeregistrationStatus;
 69import org.mobicents.protocols.ss7.m3ua.parameter.DestinationPointCode;
 70import org.mobicents.protocols.ss7.m3ua.parameter.DiagnosticInfo;
 71import org.mobicents.protocols.ss7.m3ua.parameter.ErrorCode;
 72import org.mobicents.protocols.ss7.m3ua.parameter.HeartbeatData;
 73import org.mobicents.protocols.ss7.m3ua.parameter.InfoString;
 74import org.mobicents.protocols.ss7.m3ua.parameter.LocalRKIdentifier;
 75import org.mobicents.protocols.ss7.m3ua.parameter.NetworkAppearance;
 76import org.mobicents.protocols.ss7.m3ua.parameter.OPCList;
 77import org.mobicents.protocols.ss7.m3ua.parameter.RegistrationResult;
 78import org.mobicents.protocols.ss7.m3ua.parameter.RegistrationStatus;
 79import org.mobicents.protocols.ss7.m3ua.parameter.RoutingContext;
 80import org.mobicents.protocols.ss7.m3ua.parameter.ServiceIndicators;
 81import org.mobicents.protocols.ss7.m3ua.parameter.Status;
 82import org.mobicents.protocols.ss7.m3ua.parameter.TrafficModeType;
 83import org.mobicents.protocols.ss7.m3ua.parameter.UserCause;
 84
 85/**
 86 * 
 87 * @author kulikov
 88 */
 89public class MessageTest {
 90
 91	private ParameterFactoryImpl parmFactory = new ParameterFactoryImpl();
 92	private MessageFactoryImpl messageFactory = new MessageFactoryImpl();
 93
 94	public MessageTest() {
 95	}
 96
 97	@BeforeClass
 98	public static void setUpClass() throws Exception {
 99	}
100
101	@AfterClass
102	public static void tearDownClass() throws Exception {
103	}
104
105	@BeforeMethod
106	public void setUp() {
107	}
108
109	@AfterMethod
110	public void tearDown() {
111	}
112
113	/**
114	 * Test of getOpc method, of class ProtocolDataImpl.
115	 */
116	@Test
117	public void testPayloadData() throws IOException {
118		ByteBuffer buffer = ByteBuffer.allocate(8192);
119
120		PayloadDataImpl msg = (PayloadDataImpl) messageFactory.createMessage(
121				MessageClass.TRANSFER_MESSAGES, MessageType.PAYLOAD);
122		ProtocolDataImpl p1 = (ProtocolDataImpl) parmFactory
123				.createProtocolData(1408, 14150, 1, 1, 0, 0, new byte[] { 1, 2,
124						3, 4 });
125		msg.setData(p1);
126		msg.encode(buffer);
127
128		buffer.flip();
129
130		PayloadDataImpl msg1 = (PayloadDataImpl) messageFactory
131				.createMessage(buffer);
132
133		ProtocolDataImpl p2 = (ProtocolDataImpl) msg1.getData();
134
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	}
143
144	@Test
145	public void testDestinationUnavailable() throws IOException {
146		ByteBuffer buffer = ByteBuffer.allocate(8192);
147
148		DestinationUnavailableImpl msg = (DestinationUnavailableImpl) messageFactory
149				.createMessage(MessageClass.SIGNALING_NETWORK_MANAGEMENT,
150						MessageType.DESTINATION_UNAVAILABLE);
151		NetworkAppearance netApp = parmFactory.createNetworkAppearance(1233);
152		msg.setNetworkAppearance(netApp);
153
154		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 12 });
155		msg.setRoutingContexts(rc);
156
157		AffectedPointCode afpc = parmFactory.createAffectedPointCode(
158				new int[] { 123 }, new short[] { 0 });
159		msg.setAffectedPointCodes(afpc);
160
161		msg.encode(buffer);
162
163		buffer.flip();
164
165		DestinationUnavailableImpl msg1 = (DestinationUnavailableImpl) messageFactory
166				.createMessage(buffer);
167
168		NetworkAppearance netApp1 = (NetworkAppearance) msg1
169				.getNetworkAppearance();
170
171		assertEquals(netApp.getNetApp(), netApp1.getNetApp());
172	}
173
174	@Test
175	public void testDestinationAvailable() throws IOException {
176		ByteBuffer buffer = ByteBuffer.allocate(8192);
177
178		DestinationAvailableImpl msg = (DestinationAvailableImpl) messageFactory
179				.createMessage(MessageClass.SIGNALING_NETWORK_MANAGEMENT,
180						MessageType.DESTINATION_AVAILABLE);
181		NetworkAppearance netApp = parmFactory.createNetworkAppearance(11233);
182		msg.setNetworkAppearance(netApp);
183
184		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 12,
185				13 });
186		msg.setRoutingContexts(rc);
187
188		AffectedPointCode afpc = parmFactory.createAffectedPointCode(new int[] {
189				123, 456 }, new short[] { 0, 1 });
190		msg.setAffectedPointCodes(afpc);
191
192		InfoString str = parmFactory.createInfoString("Some debug message");
193		msg.setInfoString(str);
194
195		msg.encode(buffer);
196
197		buffer.flip();
198
199		DestinationAvailableImpl msg1 = (DestinationAvailableImpl) messageFactory
200				.createMessage(buffer);
201
202		NetworkAppearance netApp1 = (NetworkAppearance) msg1
203				.getNetworkAppearance();
204
205		assertEquals(netApp.getNetApp(), netApp1.getNetApp());
206
207		RoutingContext rc1 = msg1.getRoutingContexts();
208
209		assertTrue(Arrays.equals(rc.getRoutingContexts(),
210				rc1.getRoutingContexts()));
211	}
212
213	@Test
214	public void testSignallingCongestion() throws IOException {
215		ByteBuffer buffer = ByteBuffer.allocate(8192);
216
217		SignallingCongestion msg = (SignallingCongestion) messageFactory
218				.createMessage(MessageClass.SIGNALING_NETWORK_MANAGEMENT,
219						MessageType.SIGNALING_CONGESTION);
220		NetworkAppearance netApp = parmFactory.createNetworkAppearance(11233);
221		msg.setNetworkAppearance(netApp);
222
223		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 12,
224				13 });
225		msg.setRoutingContexts(rc);
226
227		AffectedPointCode afpc = parmFactory.createAffectedPointCode(new int[] {
228				123, 456 }, new short[] { 0, 1 });
229		msg.setAffectedPointCodes(afpc);
230
231		InfoString str = parmFactory.createInfoString("Some debug message");
232		msg.setInfoString(str);
233
234		ConcernedDPC pointCode = parmFactory.createConcernedDPC(234567);
235		msg.setConcernedDPC(pointCode);
236
237		CongestedIndication congInd = parmFactory
238				.createCongestedIndication(CongestionLevel.LEVEL1);
239		msg.setCongestedIndication(congInd);
240
241		((SignallingCongestionImpl) msg).encode(buffer);
242
243		buffer.flip();
244
245		SignallingCongestion msg1 = (SignallingCongestion) messageFactory
246				.createMessage(buffer);
247
248		NetworkAppearance netApp1 = (NetworkAppearance) msg1
249				.getNetworkAppearance();
250
251		assertEquals(netApp.getNetApp(), netApp1.getNetApp());
252
253		RoutingContext rc1 = msg1.getRoutingContexts();
254
255		assertTrue(Arrays.equals(rc.getRoutingContexts(),
256				rc1.getRoutingContexts()));
257
258		assertEquals(msg.getConcernedDPC().getPointCode(), msg1
259				.getConcernedDPC().getPointCode());
260		assertEquals(msg.getCongestedIndication().getCongestionLevel(), msg1
261				.getCongestedIndication().getCongestionLevel());
262	}
263
264	@Test
265	public void testDestinationUPUnavailable() throws IOException {
266		ByteBuffer buffer = ByteBuffer.allocate(8192);
267
268		DestinationUPUnavailableImpl msg = (DestinationUPUnavailableImpl) messageFactory
269				.createMessage(MessageClass.SIGNALING_NETWORK_MANAGEMENT,
270						MessageType.DESTINATION_USER_PART_UNAVAILABLE);
271		NetworkAppearance netApp = parmFactory.createNetworkAppearance(1233);
272		msg.setNetworkAppearance(netApp);
273
274		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 12 });
275		msg.setRoutingContext(rc);
276
277		AffectedPointCode afpc = parmFactory.createAffectedPointCode(
278				new int[] { 123 }, new short[] { 0 });
279		msg.setAffectedPointCode(afpc);
280
281		UserCause usrCau = parmFactory.createUserCause(5, 0);
282		msg.setUserCause(usrCau);
283
284		msg.encode(buffer);
285
286		buffer.flip();
287
288		DestinationUPUnavailableImpl msg1 = (DestinationUPUnavailableImpl) messageFactory
289				.createMessage(buffer);
290
291		NetworkAppearance netApp1 = (NetworkAppearance) msg1
292				.getNetworkAppearance();
293
294		assertEquals(netApp.getNetApp(), netApp1.getNetApp());
295
296		assertEquals(msg.getUserCause().getUser(), msg1.getUserCause()
297				.getUser());
298		assertEquals(msg.getUserCause().getCause(), msg1.getUserCause()
299				.getCause());
300	}
301
302	@Test
303	public void testASPUp() throws IOException {
304		ByteBuffer buffer = ByteBuffer.allocate(8192);
305
306		ASPUpImpl msg = (ASPUpImpl) messageFactory.createMessage(
307				MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP);
308		ASPIdentifier aspId = parmFactory.createASPIdentifier(1234);
309		msg.setASPIdentifier(aspId);
310
311		msg.encode(buffer);
312
313		buffer.flip();
314
315		ASPUpImpl msg1 = (ASPUpImpl) messageFactory.createMessage(buffer);
316
317		assertEquals(msg.getASPIdentifier().getAspId(), msg1.getASPIdentifier()
318				.getAspId());
319	}
320
321	@Test
322	public void testASPUpAck() throws IOException {
323		ByteBuffer buffer = ByteBuffer.allocate(8192);
324
325		ASPUpAckImpl msg = (ASPUpAckImpl) messageFactory.createMessage(
326				MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP_ACK);
327		ASPIdentifier aspId = parmFactory.createASPIdentifier(1234);
328		msg.setASPIdentifier(aspId);
329
330		InfoString infStr = parmFactory.createInfoString("Hello World");
331		msg.setInfoString(infStr);
332
333		msg.encode(buffer);
334
335		buffer.flip();
336
337		ASPUpAckImpl msg1 = (ASPUpAckImpl) messageFactory.createMessage(buffer);
338
339		assertEquals(msg.getASPIdentifier().getAspId(), msg1.getASPIdentifier()
340				.getAspId());
341		assertEquals(msg.getInfoString().getString(), msg1.getInfoString()
342				.getString());
343	}
344
345	@Test
346	public void testASPDown() throws IOException {
347		ByteBuffer buffer = ByteBuffer.allocate(8192);
348
349		ASPDownImpl msg = (ASPDownImpl) messageFactory.createMessage(
350				MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_DOWN);
351
352		msg.encode(buffer);
353
354		buffer.flip();
355
356		ASPDownImpl msg1 = (ASPDownImpl) messageFactory.createMessage(buffer);
357
358		assertNotNull(msg1);
359	}
360
361	@Test
362	public void testASPDownAck() throws IOException {
363		ByteBuffer buffer = ByteBuffer.allocate(8192);
364
365		ASPDownAckImpl msg = (ASPDownAckImpl) messageFactory.createMessage(
366				MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_DOWN_ACK);
367
368		msg.encode(buffer);
369
370		buffer.flip();
371
372		ASPDownAckImpl msg1 = (ASPDownAckImpl) messageFactory
373				.createMessage(buffer);
374
375		assertNotNull(msg1);
376	}
377
378	@Test
379	public void testRegistrationRequest() throws IOException {
380		ByteBuffer buffer = ByteBuffer.allocate(8192);
381
382		RegistrationRequestImpl msg = (RegistrationRequestImpl) messageFactory
383				.createMessage(MessageClass.ROUTING_KEY_MANAGEMENT,
384						MessageType.REG_REQUEST);
385		ASPIdentifier aspId = parmFactory.createASPIdentifier(1234);
386
387		LocalRKIdentifier localRkId = parmFactory.createLocalRKIdentifier(12);
388		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
389		TrafficModeType trafMdTy = parmFactory.createTrafficModeType(1);
390		NetworkAppearance netApp = parmFactory.createNetworkAppearance(1);
391		DestinationPointCode[] dpc = new DestinationPointCode[] {
392				parmFactory.createDestinationPointCode(123, (short) 0),
393				parmFactory.createDestinationPointCode(456, (short) 1) };
394		ServiceIndicators[] servInds = new ServiceIndicators[] {
395				parmFactory.createServiceIndicators(new short[] { 1, 2 }),
396				parmFactory.createServiceIndicators(new short[] { 1, 2 }) };
397		OPCList[] opcList = new OPCList[] {
398				parmFactory.createOPCList(new int[] { 1, 2, 3 }, new short[] {
399						0, 0, 0 }),
400				parmFactory.createOPCList(new int[] { 4, 5, 6 }, new short[] {
401						0, 0, 0 }) };
402
403		RoutingKeyImpl routKey = (RoutingKeyImpl) parmFactory.createRoutingKey(
404				localRkId, rc, trafMdTy, netApp, dpc, servInds, opcList);
405
406		msg.setRoutingKey(routKey);
407
408		msg.encode(buffer);
409
410		buffer.flip();
411
412		RegistrationRequestImpl msg1 = (RegistrationRequestImpl) messageFactory
413				.createMessage(buffer);
414
415		assertEquals(msg.getRoutingKey().getLocalRKIdentifier().getId(), msg1
416				.getRoutingKey().getLocalRKIdentifier().getId());
417	}
418
419	@Test
420	public void testRegistrationResponse() throws IOException {
421		ByteBuffer buffer = ByteBuffer.allocate(8192);
422
423		RegistrationResponseImpl msg = (RegistrationResponseImpl) messageFactory
424				.createMessage(MessageClass.ROUTING_KEY_MANAGEMENT,
425						MessageType.REG_RESPONSE);
426
427		LocalRKIdentifier localRkId = parmFactory.createLocalRKIdentifier(12);
428		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
429		RegistrationStatus status = parmFactory.createRegistrationStatus(0);
430
431		RegistrationResult result = (RegistrationResult) parmFactory
432				.createRegistrationResult(localRkId, status, rc);
433
434		msg.setRegistrationResult(result);
435
436		msg.encode(buffer);
437
438		buffer.flip();
439
440		RegistrationResponseImpl msg1 = (RegistrationResponseImpl) messageFactory
441				.createMessage(buffer);
442
443		assertEquals(
444				msg.getRegistrationResult().getLocalRKIdentifier().getId(),
445				msg1.getRegistrationResult().getLocalRKIdentifier().getId());
446	}
447
448	@Test
449	public void testDeregistrationRequest() throws IOException {
450		ByteBuffer buffer = ByteBuffer.allocate(8192);
451
452		DeregistrationRequestImpl msg = (DeregistrationRequestImpl) messageFactory
453				.createMessage(MessageClass.ROUTING_KEY_MANAGEMENT,
454						MessageType.DEREG_REQUEST);
455
456		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
457
458		msg.setRoutingContext(rc);
459
460		msg.encode(buffer);
461
462		buffer.flip();
463
464		DeregistrationRequestImpl msg1 = (DeregistrationRequestImpl) messageFactory
465				.createMessage(buffer);
466
467		assertTrue(Arrays.equals(msg.getRoutingContext().getRoutingContexts(),
468				msg1.getRoutingContext().getRoutingContexts()));
469	}
470
471	@Test
472	public void testDeregistrationResponse() throws IOException {
473		ByteBuffer buffer = ByteBuffer.allocate(8192);
474
475		DeregistrationResponseImpl msg = (DeregistrationResponseImpl) messageFactory
476				.createMessage(MessageClass.ROUTING_KEY_MANAGEMENT,
477						MessageType.DEREG_RESPONSE);
478
479		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
480		DeregistrationStatus status = parmFactory.createDeregistrationStatus(0);
481
482		DeregistrationResult result = (DeregistrationResult) parmFactory
483				.createDeregistrationResult(rc, status);
484
485		msg.setDeregistrationResult(result);
486
487		msg.encode(buffer);
488
489		buffer.flip();
490
491		DeregistrationResponseImpl msg1 = (DeregistrationResponseImpl) messageFactory
492				.createMessage(buffer);
493
494		assertEquals(msg.getDeregistrationResult().getDeregistrationStatus()
495				.getStatus(), msg1.getDeregistrationResult()
496				.getDeregistrationStatus().getStatus());
497	}
498
499	@Test
500	public void testASPActive() throws IOException {
501		ByteBuffer buffer = ByteBuffer.allocate(8192);
502
503		ASPActiveImpl msg = (ASPActiveImpl) messageFactory.createMessage(
504				MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE);
505
506		TrafficModeType mode = parmFactory.createTrafficModeType(1);
507		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
508		InfoString str = parmFactory.createInfoString("There it is");
509		msg.setTrafficModeType(mode);
510		msg.setRoutingContext(rc);
511		msg.setInfoString(str);
512
513		msg.encode(buffer);
514
515		buffer.flip();
516
517		ASPActiveImpl msg1 = (ASPActiveImpl) messageFactory
518				.createMessage(buffer);
519
520		assertEquals(msg.getTrafficModeType().getMode(), msg1
521				.getTrafficModeType().getMode());
522		assertEquals(msg.getInfoString().getString(), msg1.getInfoString()
523				.getString());
524	}
525
526	@Test
527	public void testASPActiveAck() throws IOException {
528		ByteBuffer buffer = ByteBuffer.allocate(8192);
529
530		ASPActiveAckImpl msg = (ASPActiveAckImpl) messageFactory.createMessage(
531				MessageClass.ASP_TRAFFIC_MAINTENANCE,
532				MessageType.ASP_ACTIVE_ACK);
533
534		TrafficModeType mode = parmFactory.createTrafficModeType(1);
535		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
536		InfoString str = parmFactory.createInfoString("There it is");
537		msg.setTrafficModeType(mode);
538		msg.setRoutingContext(rc);
539		msg.setInfoString(str);
540
541		msg.encode(buffer);
542
543		buffer.flip();
544
545		ASPActiveAckImpl msg1 = (ASPActiveAckImpl) messageFactory
546				.createMessage(buffer);
547
548		assertEquals(msg.getTrafficModeType().getMode(), msg1
549				.getTrafficModeType().getMode());
550		assertEquals(msg.getInfoString().getString(), msg1.getInfoString()
551				.getString());
552		assertTrue(Arrays.equals(msg.getRoutingContext().getRoutingContexts(),
553				msg1.getRoutingContext().getRoutingContexts()));
554	}
555
556	@Test
557	public void testASPInactive() throws IOException {
558		ByteBuffer buffer = ByteBuffer.allocate(8192);
559
560		ASPInactiveImpl msg = (ASPInactiveImpl) messageFactory.createMessage(
561				MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_INACTIVE);
562
563		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
564		InfoString str = parmFactory.createInfoString("There it is");
565		msg.setRoutingContext(rc);
566		msg.setInfoString(str);
567
568		msg.encode(buffer);
569
570		buffer.flip();
571
572		ASPInactiveImpl msg1 = (ASPInactiveImpl) messageFactory
573				.createMessage(buffer);
574
575		assertEquals(msg.getInfoString().getString(), msg1.getInfoString()
576				.getString());
577
578		assertTrue(Arrays.equals(msg.getRoutingContext().getRoutingContexts(),
579				msg1.getRoutingContext().getRoutingContexts()));
580	}
581
582	@Test
583	public void testASPInactiveAck() throws IOException {
584		ByteBuffer buffer = ByteBuffer.allocate(8192);
585
586		ASPInactiveAckImpl msg = (ASPInactiveAckImpl) messageFactory
587				.createMessage(MessageClass.ASP_TRAFFIC_MAINTENANCE,
588						MessageType.ASP_INACTIVE_ACK);
589
590		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
591		InfoString str = parmFactory.createInfoString("There it is");
592		msg.setRoutingContext(rc);
593		msg.setInfoString(str);
594
595		msg.encode(buffer);
596
597		buffer.flip();
598
599		ASPInactiveAckImpl msg1 = (ASPInactiveAckImpl) messageFactory
600				.createMessage(buffer);
601
602		assertEquals(msg.getInfoString().getString(), msg1.getInfoString()
603				.getString());
604		assertTrue(Arrays.equals(msg.getRoutingContext().getRoutingContexts(),
605				msg1.getRoutingContext().getRoutingContexts()));
606	}
607
608	@Test
609	public void testError() throws IOException {
610		ByteBuffer buffer = ByteBuffer.allocate(8192);
611
612		ErrorImpl msg = (ErrorImpl) messageFactory.createMessage(
613				MessageClass.MANAGEMENT, MessageType.ERROR);
614
615		ErrorCode code = parmFactory.createErrorCode(0x08);
616		msg.setErrorCode(code);
617
618		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
619		msg.setRoutingContext(rc);
620
621		AffectedPointCode affPc = parmFactory.createAffectedPointCode(
622				new int[] { 1, 2 }, new short[] { 0, 0 });
623		msg.setAffectedPointCode(affPc);
624
625		NetworkAppearance netApp = parmFactory.createNetworkAppearance(12345l);
626		msg.setNetworkAppearance(netApp);
627
628		DiagnosticInfo str = parmFactory.createDiagnosticInfo("There it is");
629		msg.setDiagnosticInfo(str);
630
631		msg.encode(buffer);
632
633		buffer.flip();
634
635		ErrorImpl msg1 = (ErrorImpl) messageFactory.createMessage(buffer);
636
637		assertEquals(msg.getErrorCode().getCode(), msg1.getErrorCode()
638				.getCode());
639		assertTrue(Arrays.equals(msg.getRoutingContext().getRoutingContexts(),
640				msg1.getRoutingContext().getRoutingContexts()));
641		assertTrue(Arrays.equals(msg.getAffectedPointCode().getPointCodes(),
642				msg1.getAffectedPointCode().getPointCodes()));
643		assertTrue(Arrays.equals(msg.getAffectedPointCode().getMasks(), msg1
644				.getAffectedPointCode().getMasks()));
645
646		assertEquals(msg.getNetworkAppearance().getNetApp(), msg1
647				.getNetworkAppearance().getNetApp());
648
649		assertEquals(msg.getDiagnosticInfo().getInfo(), msg1
650				.getDiagnosticInfo().getInfo());
651	}
652
653	@Test
654	public void testNotify() throws IOException {
655		ByteBuffer buffer = ByteBuffer.allocate(8192);
656
657		NotifyImpl msg = (NotifyImpl) messageFactory.createMessage(
658				MessageClass.MANAGEMENT, MessageType.NOTIFY);
659
660		Status status = parmFactory.createStatus(1, 4);
661		msg.setStatus(status);
662
663		ASPIdentifier aspId = parmFactory.createASPIdentifier(123);
664		msg.setASPIdentifier(aspId);
665
666		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 1 });
667		msg.setRoutingContext(rc);
668
669		msg.encode(buffer);
670
671		buffer.flip();
672
673		NotifyImpl msg1 = (NotifyImpl) messageFactory.createMessage(buffer);
674
675		assertEquals(msg.getStatus().getType(), msg1.getStatus().getType());
676		assertEquals(msg.getStatus().getInfo(), msg1.getStatus().getInfo());
677		assertEquals(msg.getASPIdentifier().getAspId(), msg1.getASPIdentifier()
678				.getAspId());
679		assertTrue(Arrays.equals(msg.getRoutingContext().getRoutingContexts(),
680				msg1.getRoutingContext().getRoutingContexts()));
681	}
682
683	@Test
684	public void encodeTwoMessages() throws IOException {
685		ByteBuffer buffer = ByteBuffer.allocate(8192);
686
687		PayloadDataImpl payloadMsg = (PayloadDataImpl) messageFactory
688				.createMessage(MessageClass.TRANSFER_MESSAGES,
689						MessageType.PAYLOAD);
690		ProtocolDataImpl p1 = (ProtocolDataImpl) parmFactory
691				.createProtocolData(1408, 14150, 1, 1, 0, 0, new byte[] { 1, 2,
692						3, 4 });
693		payloadMsg.setData(p1);
694		payloadMsg.encode(buffer);
695
696		DestinationUnavailableImpl dunaMsg = (DestinationUnavailableImpl) messageFactory
697				.createMessage(MessageClass.SIGNALING_NETWORK_MANAGEMENT,
698						MessageType.DESTINATION_UNAVAILABLE);
699		NetworkAppearance netApp = parmFactory.createNetworkAppearance(1233);
700		dunaMsg.setNetworkAppearance(netApp);
701
702		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 12 });
703		dunaMsg.setRoutingContexts(rc);
704
705		AffectedPointCode afpc = parmFactory.createAffectedPointCode(
706				new int[] { 123 }, new short[] { 0 });
707		dunaMsg.setAffectedPointCodes(afpc);
708
709		dunaMsg.encode(buffer);
710
711		buffer.flip();
712
713		// Paylod decode
714		PayloadDataImpl payloadMsg1 = (PayloadDataImpl) messageFactory
715				.createMessage(buffer);
716
717		ProtocolDataImpl p2 = (ProtocolDataImpl) payloadMsg1.getData();
718
719		assertEquals(p1.getTag(), p2.getTag());
720		assertEquals(p1.getOpc(), p2.getOpc());
721		assertEquals(p1.getDpc(), p2.getDpc());
722		assertEquals(p1.getSI(), p2.getSI());
723		assertEquals(p1.getNI(), p2.getNI());
724		assertEquals(p1.getMP(), p2.getMP());
725		assertEquals(p1.getSLS(), p2.getSLS());
726
727		assertTrue(buffer.hasRemaining());
728
729		DestinationUnavailableImpl dunaMsg1 = (DestinationUnavailableImpl) messageFactory
730				.createMessage(buffer);
731
732		NetworkAppearance netApp1 = (NetworkAppearance) dunaMsg1
733				.getNetworkAppearance();
734
735		assertEquals(netApp.getNetApp(), netApp1.getNetApp());
736
737	}
738
739	@Test
740	public void testHeartBeat() throws IOException {
741
742		// Test encode
743		ByteBuffer buffer = ByteBuffer.allocate(8192);
744
745		byte[] data = new byte[] { 0x01, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00,
746				0x1c, 0x00, 0x09, 0x00, 0x14, 0x00, 0x02, 0x00, 0x00, 0x00,
747				0x07, (byte) 0xaf, 0x3e, 0x75, 0x40, 0x03, 0x13, 0x05, 0x07,
748				0x11, 0x20 };
749
750		byte[] heratbeatData = new byte[] { 0x00, 0x02, 0x00, 0x00, 0x00, 0x07,
751				(byte) 0xaf, 0x3e, 0x75, 0x40, 0x03, 0x13, 0x05, 0x07, 0x11,
752				0x20 };
753		Heartbeat heartbeat = (Heartbeat) messageFactory.createMessage(
754				MessageClass.ASP_STATE_MAINTENANCE, MessageType.HEARTBEAT);
755
756		HeartbeatData hrBtData = parmFactory.createHeartbeatData(heratbeatData);
757
758		heartbeat.setHeartbeatData(hrBtData);
759
760		((HeartbeatImpl) heartbeat).encode(buffer);
761
762		buffer.flip();
763
764		byte[] rawData = new byte[buffer.limit()];
765		buffer.get(rawData);
766
767		assertTrue(Arrays.equals(data, rawData));
768
769		// Test Decode
770		M3UAMessageImpl m3uaMessageImpl = messageFactory
771				.createSctpMessage(data);
772		assertTrue((m3uaMessageImpl instanceof HeartbeatImpl));
773		assertNotNull(((HeartbeatImpl) m3uaMessageImpl).getHeartbeatData());
774
775		assertTrue(Arrays.equals(heratbeatData,
776				((HeartbeatImpl) m3uaMessageImpl).getHeartbeatData().getData()));
777
778	}
779
780	@Test
781	public void testHeartBeatAck() throws IOException {
782
783		// Test encode
784		ByteBuffer buffer = ByteBuffer.allocate(8192);
785
786		byte[] data = new byte[] { 0x01, 0x00, 0x03, 0x06, 0x00, 0x00, 0x00,
787				0x1c, 0x00, 0x09, 0x00, 0x14, 0x00, 0x02, 0x00, 0x00, 0x00,
788				0x07, (byte) 0xaf, 0x3e, 0x75, 0x40, 0x03, 0x13, 0x05, 0x07,
789				0x11, 0x20 };
790
791		byte[] heratbeatAckData = new byte[] { 0x00, 0x02, 0x00, 0x00, 0x00,
792				0x07, (byte) 0xaf, 0x3e, 0x75, 0x40, 0x03, 0x13, 0x05, 0x07,
793				0x11, 0x20 };
794		HeartbeatAck heartbeatAck = (HeartbeatAck) messageFactory
795				.createMessage(MessageClass.ASP_STATE_MAINTENANCE,
796						MessageType.HEARTBEAT_ACK);
797
798		HeartbeatData hrBtData = parmFactory
799				.createHeartbeatData(heratbeatAckData);
800
801		heartbeatAck.setHeartbeatData(hrBtData);
802
803		((HeartbeatAckImpl) heartbeatAck).encode(buffer);
804
805		buffer.flip();
806
807		byte[] rawData = new byte[buffer.limit()];
808		buffer.get(rawData);
809
810		assertTrue(Arrays.equals(data, rawData));
811
812		// Test Decode
813		M3UAMessageImpl m3uaMessageImpl = messageFactory
814				.createSctpMessage(data);
815		assertTrue((m3uaMessageImpl instanceof HeartbeatAckImpl));
816		assertNotNull(((HeartbeatAckImpl) m3uaMessageImpl).getHeartbeatData());
817
818		assertTrue(Arrays.equals(heratbeatAckData,
819				((HeartbeatAckImpl) m3uaMessageImpl).getHeartbeatData()
820						.getData()));
821
822	}
823}