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