PageRenderTime 95ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

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