/protocols/ss7/m3ua/impl/src/test/java/org/mobicents/protocols/ss7/m3ua/impl/router/M3UARouterTest.java

http://mobicents.googlecode.com/ · Java · 137 lines · 71 code · 27 blank · 39 comment · 0 complexity · 522570c40db197c682b7318e7ef27424 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.router;
  23. import static org.junit.Assert.*;
  24. import org.junit.After;
  25. import org.junit.AfterClass;
  26. import org.junit.Before;
  27. import org.junit.BeforeClass;
  28. import org.junit.Test;
  29. import org.mobicents.protocols.ss7.m3ua.M3UAProvider;
  30. import org.mobicents.protocols.ss7.m3ua.impl.As;
  31. import org.mobicents.protocols.ss7.m3ua.impl.parameter.ParameterFactoryImpl;
  32. import org.mobicents.protocols.ss7.m3ua.impl.parameter.RoutingKeyImpl;
  33. import org.mobicents.protocols.ss7.m3ua.impl.tcp.TcpProvider;
  34. import org.mobicents.protocols.ss7.m3ua.parameter.DestinationPointCode;
  35. import org.mobicents.protocols.ss7.m3ua.parameter.OPCList;
  36. import org.mobicents.protocols.ss7.m3ua.parameter.RoutingContext;
  37. import org.mobicents.protocols.ss7.m3ua.parameter.RoutingKey;
  38. import org.mobicents.protocols.ss7.m3ua.parameter.ServiceIndicators;
  39. import org.mobicents.protocols.ss7.m3ua.parameter.TrafficModeType;
  40. /**
  41. * @author amit bhayani
  42. *
  43. */
  44. public class M3UARouterTest {
  45. private ParameterFactoryImpl factory = new ParameterFactoryImpl();
  46. private ServerM3UARouter m3uaRouter = null;
  47. private M3UAProvider m3uaProvider = TcpProvider.provider();
  48. @BeforeClass
  49. public static void setUpClass() throws Exception {
  50. }
  51. @AfterClass
  52. public static void tearDownClass() throws Exception {
  53. }
  54. @Before
  55. public void setUp() {
  56. m3uaRouter = new ServerM3UARouter();
  57. }
  58. @After
  59. public void tearDown() {
  60. }
  61. /**
  62. *
  63. * @throws Exception
  64. */
  65. @Test
  66. public void testRoute() throws Exception {
  67. // RK DPC=123, OPC=1,2,3 SI=1,2
  68. RoutingContext rc = factory.createRoutingContext(new long[] { 1 });
  69. DestinationPointCode[] dpc = new DestinationPointCode[] { factory.createDestinationPointCode(123, (short) 0) };
  70. ServiceIndicators[] servInds = new ServiceIndicators[] { factory.createServiceIndicators(new short[] { 1, 2 }) };
  71. OPCList[] opcList = new OPCList[] { factory.createOPCList(new int[] { 1, 2, 3 }, new short[] { 0, 0, 0 }) };
  72. RoutingKeyImpl rk1 = (RoutingKeyImpl) factory.createRoutingKey(null, rc, null, null, dpc, servInds, opcList);
  73. this.m3uaRouter.addRk(rk1, new AsImpl("AsImpl1", rc, rk1, null, m3uaProvider));
  74. // RK DPC=123 OPC=4 SI=2
  75. rc = factory.createRoutingContext(new long[] { 2 });
  76. dpc = new DestinationPointCode[] { factory.createDestinationPointCode(123, (short) 0) };
  77. servInds = new ServiceIndicators[] { factory.createServiceIndicators(new short[] { 2 }) };
  78. opcList = new OPCList[] { factory.createOPCList(new int[] { 4 }, new short[] { 0, 0, 0 }) };
  79. RoutingKeyImpl rk2 = (RoutingKeyImpl) factory.createRoutingKey(null, rc, null, null, dpc, servInds, opcList);
  80. this.m3uaRouter.addRk(rk2, new AsImpl("AsImpl2", rc, rk2, null, m3uaProvider));
  81. // RK DPC=123
  82. rc = factory.createRoutingContext(new long[] { 3 });
  83. dpc = new DestinationPointCode[] { factory.createDestinationPointCode(123, (short) 0) };
  84. RoutingKeyImpl rk3 = (RoutingKeyImpl) factory.createRoutingKey(null, rc, null, null, dpc, null, null);
  85. this.m3uaRouter.addRk(rk3, new AsImpl("AsImpl3", rc, rk3, null, m3uaProvider));
  86. // Retrieve As for message where dpc=123 opc=1, si=2
  87. As resultAs = this.m3uaRouter.getAs(123, 1, (short) 2);
  88. assertNotNull(resultAs);
  89. assertEquals(resultAs.getRoutingContext().getRoutingContexts()[0], 1l);
  90. // Retrieve As for message where dpc=123 and opc=4 si=3
  91. resultAs = this.m3uaRouter.getAs(123, 4, (short) 3);
  92. assertNull(resultAs);
  93. // Retrieve As for message where dpc=123 and opc=5 si=3
  94. resultAs = this.m3uaRouter.getAs(123, 5, (short) 3);
  95. assertNotNull(resultAs);
  96. assertEquals(resultAs.getRoutingContext().getRoutingContexts()[0], 3l);
  97. }
  98. private class AsImpl extends As {
  99. public AsImpl(String name, RoutingContext rc, RoutingKey rk, TrafficModeType trMode, M3UAProvider provider) {
  100. super(name, rc, rk, trMode, provider);
  101. }
  102. /* (non-Javadoc)
  103. * @see org.mobicents.protocols.ss7.m3ua.impl.As#init()
  104. */
  105. @Override
  106. public void init() {
  107. // TODO Auto-generated method stub
  108. }
  109. }
  110. }