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

http://mobicents.googlecode.com/ · Java · 124 lines · 63 code · 23 blank · 38 comment · 12 complexity · a9c2f96e70214c7a694bf9605a2bbbaa 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:16:42 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 java.util.Arrays;
  32. import static org.testng.Assert.*;
  33. import org.testng.*;
  34. import org.testng.annotations.*;
  35. import org.mobicents.protocols.ss7.isup.ISUPMessageFactory;
  36. import org.mobicents.protocols.ss7.isup.ISUPParameterFactory;
  37. import org.mobicents.protocols.ss7.isup.impl.message.parameter.ISUPParameterFactoryImpl;
  38. import org.mobicents.protocols.ss7.isup.message.ISUPMessage;
  39. import org.mobicents.protocols.ss7.isup.message.parameter.CircuitIdentificationCode;
  40. /**
  41. * Start time:09:16:42 2009-04-22<br>
  42. * Project: mobicents-isup-stack<br>
  43. *
  44. * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a>
  45. */
  46. public abstract class MessageHarness {
  47. protected ISUPParameterFactory parameterFactory = new ISUPParameterFactoryImpl();
  48. protected ISUPMessageFactory messageFactory = new ISUPMessageFactoryImpl(parameterFactory);
  49. // FIXME: add code to check values :)
  50. protected boolean makeCompare(byte[] b1, byte[] b2) {
  51. if (b1.length != b2.length)
  52. return false;
  53. for (int index = 0; index < b1.length; index++) {
  54. if (b1[index] != b2[index])
  55. return false;
  56. }
  57. return true;
  58. }
  59. protected String makeStringCompare(byte[] b1, byte[] b2) {
  60. int totalLength = 0;
  61. if (b1.length >= b2.length) {
  62. totalLength = b1.length;
  63. } else {
  64. totalLength = b2.length;
  65. }
  66. String out = "";
  67. for (int index = 0; index < totalLength; index++) {
  68. if (b1.length > index) {
  69. out += "b1[" + Integer.toHexString(b1[index]) + "]";
  70. } else {
  71. out += "b1[NOP]";
  72. }
  73. if (b2.length > index) {
  74. out += "b2[" + Integer.toHexString(b2[index]) + "]";
  75. } else {
  76. out += "b2[NOP]";
  77. }
  78. out += "\n";
  79. }
  80. return out;
  81. }
  82. protected abstract byte[] getDefaultBody();
  83. protected abstract ISUPMessage getDefaultMessage();
  84. @Test(groups = { "functional.encode","functional.decode","message"})
  85. public void testOne() throws Exception {
  86. byte[] defaultBody = getDefaultBody();
  87. // AddressCompleteMessageImpl acm=new
  88. // AddressCompleteMessageImpl(this,message);
  89. AbstractISUPMessage msg = (AbstractISUPMessage) getDefaultMessage();
  90. msg.decode(defaultBody,parameterFactory);
  91. byte[] encodedBody = msg.encode();
  92. boolean equal = Arrays.equals(defaultBody, encodedBody);
  93. assertTrue(equal,makeStringCompare(defaultBody, encodedBody));
  94. CircuitIdentificationCode cic = msg.getCircuitIdentificationCode();
  95. assertNotNull(cic,"CircuitIdentificationCode must not be null");
  96. assertEquals( getDefaultCIC(),cic.getCIC(),"CircuitIdentificationCode value does not match");
  97. }
  98. protected long getDefaultCIC() {
  99. return 0xB0C;
  100. }
  101. }