/protocols/ss7/isup/isup-impl/src/test/java/org/mobicents/protocols/ss7/isup/impl/message/parameter/TerminatingNetworkRoutingNumberTest.java

http://mobicents.googlecode.com/ · Java · 101 lines · 41 code · 15 blank · 45 comment · 4 complexity · 6da64fb3d114140fbb7279796f3c7b9b 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. /**
  23. * Start time:21:30:13 2009-04-26<br>
  24. * Project: mobicents-isup-stack<br>
  25. *
  26. * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski
  27. * </a>
  28. *
  29. */
  30. package org.mobicents.protocols.ss7.isup.impl.message.parameter;
  31. import java.io.ByteArrayOutputStream;
  32. import java.io.IOException;
  33. import java.lang.reflect.InvocationTargetException;
  34. import org.mobicents.protocols.ss7.isup.ParameterException;
  35. import org.testng.annotations.Test;
  36. /**
  37. * Start time:21:30:13 2009-04-26<br>
  38. * Project: mobicents-isup-stack<br>
  39. *
  40. * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski
  41. * </a>
  42. */
  43. public class TerminatingNetworkRoutingNumberTest extends ParameterHarness {
  44. public TerminatingNetworkRoutingNumberTest() throws IOException {
  45. super();
  46. super.goodBodies.add(getBody(false, TerminatingNetworkRoutingNumberImpl._NPI_ISDN, TerminatingNetworkRoutingNumberImpl._NAI_NATIONAL_SN, getSixDigits(),getSixDigits().length));
  47. super.goodBodies.add(getBody(false, TerminatingNetworkRoutingNumberImpl._NPI_ISDN, TerminatingNetworkRoutingNumberImpl._NAI_NATIONAL_SN, null,-1));
  48. super.goodBodies.add(getBody(false, TerminatingNetworkRoutingNumberImpl._NPI_ISDN, TerminatingNetworkRoutingNumberImpl._NAI_NATIONAL_SN, null,0));
  49. super.badBodies.add(getBody(false, TerminatingNetworkRoutingNumberImpl._NPI_ISDN, TerminatingNetworkRoutingNumberImpl._NAI_NATIONAL_SN, new byte[8],8));
  50. //The diff is that this is odd - only 15 digits :)
  51. super.goodBodies.add(getBody(true, TerminatingNetworkRoutingNumberImpl._NPI_ISDN, TerminatingNetworkRoutingNumberImpl._NAI_NATIONAL_SN, new byte[8],8));
  52. }
  53. @Test(groups = { "functional.encode","functional.decode","parameter"})
  54. public void testBody1EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
  55. TerminatingNetworkRoutingNumberImpl bci = new TerminatingNetworkRoutingNumberImpl(getBody(false, TerminatingNetworkRoutingNumberImpl._NPI_ISDN, TerminatingNetworkRoutingNumberImpl._NAI_NATIONAL_SN,
  56. getSixDigits(),getSixDigits().length));
  57. String[] methodNames = { "isOddFlag", "getNumberingPlanIndicator", "getNatureOfAddressIndicator", "getAddress", "getTnrnLengthIndicator" };
  58. Object[] expectedValues = { false, TerminatingNetworkRoutingNumberImpl._NPI_ISDN, TerminatingNetworkRoutingNumberImpl._NAI_NATIONAL_SN, getSixDigitsString(), 4 };
  59. super.testValues(bci, methodNames, expectedValues);
  60. }
  61. private byte[] getBody(boolean isODD, int npiIsdn, int naiNationalSn, byte[] sixDigits, int tnrL) throws IOException {
  62. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  63. int v = 0;
  64. if (isODD)
  65. v |= 0x80;
  66. v |= npiIsdn << 4;
  67. //v |= sixDigits.length + 1;
  68. v |= tnrL+1;
  69. bos.write(v);
  70. if(tnrL!=-1)
  71. bos.write(naiNationalSn);
  72. if(sixDigits!=null && sixDigits.length>0)
  73. bos.write(sixDigits);
  74. return bos.toByteArray();
  75. }
  76. /*
  77. * (non-Javadoc)
  78. *
  79. * @see
  80. * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
  81. * ()
  82. */
  83. public AbstractISUPParameter getTestedComponent() {
  84. return new TerminatingNetworkRoutingNumberImpl("10", 1, 1);
  85. }
  86. }