camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject svn commit: r1227310 - in /camel/trunk/components/camel-smpp/src: main/java/org/apache/camel/component/smpp/ test/java/org/apache/camel/component/smpp/
Date Wed, 04 Jan 2012 20:38:34 GMT
Author: cmueller
Date: Wed Jan  4 20:38:34 2012
New Revision: 1227310

URL: http://svn.apache.org/viewvc?rev=1227310&view=rev
Log:
CAMEL-4862: Support relative time format in Camel SMPP by setting the validity periode

Modified:
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppReplaceSmCommand.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitMultiCommand.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppReplaceSmCommandTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppSubmitMultiCommandTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppSubmitSmCommandTest.java

Modified: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppReplaceSmCommand.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppReplaceSmCommand.java?rev=1227310&r1=1227309&r2=1227310&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppReplaceSmCommand.java
(original)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppReplaceSmCommand.java
Wed Jan  4 20:38:34 2012
@@ -112,7 +112,12 @@ public class SmppReplaceSmCommand extend
         }
 
         if (in.getHeaders().containsKey(SmppConstants.VALIDITY_PERIOD)) {
-            replaceSm.setValidityPeriod(SmppUtils.formatTime(in.getHeader(SmppConstants.VALIDITY_PERIOD,
Date.class)));
+            Object validityPeriod = in.getHeader(SmppConstants.VALIDITY_PERIOD);
+            if (validityPeriod instanceof String) {
+                replaceSm.setValidityPeriod((String) validityPeriod);
+            } else if (validityPeriod instanceof Date) {
+                replaceSm.setValidityPeriod(SmppUtils.formatTime((Date) validityPeriod));
+            }
         }
 
         return replaceSm;

Modified: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitMultiCommand.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitMultiCommand.java?rev=1227310&r1=1227309&r2=1227310&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitMultiCommand.java
(original)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitMultiCommand.java
Wed Jan  4 20:38:34 2012
@@ -234,7 +234,12 @@ public class SmppSubmitMultiCommand exte
         }
 
         if (in.getHeaders().containsKey(SmppConstants.VALIDITY_PERIOD)) {
-            submitMulti.setValidityPeriod(SmppUtils.formatTime(in.getHeader(SmppConstants.VALIDITY_PERIOD,
Date.class)));
+            Object validityPeriod = in.getHeader(SmppConstants.VALIDITY_PERIOD);
+            if (validityPeriod instanceof String) {
+                submitMulti.setValidityPeriod((String) validityPeriod);
+            } else if (validityPeriod instanceof Date) {
+                submitMulti.setValidityPeriod(SmppUtils.formatTime((Date) validityPeriod));
+            }
         }
 
         if (in.getHeaders().containsKey(SmppConstants.REPLACE_IF_PRESENT_FLAG)) {

Modified: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java?rev=1227310&r1=1227309&r2=1227310&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java
(original)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java
Wed Jan  4 20:38:34 2012
@@ -186,7 +186,12 @@ public class SmppSubmitSmCommand extends
         }
 
         if (in.getHeaders().containsKey(SmppConstants.VALIDITY_PERIOD)) {
-            submitSm.setValidityPeriod(SmppUtils.formatTime(in.getHeader(SmppConstants.VALIDITY_PERIOD,
Date.class)));
+            Object validityPeriod = in.getHeader(SmppConstants.VALIDITY_PERIOD);
+            if (validityPeriod instanceof String) {
+                submitSm.setValidityPeriod((String) validityPeriod);
+            } else if (validityPeriod instanceof Date) {
+                submitSm.setValidityPeriod(SmppUtils.formatTime((Date) validityPeriod));
+            }
         }
 
         if (in.getHeaders().containsKey(SmppConstants.REPLACE_IF_PRESENT_FLAG)) {

Modified: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppReplaceSmCommandTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppReplaceSmCommandTest.java?rev=1227310&r1=1227309&r2=1227310&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppReplaceSmCommandTest.java
(original)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppReplaceSmCommandTest.java
Wed Jan  4 20:38:34 2012
@@ -112,4 +112,28 @@ public class SmppReplaceSmCommandTest {
         
         assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
     }
+    
+    @Test
+    public void executeWithValidityPeriodAsString() throws Exception {
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
+        exchange.getIn().setHeader(SmppConstants.COMMAND, "ReplaceSm");
+        exchange.getIn().setHeader(SmppConstants.ID, "1");
+        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.NATIONAL.value());
+        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value());
+        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, "1818");
+        exchange.getIn().setHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, new Date(1111111));
+        exchange.getIn().setHeader(SmppConstants.VALIDITY_PERIOD, "000003000000000R"); //
three days
+        exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS).value());
+        exchange.getIn().setBody("new short message body");
+        session.replaceShortMessage(eq("1"), eq(TypeOfNumber.NATIONAL), eq(NumberingPlanIndicator.NATIONAL),
eq("1818"), eq("-300101001831100-"), eq("000003000000000R"),
+                eq(new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS)), eq((byte) 0), aryEq("new
short message body".getBytes()));
+        
+        replay(session);
+        
+        command.execute(exchange);
+        
+        verify(session);
+        
+        assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
+    }
 }
\ No newline at end of file

Modified: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppSubmitMultiCommandTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppSubmitMultiCommandTest.java?rev=1227310&r1=1227309&r2=1227310&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppSubmitMultiCommandTest.java
(original)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppSubmitMultiCommandTest.java
Wed Jan  4 20:38:34 2012
@@ -143,4 +143,40 @@ public class SmppSubmitMultiCommandTest 
         assertEquals(1, exchange.getOut().getHeader(SmppConstants.SENT_MESSAGE_COUNT));
         assertNull(exchange.getOut().getHeader(SmppConstants.ERROR));
     }
+    
+    @Test
+    public void executeWithValidityPeriodAsString() throws Exception {
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
+        exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitMulti");
+        exchange.getIn().setHeader(SmppConstants.ID, "1");
+        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.NATIONAL.value());
+        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value());
+        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, "1818");
+        exchange.getIn().setHeader(SmppConstants.DEST_ADDR_TON, TypeOfNumber.INTERNATIONAL.value());
+        exchange.getIn().setHeader(SmppConstants.DEST_ADDR_NPI, NumberingPlanIndicator.INTERNET.value());
+        exchange.getIn().setHeader(SmppConstants.DEST_ADDR, Arrays.asList("1919"));
+        exchange.getIn().setHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, new Date(1111111));
+        exchange.getIn().setHeader(SmppConstants.VALIDITY_PERIOD, "000003000000000R"); //
three days
+        exchange.getIn().setHeader(SmppConstants.PROTOCOL_ID, (byte) 1);
+        exchange.getIn().setHeader(SmppConstants.PRIORITY_FLAG, (byte) 2);
+        exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS).value());
+        exchange.getIn().setHeader(SmppConstants.REPLACE_IF_PRESENT_FLAG, ReplaceIfPresentFlag.REPLACE.value());
+        exchange.getIn().setBody("short message body");
+        expect(session.submitMultiple(eq("CMT"), eq(TypeOfNumber.NATIONAL), eq(NumberingPlanIndicator.NATIONAL),
eq("1818"),
+                aryEq(new Address[]{new Address(TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.INTERNET,
"1919")}),
+                eq(new ESMClass()), eq((byte) 1), eq((byte) 2), eq("-300101001831100-"),
eq("000003000000000R"), eq(new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS)),
+                eq(ReplaceIfPresentFlag.REPLACE), eq(new GeneralDataCoding(false, true, MessageClass.CLASS1,
Alphabet.ALPHA_DEFAULT)), eq((byte) 0), aryEq("short message body".getBytes()),
+                aryEq(new OptionalParameter[0])))
+                .andReturn(new SubmitMultiResult("1"));
+        
+        replay(session);
+        
+        command.execute(exchange);
+        
+        verify(session);
+        
+        assertEquals(Arrays.asList("1"), exchange.getOut().getHeader(SmppConstants.ID));
+        assertEquals(1, exchange.getOut().getHeader(SmppConstants.SENT_MESSAGE_COUNT));
+        assertNull(exchange.getOut().getHeader(SmppConstants.ERROR));
+    }
 }
\ No newline at end of file

Modified: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppSubmitSmCommandTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppSubmitSmCommandTest.java?rev=1227310&r1=1227309&r2=1227310&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppSubmitSmCommandTest.java
(original)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppSubmitSmCommandTest.java
Wed Jan  4 20:38:34 2012
@@ -170,4 +170,38 @@ public class SmppSubmitSmCommandTest {
         assertEquals(Arrays.asList("1"), exchange.getOut().getHeader(SmppConstants.ID));
         assertEquals(1, exchange.getOut().getHeader(SmppConstants.SENT_MESSAGE_COUNT));
     }
+    
+    @Test
+    public void executeWithValidityPeriodAsString() throws Exception {
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
+        exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitSm");
+        exchange.getIn().setHeader(SmppConstants.ID, "1");
+        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.NATIONAL.value());
+        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value());
+        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, "1818");
+        exchange.getIn().setHeader(SmppConstants.DEST_ADDR_TON, TypeOfNumber.INTERNATIONAL.value());
+        exchange.getIn().setHeader(SmppConstants.DEST_ADDR_NPI, NumberingPlanIndicator.INTERNET.value());
+        exchange.getIn().setHeader(SmppConstants.DEST_ADDR, "1919");
+        exchange.getIn().setHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, new Date(1111111));
+        exchange.getIn().setHeader(SmppConstants.VALIDITY_PERIOD, "000003000000000R"); //
three days
+        exchange.getIn().setHeader(SmppConstants.PROTOCOL_ID, (byte) 1);
+        exchange.getIn().setHeader(SmppConstants.PRIORITY_FLAG, (byte) 2);
+        exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS).value());
+        exchange.getIn().setHeader(SmppConstants.REPLACE_IF_PRESENT_FLAG, ReplaceIfPresentFlag.REPLACE.value());
+        exchange.getIn().setBody("short message body");
+        expect(session.submitShortMessage(eq("CMT"), eq(TypeOfNumber.NATIONAL), eq(NumberingPlanIndicator.NATIONAL),
eq("1818"),
+                eq(TypeOfNumber.INTERNATIONAL), eq(NumberingPlanIndicator.INTERNET), eq("1919"),
+                eq(new ESMClass()), eq((byte) 1), eq((byte) 2), eq("-300101001831100-"),
eq("000003000000000R"), eq(new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS)),
+                eq(ReplaceIfPresentFlag.REPLACE.value()), eq(new GeneralDataCoding(false,
true, MessageClass.CLASS1, Alphabet.ALPHA_DEFAULT)), eq((byte) 0), aryEq("short message body".getBytes())))
+                .andReturn("1");
+        
+        replay(session);
+        
+        command.execute(exchange);
+        
+        verify(session);
+        
+        assertEquals(Arrays.asList("1"), exchange.getOut().getHeader(SmppConstants.ID));
+        assertEquals(1, exchange.getOut().getHeader(SmppConstants.SENT_MESSAGE_COUNT));
+    }
 }
\ No newline at end of file



Mime
View raw message