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

http://mobicents.googlecode.com/ · Java · 134 lines · 61 code · 17 blank · 56 comment · 0 complexity · f13f5b2bcf42bff6498cd01d19ac0d75 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.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 ConnectionRequestTest extends ParameterHarness {
  44. /**
  45. * @throws IOException
  46. */
  47. public ConnectionRequestTest() throws IOException {
  48. super.badBodies.add(new byte[1]);
  49. super.goodBodies.add(getBody1());
  50. // This will fail, cause this body has APRI allowed, so hardcoded body
  51. // does nto match encoded body :)
  52. // super.goodBodies.add(getBody2());
  53. }
  54. private byte[] getBody1() throws IOException {
  55. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  56. // we will use odd number of digits, so we leave zero as MSB
  57. //Local reference
  58. bos.write(12);
  59. bos.write(120);
  60. bos.write(38);
  61. //Signaling point code
  62. bos.write(120);
  63. bos.write(45);
  64. //protocol class
  65. bos.write(120);
  66. //credit
  67. bos.write(69);
  68. return bos.toByteArray();
  69. }
  70. private byte[] getBody2() throws IOException {
  71. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  72. //Local reference
  73. bos.write(12);
  74. bos.write(120);
  75. bos.write(38);
  76. //Signaling point code
  77. bos.write(120);
  78. bos.write(12);
  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. ConnectionRequestImpl bci = new ConnectionRequestImpl(getBody1());
  84. int localRef = 12;
  85. localRef|=120<<8;
  86. localRef|=38<<16;
  87. int signalingPointCode = 120;
  88. signalingPointCode |= 45<<8;
  89. int protocolClass = 120;
  90. int credit = 69;
  91. String[] methodNames = { "getLocalReference","getSignalingPointCode","getProtocolClass","getCredit"};
  92. Object[] expectedValues = { localRef,signalingPointCode,protocolClass,credit};
  93. super.testValues(bci, methodNames, expectedValues);
  94. }
  95. @Test(groups = { "functional.encode","functional.decode","parameter"})
  96. public void testBody2EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
  97. ConnectionRequestImpl bci = new ConnectionRequestImpl(getBody2());
  98. int localRef = 12;
  99. localRef|=120<<8;
  100. localRef|=38<<16;
  101. int signalingPointCode = 120;
  102. signalingPointCode |= 12<<8;
  103. String[] methodNames = { "getLocalReference","getSignalingPointCode"};
  104. Object[] expectedValues = { localRef,signalingPointCode};
  105. super.testValues(bci, methodNames, expectedValues);
  106. }
  107. /*
  108. * (non-Javadoc)
  109. *
  110. * @see
  111. * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
  112. * ()
  113. */
  114. public AbstractISUPParameter getTestedComponent() throws ParameterException {
  115. return new ConnectionRequestImpl(new byte[5]);
  116. }
  117. }