/protocols/ss7/mtp/mtp-api/src/test/java/org/mobicents/protocols/ss7/mtp/Mtp3TransferMessageTest.java

http://mobicents.googlecode.com/ · Java · 79 lines · 31 code · 16 blank · 32 comment · 0 complexity · 37d388e4f89db434afe28d81b406d32b 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. package org.mobicents.protocols.ss7.mtp;
  23. import static org.testng.Assert.assertEquals;
  24. import static org.testng.Assert.assertTrue;
  25. import java.util.Arrays;
  26. import org.testng.*;import org.testng.annotations.*;
  27. /**
  28. * @author sergey vetyutnev
  29. *
  30. */
  31. public class Mtp3TransferMessageTest {
  32. private byte[] getMsg() {
  33. return new byte[] { (byte) 0x83, (byte) 232, 3, (byte) 244, (byte) 161, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  34. }
  35. private byte[] getData() {
  36. return new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  37. }
  38. // si = 3 (SCCP)
  39. // ni = 2
  40. // mp = 0
  41. // sio = (si + (ni << 6) + (mt << 4))
  42. // dpc = 1000
  43. // opc = 2000
  44. // sls = 10
  45. @Test(groups = { "Mtp3TransferMessageTest", "decode" })
  46. public void testDecode() throws Exception {
  47. Mtp3TransferPrimitive msg = new Mtp3TransferPrimitive();
  48. msg.decodeMtp3(this.getMsg());
  49. assertEquals(msg.getSi(), 3);
  50. assertEquals(msg.getNi(), 2);
  51. assertEquals(msg.getMp(), 0);
  52. assertEquals(msg.getDpc(), 1000);
  53. assertEquals(msg.getOpc(), 2000);
  54. assertEquals(msg.getSls(), 10);
  55. assertTrue(Arrays.equals(msg.getData(), this.getData()));
  56. }
  57. @Test(groups = { "Mtp3TransferMessageTest", "encode" })
  58. public void testEncode() throws Exception {
  59. Mtp3TransferPrimitive msg = new Mtp3TransferPrimitive(3, 2, 0, 2000, 1000, 10, this.getData());
  60. byte[] res = msg.encodeMtp3();
  61. assertTrue(Arrays.equals(res, this.getMsg()));
  62. }
  63. }