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

http://mobicents.googlecode.com/ · Java · 127 lines · 67 code · 19 blank · 41 comment · 4 complexity · 1805325deb7b75ab7fcd616ebb101356 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:09:26:46 2009-04-22<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;
  31. import org.mobicents.protocols.ss7.isup.message.CircuitGroupQueryResponseMessage;
  32. import org.mobicents.protocols.ss7.isup.message.ISUPMessage;
  33. import org.mobicents.protocols.ss7.isup.message.parameter.CallReference;
  34. import org.mobicents.protocols.ss7.isup.message.parameter.CircuitStateIndicator;
  35. import org.mobicents.protocols.ss7.isup.message.parameter.RangeAndStatus;
  36. import static org.testng.Assert.*;
  37. import org.testng.*;
  38. import org.testng.annotations.*;
  39. /**
  40. * Start time:09:26:46 2009-04-22<br>
  41. * Project: mobicents-isup-stack<br>
  42. * Test for CQR
  43. *
  44. * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a>
  45. */
  46. public class CQRTest extends MessageHarness {
  47. @Test(groups = { "functional.encode","functional.decode","message"})
  48. public void testTwo_Params() throws Exception
  49. {
  50. byte[] message = getDefaultBody();
  51. //CircuitGroupQueryResponseMessage grs=new CircuitGroupQueryResponseMessageImpl(this,message);
  52. CircuitGroupQueryResponseMessage grs=super.messageFactory.createCQR();
  53. ((AbstractISUPMessage)grs).decode(message,parameterFactory);
  54. try{
  55. RangeAndStatus RS = (RangeAndStatus) grs.getParameter(RangeAndStatus._PARAMETER_CODE);
  56. assertNotNull(RS,"Range And Status retrun is null, it shoul not be");
  57. if(RS == null)
  58. return;
  59. byte range = RS.getRange();
  60. assertEquals(range,0x01,"Range is wrong,");
  61. byte[] b=RS.getStatus();
  62. assertNull(b,"RangeAndStatus.getRange() is not null");
  63. }catch(Exception e)
  64. {
  65. e.printStackTrace();
  66. fail("Failed on get parameter["+CallReference._PARAMETER_CODE+"]:"+e);
  67. }
  68. try{
  69. CircuitStateIndicator CSI = (CircuitStateIndicator) grs.getParameter(CircuitStateIndicator._PARAMETER_CODE);
  70. assertNotNull(CSI,"Circuit State Indicator return is null, it should not be");
  71. if(CSI == null)
  72. return;
  73. assertNotNull(CSI.getCircuitState(),"CircuitStateIndicator getCircuitState return is null, it should not be");
  74. byte[] circuitState = CSI.getCircuitState();
  75. assertEquals(circuitState.length,3, "CircuitStateIndicator.getCircuitState() length is nto correct");
  76. assertEquals( CSI.getMaintenanceBlockingState(circuitState[0]),1,"CircuitStateIndicator.getCircuitState()[0] value is not correct");
  77. assertEquals( CSI.getMaintenanceBlockingState(circuitState[1]),2,"CircuitStateIndicator.getCircuitState()[1] value is not correct");
  78. assertEquals( CSI.getMaintenanceBlockingState(circuitState[2]),3,"CircuitStateIndicator.getCircuitState()[2] value is not correct");
  79. }catch(Exception e)
  80. {
  81. e.printStackTrace();
  82. fail("Failed on get parameter["+CallReference._PARAMETER_CODE+"]:"+e);
  83. }
  84. }
  85. protected byte[] getDefaultBody() {
  86. //FIXME: for now we strip MTP part
  87. byte[] message={
  88. 0x0C
  89. ,(byte) 0x0B
  90. ,CircuitGroupQueryResponseMessage.MESSAGE_CODE
  91. ,0x02 // ptr to variable part
  92. ,0x03
  93. //no optional, so no pointer
  94. //RangeAndStatus._PARAMETER_CODE
  95. ,0x01
  96. ,0x01
  97. //CircuitStateIndicator
  98. ,0x03
  99. ,0x01
  100. ,0x02
  101. ,0x03
  102. };
  103. return message;
  104. }
  105. protected ISUPMessage getDefaultMessage() {
  106. return super.messageFactory.createCQR();
  107. }
  108. }