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

http://mobicents.googlecode.com/ · Java · 144 lines · 76 code · 21 blank · 47 comment · 0 complexity · 200d6b045c03010f8f74cf03f6a0479b 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.IOException;
  32. import java.lang.reflect.InvocationTargetException;
  33. import org.mobicents.protocols.ss7.isup.ParameterException;
  34. import org.testng.annotations.Test;
  35. import static org.testng.Assert.*;
  36. import org.testng.*;
  37. import org.testng.annotations.*;
  38. /**
  39. * Start time:14:11:03 2009-04-23<br>
  40. * Project: mobicents-isup-stack<br>
  41. *
  42. * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski
  43. * </a>
  44. */
  45. public class CircuitAssigmentMapTest extends ParameterHarness {
  46. /**
  47. * @throws IOException
  48. */
  49. public CircuitAssigmentMapTest() throws IOException {
  50. super.badBodies.add(new byte[1]);
  51. super.badBodies.add(new byte[6]);
  52. super.goodBodies.add(getBody1());
  53. }
  54. private byte[] getBody1() throws IOException {
  55. // we will use odd number of digits, so we leave zero as MSB
  56. byte[] body = new byte[5];
  57. body[0]=12;
  58. body[1]=120;
  59. body[2]=67;
  60. return body;
  61. }
  62. @Test(groups = { "functional.encode","functional.decode","parameter"})
  63. public void testBody1EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
  64. CircuitAssigmentMapImpl bci = new CircuitAssigmentMapImpl(getBody1());
  65. int format = 120;
  66. format |= 67 << 8;
  67. format |= 0 << 16;
  68. format |= 0 << 24;
  69. String[] methodNames = { "getMapType","getMapFormat"};
  70. Object[] expectedValues = { 12, format};
  71. super.testValues(bci, methodNames, expectedValues);
  72. }
  73. @Test(groups = { "functional.flags","parameter"})
  74. public void testBoundries() throws IOException, ParameterException
  75. {
  76. CircuitAssigmentMapImpl bci = new CircuitAssigmentMapImpl(getBody1());
  77. try{
  78. bci.disableCircuit(0);
  79. fail("Failed, disabled circuit 0");
  80. }catch(IllegalArgumentException e)
  81. {
  82. }
  83. try{
  84. bci.disableCircuit(32);
  85. fail("Failed, disabled circuit 32");
  86. }catch(IllegalArgumentException e)
  87. {
  88. }
  89. try{
  90. bci.enableCircuit(0);
  91. fail("Enabled, disabled circuit 0");
  92. }catch(IllegalArgumentException e)
  93. {
  94. }
  95. try{
  96. bci.enableCircuit(32);
  97. fail("Enabled, disabled circuit 32");
  98. }catch(IllegalArgumentException e)
  99. {
  100. }
  101. }
  102. @Test(groups = { "functional.flags","parameter"})
  103. public void testEnableDissable() throws IOException, ParameterException
  104. {
  105. CircuitAssigmentMapImpl bci = new CircuitAssigmentMapImpl(getBody1());
  106. assertFalse(bci.isCircuitEnabled(30),"Circuit was enabled, it should not.");
  107. bci.enableCircuit(30);
  108. assertTrue(bci.isCircuitEnabled(30),"Circuit was not enabled, it should not.");
  109. bci.disableCircuit(30);
  110. assertFalse(bci.isCircuitEnabled(30),"Circuit was not disabled, it should not.");
  111. super.makeCompare(getBody1(), bci.encode());
  112. }
  113. /*
  114. * (non-Javadoc)
  115. *
  116. * @see
  117. * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
  118. * ()
  119. */
  120. public AbstractISUPParameter getTestedComponent() throws ParameterException {
  121. return new CircuitAssigmentMapImpl(new byte[5]);
  122. }
  123. }