PageRenderTime 34ms CodeModel.GetById 3ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/m3ua/impl/src/test/java/org/mobicents/protocols/ss7/m3ua/impl/as/RemSgFSMTest.java

http://mobicents.googlecode.com/
Java | 551 lines | 331 code | 104 blank | 116 comment | 16 complexity | ca83baf897aa35a6e0c1f432eb767078 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.as;
 24
 25import static org.junit.Assert.assertEquals;
 26import static org.junit.Assert.assertNotNull;
 27import static org.junit.Assert.assertNull;
 28import static org.junit.Assert.assertTrue;
 29
 30import java.io.IOException;
 31
 32import org.junit.After;
 33import org.junit.AfterClass;
 34import org.junit.Before;
 35import org.junit.BeforeClass;
 36import org.junit.Test;
 37import org.mobicents.protocols.ss7.m3ua.impl.As;
 38import org.mobicents.protocols.ss7.m3ua.impl.AsState;
 39import org.mobicents.protocols.ss7.m3ua.impl.Asp;
 40import org.mobicents.protocols.ss7.m3ua.impl.AspFactory;
 41import org.mobicents.protocols.ss7.m3ua.impl.AspState;
 42import org.mobicents.protocols.ss7.m3ua.impl.CommunicationListener.CommunicationState;
 43import org.mobicents.protocols.ss7.m3ua.impl.message.M3UAMessageImpl;
 44import org.mobicents.protocols.ss7.m3ua.impl.message.MessageFactoryImpl;
 45import org.mobicents.protocols.ss7.m3ua.impl.message.transfer.PayloadDataImpl;
 46import org.mobicents.protocols.ss7.m3ua.impl.parameter.ParameterFactoryImpl;
 47import org.mobicents.protocols.ss7.m3ua.impl.parameter.ProtocolDataImpl;
 48import org.mobicents.protocols.ss7.m3ua.message.M3UAMessage;
 49import org.mobicents.protocols.ss7.m3ua.message.MessageClass;
 50import org.mobicents.protocols.ss7.m3ua.message.MessageType;
 51import org.mobicents.protocols.ss7.m3ua.message.asptm.ASPActiveAck;
 52import org.mobicents.protocols.ss7.m3ua.message.mgmt.Notify;
 53import org.mobicents.protocols.ss7.m3ua.parameter.RoutingContext;
 54import org.mobicents.protocols.ss7.m3ua.parameter.Status;
 55import org.mobicents.protocols.ss7.m3ua.parameter.TrafficModeType;
 56
 57/**
 58 * Tests the FSM of client side AS and ASP's
 59 * 
 60 * @author amit bhayani
 61 * 
 62 */
 63public class RemSgFSMTest {
 64
 65	private ParameterFactoryImpl parmFactory = new ParameterFactoryImpl();
 66	private MessageFactoryImpl messageFactory = new MessageFactoryImpl();
 67	private ClientM3UAManagement clientM3UAMgmt = new ClientM3UAManagement();
 68
 69	public RemSgFSMTest() {
 70	}
 71
 72	@BeforeClass
 73	public static void setUpClass() throws Exception {
 74	}
 75
 76	@AfterClass
 77	public static void tearDownClass() throws Exception {
 78	}
 79
 80	@Before
 81	public void setUp() throws IOException {
 82		clientM3UAMgmt.start();
 83	}
 84
 85	@After
 86	public void tearDown() throws IOException {
 87		clientM3UAMgmt.getAppServers().clear();
 88		clientM3UAMgmt.getAspfactories().clear();
 89		clientM3UAMgmt.getDpcVsAsName().clear();
 90		clientM3UAMgmt.stop();
 91	}
 92
 93	@Test
 94	public void testSingleAspInAs() throws Exception {
 95		// 5.1.1. Single ASP in an Application Server ("1+0" sparing),
 96
 97		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 100 });
 98
 99		// As as = rsgw.createAppServer("testas", rc, rKey, trModType);
100		As as = clientM3UAMgmt.createAppServer("m3ua as create rc 100 testas".split(" "));
101		// AspFactory localAspFactory = rsgw.createAspFactory("testasp",
102		// "127.0.0.1", 2777, "127.0.0.1", 2778);
103		AspFactory localAspFactory = clientM3UAMgmt
104				.createAspFactory("m3ua asp create ip 127.0.0.1 port 2777 remip 127.0.0.1 remport 2778 testasp"
105						.split(" "));
106		localAspFactory.start();
107
108		Asp asp = clientM3UAMgmt.assignAspToAs("testas", "testasp");
109
110		// Check for Communication UP
111		localAspFactory.onCommStateChange(CommunicationState.UP);
112
113		// Once comunication is UP, ASP_UP should have been sent.
114		assertEquals(AspState.UP_SENT, asp.getState());
115		assertTrue(validateMessage(localAspFactory, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP, -1, -1));
116
117		// The other side will send ASP_UP_ACK and after that NTFY(AS-INACTIVE)
118		M3UAMessageImpl message = messageFactory.createMessage(MessageClass.ASP_STATE_MAINTENANCE,
119				MessageType.ASP_UP_ACK);
120		localAspFactory.read(message);
121
122		Notify notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
123		notify.setRoutingContext(rc);
124		Status status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_INACTIVE);
125		notify.setStatus(status);
126		localAspFactory.read(notify);
127
128		assertEquals(AspState.ACTIVE_SENT, asp.getState());
129		assertTrue(validateMessage(localAspFactory, MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE, -1,
130				-1));
131		// also the AS should be INACTIVE now
132		assertEquals(AsState.INACTIVE, as.getState());
133
134		// The other side will send ASP_ACTIVE_ACK and after that
135		// NTFY(AS-ACTIVE)
136		ASPActiveAck aspActiveAck = (ASPActiveAck) messageFactory.createMessage(MessageClass.ASP_TRAFFIC_MAINTENANCE,
137				MessageType.ASP_ACTIVE_ACK);
138		aspActiveAck.setRoutingContext(rc);
139		localAspFactory.read(aspActiveAck);
140
141		notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
142		notify.setRoutingContext(rc);
143		status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
144		notify.setStatus(status);
145		localAspFactory.read(notify);
146
147		assertEquals(AspState.ACTIVE, asp.getState());
148		// also the AS should be ACTIVE now
149		assertEquals(AsState.ACTIVE, as.getState());
150
151		// Lets stop ASP Factory
152		localAspFactory.stop();
153
154		assertEquals(AspState.DOWN_SENT, asp.getState());
155		assertTrue(validateMessage(localAspFactory, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_DOWN, -1, -1));
156		// also the AS is PENDING
157		assertEquals(AsState.PENDING, as.getState());
158
159		// Make sure we don't have any more
160		assertNull(localAspFactory.txPoll());
161
162	}
163
164	@Test
165	public void testSingleAspInMultipleAs() throws Exception {
166		// 5.1.1.3. Single ASP in Multiple Application Servers (Each with "1+0"
167		// Sparing)
168
169		// Define 1st AS
170		RoutingContext rc1 = parmFactory.createRoutingContext(new long[] { 100 });
171
172		// As remAs1 = rsgw.createAppServer("testas1", rc1, rKey1, trModType1);
173		As remAs1 = clientM3UAMgmt.createAppServer("m3ua as create rc 100 testas1".split(" "));
174
175		// Define 2nd AS
176		RoutingContext rc2 = parmFactory.createRoutingContext(new long[] { 200 });
177
178		// As remAs2 = rsgw.createAppServer("testas2", rc2, rKey2, trModType2);
179		As remAs2 = clientM3UAMgmt.createAppServer("m3ua as create rc 200 testas2".split(" "));
180
181		// AspFactory aspFactory = rsgw.createAspFactory("testasp", "127.0.0.1",
182		// 2777, "127.0.0.1", 2778);
183		AspFactory aspFactory = clientM3UAMgmt
184				.createAspFactory("m3ua asp create ip 127.0.0.1 port 3777 remip 127.0.0.1 remport 3112 testasp"
185						.split(" "));
186		aspFactory.start();
187
188		// Both ASP uses same underlying M3UAChannel
189		Asp remAsp1 = clientM3UAMgmt.assignAspToAs("testas1", "testasp");
190		Asp remAsp2 = clientM3UAMgmt.assignAspToAs("testas2", "testasp");
191
192		// Check for Communication UP
193		aspFactory.onCommStateChange(CommunicationState.UP);
194
195		assertEquals(AspState.UP_SENT, remAsp1.getState());
196		assertEquals(AspState.UP_SENT, remAsp2.getState());
197		// Once communication is UP, ASP_UP should have been sent.
198		assertTrue(validateMessage(aspFactory, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP, -1, -1));
199
200		// Both the AS is still DOWN
201		assertEquals(AsState.DOWN, remAs1.getState());
202		assertEquals(AsState.DOWN, remAs2.getState());
203
204		// The other side will send ASP_UP_ACK and after that NTFY(AS-INACTIVE)
205		// for both the AS
206		M3UAMessageImpl message = messageFactory.createMessage(MessageClass.ASP_STATE_MAINTENANCE,
207				MessageType.ASP_UP_ACK);
208		aspFactory.read(message);
209		assertEquals(AspState.ACTIVE_SENT, remAsp1.getState());
210		assertEquals(AspState.ACTIVE_SENT, remAsp2.getState());
211		// ASP_ACTIVE for both ASP in txQueue
212		assertTrue(validateMessage(aspFactory, MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE, -1, -1));
213		assertTrue(validateMessage(aspFactory, MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE, -1, -1));
214
215		Notify notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
216		notify.setRoutingContext(rc1);
217		Status status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_INACTIVE);
218		notify.setStatus(status);
219		aspFactory.read(notify);
220		// the AS1 should be INACTIVE now but AS2 still DOWN
221		assertEquals(AsState.INACTIVE, remAs1.getState());
222		assertEquals(AsState.DOWN, remAs2.getState());
223
224		notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
225		notify.setRoutingContext(rc2);// RC 200
226		status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_INACTIVE);
227		notify.setStatus(status);
228		aspFactory.read(notify);
229		// AS2 should be INACTIVE now
230		assertEquals(AsState.INACTIVE, remAs2.getState());
231
232		// The other side will send ASP_ACTIVE_ACK and after that
233		// NTFY(AS-ACTIVE)
234		ASPActiveAck aspActiveAck = (ASPActiveAck) messageFactory.createMessage(MessageClass.ASP_TRAFFIC_MAINTENANCE,
235				MessageType.ASP_ACTIVE_ACK);
236		aspActiveAck.setRoutingContext(this.parmFactory.createRoutingContext(new long[] { 100, 200 }));
237		aspFactory.read(aspActiveAck);
238
239		// Both ASP are ACTIVE now
240		assertEquals(AspState.ACTIVE, remAsp1.getState());
241		assertEquals(AspState.ACTIVE, remAsp2.getState());
242
243		notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
244		notify.setRoutingContext(rc1);
245		status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
246		notify.setStatus(status);
247		aspFactory.read(notify);
248		// the AS1 should be ACTIVE now but AS2 still INACTIVE
249		assertEquals(AsState.ACTIVE, remAs1.getState());
250		assertEquals(AsState.INACTIVE, remAs2.getState());
251
252		notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
253		notify.setRoutingContext(rc2);
254		status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
255		notify.setStatus(status);
256		aspFactory.read(notify);
257		// the AS2 is also ACTIVE now
258		assertEquals(AsState.ACTIVE, remAs1.getState());
259		assertEquals(AsState.ACTIVE, remAs2.getState());
260
261		// Lets stop ASP Factory
262		aspFactory.stop();
263
264		assertEquals(AspState.DOWN_SENT, remAsp1.getState());
265		assertEquals(AspState.DOWN_SENT, remAsp2.getState());
266		assertTrue(validateMessage(aspFactory, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_DOWN, -1, -1));
267		// also the both AS is PENDING
268		assertEquals(AsState.PENDING, remAs1.getState());
269		assertEquals(AsState.PENDING, remAs2.getState());
270
271		// Make sure we don't have any more
272		assertNull(aspFactory.txPoll());
273
274	}
275
276	@Test
277	public void testTwoAspInAsOverride() throws Exception {
278		// 5.1.2. Two ASPs in Application Server ("1+1" Sparing)
279
280		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 100 });
281
282		TrafficModeType trModType = parmFactory.createTrafficModeType(TrafficModeType.Override);
283
284		// As remAs = rsgw.createAppServer("testas", rc, rKey, trModType);
285		As remAs = clientM3UAMgmt.createAppServer("m3ua as create rc 100 testas".split(" "));
286
287		// AspFactory aspFactory1 = rsgw.createAspFactory("testasp1",
288		// "127.0.0.1", 2777, "127.0.0.1", 2777);
289		AspFactory aspFactory1 = clientM3UAMgmt
290				.createAspFactory("m3ua asp create ip 127.0.0.1 port 3777 remip 127.0.0.1 remport 3112 testasp1"
291						.split(" "));
292		aspFactory1.start();
293
294		// AspFactory aspFactory2 = rsgw.createAspFactory("testasp2",
295		// "127.0.0.1", 2777, "127.0.0.1", 2778);
296		AspFactory aspFactory2 = clientM3UAMgmt
297				.createAspFactory("m3ua asp create ip 127.0.0.1 port 3778 remip 127.0.0.1 remport 3112 testasp2"
298						.split(" "));
299		aspFactory2.start();
300
301		Asp remAsp1 = clientM3UAMgmt.assignAspToAs("testas", "testasp1");
302		Asp remAsp2 = clientM3UAMgmt.assignAspToAs("testas", "testasp2");
303
304		// Check for Communication UP for ASP1
305		aspFactory1.onCommStateChange(CommunicationState.UP);
306		assertEquals(AspState.UP_SENT, remAsp1.getState());
307		// ASP_UP should have been sent.
308		assertTrue(validateMessage(aspFactory1, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP, -1, -1));
309		// But AS is still Down
310		assertEquals(AsState.DOWN, remAs.getState());
311
312		// Far end send ASP_UP_ACK and NTFY
313		M3UAMessageImpl message = messageFactory.createMessage(MessageClass.ASP_STATE_MAINTENANCE,
314				MessageType.ASP_UP_ACK);
315		aspFactory1.read(message);
316		assertEquals(AspState.ACTIVE_SENT, remAsp1.getState());
317		assertTrue(validateMessage(aspFactory1, MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE, -1, -1));
318
319		Notify notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
320		notify.setRoutingContext(rc);
321		Status status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_INACTIVE);
322		notify.setStatus(status);
323		aspFactory1.read(notify);
324		// the AS1 should be INACTIVE
325		assertEquals(AsState.INACTIVE, remAs.getState());
326
327		// The other side will send ASP_ACTIVE_ACK and after that
328		// NTFY(AS-ACTIVE)
329		ASPActiveAck aspActiveAck = (ASPActiveAck) messageFactory.createMessage(MessageClass.ASP_TRAFFIC_MAINTENANCE,
330				MessageType.ASP_ACTIVE_ACK);
331		aspActiveAck.setRoutingContext(rc);
332		aspActiveAck.setTrafficModeType(trModType);
333		aspFactory1.read(aspActiveAck);
334
335		assertEquals(AspState.ACTIVE, remAsp1.getState());
336
337		notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
338		notify.setRoutingContext(rc);
339		status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
340		notify.setStatus(status);
341		aspFactory1.read(notify);
342		aspFactory2.read(notify);
343
344		assertEquals(AsState.ACTIVE, remAs.getState());
345
346		// Communication UP for ASP2
347		aspFactory2.onCommStateChange(CommunicationState.UP);
348		assertEquals(AspState.UP_SENT, remAsp2.getState());
349		// ASP_UP should have been sent.
350		assertTrue(validateMessage(aspFactory2, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP, -1, -1));
351		// Far end send ASP_UP_ACK
352		message = messageFactory.createMessage(MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP_ACK);
353		aspFactory2.read(message);
354		// ASP2 now is INACTIVE as ASP1 is still ACTIVATING
355		assertEquals(AspState.INACTIVE, remAsp2.getState());
356
357		// Bring down ASP1
358		// 5.2.1. 1+1 Sparing, Withdrawal of ASP, Backup Override
359		aspFactory1.onCommStateChange(CommunicationState.LOST);
360		// the ASP is DOWN and AS goes in PENDING STATE
361		assertEquals(AspState.DOWN, remAsp1.getState());
362		assertEquals(AsState.PENDING, remAs.getState());
363
364		// Aslo the ASP_ACTIVE for ASP2 should have been sent
365		assertEquals(AspState.ACTIVE_SENT, remAsp2.getState());
366		assertTrue(validateMessage(aspFactory2, MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE, -1, -1));
367
368		// We will not get Alternate ASP Active as this ASP's channel is dead
369		// The other side will send ASP_ACTIVE_ACK and after that
370		// NTFY(AS-ACTIVE)
371		aspActiveAck = (ASPActiveAck) messageFactory.createMessage(MessageClass.ASP_TRAFFIC_MAINTENANCE,
372				MessageType.ASP_ACTIVE_ACK);
373		aspActiveAck.setRoutingContext(rc);
374		aspFactory2.read(aspActiveAck);
375		assertEquals(AspState.ACTIVE, remAsp2.getState());
376
377		// We should get Notify that AS is ACTIVE
378		notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
379		notify.setRoutingContext(rc);
380		status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
381		notify.setStatus(status);
382		aspFactory2.read(notify);
383
384		assertEquals(AsState.ACTIVE, remAs.getState());
385
386		assertNull(aspFactory1.txPoll());
387		assertNull(aspFactory2.txPoll());
388
389	}
390
391	@Test
392	public void testPendingQueue() throws Exception {
393		RoutingContext rc = parmFactory.createRoutingContext(new long[] { 100 });
394
395		// As as = rsgw.createAppServer("testas", rc, rKey, trModType);
396		As as = clientM3UAMgmt.createAppServer("m3ua as create rc 100 testas".split(" "));
397		// AspFactory localAspFactory = rsgw.createAspFactory("testasp",
398		// "127.0.0.1", 2777, "127.0.0.1", 2778);
399		AspFactory localAspFactory = clientM3UAMgmt
400				.createAspFactory("m3ua asp create ip 127.0.0.1 port 2777 remip 127.0.0.1 remport 2778 testasp"
401						.split(" "));
402		localAspFactory.start();
403
404		Asp asp = clientM3UAMgmt.assignAspToAs("testas", "testasp");
405
406		// Check for Communication UP
407		localAspFactory.onCommStateChange(CommunicationState.UP);
408
409		// Once comunication is UP, ASP_UP should have been sent.
410		assertEquals(AspState.UP_SENT, asp.getState());
411		assertTrue(validateMessage(localAspFactory, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP, -1, -1));
412
413		// The other side will send ASP_UP_ACK and after that NTFY(AS-INACTIVE)
414		M3UAMessageImpl message = messageFactory.createMessage(MessageClass.ASP_STATE_MAINTENANCE,
415				MessageType.ASP_UP_ACK);
416		localAspFactory.read(message);
417
418		Notify notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
419		notify.setRoutingContext(rc);
420		Status status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_INACTIVE);
421		notify.setStatus(status);
422		localAspFactory.read(notify);
423
424		assertEquals(AspState.ACTIVE_SENT, asp.getState());
425		assertTrue(validateMessage(localAspFactory, MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE, -1,
426				-1));
427		// also the AS should be INACTIVE now
428		assertEquals(AsState.INACTIVE, as.getState());
429
430		// The other side will send ASP_ACTIVE_ACK and after that
431		// NTFY(AS-ACTIVE)
432		ASPActiveAck aspActiveAck = (ASPActiveAck) messageFactory.createMessage(MessageClass.ASP_TRAFFIC_MAINTENANCE,
433				MessageType.ASP_ACTIVE_ACK);
434		aspActiveAck.setRoutingContext(rc);
435		localAspFactory.read(aspActiveAck);
436
437		notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
438		notify.setRoutingContext(rc);
439		status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
440		notify.setStatus(status);
441		localAspFactory.read(notify);
442
443		assertEquals(AspState.ACTIVE, asp.getState());
444		// also the AS should be ACTIVE now
445		assertEquals(AsState.ACTIVE, as.getState());
446
447		// Lets stop ASP Factory
448		localAspFactory.stop();
449
450		assertEquals(AspState.DOWN_SENT, asp.getState());
451		assertTrue(validateMessage(localAspFactory, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_DOWN, -1, -1));
452		// also the AS is PENDING
453		assertEquals(AsState.PENDING, as.getState());
454
455		// The far end sends DOWN_ACK
456		message = messageFactory.createMessage(MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_DOWN_ACK);
457		localAspFactory.read(message);
458
459		// start the ASP Factory again
460		localAspFactory.start();
461
462		// Now lets add some PayloadData
463		PayloadDataImpl payload = (PayloadDataImpl) messageFactory.createMessage(MessageClass.TRANSFER_MESSAGES,
464				MessageType.PAYLOAD);
465		ProtocolDataImpl p1 = (ProtocolDataImpl) parmFactory.createProtocolData(1408, 123, 3, 1, 0, 1, new byte[] { 1,
466				2, 3, 4 });
467		payload.setRoutingContext(rc);
468		payload.setData(p1);
469
470		as.write(payload);
471
472		// Now again the ASP is brought up
473		localAspFactory.onCommStateChange(CommunicationState.UP);
474
475		// Once communication is UP, ASP_UP should have been sent.
476		assertEquals(AspState.UP_SENT, asp.getState());
477		assertTrue(validateMessage(localAspFactory, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP, -1, -1));
478
479		// The other side will send ASP_UP_ACK and after that NTFY(AS-INACTIVE)
480		message = messageFactory.createMessage(MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP_ACK);
481		localAspFactory.read(message);
482
483		notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
484		notify.setRoutingContext(rc);
485		status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_INACTIVE);
486		notify.setStatus(status);
487		localAspFactory.read(notify);
488
489		assertEquals(AspState.ACTIVE_SENT, asp.getState());
490		assertTrue(validateMessage(localAspFactory, MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE, -1,
491				-1));
492		// AS should still be PENDING
493		assertEquals(AsState.PENDING, as.getState());
494
495		// The other side will send ASP_ACTIVE_ACK and after that
496		// NTFY(AS-ACTIVE)
497		aspActiveAck = (ASPActiveAck) messageFactory.createMessage(MessageClass.ASP_TRAFFIC_MAINTENANCE,
498				MessageType.ASP_ACTIVE_ACK);
499		aspActiveAck.setRoutingContext(rc);
500		localAspFactory.read(aspActiveAck);
501
502		notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
503		notify.setRoutingContext(rc);
504		status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
505		notify.setStatus(status);
506		localAspFactory.read(notify);
507
508		assertEquals(AspState.ACTIVE, asp.getState());
509		// also the AS should be ACTIVE now
510		assertEquals(AsState.ACTIVE, as.getState());
511
512		// Also we should have PayloadData
513		M3UAMessage payLoadTemp = localAspFactory.txPoll();
514		assertNotNull(payLoadTemp);
515		assertEquals(MessageClass.TRANSFER_MESSAGES, payLoadTemp.getMessageClass());
516		assertEquals(MessageType.PAYLOAD, payLoadTemp.getMessageType());
517
518		// Make sure we don't have any more
519		assertNull(localAspFactory.txPoll());
520
521	}
522
523	private boolean validateMessage(AspFactory factory, int msgClass, int msgType, int type, int info) {
524		M3UAMessage message = factory.txPoll();
525		if (message == null) {
526			return false;
527		}
528
529		if (message.getMessageClass() != msgClass || message.getMessageType() != msgType) {
530			return false;
531		}
532
533		if (message.getMessageClass() == MessageClass.MANAGEMENT) {
534			if (message.getMessageType() == MessageType.NOTIFY) {
535				Status s = ((Notify) message).getStatus();
536				if (s.getType() != type || s.getInfo() != info) {
537					return false;
538				} else {
539					return true;
540				}
541			}
542
543			// TODO take care of Error?
544			return true;
545		} else {
546			return true;
547		}
548
549	}
550
551}