Revision: 49483bb9455b
Author:   [email protected] <[email protected]>
Date:     Fri Sep  6 11:38:02 2013 UTC
Log:      Fixed Issue #315 serilization bug

http://code.google.com/p/jss7/source/detail?r=49483bb9455b

Added:
/map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/service/supplementary/UnstructuredSSResponseTest.java
Modified:
/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/supplementary/SupplementaryMessageImpl.java

=======================================
--- /dev/null
+++ /map/map-impl/src/test/java/org/mobicents/protocols/ss7/map/service/supplementary/UnstructuredSSResponseTest.java Fri Sep 6 11:38:02 2013 UTC
@@ -0,0 +1,127 @@
+/*
+ * TeleStax, Open Source Cloud Communications
+ * Copyright 2011-2013, Telestax Inc and individual contributors
+ * by the @authors tag.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.mobicents.protocols.ss7.map.service.supplementary;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import javolution.xml.XMLObjectReader;
+import javolution.xml.XMLObjectWriter;
+
+import org.mobicents.protocols.ss7.map.api.primitives.USSDString;
+import org.mobicents.protocols.ss7.map.datacoding.CBSDataCodingSchemeImpl;
+import org.mobicents.protocols.ss7.map.primitives.USSDStringImpl;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+/**
+ * @author Amit Bhayani
+ *
+ */
+public class UnstructuredSSResponseTest {
+
+    /**
+     *
+     */
+    public UnstructuredSSResponseTest() {
+        // TODO Auto-generated constructor stub
+    }
+
+    @BeforeClass
+    public static void setUpClass() throws Exception {
+    }
+
+    @AfterClass
+    public static void tearDownClass() throws Exception {
+    }
+
+    @BeforeTest
+    public void setUp() {
+    }
+
+    @AfterTest
+    public void tearDown() {
+    }
+
+    @Test(groups = { "functional.xml.serialize", "service.ussd" })
+    public void testXMLSerialize() throws Exception {
+
+        USSDString ussdStr = new USSDStringImpl("1", null, null);
+ UnstructuredSSResponseImpl original = new UnstructuredSSResponseImpl(new CBSDataCodingSchemeImpl(0x0f), ussdStr);
+
+        // Writes the area to a file.
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        XMLObjectWriter writer = XMLObjectWriter.newInstance(baos);
+        // writer.setBinding(binding); // Optional.
+        writer.setIndentation("\t"); // Optional (use tabulation for
+                                     // indentation).
+ writer.write(original, "unstructuredSSResponse", UnstructuredSSResponseImpl.class);
+        writer.close();
+
+        byte[] rawData = baos.toByteArray();
+        String serializedEvent = new String(rawData);
+
+        System.out.println(serializedEvent);
+
+        ByteArrayInputStream bais = new ByteArrayInputStream(rawData);
+        XMLObjectReader reader = XMLObjectReader.newInstance(bais);
+ UnstructuredSSResponseImpl copy = reader.read("unstructuredSSResponse", UnstructuredSSResponseImpl.class);
+
+ assertEquals(copy.getDataCodingScheme().getCode(), original.getDataCodingScheme().getCode());
+        assertEquals(copy.getUSSDString(), original.getUSSDString());
+
+    }
+
+    @Test(groups = { "functional.xml.serialize", "service.ussd" })
+    public void testXMLSerializeNullUssd() throws Exception {
+
+ UnstructuredSSResponseImpl original = new UnstructuredSSResponseImpl();
+
+        // Writes the area to a file.
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        XMLObjectWriter writer = XMLObjectWriter.newInstance(baos);
+        // writer.setBinding(binding); // Optional.
+        writer.setIndentation("\t"); // Optional (use tabulation for
+                                     // indentation).
+ writer.write(original, "unstructuredSSResponse", UnstructuredSSResponseImpl.class);
+        writer.close();
+
+        byte[] rawData = baos.toByteArray();
+        String serializedEvent = new String(rawData);
+
+        System.out.println(serializedEvent);
+
+        ByteArrayInputStream bais = new ByteArrayInputStream(rawData);
+        XMLObjectReader reader = XMLObjectReader.newInstance(bais);
+ UnstructuredSSResponseImpl copy = reader.read("unstructuredSSResponse", UnstructuredSSResponseImpl.class);
+
+        assertNull(copy.getUSSDString());
+
+    }
+
+}
=======================================
--- /map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/supplementary/SupplementaryMessageImpl.java Mon May 20 20:09:00 2013 UTC +++ /map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/supplementary/SupplementaryMessageImpl.java Fri Sep 6 11:38:02 2013 UTC
@@ -106,11 +106,15 @@
public void read(javolution.xml.XMLFormat.InputElement xml, SupplementaryMessageImpl ussdMessage)
                 throws XMLStreamException {
             MAP_MESSAGE_XML.read(xml, ussdMessage);
+
             // TODO: this is wrong, if no CBS, this will set default.
- ussdMessage.ussdDataCodingSch = new CBSDataCodingSchemeImpl(xml.getAttribute(DATA_CODING_SCHEME,
-                    DEFAULT_DATA_CODING_SCHEME));
+
+            int cbs = xml.getAttribute(DATA_CODING_SCHEME,-1);
+            if(cbs != -1){
+ ussdMessage.ussdDataCodingSch = new CBSDataCodingSchemeImpl(cbs);
+            }

- String encodedString = xml.getAttribute(STRING, DEFAULT_USSD_STRING);
+            String encodedString = xml.getAttribute(STRING, null);
             if (encodedString != null)
                 try {
ussdMessage.ussdString = new USSDStringImpl(encodedString, ussdMessage.ussdDataCodingSch, null);

--

--- You received this message because you are subscribed to the Google Groups "mobicents-commits" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to