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

http://mobicents.googlecode.com/ · Java · 103 lines · 41 code · 15 blank · 47 comment · 2 complexity · 23aba6dd22734370bdf63b3b583974b4 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.RedirectionNumber;
  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 RedirectionNumberTest extends ParameterHarness {
  45. /**
  46. * @throws IOException
  47. */
  48. public RedirectionNumberTest() throws IOException {
  49. super.badBodies.add(new byte[1]);
  50. }
  51. @Test(groups = { "functional.encode","functional.decode","parameter"})
  52. public void testBody1EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
  53. RedirectionNumberImpl bci = new RedirectionNumberImpl(getBody(false, RedirectionNumber._NAI_INTERNATIONAL_NUMBER, RedirectionNumberImpl._INN_ROUTING_ALLOWED, RedirectionNumberImpl._NPI_TELEX, getSixDigits()));
  54. String[] methodNames = { "isOddFlag",
  55. "getNatureOfAddressIndicator",
  56. "getInternalNetworkNumberIndicator",
  57. "getNumberingPlanIndicator" ,
  58. "getAddress" };
  59. Object[] expectedValues = {false,
  60. RedirectionNumber._NAI_INTERNATIONAL_NUMBER,
  61. RedirectionNumberImpl._INN_ROUTING_ALLOWED,
  62. RedirectionNumberImpl._NPI_TELEX,
  63. getSixDigitsString()};
  64. super.testValues(bci, methodNames, expectedValues);
  65. }
  66. private byte[] getBody(boolean isODD, int naiNetworkSpecific, int innRoutingAllowed, int npiTelex, byte[] dgits) throws IOException {
  67. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  68. // we will use odd number of digits, so we leave zero as MSB
  69. if (isODD) {
  70. bos.write(0x80 | naiNetworkSpecific);
  71. } else {
  72. bos.write(naiNetworkSpecific);
  73. }
  74. bos.write((innRoutingAllowed << 7) | (npiTelex << 4));
  75. bos.write(dgits);
  76. return bos.toByteArray();
  77. }
  78. /*
  79. * (non-Javadoc)
  80. *
  81. * @see
  82. * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
  83. * ()
  84. */
  85. public AbstractISUPParameter getTestedComponent() {
  86. return new RedirectionNumberImpl(0, "1", 1, 1);
  87. }
  88. }