PageRenderTime 44ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 110 lines | 43 code | 18 blank | 49 comment | 1 complexity | 9d50caa6ea95839f7c56959f3ba82449 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. /**
  23. * Start time:14:11:03 2009-04-23<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:14:11:03 2009-04-23<br>
  38. * Project: mobicents-isup-stack<br>
  39. *
  40. * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski
  41. * </a>
  42. */
  43. public class NetworkRoutingNumberTest extends ParameterHarness {
  44. /**
  45. * @throws IOException
  46. */
  47. public NetworkRoutingNumberTest() throws IOException {
  48. super.badBodies.add(new byte[1]);
  49. super.goodBodies.add(getBody(false,getSixDigits(), NetworkRoutingNumberImpl._NPI_ISDN_NP, NetworkRoutingNumberImpl._NAI_NRNI_NETWORK_SNF));
  50. super.goodBodies.add(getBody(true,getFiveDigits(), NetworkRoutingNumberImpl._NPI_ISDN_NP, NetworkRoutingNumberImpl._NAI_NRNI_NETWORK_SNF));
  51. // This will fail, cause this body has APRI allowed, so hardcoded body
  52. // does nto match encoded body :)
  53. // super.goodBodies.add(getBody2());
  54. }
  55. @Test(groups = { "functional.encode","functional.decode","parameter"})
  56. public void testBody1EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
  57. NetworkRoutingNumberImpl bci = new NetworkRoutingNumberImpl(getBody(false,getSixDigits(), NetworkRoutingNumberImpl._NPI_ISDN_NP, NetworkRoutingNumberImpl._NAI_NRNI_NETWORK_SNF));
  58. String[] methodNames = { "isOddFlag", "getNumberingPlanIndicator", "getNatureOfAddressIndicator", "getAddress" };
  59. Object[] expectedValues = { false, NetworkRoutingNumberImpl._NPI_ISDN_NP, NetworkRoutingNumberImpl._NAI_NRNI_NETWORK_SNF,getSixDigitsString() };
  60. super.testValues(bci, methodNames, expectedValues);
  61. }
  62. @Test(groups = { "functional.encode","functional.decode","parameter"})
  63. public void testBody2EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
  64. NetworkRoutingNumberImpl bci = new NetworkRoutingNumberImpl(getBody(true,getFiveDigits(), NetworkRoutingNumberImpl._NPI_ISDN_NP, NetworkRoutingNumberImpl._NAI_NRNI_NETWORK_SNF));
  65. String[] methodNames = { "isOddFlag", "getNumberingPlanIndicator", "getNatureOfAddressIndicator", "getAddress" };
  66. Object[] expectedValues = { true, NetworkRoutingNumberImpl._NPI_ISDN_NP, NetworkRoutingNumberImpl._NAI_NRNI_NETWORK_SNF,getFiveDigitsString() };
  67. super.testValues(bci, methodNames, expectedValues);
  68. }
  69. private byte[] getBody(boolean isODD, byte[] digits, int npiIsdnNp, int naiNrniNetworkSnf) throws IOException {
  70. int b = 0;
  71. if(isODD)
  72. {
  73. b|=0x01<<7;
  74. }
  75. b|=npiIsdnNp<<4;
  76. b|=naiNrniNetworkSnf;
  77. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  78. bos.write(b);
  79. bos.write(digits);
  80. return bos.toByteArray();
  81. }
  82. /*
  83. * (non-Javadoc)
  84. *
  85. * @see
  86. * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
  87. * ()
  88. */
  89. public AbstractISUPParameter getTestedComponent() {
  90. return new NetworkRoutingNumberImpl("1", 1, 1);
  91. }
  92. }