Revision: 1d57efd44d4f
Author: [email protected] <[email protected]>
Date: Fri Jan 25 02:22:47 2013
Log: Issue 228:Adding XML serialization support for a list of MAP/CAP
messages (that are used in CAP V2) : ApplyChargingReportRequest
http://code.google.com/p/jss7/source/detail?r=1d57efd44d4f
Modified:
/cap/cap-impl/src/main/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/ApplyChargingReportRequestImpl.java
/cap/cap-impl/src/main/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeDurationChargingResultImpl.java
/cap/cap-impl/src/main/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeIfTariffSwitchImpl.java
/cap/cap-impl/src/main/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeInformationImpl.java
/cap/cap-impl/src/test/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/ApplyChargingReportRequestTest.java
/cap/cap-impl/src/test/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeDurationChargingResultTest.java
/cap/cap-impl/src/test/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeIfTariffSwitchTest.java
/cap/cap-impl/src/test/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeInformationTest.java
=======================================
---
/cap/cap-impl/src/main/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/ApplyChargingReportRequestImpl.java
Wed May 16 05:00:01 2012
+++
/cap/cap-impl/src/main/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/ApplyChargingReportRequestImpl.java
Fri Jan 25 02:22:47 2013
@@ -1,6 +1,6 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and individual contributors
+ * TeleStax, Open Source Cloud Communications
+ * Copyright 2012, Telestax Inc and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -24,6 +24,9 @@
import java.io.IOException;
+import javolution.xml.XMLFormat;
+import javolution.xml.stream.XMLStreamException;
+
import org.mobicents.protocols.asn.AsnException;
import org.mobicents.protocols.asn.AsnInputStream;
import org.mobicents.protocols.asn.AsnOutputStream;
@@ -40,9 +43,13 @@
/**
*
* @author sergey vetyutnev
+ * @author Amit Bhayani
*
*/
-public class ApplyChargingReportRequestImpl extends
CircuitSwitchedCallMessageImpl implements ApplyChargingReportRequest {
+public class ApplyChargingReportRequestImpl extends
CircuitSwitchedCallMessageImpl implements
+ ApplyChargingReportRequest {
+
+ private static final String TIME_DURATION_CHARGING_RESULT
= "timeDurationChargingResult";
public static final int _ID_timeDurationChargingResult = 0;
@@ -51,8 +58,7 @@
public static final String _PrimitiveName
= "ApplyChargingReportRequestIndication";
private TimeDurationChargingResult timeDurationChargingResult;
-
-
+
public ApplyChargingReportRequestImpl() {
}
@@ -75,7 +81,6 @@
return timeDurationChargingResult;
}
-
@Override
public int getTag() throws CAPException {
return Tag.STRING_OCTET;
@@ -98,11 +103,11 @@
int length = ansIS.readLength();
this._decode(ansIS, length);
} catch (IOException e) {
- throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
} catch (AsnException e) {
- throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
}
}
@@ -112,15 +117,16 @@
try {
this._decode(ansIS, length);
} catch (IOException e) {
- throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
} catch (AsnException e) {
- throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
}
}
- private void _decode(AsnInputStream ansIS, int length) throws
CAPParsingComponentException, IOException, AsnException {
+ private void _decode(AsnInputStream ansIS, int length) throws
CAPParsingComponentException, IOException,
+ AsnException {
this.timeDurationChargingResult = null;
@@ -129,9 +135,11 @@
int tag = aiss.readTag();
- if (tag != _ID_timeDurationChargingResult || aiss.getTagClass() !=
Tag.CLASS_CONTEXT_SPECIFIC || aiss.isTagPrimitive())
+ if (tag != _ID_timeDurationChargingResult || aiss.getTagClass() !=
Tag.CLASS_CONTEXT_SPECIFIC
+ || aiss.isTagPrimitive())
throw new CAPParsingComponentException("Error when decoding " +
_PrimitiveName
- + ": bad tag or tagClass or is primitive of the choice
timeDurationChargingResult",
CAPParsingComponentExceptionReason.MistypedParameter);
+ + ": bad tag or tagClass or is primitive of the choice
timeDurationChargingResult",
+
CAPParsingComponentExceptionReason.MistypedParameter);
this.timeDurationChargingResult = new
TimeDurationChargingResultImpl();
((TimeDurationChargingResultImpl)
this.timeDurationChargingResult).decodeAll(aiss);
@@ -159,7 +167,8 @@
public void encodeData(AsnOutputStream asnOs) throws CAPException {
if (this.timeDurationChargingResult == null)
- throw new CAPException("Error while encoding " + _PrimitiveName + ":
timeDurationChargingResult must not be null");
+ throw new CAPException("Error while encoding " +
_PrimitiveName
+ + ": timeDurationChargingResult must not be
null");
try {
asnOs.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false,
_ID_timeDurationChargingResult);
@@ -187,4 +196,26 @@
return sb.toString();
}
+
+ /**
+ * XML Serialization/Deserialization
+ */
+ protected static final XMLFormat<ApplyChargingReportRequestImpl>
APPLY_CHARGING_REPORT_REQUEST_XML = new
XMLFormat<ApplyChargingReportRequestImpl>(
+ ApplyChargingReportRequestImpl.class) {
+
+ @Override
+ public void read(javolution.xml.XMLFormat.InputElement xml,
+ ApplyChargingReportRequestImpl applyChargingReportRequest) throws
XMLStreamException {
+ applyChargingReportRequest.timeDurationChargingResult =
xml.get(TIME_DURATION_CHARGING_RESULT,
+ TimeDurationChargingResultImpl.class);
+ }
+
+ @Override
+ public void write(ApplyChargingReportRequestImpl
applyChargingReportRequest,
+ javolution.xml.XMLFormat.OutputElement xml)
throws XMLStreamException {
+ xml.add((TimeDurationChargingResultImpl)
applyChargingReportRequest.timeDurationChargingResult,
+ TIME_DURATION_CHARGING_RESULT,
TimeDurationChargingResultImpl.class);
+ }
+ };
+
}
=======================================
---
/cap/cap-impl/src/main/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeDurationChargingResultImpl.java
Mon Apr 23 10:53:14 2012
+++
/cap/cap-impl/src/main/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeDurationChargingResultImpl.java
Fri Jan 25 02:22:47 2013
@@ -1,6 +1,6 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and individual contributors
+ * TeleStax, Open Source Cloud Communications
+ * Copyright 2012, Telestax Inc and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -24,6 +24,9 @@
import java.io.IOException;
+import javolution.xml.XMLFormat;
+import javolution.xml.stream.XMLStreamException;
+
import org.mobicents.protocols.asn.AsnException;
import org.mobicents.protocols.asn.AsnInputStream;
import org.mobicents.protocols.asn.AsnOutputStream;
@@ -44,17 +47,25 @@
/**
*
* @author sergey vetyutnev
+ * @author Amit Bhayani
*
*/
public class TimeDurationChargingResultImpl implements
TimeDurationChargingResult, CAPAsnPrimitive {
+ private static final String PARTY_TO_CHARGE = "partyToCharge";
+ private static final String TIME_INFORMATION = "timeInformation";
+ private static final String LEG_ACTIVE = "legActive";
+ private static final String CALL_LEG_RELEASED_AT_TCP_EXPIRY
= "callLegReleasedAtTcpExpiry";
+ private static final String EXTENSIONS = "extensions";
+ private static final String A_CH_CHARGING_ADDRESS =
"aChChargingAddress";
+
public static final int _ID_partyToCharge = 0;
public static final int _ID_timeInformation = 1;
public static final int _ID_legActive = 2;
public static final int _ID_callLegReleasedAtTcpExpiry = 3;
public static final int _ID_extensions = 4;
public static final int _ID_aChChargingAddress = 5;
-
+
public static final String _PrimitiveName =
"TimeDurationChargingResult";
private ReceivingSideID partyToCharge;
@@ -64,12 +75,12 @@
private CAPExtensions extensions;
private AChChargingAddress aChChargingAddress;
-
- public TimeDurationChargingResultImpl(){
+ public TimeDurationChargingResultImpl() {
}
-
- public TimeDurationChargingResultImpl(ReceivingSideID partyToCharge,
TimeInformation timeInformation, boolean legActive,
- boolean callLegReleasedAtTcpExpiry, CAPExtensions extensions,
AChChargingAddress aChChargingAddress) {
+
+ public TimeDurationChargingResultImpl(ReceivingSideID partyToCharge,
TimeInformation timeInformation,
+ boolean legActive, boolean callLegReleasedAtTcpExpiry, CAPExtensions
extensions,
+ AChChargingAddress aChChargingAddress) {
this.partyToCharge = partyToCharge;
this.timeInformation = timeInformation;
this.legActive = legActive;
@@ -77,7 +88,7 @@
this.extensions = extensions;
this.aChChargingAddress = aChChargingAddress;
}
-
+
@Override
public ReceivingSideID getPartyToCharge() {
return partyToCharge;
@@ -107,8 +118,7 @@
public AChChargingAddress getAChChargingAddress() {
return aChChargingAddress;
}
-
-
+
@Override
public int getTag() throws CAPException {
return Tag.SEQUENCE;
@@ -131,14 +141,14 @@
int length = ansIS.readLength();
this._decode(ansIS, length);
} catch (IOException e) {
- throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
} catch (AsnException e) {
- throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
} catch (MAPParsingComponentException e) {
- throw new CAPParsingComponentException("MAPParsingComponentException
when decoding " + _PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("MAPParsingComponentException
when decoding " + _PrimitiveName
+ + ": " + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
}
}
@@ -148,26 +158,28 @@
try {
this._decode(ansIS, length);
} catch (IOException e) {
- throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
} catch (AsnException e) {
- throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
} catch (MAPParsingComponentException e) {
- throw new CAPParsingComponentException("MAPParsingComponentException
when decoding " + _PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("MAPParsingComponentException
when decoding " + _PrimitiveName
+ + ": " + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
}
}
- private void _decode(AsnInputStream ansIS, int length) throws
CAPParsingComponentException, MAPParsingComponentException, IOException,
AsnException {
+ private void _decode(AsnInputStream ansIS, int length) throws
CAPParsingComponentException,
+ MAPParsingComponentException, IOException, AsnException
{
this.partyToCharge = null;
this.timeInformation = null;
this.legActive = true;
this.callLegReleasedAtTcpExpiry = false;
this.extensions = null;
- this.aChChargingAddress = null; // TODO: DEFAULT
legID:receivingSideID:leg1
-
+ this.aChChargingAddress = null; // TODO: DEFAULT
+
// legID:receivingSideID:leg1
+
AsnInputStream ais = ansIS.readSequenceStreamData(length);
while (true) {
if (ais.available() == 0)
@@ -181,13 +193,13 @@
AsnInputStream ais2 =
ais.readSequenceStream();
ais2.readTag();
this.partyToCharge = new
ReceivingSideIDImpl();
-
((ReceivingSideIDImpl)this.partyToCharge).decodeAll(ais2);
+ ((ReceivingSideIDImpl)
this.partyToCharge).decodeAll(ais2);
break;
case _ID_timeInformation:
ais2 = ais.readSequenceStream();
ais2.readTag();
this.timeInformation = new
TimeInformationImpl();
-
((TimeInformationImpl)this.timeInformation).decodeAll(ais2);
+ ((TimeInformationImpl)
this.timeInformation).decodeAll(ais2);
break;
case _ID_legActive:
this.legActive = ais.readBoolean();
@@ -214,7 +226,8 @@
}
if (this.partyToCharge == null || this.timeInformation == null)
- throw new CAPParsingComponentException("Error while decoding " +
_PrimitiveName + ": partyToCharge and timeInformation are mandatory but not
found",
+ throw new CAPParsingComponentException("Error while decoding " +
_PrimitiveName
+ + ": partyToCharge and timeInformation are
mandatory but not found",
CAPParsingComponentExceptionReason.MistypedParameter);
}
@@ -240,7 +253,8 @@
public void encodeData(AsnOutputStream aos) throws CAPException {
if (this.partyToCharge == null || this.timeInformation == null)
- throw new CAPException("Error while encoding " + _PrimitiveName + ":
partyToCharge and timeInformation must not be null");
+ throw new CAPException("Error while encoding " +
_PrimitiveName
+ + ": partyToCharge and timeInformation must
not be null");
try {
aos.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false,
_ID_partyToCharge);
@@ -306,5 +320,52 @@
return sb.toString();
}
+
+ /**
+ * XML Serialization/Deserialization
+ */
+ protected static final XMLFormat<TimeDurationChargingResultImpl>
TIME_DURATION_CHARGING_RESULT_XML = new
XMLFormat<TimeDurationChargingResultImpl>(
+ TimeDurationChargingResultImpl.class) {
+
+ @Override
+ public void read(javolution.xml.XMLFormat.InputElement xml,
+ TimeDurationChargingResultImpl timeDurationChargingResult) throws
XMLStreamException {
+ timeDurationChargingResult.partyToCharge = xml.get(PARTY_TO_CHARGE,
ReceivingSideIDImpl.class);
+ timeDurationChargingResult.timeInformation = xml.get(TIME_INFORMATION,
TimeInformationImpl.class);
+ timeDurationChargingResult.legActive = xml.get(LEG_ACTIVE,
Boolean.class);
+ timeDurationChargingResult.callLegReleasedAtTcpExpiry =
xml.get(CALL_LEG_RELEASED_AT_TCP_EXPIRY,
+ Boolean.class);
+
+ // TODO AChChargingAddressImpl is not yet implemented
+ // timeDurationChargingResult.aChChargingAddress = xml
+ // .get(A_CH_CHARGING_ADDRESS,
AChChargingAddressImpl.class);
+
+ timeDurationChargingResult.extensions = xml.get(EXTENSIONS,
CAPExtensionsImpl.class);
+
+ }
+
+ @Override
+ public void write(TimeDurationChargingResultImpl
timeDurationChargingResult,
+ javolution.xml.XMLFormat.OutputElement xml)
throws XMLStreamException {
+
+ xml.add((ReceivingSideIDImpl) timeDurationChargingResult.partyToCharge,
PARTY_TO_CHARGE,
+ ReceivingSideIDImpl.class);
+
+ xml.add((TimeInformationImpl)
timeDurationChargingResult.timeInformation, TIME_INFORMATION,
+ TimeInformationImpl.class);
+
+ xml.add(timeDurationChargingResult.legActive, LEG_ACTIVE,
Boolean.class);
+ xml.add(timeDurationChargingResult.callLegReleasedAtTcpExpiry,
CALL_LEG_RELEASED_AT_TCP_EXPIRY,
+ Boolean.class);
+
+ // TODO AChChargingAddressImpl is not yet implemented
+ // xml.add((AChChargingAddressImpl)
+ // timeDurationChargingResult.aChChargingAddress,
+ // A_CH_CHARGING_ADDRESS,
+ // AChChargingAddressImpl.class);
+
+ xml.add((CAPExtensionsImpl) timeDurationChargingResult.extensions,
EXTENSIONS, CAPExtensionsImpl.class);
+
+ }
+ };
}
-
=======================================
---
/cap/cap-impl/src/main/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeIfTariffSwitchImpl.java
Mon Apr 23 10:53:14 2012
+++
/cap/cap-impl/src/main/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeIfTariffSwitchImpl.java
Fri Jan 25 02:22:47 2013
@@ -1,6 +1,6 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and individual contributors
+ * TeleStax, Open Source Cloud Communications
+ * Copyright 2012, Telestax Inc and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -24,6 +24,9 @@
import java.io.IOException;
+import javolution.xml.XMLFormat;
+import javolution.xml.stream.XMLStreamException;
+
import org.mobicents.protocols.asn.AsnException;
import org.mobicents.protocols.asn.AsnInputStream;
import org.mobicents.protocols.asn.AsnOutputStream;
@@ -38,18 +41,21 @@
/**
*
* @author sergey vetyutnev
+ * @author Amit Bhayani
*
*/
public class TimeIfTariffSwitchImpl implements TimeIfTariffSwitch,
CAPAsnPrimitive {
+ private static final String TIME_SINCE_TARIFF_SWITCH
= "timeSinceTariffSwitch";
+ private static final String TARIFF_SWITCH_INTERVAL
= "tariffSwitchInterval";
+
public static final int _ID_timeSinceTariffSwitch = 0;
public static final int _ID_tariffSwitchInterval = 1;
public static final String _PrimitiveName = "TimeIfTariffSwitch";
private int timeSinceTariffSwitch;
- private Integer tariffSwitchInterval;
-
+ private Integer tariffSwitchInterval;
public TimeIfTariffSwitchImpl() {
}
@@ -91,14 +97,14 @@
int length = ansIS.readLength();
this._decode(ansIS, length);
} catch (IOException e) {
- throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
} catch (AsnException e) {
- throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
} catch (MAPParsingComponentException e) {
- throw new CAPParsingComponentException("MAPParsingComponentException
when decoding " + _PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("MAPParsingComponentException
when decoding " + _PrimitiveName
+ + ": " + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
}
}
@@ -108,22 +114,23 @@
try {
this._decode(ansIS, length);
} catch (IOException e) {
- throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
} catch (AsnException e) {
- throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
} catch (MAPParsingComponentException e) {
- throw new CAPParsingComponentException("MAPParsingComponentException
when decoding " + _PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("MAPParsingComponentException
when decoding " + _PrimitiveName
+ + ": " + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
}
}
- private void _decode(AsnInputStream ansIS, int length) throws
CAPParsingComponentException, MAPParsingComponentException, IOException,
AsnException {
+ private void _decode(AsnInputStream ansIS, int length) throws
CAPParsingComponentException,
+ MAPParsingComponentException, IOException, AsnException
{
this.timeSinceTariffSwitch = -1;
this.tariffSwitchInterval = null;
-
+
AsnInputStream ais = ansIS.readSequenceStreamData(length);
while (true) {
if (ais.available() == 0)
@@ -134,10 +141,10 @@
if (ais.getTagClass() == Tag.CLASS_CONTEXT_SPECIFIC) {
switch (tag) {
case _ID_timeSinceTariffSwitch:
- this.timeSinceTariffSwitch =
(int)ais.readInteger();
+ this.timeSinceTariffSwitch = (int)
ais.readInteger();
break;
case _ID_tariffSwitchInterval:
- this.tariffSwitchInterval =
(int)ais.readInteger();
+ this.tariffSwitchInterval = (int)
ais.readInteger();
break;
default:
@@ -150,7 +157,8 @@
}
if (this.timeSinceTariffSwitch == -1)
- throw new CAPParsingComponentException("Error while decoding " +
_PrimitiveName + ": timeSinceTariffSwitch is mandatory but not found",
+ throw new CAPParsingComponentException("Error while decoding " +
_PrimitiveName
+ + ": timeSinceTariffSwitch is mandatory but
not found",
CAPParsingComponentExceptionReason.MistypedParameter);
}
@@ -177,13 +185,15 @@
try {
if (this.timeSinceTariffSwitch < 0 || this.timeSinceTariffSwitch >
864000)
- throw new CAPException("Error while encoding " + _PrimitiveName + ":
timeSinceTariffSwitch must be from 0 to 864000");
-
+ throw new CAPException("Error while encoding "
+ _PrimitiveName
+ + ": timeSinceTariffSwitch must be
from 0 to 864000");
+
aos.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _ID_timeSinceTariffSwitch,
this.timeSinceTariffSwitch);
- if (this.tariffSwitchInterval != null){
+ if (this.tariffSwitchInterval != null) {
if (this.tariffSwitchInterval < 1 || this.tariffSwitchInterval >
864000)
- throw new CAPException("Error while encoding " + _PrimitiveName + ":
tariffSwitchInterval must be from 1 to 864000");
+ throw new CAPException("Error while encoding
" + _PrimitiveName
+ + ": tariffSwitchInterval
must be from 1 to 864000");
aos.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _ID_tariffSwitchInterval,
this.tariffSwitchInterval);
}
} catch (IOException e) {
@@ -211,4 +221,28 @@
return sb.toString();
}
+
+ /**
+ * XML Serialization/Deserialization
+ */
+ protected static final XMLFormat<TimeIfTariffSwitchImpl>
TIME_IF_TARIFF_SWITCH_XML = new XMLFormat<TimeIfTariffSwitchImpl>(
+ TimeIfTariffSwitchImpl.class) {
+
+ @Override
+ public void read(javolution.xml.XMLFormat.InputElement xml,
TimeIfTariffSwitchImpl timeIfTariffSwitch)
+ throws XMLStreamException {
+ timeIfTariffSwitch.timeSinceTariffSwitch =
xml.get(TIME_SINCE_TARIFF_SWITCH, Integer.class);
+ timeIfTariffSwitch.tariffSwitchInterval =
xml.get(TARIFF_SWITCH_INTERVAL, Integer.class);
+ }
+
+ @Override
+ public void write(TimeIfTariffSwitchImpl timeIfTariffSwitch,
javolution.xml.XMLFormat.OutputElement xml)
+ throws XMLStreamException {
+ xml.add(timeIfTariffSwitch.timeSinceTariffSwitch,
TIME_SINCE_TARIFF_SWITCH, Integer.class);
+
+ if (timeIfTariffSwitch.tariffSwitchInterval != null) {
+ xml.add(timeIfTariffSwitch.tariffSwitchInterval,
TARIFF_SWITCH_INTERVAL, Integer.class);
+ }
+ }
+ };
}
=======================================
---
/cap/cap-impl/src/main/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeInformationImpl.java
Mon Apr 23 10:53:14 2012
+++
/cap/cap-impl/src/main/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeInformationImpl.java
Fri Jan 25 02:22:47 2013
@@ -1,6 +1,6 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and individual contributors
+ * TeleStax, Open Source Cloud Communications
+ * Copyright 2012, Telestax Inc and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -24,6 +24,9 @@
import java.io.IOException;
+import javolution.xml.XMLFormat;
+import javolution.xml.stream.XMLStreamException;
+
import org.mobicents.protocols.asn.AsnException;
import org.mobicents.protocols.asn.AsnInputStream;
import org.mobicents.protocols.asn.AsnOutputStream;
@@ -39,10 +42,14 @@
/**
*
* @author sergey vetyutnev
+ * @author Amit Bhayani
*
*/
public class TimeInformationImpl implements TimeInformation,
CAPAsnPrimitive {
+ private static final String TIME_IF_NO_TARIFF_SWITCH
= "timeIfNoTariffSwitch";
+ private static final String TIME_IF_TARIFF_SWITCH =
"timeIfTariffSwitch";
+
public static final int _ID_timeIfNoTariffSwitch = 0;
public static final int _ID_timeIfTariffSwitch = 1;
@@ -50,7 +57,6 @@
private Integer timeIfNoTariffSwitch;
private TimeIfTariffSwitch timeIfTariffSwitch;
-
public TimeInformationImpl() {
}
@@ -73,7 +79,6 @@
return timeIfTariffSwitch;
}
-
@Override
public int getTag() throws CAPException {
if (timeIfNoTariffSwitch != null)
@@ -102,14 +107,14 @@
int length = ansIS.readLength();
this._decode(ansIS, length);
} catch (IOException e) {
- throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
} catch (AsnException e) {
- throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
} catch (MAPParsingComponentException e) {
- throw new CAPParsingComponentException("MAPParsingComponentException
when decoding " + _PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("MAPParsingComponentException
when decoding " + _PrimitiveName
+ + ": " + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
}
}
@@ -119,21 +124,22 @@
try {
this._decode(ansIS, length);
} catch (IOException e) {
- throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("IOException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
} catch (AsnException e) {
- throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("AsnException when decoding " +
_PrimitiveName + ": "
+ + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
} catch (MAPParsingComponentException e) {
- throw new CAPParsingComponentException("MAPParsingComponentException
when decoding " + _PrimitiveName + ": " + e.getMessage(), e,
-
CAPParsingComponentExceptionReason.MistypedParameter);
+ throw new CAPParsingComponentException("MAPParsingComponentException
when decoding " + _PrimitiveName
+ + ": " + e.getMessage(), e,
CAPParsingComponentExceptionReason.MistypedParameter);
}
}
- private void _decode(AsnInputStream ais, int length) throws
CAPParsingComponentException, MAPParsingComponentException, IOException,
AsnException {
+ private void _decode(AsnInputStream ais, int length) throws
CAPParsingComponentException,
+ MAPParsingComponentException, IOException, AsnException
{
this.timeIfNoTariffSwitch = null;
- this.timeIfTariffSwitch = null;
+ this.timeIfTariffSwitch = null;
int tag = ais.getTag();
@@ -179,12 +185,14 @@
public void encodeData(AsnOutputStream aos) throws CAPException {
if (this.timeIfNoTariffSwitch == null &&
this.timeIfTariffSwitch == null)
- throw new CAPException("Error while encoding " + _PrimitiveName + ":
both timeIfNoTariffSwitch and this.timeIfTariffSwitch must not be null");
+ throw new CAPException("Error while encoding " +
_PrimitiveName
+ + ": both timeIfNoTariffSwitch and this.timeIfTariffSwitch must not
be null");
try {
if (this.timeIfNoTariffSwitch != null) {
if (this.timeIfNoTariffSwitch < 0 || this.timeIfNoTariffSwitch >
864000)
- throw new CAPException("Error while encoding " + _PrimitiveName + ":
timeIfNoTariffSwitch must be from 0 to 864000");
+ throw new CAPException("Error while encoding
" + _PrimitiveName
+ + ": timeIfNoTariffSwitch
must be from 0 to 864000");
aos.writeIntegerData(this.timeIfNoTariffSwitch);
} else {
((TimeIfTariffSwitchImpl)
this.timeIfTariffSwitch).encodeData(aos);
@@ -214,4 +222,32 @@
return sb.toString();
}
+
+ /**
+ * XML Serialization/Deserialization
+ */
+ protected static final XMLFormat<TimeInformationImpl>
TIME_INFORMATION_XML = new XMLFormat<TimeInformationImpl>(
+ TimeInformationImpl.class) {
+
+ @Override
+ public void read(javolution.xml.XMLFormat.InputElement xml,
TimeInformationImpl timeInformation)
+ throws XMLStreamException {
+ timeInformation.timeIfNoTariffSwitch =
xml.get(TIME_IF_NO_TARIFF_SWITCH, Integer.class);
+ timeInformation.timeIfTariffSwitch = xml.get(TIME_IF_TARIFF_SWITCH,
TimeIfTariffSwitchImpl.class);
+ }
+
+ @Override
+ public void write(TimeInformationImpl timeInformation,
javolution.xml.XMLFormat.OutputElement xml)
+ throws XMLStreamException {
+
+ if (timeInformation.timeIfNoTariffSwitch != null) {
+ xml.add(timeInformation.timeIfNoTariffSwitch,
TIME_IF_NO_TARIFF_SWITCH, Integer.class);
+ }
+
+ if (timeInformation.timeIfTariffSwitch != null) {
+ xml.add((TimeIfTariffSwitchImpl) timeInformation.timeIfTariffSwitch,
TIME_IF_TARIFF_SWITCH,
+ TimeIfTariffSwitchImpl.class);
+ }
+ }
+ };
}
=======================================
---
/cap/cap-impl/src/test/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/ApplyChargingReportRequestTest.java
Wed May 16 05:00:01 2012
+++
/cap/cap-impl/src/test/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/ApplyChargingReportRequestTest.java
Fri Jan 25 02:22:47 2013
@@ -1,6 +1,6 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and individual contributors
+ * TeleStax, Open Source Cloud Communications
+ * Copyright 2012, Telestax Inc and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -22,30 +22,40 @@
package org.mobicents.protocols.ss7.cap.service.circuitSwitchedCall;
-import static org.testng.Assert.*;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.util.Arrays;
+import javolution.xml.XMLObjectReader;
+import javolution.xml.XMLObjectWriter;
+
import org.mobicents.protocols.asn.AsnInputStream;
import org.mobicents.protocols.asn.AsnOutputStream;
import org.mobicents.protocols.ss7.cap.primitives.ReceivingSideIDImpl;
import
org.mobicents.protocols.ss7.cap.service.circuitSwitchedCall.primitive.TimeDurationChargingResultImpl;
import
org.mobicents.protocols.ss7.cap.service.circuitSwitchedCall.primitive.TimeInformationImpl;
import org.mobicents.protocols.ss7.inap.api.primitives.LegType;
-import org.testng.*;import org.testng.annotations.*;
+import org.testng.annotations.Test;
/**
*
* @author sergey vetyutnev
+ * @author Amit Bhayani
*
*/
public class ApplyChargingReportRequestTest {
public byte[] getData1() {
- return new byte[] { 4, 15, (byte) 160, 13, (byte) 160, 3, (byte) 129, 1,
1, (byte) 161, 3, (byte) 128, 1, 26, (byte) 130, 1, 0 };
+ return new byte[] { 4, 15, (byte) 160, 13, (byte) 160, 3, (byte) 129, 1,
1, (byte) 161, 3, (byte) 128, 1, 26,
+ (byte) 130, 1, 0 };
}
- @Test(groups = { "functional.decode","circuitSwitchedCall"})
+ @Test(groups = { "functional.decode", "circuitSwitchedCall" })
public void testDecode() throws Exception {
byte[] data = this.getData1();
@@ -53,7 +63,7 @@
ApplyChargingReportRequestImpl elem = new
ApplyChargingReportRequestImpl();
int tag = ais.readTag();
elem.decodeAll(ais);
-
+
assertEquals(elem.getTimeDurationChargingResult().getPartyToCharge().getReceivingSideID(),
LegType.leg1);
assertEquals((int)
elem.getTimeDurationChargingResult().getTimeInformation().getTimeIfNoTariffSwitch(),
26);
assertFalse(elem.getTimeDurationChargingResult().getLegActive());
@@ -62,19 +72,55 @@
assertNull(elem.getTimeDurationChargingResult().getAChChargingAddress());
}
- @Test(groups = { "functional.encode","circuitSwitchedCall"})
+ @Test(groups = { "functional.encode", "circuitSwitchedCall" })
public void testEncode() throws Exception {
ReceivingSideIDImpl partyToCharge = new
ReceivingSideIDImpl(LegType.leg1);
TimeInformationImpl timeInformation = new
TimeInformationImpl(26);
- TimeDurationChargingResultImpl timeDurationChargingResult = new
TimeDurationChargingResultImpl(partyToCharge, timeInformation, false,
false, null, null);
-// ReceivingSideID partyToCharge, TimeInformation timeInformation,
boolean legActive,
-// boolean callLegReleasedAtTcpExpiry, CAPExtensions extensions,
AChChargingAddress aChChargingAddress
+ TimeDurationChargingResultImpl timeDurationChargingResult = new
TimeDurationChargingResultImpl(partyToCharge,
+ timeInformation, false, false, null, null);
+ // ReceivingSideID partyToCharge, TimeInformation
timeInformation,
+ // boolean legActive,
+ // boolean callLegReleasedAtTcpExpiry, CAPExtensions extensions,
+ // AChChargingAddress aChChargingAddress
ApplyChargingReportRequestImpl elem = new
ApplyChargingReportRequestImpl(timeDurationChargingResult);
AsnOutputStream aos = new AsnOutputStream();
elem.encodeAll(aos);
assertTrue(Arrays.equals(aos.toByteArray(), this.getData1()));
}
-}
+ @Test(groups = { "functional.xml.serialize", "circuitSwitchedCall" })
+ public void testXMLSerializaion() throws Exception {
+
+ ReceivingSideIDImpl partyToCharge = new
ReceivingSideIDImpl(LegType.leg1);
+ TimeInformationImpl timeInformation = new
TimeInformationImpl(26);
+ TimeDurationChargingResultImpl timeDurationChargingResult = new
TimeDurationChargingResultImpl(partyToCharge,
+ timeInformation, false, false, null, null);
+
+ ApplyChargingReportRequestImpl original = new
ApplyChargingReportRequestImpl(timeDurationChargingResult);
+
+ // 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, "applyChargingReportRequest",
ApplyChargingReportRequestImpl.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);
+ ApplyChargingReportRequestImpl copy =
reader.read("applyChargingReportRequest",
+ ApplyChargingReportRequestImpl.class);
+
+
assertEquals(copy.getTimeDurationChargingResult().getPartyToCharge().getReceivingSideID(),
original
+
.getTimeDurationChargingResult().getPartyToCharge().getReceivingSideID());
+
+ }
+}
=======================================
---
/cap/cap-impl/src/test/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeDurationChargingResultTest.java
Mon Apr 23 10:53:14 2012
+++
/cap/cap-impl/src/test/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeDurationChargingResultTest.java
Fri Jan 25 02:22:47 2013
@@ -1,6 +1,6 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and individual contributors
+ * TeleStax, Open Source Cloud Communications
+ * Copyright 2012, Telestax Inc and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -22,10 +22,18 @@
package
org.mobicents.protocols.ss7.cap.service.circuitSwitchedCall.primitive;
-import static org.testng.Assert.*;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.util.Arrays;
+import javolution.xml.XMLObjectReader;
+import javolution.xml.XMLObjectWriter;
+
import org.mobicents.protocols.asn.AsnInputStream;
import org.mobicents.protocols.asn.AsnOutputStream;
import org.mobicents.protocols.asn.Tag;
@@ -34,25 +42,28 @@
import org.mobicents.protocols.ss7.cap.primitives.CAPExtensionsTest;
import org.mobicents.protocols.ss7.cap.primitives.ReceivingSideIDImpl;
import org.mobicents.protocols.ss7.inap.api.primitives.LegType;
-import org.testng.*;import org.testng.annotations.*;
+import org.testng.annotations.Test;
/**
*
* @author sergey vetyutnev
+ * @author Amit Bhayani
*
*/
public class TimeDurationChargingResultTest {
public byte[] getData1() {
- return new byte[] { (byte) 160, 13, (byte) 160, 3, (byte) 129, 1, 1,
(byte) 161, 3, (byte) 128, 1, 26, (byte) 130, 1, 0 };
+ return new byte[] { (byte) 160, 13, (byte) 160, 3, (byte) 129, 1, 1,
(byte) 161, 3, (byte) 128, 1, 26,
+ (byte) 130, 1, 0 };
}
public byte[] getData2() {
- return new byte[] { (byte) 160, 32, (byte) 160, 3, (byte) 129, 1, 2,
(byte) 161, 3, (byte) 128, 1, 55, (byte) 131, 0, (byte) 164, 18, 48, 5, 2,
1, 2,
- (byte) 129, 0, 48, 9, 2, 1, 3, 10, 1, 1, (byte)
129, 1, (byte) 255 };
+ return new byte[] { (byte) 160, 32, (byte) 160, 3, (byte) 129, 1, 2,
(byte) 161, 3, (byte) 128, 1, 55,
+ (byte) 131, 0, (byte) 164, 18, 48, 5, 2, 1, 2, (byte) 129, 0, 48, 9,
2, 1, 3, 10, 1, 1, (byte) 129, 1,
+ (byte) 255 };
}
- @Test(groups = { "functional.decode","circuitSwitchedCall.primitive"})
+ @Test(groups = { "functional.decode", "circuitSwitchedCall.primitive" })
public void testDecode() throws Exception {
byte[] data = this.getData1();
@@ -80,26 +91,63 @@
assertNull(elem.getAChChargingAddress());
}
- @Test(groups = { "functional.encode","circuitSwitchedCall.primitive"})
+ @Test(groups = { "functional.encode", "circuitSwitchedCall.primitive" })
public void testEncode() throws Exception {
ReceivingSideID partyToCharge = new
ReceivingSideIDImpl(LegType.leg1);
TimeInformation ti = new TimeInformationImpl(26);
- TimeDurationChargingResultImpl elem = new
TimeDurationChargingResultImpl(partyToCharge, ti, false, false, null, null);
- // ReceivingSideID partyToCharge, TimeInformation timeInformation,
boolean legActive,
- // boolean callLegReleasedAtTcpExpiry, CAPExtensions extensions,
AChChargingAddress aChChargingAddress
+ TimeDurationChargingResultImpl elem = new
TimeDurationChargingResultImpl(partyToCharge, ti, false, false, null,
+ null);
+ // ReceivingSideID partyToCharge, TimeInformation
timeInformation,
+ // boolean legActive,
+ // boolean callLegReleasedAtTcpExpiry, CAPExtensions extensions,
+ // AChChargingAddress aChChargingAddress
AsnOutputStream aos = new AsnOutputStream();
elem.encodeAll(aos, Tag.CLASS_CONTEXT_SPECIFIC, 0);
assertTrue(Arrays.equals(aos.toByteArray(), this.getData1()));
partyToCharge = new ReceivingSideIDImpl(LegType.leg2);
ti = new TimeInformationImpl(55);
- elem = new TimeDurationChargingResultImpl(partyToCharge, ti, true, true,
CAPExtensionsTest.createTestCAPExtensions(), null);
- // ReceivingSideID partyToCharge, TimeInformation timeInformation,
boolean legActive,
- // boolean callLegReleasedAtTcpExpiry, CAPExtensions extensions,
AChChargingAddress aChChargingAddress
+ elem = new TimeDurationChargingResultImpl(partyToCharge, ti,
true, true,
+ CAPExtensionsTest.createTestCAPExtensions(),
null);
+ // ReceivingSideID partyToCharge, TimeInformation
timeInformation,
+ // boolean legActive,
+ // boolean callLegReleasedAtTcpExpiry, CAPExtensions extensions,
+ // AChChargingAddress aChChargingAddress
aos = new AsnOutputStream();
elem.encodeAll(aos, Tag.CLASS_CONTEXT_SPECIFIC, 0);
assertTrue(Arrays.equals(aos.toByteArray(), this.getData2()));
}
+
+ @Test(groups = { "functional.xml.serialize", "circuitSwitchedCall" })
+ public void testXMLSerializaion() throws Exception {
+ ReceivingSideID partyToCharge = new
ReceivingSideIDImpl(LegType.leg1);
+ TimeInformation ti = new TimeInformationImpl(26);
+ TimeDurationChargingResultImpl original = new
TimeDurationChargingResultImpl(partyToCharge, ti, false, false,
+ null, null);
+
+ // 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, "timeDurationChargingResult",
TimeDurationChargingResultImpl.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);
+ TimeDurationChargingResultImpl copy =
reader.read("timeDurationChargingResult",
+ TimeDurationChargingResultImpl.class);
+
+ assertEquals(copy.getPartyToCharge().getReceivingSideID(),
original.getPartyToCharge().getReceivingSideID());
+ assertEquals(copy.getTimeInformation().getTimeIfNoTariffSwitch(),
original.getTimeInformation()
+ .getTimeIfNoTariffSwitch());
+
+ }
}
-
=======================================
---
/cap/cap-impl/src/test/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeIfTariffSwitchTest.java
Mon Apr 23 10:53:14 2012
+++
/cap/cap-impl/src/test/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeIfTariffSwitchTest.java
Fri Jan 25 02:22:47 2013
@@ -1,6 +1,6 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and individual contributors
+ * TeleStax, Open Source Cloud Communications
+ * Copyright 2012, Telestax Inc and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -22,17 +22,24 @@
package
org.mobicents.protocols.ss7.cap.service.circuitSwitchedCall.primitive;
-import static org.testng.Assert.*;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.util.Arrays;
+import javolution.xml.XMLObjectReader;
+import javolution.xml.XMLObjectWriter;
+
import org.mobicents.protocols.asn.AsnInputStream;
import org.mobicents.protocols.asn.AsnOutputStream;
-import org.testng.*;import org.testng.annotations.*;
+import org.testng.annotations.Test;
/**
*
* @author sergey vetyutnev
+ * @author Amit Bhayani
*
*/
public class TimeIfTariffSwitchTest {
@@ -41,7 +48,7 @@
return new byte[] { 48, 6, (byte) 128, 1, 11, (byte) 129, 1, 22
};
}
- @Test(groups = { "functional.decode","circuitSwitchedCall.primitive"})
+ @Test(groups = { "functional.decode", "circuitSwitchedCall.primitive" })
public void testDecode() throws Exception {
byte[] data = this.getData1();
@@ -50,10 +57,10 @@
int tag = ais.readTag();
elem.decodeAll(ais);
assertEquals(elem.getTimeSinceTariffSwitch(), 11);
- assertEquals((int)elem.getTariffSwitchInterval(), 22);
+ assertEquals((int) elem.getTariffSwitchInterval(), 22);
}
- @Test(groups = { "functional.encode","circuitSwitchedCall.primitive"})
+ @Test(groups = { "functional.encode", "circuitSwitchedCall.primitive" })
public void testEncode() throws Exception {
TimeIfTariffSwitchImpl elem = new TimeIfTariffSwitchImpl(11,
22);
@@ -61,4 +68,31 @@
elem.encodeAll(aos);
assertTrue(Arrays.equals(aos.toByteArray(), this.getData1()));
}
+
+ @Test(groups = { "functional.xml.serialize", "circuitSwitchedCall" })
+ public void testXMLSerializaion() throws Exception {
+ TimeIfTariffSwitchImpl original = new
TimeIfTariffSwitchImpl(11, 22);
+
+ // 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, "timeIfTariffSwitch",
TimeIfTariffSwitchImpl.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);
+ TimeIfTariffSwitchImpl copy = reader.read("timeIfTariffSwitch",
TimeIfTariffSwitchImpl.class);
+
+ assertEquals(copy.getTimeSinceTariffSwitch(),
original.getTimeSinceTariffSwitch());
+ assertEquals(copy.getTariffSwitchInterval(),
original.getTariffSwitchInterval());
+
+ }
}
=======================================
---
/cap/cap-impl/src/test/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeInformationTest.java
Mon Apr 23 10:53:14 2012
+++
/cap/cap-impl/src/test/java/org/mobicents/protocols/ss7/cap/service/circuitSwitchedCall/primitive/TimeInformationTest.java
Fri Jan 25 02:22:47 2013
@@ -1,6 +1,6 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and individual contributors
+ * TeleStax, Open Source Cloud Communications
+ * Copyright 2012, Telestax Inc and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -22,17 +22,25 @@
package
org.mobicents.protocols.ss7.cap.service.circuitSwitchedCall.primitive;
-import static org.testng.Assert.*;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.util.Arrays;
+import javolution.xml.XMLObjectReader;
+import javolution.xml.XMLObjectWriter;
+
import org.mobicents.protocols.asn.AsnInputStream;
import org.mobicents.protocols.asn.AsnOutputStream;
-import org.testng.*;import org.testng.annotations.*;
+import org.testng.annotations.Test;
/**
*
* @author sergey vetyutnev
+ * @author Amit Bhayani
*
*/
public class TimeInformationTest {
@@ -45,7 +53,7 @@
return new byte[] { (byte) 161, 4, (byte) 128, 2, 3, (byte) 232
};
}
- @Test(groups = { "functional.decode","circuitSwitchedCall.primitive"})
+ @Test(groups = { "functional.decode", "circuitSwitchedCall.primitive" })
public void testDecode() throws Exception {
byte[] data = this.getData1();
@@ -64,7 +72,7 @@
assertNull(elem.getTimeIfTariffSwitch().getTariffSwitchInterval());
}
- @Test(groups = { "functional.encode","circuitSwitchedCall.primitive"})
+ @Test(groups = { "functional.encode", "circuitSwitchedCall.primitive" })
public void testEncode() throws Exception {
TimeInformationImpl elem = new TimeInformationImpl(26);
@@ -78,5 +86,55 @@
elem.encodeAll(aos);
assertTrue(Arrays.equals(aos.toByteArray(), this.getData2()));
}
-}
+ @Test(groups = { "functional.xml.serialize", "circuitSwitchedCall" })
+ public void testXMLSerializaion() throws Exception {
+ TimeInformationImpl original = new TimeInformationImpl(26);
+
+ // 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, "timeInformation",
TimeInformationImpl.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);
+ TimeInformationImpl copy = reader.read("timeInformation",
TimeInformationImpl.class);
+
+ assertEquals(copy.getTimeIfNoTariffSwitch(),
original.getTimeIfNoTariffSwitch());
+ assertNull(copy.getTimeIfTariffSwitch());
+
+ TimeIfTariffSwitchImpl tit = new TimeIfTariffSwitchImpl(1000,
null);
+ original = new TimeInformationImpl(tit);
+
+ baos = new ByteArrayOutputStream();
+ writer = XMLObjectWriter.newInstance(baos);
+ // writer.setBinding(binding); // Optional.
+ writer.setIndentation("\t"); // Optional (use tabulation for
+
// indentation).
+ writer.write(original, "timeInformation",
TimeInformationImpl.class);
+ writer.close();
+
+ rawData = baos.toByteArray();
+
+ serializedEvent = new String(rawData);
+
+ System.out.println(serializedEvent);
+
+ bais = new ByteArrayInputStream(rawData);
+ reader = XMLObjectReader.newInstance(bais);
+ copy = reader.read("timeInformation",
TimeInformationImpl.class);
+
+ assertEquals(copy.getTimeIfTariffSwitch().getTariffSwitchInterval(),
original.getTimeIfTariffSwitch()
+ .getTariffSwitchInterval());
+ assertNull(copy.getTimeIfNoTariffSwitch());
+ }
+}
--