View Javadoc
1   package org.kuali.ole.deliver;
2   
3   /**
4    * Created with IntelliJ IDEA.
5    * User: bala.km
6    * Date: 11/26/12
7    * Time: 12:38 PM
8    * To change this template use File | Settings | File Templates.
9    */
10  
11  import org.apache.camel.Exchange;
12  import org.apache.camel.ExchangePattern;
13  import org.apache.camel.component.smpp.SmppConfiguration;
14  import org.apache.camel.component.smpp.SmppConstants;
15  import org.apache.camel.component.smpp.SmppSubmitSmCommand;
16  import org.apache.camel.impl.DefaultCamelContext;
17  import org.apache.camel.impl.DefaultExchange;
18  import org.jsmpp.bean.*;
19  import org.jsmpp.session.SMPPSession;
20  import org.junit.AfterClass;
21  import org.junit.Before;
22  import org.junit.BeforeClass;
23  import org.junit.Test;
24  import org.mockito.Mock;
25  import org.mockito.MockitoAnnotations;
26  
27  import java.util.Date;
28  import java.util.TimeZone;
29  
30  import static junit.framework.Assert.assertTrue;
31  
32  
33  public class OleSMS_UT {
34  
35      private static TimeZone defaultTimeZone;
36  
37      @Mock
38      private SMPPSession session;
39  
40      private SmppConfiguration config;
41      private SmppSubmitSmCommand command;
42  
43      @BeforeClass
44      public static void setUpBeforeClass() {
45          defaultTimeZone = TimeZone.getDefault();
46  
47          TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
48      }
49  
50      @AfterClass
51      public static void tearDownAfterClass() {
52          if (defaultTimeZone != null) {
53              TimeZone.setDefault(defaultTimeZone);
54          }
55      }
56  
57      @Before
58      public void setUp() {
59          MockitoAnnotations.initMocks(this);
60          config = new SmppConfiguration();
61          command = new SmppSubmitSmCommand(session, config);
62      }
63  
64      @Test
65      public void execute() throws Exception {
66          Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
67          exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitSm");
68          exchange.getIn().setHeader(SmppConstants.ID, "1");
69          exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.INTERNATIONAL.value());
70          exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.ISDN.value());
71          exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, "1111111111");
72          exchange.getIn().setHeader(SmppConstants.DEST_ADDR_TON, TypeOfNumber.INTERNATIONAL.value());
73          exchange.getIn().setHeader(SmppConstants.DEST_ADDR_NPI, NumberingPlanIndicator.ISDN.value());
74          exchange.getIn().setHeader(SmppConstants.DEST_ADDR, "2222222222");
75          exchange.getIn().setHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, new Date(1111111));
76          exchange.getIn().setHeader(SmppConstants.VALIDITY_PERIOD, new Date(2222222));
77          exchange.getIn().setHeader(SmppConstants.PROTOCOL_ID, (byte) 1);
78          exchange.getIn().setHeader(SmppConstants.PRIORITY_FLAG, (byte) 2);
79          exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS).value());
80          exchange.getIn().setHeader(SmppConstants.REPLACE_IF_PRESENT_FLAG, ReplaceIfPresentFlag.REPLACE.value());
81          exchange.getIn().setBody("short message body");
82  
83          try{
84              command.execute(exchange);
85          }catch(Exception e){
86              assertTrue(false);
87          }
88  
89      }
90  
91      @Test
92      public void executeLongBody() throws Exception {
93  
94          Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
95          exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitSm");
96          exchange.getIn().setHeader(SmppConstants.ID, "1");
97          exchange.getIn().setBody("12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901");
98  
99          try{
100             command.execute(exchange);
101         }catch(Exception e){
102             assertTrue(false);
103         }
104 
105     }
106 
107 }