PageRenderTime 21ms CodeModel.GetById 1ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 1ms

/protocols/ss7/m3ua/impl/src/test/java/org/mobicents/protocols/ss7/m3ua/impl/oam/M3UAShellExecutorTest.java

http://mobicents.googlecode.com/
Java | 387 lines | 238 code | 93 blank | 56 comment | 0 complexity | 04380c1f416733af5e66e3e8784da8a2 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.oam;
 24
 25
 26import java.util.List;
 27import java.util.Map;
 28
 29import javolution.util.FastMap;
 30
 31import org.testng.annotations.*;
 32import static org.testng.Assert.*;
 33
 34import org.mobicents.protocols.api.Association;
 35import org.mobicents.protocols.api.AssociationListener;
 36import org.mobicents.protocols.api.AssociationType;
 37import org.mobicents.protocols.api.IpChannelType;
 38import org.mobicents.protocols.api.Management;
 39import org.mobicents.protocols.api.PayloadData;
 40import org.mobicents.protocols.api.Server;
 41import org.mobicents.protocols.ss7.m3ua.impl.M3UAManagement;
 42
 43/**
 44 * 
 45 * @author amit bhayani
 46 * 
 47 */
 48public class M3UAShellExecutorTest {
 49
 50	M3UAShellExecutor m3uaExec = null;
 51	private TransportManagement transportManagement = null;
 52	M3UAManagement clientM3UAMgmt = null;
 53
 54	@BeforeClass
 55	public static void setUpClass() throws Exception {
 56	}
 57
 58	@AfterClass
 59	public static void tearDownClass() throws Exception {
 60	}
 61
 62	@BeforeMethod
 63	public void setUp() throws Exception {
 64		m3uaExec = new M3UAShellExecutor();
 65
 66		this.transportManagement = new TransportManagement();
 67
 68		this.clientM3UAMgmt = new M3UAManagement("M3UAShellExecutorTest");
 69		this.clientM3UAMgmt.setTransportManagement(this.transportManagement);
 70		this.clientM3UAMgmt.start();
 71
 72	}
 73
 74	@AfterMethod
 75	public void tearDown() throws Exception {
 76		// Clean up
 77		clientM3UAMgmt.getAppServers().clear();
 78		clientM3UAMgmt.getAspfactories().clear();
 79		clientM3UAMgmt.getRoute().clear();
 80		clientM3UAMgmt.stop();
 81
 82	}
 83
 84	@Test
 85	public void testServerCommands() throws Exception {
 86
 87		m3uaExec.setM3uaManagement(clientM3UAMgmt);
 88
 89		this.transportManagement.addAssociation(null, 0, null, 0, "testAssoc1");
 90
 91		// Test creating new AS
 92		String result = m3uaExec.execute("m3ua as create testas AS mode SE rc 100 traffic-mode loadshare".split(" "));
 93		assertEquals(String.format(M3UAOAMMessages.CREATE_AS_SUCESSFULL, "testas"), result);
 94
 95		// Try adding same again
 96		result = m3uaExec.execute("m3ua as create testas AS mode SE rc 100 traffic-mode loadshare".split(" "));
 97		assertEquals(String.format(M3UAOAMMessages.CREATE_AS_FAIL_NAME_EXIST, "testas"), result);
 98
 99		// Create AS with only mandatory params
100		result = m3uaExec.execute("m3ua as create testas1 AS".split(" "));
101		assertEquals(String.format(M3UAOAMMessages.CREATE_AS_SUCESSFULL, "testas1"), result);
102
103		// Create AS with all params
104		result = m3uaExec.execute("m3ua as create testas2 AS mode DE ipspType CLIENT rc 100 traffic-mode loadshare network-appearance 12"
105				.split(" "));
106		assertEquals(String.format(M3UAOAMMessages.CREATE_AS_SUCESSFULL, "testas2"), result);
107
108		// Create AS of type IPSP
109		result = m3uaExec.execute("m3ua as create MTUAS IPSP mode DE ipspType server rc 1 traffic-mode loadshare"
110				.split(" "));
111		assertEquals(String.format(M3UAOAMMessages.CREATE_AS_SUCESSFULL, "MTUAS"), result);
112
113		// create ASP
114		result = m3uaExec.execute("m3ua asp create testasp1 testAssoc1".split(" "));
115		assertEquals(String.format(M3UAOAMMessages.CREATE_ASP_SUCESSFULL, "testasp1"), result);
116
117		// Error for same name
118		result = m3uaExec.execute("m3ua asp create testasp1 testAssoc1".split(" "));
119		assertEquals(String.format(M3UAOAMMessages.CREATE_ASP_FAIL_NAME_EXIST, "testasp1"), result);
120
121		// assign ASP to AS
122		result = m3uaExec.execute("m3ua as add testas testasp1".split(" "));
123		assertEquals(String.format(M3UAOAMMessages.ADD_ASP_TO_AS_SUCESSFULL, "testasp1", "testas"), result);
124
125		// add again
126		result = m3uaExec.execute("m3ua as add testas testasp1".split(" "));
127		assertEquals(String.format("Cannot assign ASP=%s to AS=%s. This ASP is already assigned to this AS",
128				"testasp1", "testas"), result);
129		
130		
131		//Test Routes
132		result = m3uaExec.execute("m3ua route add testas 2 -1 -1".split(" "));
133		assertEquals(String.format(M3UAOAMMessages.ADD_ROUTE_AS_FOR_DPC_SUCCESSFULL, "testas", 2), result);
134
135		clientM3UAMgmt.stop();
136	}
137
138	class TestAssociation implements Association {
139
140		private AssociationListener associationListener = null;
141		private String name = null;
142
143		TestAssociation(String name) {
144			this.name = name;
145		}
146
147		@Override
148		public AssociationListener getAssociationListener() {
149			return this.associationListener;
150		}
151
152		@Override
153		public String getHostAddress() {
154			return null;
155		}
156
157		@Override
158		public int getHostPort() {
159			return 0;
160		}
161
162		@Override
163		public String getName() {
164			return null;
165		}
166
167		@Override
168		public String getPeerAddress() {
169			return null;
170		}
171
172		@Override
173		public int getPeerPort() {
174			return 0;
175		}
176
177		@Override
178		public String getServerName() {
179			return null;
180		}
181
182		@Override
183		public boolean isStarted() {
184			return false;
185		}
186
187		@Override
188		public void send(PayloadData payloadData) throws Exception {
189		}
190
191		@Override
192		public void setAssociationListener(AssociationListener associationListener) {
193			this.associationListener = associationListener;
194		}
195
196		public void signalCommUp() {
197			this.associationListener.onCommunicationUp(this);
198		}
199
200		public void signalCommLost() {
201			this.associationListener.onCommunicationLost(this);
202		}
203
204		@Override
205		public IpChannelType getIpChannelType() {
206			// TODO Auto-generated method stub
207			return null;
208		}
209
210		@Override
211		public AssociationType getAssociationType() {
212			// TODO Auto-generated method stub
213			return null;
214		}
215
216		@Override
217		public String[] getExtraHostAddresses() {
218			// TODO Auto-generated method stub
219			return null;
220		}
221
222	}
223
224	class TransportManagement implements Management {
225
226		private FastMap<String, Association> associations = new FastMap<String, Association>();
227
228		@Override
229		public Association addAssociation(String hostAddress, int hostPort, String peerAddress, int peerPort,
230				String assocName) throws Exception {
231			TestAssociation testAssociation = new TestAssociation(assocName);
232			this.associations.put(assocName, testAssociation);
233			return testAssociation;
234		}
235
236		@Override
237		public Server addServer(String serverName, String hostAddress, int port) throws Exception {
238			// TODO Auto-generated method stub
239			return null;
240		}
241
242		@Override
243		public Association addServerAssociation(String peerAddress, int peerPort, String serverName, String assocName)
244				throws Exception {
245			// TODO Auto-generated method stub
246			return null;
247		}
248
249		@Override
250		public Association getAssociation(String assocName) throws Exception {
251			return this.associations.get(assocName);
252		}
253
254		@Override
255		public Map<String, Association> getAssociations() {
256			return associations.unmodifiable();
257		}
258
259		@Override
260		public int getConnectDelay() {
261			return 0;
262		}
263
264		@Override
265		public String getName() {
266			return null;
267		}
268
269		@Override
270		public List<Server> getServers() {
271			return null;
272		}
273
274		@Override
275		public int getWorkerThreads() {
276			return 0;
277		}
278
279		@Override
280		public boolean isSingleThread() {
281			return false;
282		}
283
284		@Override
285		public void removeAssociation(String assocName) throws Exception {
286
287		}
288
289		@Override
290		public void removeServer(String serverName) throws Exception {
291
292		}
293
294		@Override
295		public void setConnectDelay(int connectDelay) {
296
297		}
298
299		@Override
300		public void setSingleThread(boolean arg0) {
301			// TODO Auto-generated method stub
302
303		}
304
305		@Override
306		public void setWorkerThreads(int arg0) {
307			// TODO Auto-generated method stub
308
309		}
310
311		@Override
312		public void start() throws Exception {
313			// TODO Auto-generated method stub
314
315		}
316
317		@Override
318		public void startAssociation(String arg0) throws Exception {
319			// TODO Auto-generated method stub
320
321		}
322
323		@Override
324		public void startServer(String arg0) throws Exception {
325			// TODO Auto-generated method stub
326
327		}
328
329		@Override
330		public void stop() throws Exception {
331			// TODO Auto-generated method stub
332
333		}
334
335		@Override
336		public void stopAssociation(String arg0) throws Exception {
337			// TODO Auto-generated method stub
338
339		}
340
341		@Override
342		public void stopServer(String arg0) throws Exception {
343			// TODO Auto-generated method stub
344
345		}
346
347		@Override
348		public String getPersistDir() {
349			// TODO Auto-generated method stub
350			return null;
351		}
352
353		@Override
354		public void setPersistDir(String arg0) {
355			// TODO Auto-generated method stub
356			
357		}
358
359		@Override
360		public Association addAssociation(String arg0, int arg1, String arg2,
361				int arg3, String arg4, IpChannelType arg5, String[] extraHostAddresses) throws Exception {
362			// TODO Auto-generated method stub
363			return null;
364		}
365
366		@Override
367		public Server addServer(String arg0, String arg1, int arg2,
368				IpChannelType arg3, String[] extraHostAddresses) throws Exception {
369			// TODO Auto-generated method stub
370			return null;
371		}
372
373		@Override
374		public Association addServerAssociation(String arg0, int arg1,
375				String arg2, String arg3, IpChannelType arg4) throws Exception {
376			// TODO Auto-generated method stub
377			return null;
378		}
379
380		@Override
381		public void removeAllResourses() throws Exception {
382			// TODO Auto-generated method stub
383			
384		}
385
386	}
387}