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

http://mobicents.googlecode.com/ · Java · 121 lines · 55 code · 18 blank · 48 comment · 0 complexity · 1700b99ce54f48675fd6c2c491b8a740 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 java.util.Arrays;
  35. import org.mobicents.protocols.ss7.isup.ParameterException;
  36. import org.testng.annotations.Test;
  37. import static org.testng.Assert.*;
  38. import org.testng.*;
  39. import org.testng.annotations.*;
  40. /**
  41. * Start time:14:11:03 2009-04-23<br>
  42. * Project: mobicents-isup-stack<br>
  43. *
  44. * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski
  45. * </a>
  46. */
  47. public class RangeAndStatusTest extends ParameterHarness {
  48. /**
  49. * @throws IOException
  50. */
  51. public RangeAndStatusTest() throws IOException {
  52. //super.badBodies.add(new byte[0]);
  53. }
  54. @Test(groups = { "functional.encode","functional.decode","parameter"})
  55. public void testBody1EncodedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
  56. RangeAndStatusImpl bci = new RangeAndStatusImpl(getBody((byte)12,new byte[]{0x0F,0x04}));
  57. //not a best here. ech.
  58. String[] methodNames = { "getRange",
  59. "getStatus",
  60. };
  61. Object[] expectedValues = {(byte)12,
  62. new byte[]{0x0F,0x04}};
  63. super.testValues(bci, methodNames, expectedValues);
  64. }
  65. @Test(groups = { "functional.flags","parameter"})
  66. public void testAffectedValues() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException, ParameterException {
  67. RangeAndStatusImpl bci = new RangeAndStatusImpl(getBody((byte)12,new byte[]{0x0F,0x04}));
  68. assertEquals((byte)12, bci.getRange());
  69. assertTrue(bci.isAffected((byte) 0));
  70. assertTrue(bci.isAffected((byte) 1));
  71. assertTrue(bci.isAffected((byte) 2));
  72. assertTrue(bci.isAffected((byte) 3));
  73. assertTrue(!bci.isAffected((byte) 4));
  74. assertTrue(!bci.isAffected((byte) 5));
  75. assertTrue(!bci.isAffected((byte) 6));
  76. assertTrue(!bci.isAffected((byte) 7));
  77. assertTrue(!bci.isAffected((byte) 8));
  78. assertTrue(!bci.isAffected((byte) 9));
  79. assertTrue(bci.isAffected((byte) 10));
  80. bci.setAffected((byte)9, true);
  81. bci.setAffected((byte)10, false);
  82. assertTrue(!bci.isAffected((byte) 10));
  83. assertTrue(bci.isAffected((byte) 9));
  84. byte[] stat = bci.getStatus();
  85. assertTrue(Arrays.equals(new byte[]{0x0F,0x02}, stat));
  86. }
  87. private byte[] getBody(byte rannge,byte[] enabled) throws IOException {
  88. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  89. bos.write(rannge);
  90. bos.write(enabled);
  91. return bos.toByteArray();
  92. }
  93. /*
  94. * (non-Javadoc)
  95. *
  96. * @see
  97. * org.mobicents.isup.messages.parameters.ParameterHarness#getTestedComponent
  98. * ()
  99. */
  100. public AbstractISUPParameter getTestedComponent() {
  101. return new RangeAndStatusImpl();
  102. }
  103. }