Index: src/main/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshaler.java
===================================================================
--- src/main/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshaler.java (revision 738572)
+++ src/main/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshaler.java (working copy)
@@ -27,6 +27,7 @@
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.jsmpp.bean.MessageRequest;
import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.SMSCDeliveryReceipt;
import org.jsmpp.bean.SubmitSm;
import org.jsmpp.bean.TypeOfNumber;
import org.w3c.dom.Document;
@@ -37,19 +38,21 @@
*
* @author jbonofre
* @author lhein
+ * @author mullerc
*/
public class DefaultSmppMarshaler implements SmppMarshalerSupport {
- // logging facility
private static final transient Log log = LogFactory.getLog(DefaultSmppMarshaler.class);
- // message tags
private final static String TAG_MESSAGE = "message";
private final static String TAG_SOURCE = "source";
private final static String TAG_DESTINATION = "destination";
private final static String TAG_TEXT = "text";
private final static String TAG_TON = "ton";
private final static String TAG_NPI = "npi";
+ private final static String TAG_REGISTERED_DELIVERY = "registeredDelivery";
+ private final static String TAG_SCHEDULE_DELIVERY_TIME = "scheduleDeliveryTime";
+ private final static String TAG_VALIDITY_PERIOD = "validityPeriod";
private final static String TAG_MESSAGE_OPEN = "<" + TAG_MESSAGE + ">";
private final static String TAG_MESSAGE_CLOSE = "" + TAG_MESSAGE + ">";
@@ -63,86 +66,100 @@
private final static String TAG_TON_CLOSE = "" + TAG_TON + ">";
private final static String TAG_NPI_OPEN = "<" + TAG_NPI + ">";
private final static String TAG_NPI_CLOSE = "" + TAG_NPI + ">";
-
- // source transformer
+ private final static String TAG_REGISTERED_DELIVERY_OPEN = "<" + TAG_REGISTERED_DELIVERY + ">";
+ private final static String TAG_REGISTERED_DELIVERY_CLOSE = "" + TAG_REGISTERED_DELIVERY + ">";
+ private final static String TAG_SCHEDULE_DELIVERY_TIME_OPEN = "<" + TAG_SCHEDULE_DELIVERY_TIME + ">";
+ private final static String TAG_SCHEDULE_DELIVERY_TIME_CLOSE = "" + TAG_SCHEDULE_DELIVERY_TIME + ">";
+ private final static String TAG_VALIDITY_PERIOD_OPEN = "<" + TAG_VALIDITY_PERIOD + ">";
+ private final static String TAG_VALIDITY_PERIOD_CLOSE = "" + TAG_VALIDITY_PERIOD + ">";
+
private SourceTransformer transformer = new SourceTransformer();
/*
* (non-Javadoc)
* @see org.apache.servicemix.smpp.marshaler.SmppMarshalerSupport#fromNMS(javax.jbi.messaging.MessageExchange, javax.jbi.messaging.NormalizedMessage)
*/
- public MessageRequest fromNMS(MessageExchange exchange, NormalizedMessage message)
- throws TransformerException {
+ public MessageRequest fromNMS(MessageExchange exchange, NormalizedMessage message) throws TransformerException {
SubmitSm sm = new SubmitSm();
String ton = null;
String npi = null;
+
try {
- log.debug("Convert normalized message content to DOM document");
Document document = transformer.toDOMDocument(message);
- log.debug("Normalize test representation");
document.getDocumentElement().normalize();
- log.debug("Get the normalized message source");
- NodeList node = document.getElementsByTagName(TAG_SOURCE);
- if (node != null && node.getLength() > 0) {
- log.debug("The source exists in the normalized message");
- sm.setSourceAddr(node.item(0).getChildNodes().item(0).getNodeValue());
+ NodeList node = null;
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_SOURCE)) != null) {
+ sm.setSourceAddr(getFirstNodeValue(node));
log.debug(TAG_SOURCE + ": " + sm.getSourceAddr());
}
- log.debug("Get the normalized message destination");
- node = document.getElementsByTagName(TAG_DESTINATION);
- if (node != null && node.getLength() > 0) {
- log.debug("The destination exists in the normalized message");
- sm.setDestAddress(node.item(0).getChildNodes().item(0).getNodeValue());
- log.debug(TAG_DESTINATION + ": " + sm.getDestAddress());
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_DESTINATION)) != null) {
+ sm.setDestAddress(getFirstNodeValue(node));
+ log.debug(TAG_DESTINATION + ": " + sm.getDestAddress());
}
- log.debug("Get the normalized message text");
- node = document.getElementsByTagName(TAG_TEXT);
- if (node != null && node.getLength() > 0) {
- log.debug("The text exists in the normalized message");
- sm.setShortMessage(node.item(0).getChildNodes().item(0).getNodeValue().getBytes());
- log.debug(TAG_TEXT + ": " + new String(sm.getShortMessage()));
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_TEXT)) != null) {
+ sm.setShortMessage(getFirstNodeValue(node).getBytes());
+ log.debug(TAG_TEXT + ": " + new String(sm.getShortMessage()));
}
- log.debug("Get the normalized message TON");
- node = document.getElementsByTagName(TAG_TON);
- if (node != null && node.getLength() > 0) {
- log.debug("The TON exists in the normalized message");
- ton = node.item(0).getChildNodes().item(0).getNodeValue();
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_TON)) != null) {
+ ton = getFirstNodeValue(node);
sm.setDestAddrTon(TypeOfNumber.valueOf(ton).value());
sm.setSourceAddrTon(TypeOfNumber.valueOf(ton).value());
log.debug(TAG_TON + ": " + ton);
}
- log.debug("Get the normalized message NPI");
- node = document.getElementsByTagName(TAG_NPI);
- if (node != null && node.getLength() > 0) {
- log.debug("The NPI exists in the normalized message");
- npi = node.item(0).getChildNodes().item(0).getNodeValue();
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_NPI)) != null) {
+ npi = getFirstNodeValue(node);
sm.setDestAddrNpi(NumberingPlanIndicator.valueOf(npi).value());
sm.setSourceAddrNpi(NumberingPlanIndicator.valueOf(npi).value());
log.debug(TAG_NPI + ": " + npi);
}
-
- log.debug("Check the mandatory attribute 'source'");
- if (sm.getSourceAddr() == null) {
- throw new TransformerException("Invalid message content. Missing tag: " + TAG_SOURCE);
- }
- log.debug("Check the mandatory attribute 'destination'");
- if (sm.getDestAddress() == null) {
- throw new TransformerException("Invalid message content. Missing tag: " + TAG_DESTINATION);
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_REGISTERED_DELIVERY)) != null) {
+ String registeredDelivery = getFirstNodeValue(node);
+ sm.setRegisteredDelivery(SMSCDeliveryReceipt.valueOf(registeredDelivery).value());
+ log.debug(TAG_REGISTERED_DELIVERY + ": " + registeredDelivery);
+ } else {
+ sm.setRegisteredDelivery(SMSCDeliveryReceipt.DEFAULT.value());
+ log.debug(TAG_REGISTERED_DELIVERY + ": DEFAULT");
}
- log.debug("Check the mandatory attribute 'ton'");
- if (ton == null) {
- throw new TransformerException("Invalid message content. Missing tag: " + TAG_TON);
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_SCHEDULE_DELIVERY_TIME)) != null) {
+ sm.setScheduleDeliveryTime(getFirstNodeValue(node));
+ log.debug(TAG_SCHEDULE_DELIVERY_TIME + ": " + sm.getScheduleDeliveryTime());
}
- if (npi == null) {
- throw new TransformerException("Invalid message content. Missing tag: " + TAG_NPI);
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_VALIDITY_PERIOD)) != null) {
+ sm.setValidityPeriod(getFirstNodeValue(node));
+ log.debug(TAG_VALIDITY_PERIOD + ": " + sm.getValidityPeriod());
}
} catch (Exception exception) {
throw new TransformerException(exception);
}
+
+ if (sm.getSourceAddr() == null) {
+ throw new TransformerException("Invalid message content. Missing tag: " + TAG_SOURCE);
+ }
+
+ if (sm.getDestAddress() == null) {
+ throw new TransformerException("Invalid message content. Missing tag: " + TAG_DESTINATION);
+ }
+
+ if (ton == null) {
+ throw new TransformerException("Invalid message content. Missing tag: " + TAG_TON);
+ }
+
+ if (npi == null) {
+ throw new TransformerException("Invalid message content. Missing tag: " + TAG_NPI);
+ }
+
return sm;
}
- /*
+ /*
* (non-Javadoc)
* @see org.apache.servicemix.smpp.marshaler.SmppMarshalerSupport#toNMS(javax.jbi.messaging.NormalizedMessage, org.jsmpp.bean.MessageRequest)
*/
@@ -150,76 +167,115 @@
if (message == null) {
throw new MessagingException("The NormalizedMessage is null");
}
+
if (mr == null) {
throw new MessagingException("The MessageRequest is null");
}
- log.debug("Check if the MessageRequest is valid");
- log.debug("Check the MessageRequest source address");
if (mr.getSourceAddr() == null || mr.getSourceAddr().trim().length() < 1) {
log.error("The MessageRequest source address is not defined");
throw new MessagingException("The MessageRequest source address is not defined");
}
- log.debug("Check the MessageRequest destination address");
+
if (mr.getDestAddress() == null || mr.getDestAddress().trim().length() < 1) {
log.error("The MessageRequest destination address is not defined");
throw new MessagingException("The MessageRequest destination address is not defined");
}
- log.debug("Check the MessageRequest destination numbering plan indicator");
+
try {
NumberingPlanIndicator.valueOf(mr.getDestAddrNpi());
} catch (IllegalArgumentException illegalArgumentException) {
log.error("The MessageRequest destination numbering plan indicator is not valid");
- throw new MessagingException(
- "The MessageRequest destination numbering plan indicator is not valid");
+ throw new MessagingException("The MessageRequest destination numbering plan indicator is not valid");
}
- log.debug("Check the MessageRequest destination type of numbner");
+
try {
TypeOfNumber.valueOf(mr.getDestAddrTon());
} catch (IllegalArgumentException illegalArgumentException) {
log.error("The MessageRequest destination type of number is not valid");
throw new MessagingException("The MessageRequest destination type of number is not valid");
}
-
- String text = null;
+
try {
- text = new String(mr.getShortMessage());
- } catch (NullPointerException exception) {
- log.warn("The MessageRequest Short Message is null");
+ determineSMSCDeliveryReceipt(mr.getRegisteredDelivery());
+ } catch (IllegalArgumentException illegalArgumentException) {
+ log.error("The MessageRequest registered delivery is not valid");
+ throw new MessagingException("The MessageRequest registered delivery is not valid");
+ }
+
+ if (mr.getShortMessage() == null || mr.getShortMessage().length == 0) {
+ log.warn("Received message without text content. Ignore the message");
+ return;
}
- if (text != null && text.trim().length() > 0) {
- StringBuffer data = new StringBuffer();
+ StringBuffer data = new StringBuffer();
+ data.append(TAG_MESSAGE_OPEN);
- // build the message content
- data.append(TAG_MESSAGE_OPEN);
+ data.append(TAG_SOURCE_OPEN);
+ data.append(mr.getSourceAddr());
+ data.append(TAG_SOURCE_CLOSE);
- data.append(TAG_SOURCE_OPEN);
- data.append(mr.getSourceAddr());
- data.append(TAG_SOURCE_CLOSE);
+ data.append(TAG_DESTINATION_OPEN);
+ data.append(mr.getDestAddress());
+ data.append(TAG_DESTINATION_CLOSE);
- data.append(TAG_DESTINATION_OPEN);
- data.append(mr.getDestAddress());
- data.append(TAG_DESTINATION_CLOSE);
+ data.append(TAG_TEXT_OPEN);
+ data.append(new String(mr.getShortMessage()));
+ data.append(TAG_TEXT_CLOSE);
- data.append(TAG_TEXT_OPEN);
- data.append(text);
- data.append(TAG_TEXT_CLOSE);
+ data.append(TAG_NPI_OPEN);
+ data.append(NumberingPlanIndicator.valueOf(mr.getDestAddrNpi()).toString());
+ data.append(TAG_NPI_CLOSE);
- data.append(TAG_NPI_OPEN);
- data.append(NumberingPlanIndicator.valueOf(mr.getDestAddrNpi()).toString());
- data.append(TAG_NPI_CLOSE);
+ data.append(TAG_TON_OPEN);
+ data.append(TypeOfNumber.valueOf(mr.getDestAddrTon()).toString());
+ data.append(TAG_TON_CLOSE);
+
+ data.append(TAG_REGISTERED_DELIVERY_OPEN);
+ data.append(determineSMSCDeliveryReceipt(mr.getRegisteredDelivery()).toString());
+ data.append(TAG_REGISTERED_DELIVERY_CLOSE);
+
+ if (mr.getScheduleDeliveryTime() != null && mr.getScheduleDeliveryTime().trim().length() > 0) {
+ data.append(TAG_SCHEDULE_DELIVERY_TIME_OPEN);
+ data.append(mr.getScheduleDeliveryTime());
+ data.append(TAG_SCHEDULE_DELIVERY_TIME_CLOSE);
+ }
- data.append(TAG_TON_OPEN);
- data.append(TypeOfNumber.valueOf(mr.getDestAddrTon()).toString());
- data.append(TAG_TON_CLOSE);
+ if (mr.getValidityPeriod() != null && mr.getValidityPeriod().trim().length() > 0) {
+ data.append(TAG_VALIDITY_PERIOD_OPEN);
+ data.append(mr.getValidityPeriod());
+ data.append(TAG_VALIDITY_PERIOD_CLOSE);
+ }
+
+ data.append(TAG_MESSAGE_CLOSE);
- data.append(TAG_MESSAGE_CLOSE);
-
- // put the content to message body
- message.setContent(new StringSource(data.toString()));
- } else {
- log.debug("Received message without text content. Ignore the message");
- }
+ message.setContent(new StringSource(data.toString()));
+ }
+
+ private String getFirstNodeValue(NodeList node) {
+ return node.item(0).getChildNodes().item(0).getNodeValue();
+ }
+
+ private NodeList getNotEmptyNodeListOrNull(Document document, String nodeName) {
+ NodeList node = document.getElementsByTagName(nodeName);
+ return (node != null && node.getLength() > 0) ? node : null;
}
-}
+
+ /**
+ * Get the SMSCDeliveryReceipt based on the specified byte value
+ * representation.
+ *
+ * @param value is the byte value representation.
+ * @return is the enum const related to the specified byte value.
+ * @throws IllegalArgumentException if there is no enum const associated
+ * with specified byte value.
+ */
+ private SMSCDeliveryReceipt determineSMSCDeliveryReceipt(byte value) {
+ for (SMSCDeliveryReceipt val : SMSCDeliveryReceipt.values()) {
+ if (val.value() == value)
+ return val;
+ }
+
+ throw new IllegalArgumentException("No enum const SMSCDeliveryReceipt with value " + value);
+ }
+}
\ No newline at end of file
Index: src/test/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshalerTest.java
===================================================================
--- src/test/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshalerTest.java (revision 738572)
+++ src/test/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshalerTest.java (working copy)
@@ -16,14 +16,12 @@
*/
package org.apache.servicemix.smpp.marshaler;
-import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessageExchangeFactory;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
-import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import junit.framework.TestCase;
@@ -33,171 +31,230 @@
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.jbi.messaging.MessageExchangeFactoryImpl;
-import org.apache.servicemix.smpp.marshaler.DefaultSmppMarshaler;
-import org.apache.servicemix.smpp.marshaler.SmppMarshalerSupport;
import org.jsmpp.bean.MessageRequest;
import org.jsmpp.bean.NumberingPlanIndicator;
import org.jsmpp.bean.SubmitSm;
import org.jsmpp.bean.TypeOfNumber;
-import org.xml.sax.SAXException;
/**
* Unit tests on the SMPP marshaler
*
* @author jbonofre
+ * @author mullerc
*/
public class DefaultSmppMarshalerTest extends TestCase {
-
+
private static final String SOURCE = "0123456789";
private static final String DESTINATION = "9876543210";
private static final String TEXT = "This is a SMPP test ...";
private static final String NPI = "NATIONAL";
private static final String TON = "INTERNATIONAL";
+ private static final String REGISTERED_DELIVERY = "SUCCESS_FAILURE";
+ private static final String SCHEDULE_DELIVERY_TIME = "091231143301300+";
+ private static final String VALIDITY_PERIOD = "091231153301300+";
- private static final String MSG_VALID = "" + SOURCE + ""
- + DESTINATION + "" + TEXT + ""
- + NPI + "" + TON + "";
+ private static final String MSG_VALID_MIN_ATTR =
+ "" +
+ "" + SOURCE + "" +
+ "" + DESTINATION + "" +
+ "" + TEXT + "" +
+ "" + NPI + "" +
+ "" + TON + "" +
+ "";
+
+ private static final String MSG_VALID_MAX_ATTR =
+ "" +
+ "" + SOURCE + "" +
+ "" + DESTINATION + "" +
+ "" + TEXT + "" +
+ "" + NPI + "" +
+ "" + TON + "" +
+ "" + REGISTERED_DELIVERY + "" +
+ "" + SCHEDULE_DELIVERY_TIME + "" +
+ "" + VALIDITY_PERIOD + "" +
+ "";
+
+ private static final String MSG_VALID_MAX_DEF_ATTR =
+ "" +
+ "" + SOURCE + "" +
+ "" + DESTINATION + "" +
+ "" + TEXT + "" +
+ "" + NPI + "" +
+ "" + TON + "" +
+ "DEFAULT" +
+ "";
+
private static final String MSG_INVALID = "Test breaker ...";
- private static final String MSG_INVALID_DEST = "" + SOURCE + "" + TEXT
- + "" + NPI + "" + TON
- + "";
- private static final String MSG_INVALID_TON = "" + SOURCE + ""
- + DESTINATION + "" + TEXT
- + "" + NPI + "";
- private static final String MSG_INVALID_NPI = "" + SOURCE + ""
- + DESTINATION + "" + TEXT
- + "" + TON + "";
+
+ private static final String MSG_INVALID_DEST =
+ "" +
+ "" + SOURCE + "" +
+ "" + TEXT + "" +
+ "" + NPI + "" +
+ "" + TON + "" +
+ "";
+
+ private static final String MSG_INVALID_TON =
+ "" +
+ "" + SOURCE + "" +
+ "" + DESTINATION + "" +
+ "" + TEXT + "" +
+ "" + NPI + "" +
+ "";
+
+ private static final String MSG_INVALID_NPI =
+ "" +
+ "" + SOURCE + "" +
+ "" + DESTINATION + "" +
+ "" + TEXT + "" +
+ "" + TON + "" +
+ "";
+
+ private static final String MSG_INVALID_REGISTERED_DELIVERY =
+ "" +
+ "" + SOURCE + "" +
+ "" + DESTINATION + "" +
+ "" + TEXT + "" +
+ "" + NPI + "" +
+ "" + TON + "" +
+ "xxx" +
+ "";
private SmppMarshalerSupport marshaler;
private MessageExchangeFactory factory;
- /**
- * @see junit.framework.TestCase#setUp()
- */
public void setUp() throws Exception {
this.marshaler = new DefaultSmppMarshaler();
this.factory = new MessageExchangeFactoryImpl(new IdGenerator(), new AtomicBoolean(false));
}
- /**
- * @see junit.framework.TestCase#tearDown()
- */
- public void tearDown() {
- this.marshaler = null;
- this.factory = null;
- }
-
// UNIT TESTS
- public void testFromNMSValid() {
- try {
- // construct the MessageExchange and NormalizedMessage
- MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
- NormalizedMessage message = exchange.createMessage();
- message.setContent(new StringSource(MSG_VALID));
- exchange.setMessage(message, "in");
- // use the marshaler to converts the NormalizedMessage to a
- // MessageRequest
- MessageRequest mr = marshaler.fromNMS(exchange, message);
- assertEquals("The message text is not the same: ", TEXT, new String(mr.getShortMessage()));
- assertEquals("The destination address is not the same: ", mr.getDestAddress(), DESTINATION);
- assertEquals("The source address is not the same: ", SOURCE, mr.getSourceAddr());
- assertEquals("The destination type of number is not the same: ", TON, TypeOfNumber
- .valueOf(mr.getDestAddrTon()).toString());
- assertEquals("The source type of number is not the same: ", TON, TypeOfNumber
- .valueOf(mr.getSourceAddrTon()).toString());
- assertEquals("The destination numbering plan indicator is not the same: ", NPI,
- NumberingPlanIndicator.valueOf(mr.getDestAddrNpi()).toString());
- assertEquals("The source numbering plan indicator is not the same: ", NPI, NumberingPlanIndicator
- .valueOf(mr.getSourceAddrNpi()).toString());
- } catch (MessagingException messagingException) {
- fail("Messaging exception occurs when constructing the exchange and the normalized message : "
- + messagingException.getMessage());
- } catch (TransformerException transformerException) {
- fail("Transformer exception occurs while using the marshaler to converts the normalized message to the message request : "
- + transformerException.getMessage());
- }
+ public void testFromNMSValidMinAttr() throws Exception {
+ MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
+ NormalizedMessage message = exchange.createMessage();
+ message.setContent(new StringSource(MSG_VALID_MIN_ATTR));
+ exchange.setMessage(message, "in");
+
+ MessageRequest mr = this.marshaler.fromNMS(exchange, message);
+
+ assertEquals(TEXT, new String(mr.getShortMessage()));
+ assertEquals(mr.getDestAddress(), DESTINATION);
+ assertEquals(SOURCE, mr.getSourceAddr());
+ assertEquals(TON, TypeOfNumber.valueOf(mr.getDestAddrTon()).toString());
+ assertEquals(TON, TypeOfNumber.valueOf(mr.getSourceAddrTon()).toString());
+ assertEquals(NPI, NumberingPlanIndicator.valueOf(mr.getDestAddrNpi()).toString());
+ assertEquals(NPI, NumberingPlanIndicator.valueOf(mr.getSourceAddrNpi()).toString());
+ assertEquals((byte)0x00, mr.getRegisteredDelivery());
+ assertNull(mr.getScheduleDeliveryTime());
+ assertNull(mr.getValidityPeriod());
}
+ public void testFromNMSValidMaxAttr() throws Exception {
+ MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
+ NormalizedMessage message = exchange.createMessage();
+ message.setContent(new StringSource(MSG_VALID_MAX_ATTR));
+ exchange.setMessage(message, "in");
+
+ MessageRequest mr = this.marshaler.fromNMS(exchange, message);
+
+ assertEquals(TEXT, new String(mr.getShortMessage()));
+ assertEquals(mr.getDestAddress(), DESTINATION);
+ assertEquals(SOURCE, mr.getSourceAddr());
+ assertEquals(TON, TypeOfNumber.valueOf(mr.getDestAddrTon()).toString());
+ assertEquals(TON, TypeOfNumber.valueOf(mr.getSourceAddrTon()).toString());
+ assertEquals(NPI, NumberingPlanIndicator.valueOf(mr.getDestAddrNpi()).toString());
+ assertEquals(NPI, NumberingPlanIndicator.valueOf(mr.getSourceAddrNpi()).toString());
+ assertEquals((byte)0x01, mr.getRegisteredDelivery());
+ assertEquals(SCHEDULE_DELIVERY_TIME, mr.getScheduleDeliveryTime());
+ assertEquals(VALIDITY_PERIOD, mr.getValidityPeriod());
+ }
+
public void testFromNMSNullExchange() {
try {
- marshaler.fromNMS(null, null);
+ this.marshaler.fromNMS(null, null);
fail("Seems we processed a message with null exchange...");
} catch (TransformerException transformerException) {
- // fine
+ // expected
}
}
- public void testFromNMSInvalid() {
+ public void testFromNMSInvalid() throws Exception {
try {
MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
NormalizedMessage message = exchange.createMessage();
message.setContent(new StringSource(MSG_INVALID));
exchange.setMessage(message, "in");
- // use the marshaler to converts the NormalizedMessage to a
- // MessageRequest
- MessageRequest mr = marshaler.fromNMS(exchange, message);
+
+ this.marshaler.fromNMS(exchange, message);
+
fail("Seems we processed a invalid message...");
- } catch (MessagingException messagingException) {
- fail("Messaging exception occurs : " + messagingException.getMessage());
} catch (TransformerException transformerException) {
- // fine
+ // expected
}
}
- public void testFromNMSInvalidDest() {
+ public void testFromNMSInvalidDest() throws Exception {
try {
MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
NormalizedMessage message = exchange.createMessage();
message.setContent(new StringSource(MSG_INVALID_DEST));
exchange.setMessage(message, "in");
- // use the marshaler to converts the NormalizedMessage to a
- // MessageRequest
- MessageRequest mr = marshaler.fromNMS(exchange, message);
+
+ this.marshaler.fromNMS(exchange, message);
+
fail("Seems we processed a message with a invalid destination...");
- } catch (MessagingException messagingException) {
- fail("Messaging exception occurs : " + messagingException.getMessage());
} catch (TransformerException transformerException) {
- // fine
+ // expected
}
}
- public void testFromNMSInvalidTon() {
+ public void testFromNMSInvalidTon() throws Exception {
try {
MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
NormalizedMessage message = exchange.createMessage();
message.setContent(new StringSource(MSG_INVALID_TON));
exchange.setMessage(message, "in");
- // use the marshaler to converts the NormalizedMessage to a
- // MessageRequest
- MessageRequest mr = marshaler.fromNMS(exchange, message);
+
+ this.marshaler.fromNMS(exchange, message);
+
fail("Seems we processed a message with a invlid type of number...");
- } catch (MessagingException messagingException) {
- fail("Messaging exception occurs : " + messagingException.getMessage());
} catch (TransformerException transformerException) {
- // fine
+ // expected
}
}
- public void testFromNMSInvalidNpi() {
+ public void testFromNMSInvalidNpi() throws Exception {
try {
MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
NormalizedMessage message = exchange.createMessage();
message.setContent(new StringSource(MSG_INVALID_NPI));
exchange.setMessage(message, "in");
- // use the marshaler to converts the NormalizedMessage to a
- // MessageRequest
- MessageRequest mr = marshaler.fromNMS(exchange, message);
+
+ this.marshaler.fromNMS(exchange, message);
+
fail("Seems we processed a message with a invlid numbering plan indicator...");
- } catch (MessagingException messagingException) {
- fail("Messaging exception occurs : " + messagingException.getMessage());
} catch (TransformerException transformerException) {
- // fine
+ // expected
+ }
+ }
+
+ public void testFromNMSInvalidRegisteredDelivery() throws MessagingException {
+ try {
+ MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
+ NormalizedMessage message = exchange.createMessage();
+ message.setContent(new StringSource(MSG_INVALID_REGISTERED_DELIVERY));
+ exchange.setMessage(message, "in");
+
+ this.marshaler.fromNMS(exchange, message);
+
+ fail("Seems we processed a message with a invlid registered delivery value...");
+ } catch (TransformerException transformerException) {
+ // expected
}
}
- public void testToNMSValid() {
- // constructs the MessageRequest
+ public void testToNMSValidMinAttr() throws Exception {
MessageRequest mr = new SubmitSm();
mr.setDestAddress(DESTINATION);
mr.setDestAddrNpi(NumberingPlanIndicator.valueOf(NPI).value());
@@ -206,68 +263,80 @@
mr.setSourceAddrNpi(NumberingPlanIndicator.valueOf(NPI).value());
mr.setSourceAddrTon(TypeOfNumber.valueOf(TON).value());
mr.setShortMessage(TEXT.getBytes());
- try {
- MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
- NormalizedMessage message = exchange.createMessage();
- exchange.setMessage(message, "in");
- marshaler.toNMS(message, mr);
- SourceTransformer sourceTransformer = new SourceTransformer();
- assertEquals("Message not correct: ", MSG_VALID, sourceTransformer.contentToString(message));
- } catch (MessagingException messagingException) {
- fail("Messaging exception occurs during the construction of the MessageExchange and NormalizedMessage: "
- + messagingException.getMessage());
- } catch (TransformerException transformerException) {
- fail("Transformer exception occurs using the marshaler: " + transformerException.getMessage());
- } catch (ParserConfigurationException parserConfigurationException) {
- fail("Parser configuration exception occurs using the SourceTransformer: "
- + parserConfigurationException.getMessage());
- } catch (SAXException saxException) {
- fail("SAX exception occurs using the SourceTransformer: " + saxException.getMessage());
- } catch (IOException ioException) {
- fail("IO exception occurs using the SourceTransformer: " + ioException.getMessage());
- }
+
+ MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
+ NormalizedMessage message = exchange.createMessage();
+ exchange.setMessage(message, "in");
+
+ this.marshaler.toNMS(message, mr);
+
+ assertEquals(MSG_VALID_MAX_DEF_ATTR, new SourceTransformer().contentToString(message));
+ }
+
+ public void testToNMSValidMaxAttr() throws Exception {
+ MessageRequest mr = new SubmitSm();
+ mr.setDestAddress(DESTINATION);
+ mr.setDestAddrNpi(NumberingPlanIndicator.valueOf(NPI).value());
+ mr.setDestAddrTon(TypeOfNumber.valueOf(TON).value());
+ mr.setSourceAddr(SOURCE);
+ mr.setSourceAddrNpi(NumberingPlanIndicator.valueOf(NPI).value());
+ mr.setSourceAddrTon(TypeOfNumber.valueOf(TON).value());
+ mr.setShortMessage(TEXT.getBytes());
+ mr.setRegisteredDelivery((byte)0x01);
+ mr.setScheduleDeliveryTime(SCHEDULE_DELIVERY_TIME);
+ mr.setValidityPeriod(VALIDITY_PERIOD);
+
+ MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
+ NormalizedMessage message = exchange.createMessage();
+ exchange.setMessage(message, "in");
+
+ this.marshaler.toNMS(message, mr);
+
+ assertEquals(MSG_VALID_MAX_ATTR, new SourceTransformer().contentToString(message));
}
- public void testToNMSInvalid() {
- // constructs a invalid MessageRequest (without destination, source,
- // NPI, TON)
+ public void testToNMSInvalid() throws Exception {
MessageRequest mr = new SubmitSm();
mr.setShortMessage(TEXT.getBytes());
+
+ MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
+ NormalizedMessage message = exchange.createMessage();
+ exchange.setMessage(message, "in");
+
try {
- MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
- NormalizedMessage message = exchange.createMessage();
- exchange.setMessage(message, "in");
- marshaler.toNMS(message, mr);
+ this.marshaler.toNMS(message, mr);
+
fail("Seems we processed an invalid MessageRequest...");
} catch (MessagingException messagingException) {
- // fine
+ // expected
}
}
- public void testToNMSNullMessageRequest() {
+ public void testToNMSNullMessageRequest() throws Exception {
MessageRequest mr = null;
+ MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
+ NormalizedMessage message = exchange.createMessage();
+ exchange.setMessage(message, "in");
+
try {
- MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
- NormalizedMessage message = exchange.createMessage();
- exchange.setMessage(message, "in");
- marshaler.toNMS(message, mr);
+ this.marshaler.toNMS(message, mr);
+
fail("Seems we processed a Null MessageRequest...");
} catch (MessagingException messagingException) {
- // fine
+ // expected
}
}
public void testToNMSNullMessage() {
- // constructs a invalid MessageRequest (without destination, source,
- // NPI, TON)
MessageRequest mr = new SubmitSm();
mr.setShortMessage(TEXT.getBytes());
+
try {
marshaler.toNMS(null, mr);
+
fail("Seems we processed a MessageRequest with a Null NormalizedMessage...");
} catch (MessagingException messagingException) {
- // fine
+ // expected
}
}
-
-}
+}
\ No newline at end of file