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

http://mobicents.googlecode.com/ · Java · 121 lines · 55 code · 15 blank · 51 comment · 0 complexity · 751f6a18f64515d038acb5c8c3e59947 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: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.mobicents.protocols.ss7.isup.message.parameter.ConnectedNumber;
  36. import org.testng.annotations.Test;
  37. /**
  38. * Start time:14:11:03 2009-04-23<br>
  39. * Project: mobicents-isup-stack<br>
  40. *
  41. * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski
  42. * </a>
  43. */
  44. public class ConnectedNumberTest extends ParameterHarness {
  45. /**
  46. * @throws IOException
  47. */
  48. public ConnectedNumberTest() throws IOException {
  49. super.badBodies.add(new byte[1]);
  50. super.goodBodies.add(getBody1());
  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. private byte[] getBody1() throws IOException {
  56. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  57. // we will use odd number of digits, so we leave zero as MSB
  58. int v = ConnectedNumber._NAI_SUBSCRIBER_NUMBER;
  59. bos.write(v);
  60. v = 0;
  61. v = ConnectedNumberImpl._NPI_TELEX << 4;
  62. v |= ConnectedNumberImpl._APRI_NOT_AVAILABLE << 2;
  63. v |= ConnectedNumberImpl._SI_NETWORK_PROVIDED;
  64. bos.write(v & 0x7F);
  65. bos.write(super.getSixDigits());
  66. return bos.toByteArray();
  67. }
  68. private byte[] getBody2() throws IOException {
  69. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  70. // We have odd number
  71. int v = ConnectedNumber._NAI_SUBSCRIBER_NUMBER | (0x01 << 7);
  72. bos.write(v);
  73. v = 0;
  74. v = ConnectedNumberImpl._NPI_TELEX << 4;
  75. v |= ConnectedNumberImpl._APRI_ALLOWED << 2;
  76. v |= ConnectedNumberImpl._SI_NETWORK_PROVIDED;
  77. bos.write(v & 0x7F);
  78. bos.write(super.getFiveDigits());
  79. return bos.toByteArray();
  80. }
  81. @Test(groups = { "functional.encode","functional.decode","parameter"})
  82. public void testBody1EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
  83. ConnectedNumberImpl bci = new ConnectedNumberImpl(getBody1());
  84. String[] methodNames = { "getNumberingPlanIndicator", "getAddressRepresentationRestrictedIndicator", "getNatureOfAddressIndicator", "getScreeningIndicator", "isOddFlag", "getAddress" };
  85. Object[] expectedValues = { ConnectedNumberImpl._NPI_TELEX, ConnectedNumberImpl._APRI_NOT_AVAILABLE, ConnectedNumber._NAI_SUBSCRIBER_NUMBER, ConnectedNumberImpl._SI_NETWORK_PROVIDED, false,
  86. super.getSixDigitsString() };
  87. super.testValues(bci, methodNames, expectedValues);
  88. }
  89. @Test(groups = { "functional.encode","functional.decode","parameter"})
  90. public void testBody2EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
  91. ConnectedNumberImpl bci = new ConnectedNumberImpl(getBody2());
  92. String[] methodNames = { "getNumberingPlanIndicator", "getAddressRepresentationRestrictedIndicator", "getNatureOfAddressIndicator", "getScreeningIndicator", "isOddFlag", "getAddress" };
  93. Object[] expectedValues = { ConnectedNumberImpl._NPI_TELEX, ConnectedNumberImpl._APRI_ALLOWED, ConnectedNumber._NAI_SUBSCRIBER_NUMBER, ConnectedNumberImpl._SI_NETWORK_PROVIDED, true, super.getFiveDigitsString() };
  94. super.testValues(bci, methodNames, expectedValues);
  95. }
  96. /*
  97. * (non-Javadoc)
  98. *
  99. * @see
  100. * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
  101. * ()
  102. */
  103. public AbstractISUPParameter getTestedComponent() {
  104. return new ConnectedNumberImpl(1, "1", 1, 1, 1);
  105. }
  106. }