PageRenderTime 28ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/protocols/ss7/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/service/sms/MWStatusTest.java

http://mobicents.googlecode.com/
Java | 108 lines | 58 code | 21 blank | 29 comment | 0 complexity | 656500ec1259614b21a3a8d1b281f8a4 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  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.map.service.sms;
  23. import static org.testng.Assert.assertEquals;
  24. import static org.testng.Assert.assertTrue;
  25. import java.io.ByteArrayInputStream;
  26. import java.io.ByteArrayOutputStream;
  27. import java.io.InputStream;
  28. import java.io.ObjectInputStream;
  29. import java.io.ObjectOutputStream;
  30. import java.util.Arrays;
  31. import org.mobicents.protocols.asn.AsnInputStream;
  32. import org.mobicents.protocols.asn.AsnOutputStream;
  33. import org.mobicents.protocols.asn.Tag;
  34. import org.testng.annotations.Test;
  35. /**
  36. *
  37. * @author sergey vetyutnev
  38. *
  39. */
  40. public class MWStatusTest {
  41. private byte[] getEncodedData() {
  42. return new byte[] { 3, 2, 2, 64 };
  43. }
  44. @Test(groups = { "functional.decode","service.sms"})
  45. public void testDecode() throws Exception {
  46. byte[] rawData = getEncodedData();
  47. AsnInputStream asn = new AsnInputStream(rawData);
  48. int tag = asn.readTag();
  49. MWStatusImpl mws = new MWStatusImpl();
  50. mws.decodeAll(asn);
  51. assertEquals( tag,Tag.STRING_BIT);
  52. assertEquals( asn.getTagClass(),Tag.CLASS_UNIVERSAL);
  53. assertEquals( (boolean)mws.getMcefSet(),false);
  54. assertEquals( (boolean)mws.getMnrfSet(),true);
  55. assertEquals( (boolean)mws.getMnrgSet(),false);
  56. assertEquals( (boolean)mws.getScAddressNotIncluded(),false);
  57. }
  58. @Test(groups = { "functional.encode","service.sms"})
  59. public void testEncode() throws Exception {
  60. MWStatusImpl mws = new MWStatusImpl(false, true, false, false);
  61. AsnOutputStream asnOS = new AsnOutputStream();
  62. mws.encodeAll(asnOS);
  63. byte[] encodedData = asnOS.toByteArray();
  64. byte[] rawData = getEncodedData();
  65. assertTrue( Arrays.equals(rawData,encodedData));
  66. }
  67. @Test(groups = { "functional.serialize", "service.sms" })
  68. public void testSerialization() throws Exception {
  69. MWStatusImpl original = new MWStatusImpl(false, true, false, false);
  70. // serialize
  71. ByteArrayOutputStream out = new ByteArrayOutputStream();
  72. ObjectOutputStream oos = new ObjectOutputStream(out);
  73. oos.writeObject(original);
  74. oos.close();
  75. // deserialize
  76. byte[] pickled = out.toByteArray();
  77. InputStream in = new ByteArrayInputStream(pickled);
  78. ObjectInputStream ois = new ObjectInputStream(in);
  79. Object o = ois.readObject();
  80. MWStatusImpl copy = (MWStatusImpl) o;
  81. //test result
  82. assertEquals(copy.getMcefSet(), original.getMcefSet());
  83. assertEquals(copy.getScAddressNotIncluded(), original.getScAddressNotIncluded());
  84. assertEquals(copy.getMnrfSet(), original.getMnrfSet());
  85. assertEquals(copy.getMnrgSet(), original.getMnrgSet());
  86. }
  87. }