Skip to content

Commit 7d31589

Browse files
RESTCOMM-1856: Modify MockSmppserver to decode messages correctly. Add UTF-8 and UCS-2 tests. Add special chars in test
1 parent 839e0cb commit 7d31589

2 files changed

Lines changed: 51 additions & 31 deletions

File tree

restcomm/restcomm.testsuite/src/main/java/org/restcomm/connect/testsuite/smpp/MockSmppServer.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.cloudhopper.commons.charset.Charset;
2020
import com.cloudhopper.commons.charset.CharsetUtil;
21+
import com.cloudhopper.smpp.SmppConstants;
2122
import com.cloudhopper.smpp.SmppServerConfiguration;
2223
import com.cloudhopper.smpp.SmppServerHandler;
2324
import com.cloudhopper.smpp.SmppServerSession;
@@ -34,7 +35,6 @@
3435
import com.cloudhopper.smpp.type.SmppProcessingException;
3536

3637
import org.restcomm.connect.sms.smpp.SmppInboundMessageEntity;
37-
import org.restcomm.connect.sms.smpp.DataCoding;
3838

3939
public class MockSmppServer {
4040

@@ -87,21 +87,17 @@ public void sendSmppMessageToRestcomm(String smppMessage, String smppTo, String
8787
//http://stackoverflow.com/a/25885741
8888
try {
8989
byte[] textBytes;
90-
if (CharsetUtil.CHARSET_UCS_2 == charset) {
91-
textBytes = smppMessage.getBytes();
92-
} else {
93-
textBytes = CharsetUtil.encode(smppMessage, charset);
94-
}
90+
textBytes = CharsetUtil.encode(smppMessage, charset);
9591

9692
DeliverSm deliver = new DeliverSm();
9793

9894
deliver.setSourceAddress(new Address((byte) 0x03, (byte) 0x00, smppFrom));
9995
deliver.setDestAddress(new Address((byte) 0x01, (byte) 0x01, smppTo));
10096
deliver.setShortMessage(textBytes);
10197
if (CharsetUtil.CHARSET_UCS_2 == charset) {
102-
deliver.setDataCoding(DataCoding.DATA_CODING_UCS2);
98+
deliver.setDataCoding(SmppConstants.DATA_CODING_UCS2);
10399
} else {
104-
deliver.setDataCoding(DataCoding.DATA_CODING_GSM7);
100+
deliver.setDataCoding(SmppConstants.DATA_CODING_DEFAULT);
105101
}
106102
logger.info("deliver.getDataCoding: " + deliver.getDataCoding());
107103

@@ -211,10 +207,14 @@ public PduResponse firePduRequestReceived(PduRequest pduRequest) {
211207

212208
// mimic how long processing could take on a slower smsc
213209
//processing received SMPP message from Restcomm
210+
214211
String decodedPduMessage = null;
212+
byte dcs = 0;
215213
String destSmppAddress = null;
216214
String sourceSmppAddress = null;
217215
boolean isDeliveryReceipt = false;
216+
//FIXME: make MockSmppServer configurable
217+
Charset charset = CharsetUtil.CHARSET_UTF_8;
218218

219219
if (pduRequest.toString().toLowerCase().contains("enquire_link")) {
220220
//logger.info("This is a response to the enquire_link, therefore, do NOTHING ");
@@ -225,7 +225,13 @@ public PduResponse firePduRequestReceived(PduRequest pduRequest) {
225225

226226
try {
227227
SubmitSm deliverSm = (SubmitSm) pduRequest;
228-
decodedPduMessage = CharsetUtil.CHARSET_MODIFIED_UTF8.decode(deliverSm.getShortMessage());
228+
229+
dcs = deliverSm.getDataCoding();
230+
if(dcs==SmppConstants.DATA_CODING_UCS2) {
231+
charset = CharsetUtil.CHARSET_UCS_2;
232+
}
233+
234+
decodedPduMessage = CharsetUtil.decode(deliverSm.getShortMessage(), charset);
229235
destSmppAddress = deliverSm.getDestAddress().getAddress();
230236
sourceSmppAddress = deliverSm.getSourceAddress().getAddress();
231237
if (deliverSm.getRegisteredDelivery() == (byte) 0x01) {
@@ -237,7 +243,8 @@ public PduResponse firePduRequestReceived(PduRequest pduRequest) {
237243
logger.info("********DeliverSm Exception******* " + e);
238244
}
239245

240-
smppInboundMessageEntity = new SmppInboundMessageEntity(destSmppAddress, sourceSmppAddress, decodedPduMessage, CharsetUtil.CHARSET_GSM, isDeliveryReceipt);
246+
247+
smppInboundMessageEntity = new SmppInboundMessageEntity(destSmppAddress, sourceSmppAddress, decodedPduMessage, charset, isDeliveryReceipt);
241248
messageReceived = true;
242249
}
243250
return pduRequest.createResponse();

restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/smpp/SmppTest.java

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.restcomm.connect.commons.annotations.WithInSecsTests;
4747
import org.restcomm.connect.sms.smpp.SmppInboundMessageEntity;
4848

49+
import com.cloudhopper.commons.charset.Charset;
4950
import com.cloudhopper.commons.charset.CharsetUtil;
5051
import com.cloudhopper.smpp.type.SmppChannelException;
5152
import com.cloudhopper.smpp.type.SmppInvalidArgumentException;
@@ -66,9 +67,9 @@ public class SmppTest {
6667
private static String to = "7777";
6768
private static String toPureSipProviderNumber = "7007";
6869
private static String from = "9999";
69-
private static String msgBody = "Message from SMPP Server to Restcomm";
70-
private static String msgBodyResp = "Response from Restcomm to SMPP server";
71-
private static String msgBodyRespUCS2 = "Response from Restcomm to SMPP serverПППРРр";
70+
private static String msgBody = "か~!@#$%^&*()-=\u263a\u00a1\u00a2\u00a3\u00a4\u00a5Message from SMPP Server to Restcomm";
71+
private static String msgBodyResp = "か~!@#$%^&*()-=\u263a\u00a1\u00a2\u00a3\u00a4\u00a5Response from Restcomm to SMPP server";
72+
private static String msgBodyRespUCS2 = "か~!@#$%^&*()-=\u263a\u00a1\u00a2\u00a3\u00a4\u00a5Response from Restcomm to SMPP server";
7273

7374
@Rule
7475
public WireMockRule wireMockRule = new WireMockRule(8090); // No-args constructor defaults to port 8080
@@ -190,27 +191,39 @@ public void after() throws InterruptedException {
190191
Thread.sleep(2000);
191192
}
192193

193-
private String smsEchoRcml = "<Response><Sms to=\""+from+"\" from=\""+to+"\">"+msgBodyResp+"</Sms></Response>";
194-
@Test
195-
public void testSendMessageToRestcomm () throws SmppInvalidArgumentException, IOException, InterruptedException {
194+
@Test
195+
public void testSendMessageToRestcommUTF8() throws SmppInvalidArgumentException, IOException, InterruptedException {
196+
testSendMessageToRestcomm(msgBody, msgBodyResp, CharsetUtil.CHARSET_UTF_8);
197+
}
196198

197-
stubFor(get(urlPathEqualTo("/smsApp"))
198-
.willReturn(aResponse()
199-
.withStatus(200)
200-
.withHeader("Content-Type", "text/xml")
201-
.withBody(smsEchoRcml)));
199+
@Test
200+
public void testSendMessageToRestcommUCS2() throws SmppInvalidArgumentException, IOException, InterruptedException {
201+
testSendMessageToRestcomm(msgBody, msgBodyRespUCS2, CharsetUtil.CHARSET_UCS_2);
202+
}
203+
204+
public void testSendMessageToRestcomm(String msgBodySend, String msgBodyResp, Charset charset) throws SmppInvalidArgumentException, IOException, InterruptedException {
202205

203-
mockSmppServer.sendSmppMessageToRestcomm(msgBody,to,from,CharsetUtil.CHARSET_GSM);
206+
String smsEchoRcml = "<Response><Sms to=\"" + from + "\" from=\"" + to + "\">" + msgBodyResp + "</Sms></Response>";
207+
stubFor(get(urlPathEqualTo("/smsApp")).willReturn(aResponse()
208+
.withStatus(200).withHeader("Content-Type", "text/xml")
209+
.withBody(smsEchoRcml)));
210+
211+
mockSmppServer.sendSmppMessageToRestcomm(msgBodySend, to, from,
212+
charset);
204213
Thread.sleep(2000);
205214
assertTrue(mockSmppServer.isMessageSent());
206-
Thread.sleep(2000);
207-
assertTrue(mockSmppServer.isMessageReceived());
208-
SmppInboundMessageEntity inboundMessageEntity = mockSmppServer.getSmppInboundMessageEntity();
209-
assertNotNull(inboundMessageEntity);
210-
assertTrue(inboundMessageEntity.getSmppTo().equals(from));
211-
assertTrue(inboundMessageEntity.getSmppFrom().equals(to));
212-
assertTrue(inboundMessageEntity.getSmppContent().equals(msgBodyResp));
213-
}
215+
Thread.sleep(2000);
216+
assertTrue(mockSmppServer.isMessageReceived());
217+
SmppInboundMessageEntity inboundMessageEntity = mockSmppServer.getSmppInboundMessageEntity();
218+
assertNotNull(inboundMessageEntity);
219+
220+
logger.info("msgBodyResp: " + msgBodyResp);
221+
logger.info("getSmppContent: " + inboundMessageEntity.getSmppContent());
222+
223+
assertTrue(inboundMessageEntity.getSmppTo().equals(from));
224+
assertTrue(inboundMessageEntity.getSmppFrom().equals(to));
225+
assertTrue(inboundMessageEntity.getSmppContent().equals(msgBodyResp));
226+
}
214227

215228
private String smsEchoRcmlPureSipProviderNumber = "<Response><Sms to=\""+from+"\" from=\""+toPureSipProviderNumber+"\">"+msgBodyResp+"</Sms></Response>";
216229
@Test //https://telestax.atlassian.net/browse/RESTCOMM-1428, https://telestax.atlassian.net/browse/POSTMORTEM-13
@@ -237,7 +250,7 @@ public void testSendSMPPMessageToRestcommPureSipProviderNumber () throws SmppInv
237250
private String smsEchoRcmlUCS2 = "<Response><Sms to=\""+from+"\" from=\""+to+"\">"+msgBodyRespUCS2+"</Sms></Response>";
238251
@Test
239252
@Category(value={FeatureAltTests.class, BrokenTests.class})
240-
public void testSendMessageToRestcommUCS2 () throws SmppInvalidArgumentException, IOException, InterruptedException {
253+
public void testSendMessageToRestcommUCS2_2 () throws SmppInvalidArgumentException, IOException, InterruptedException {
241254

242255
stubFor(get(urlPathEqualTo("/smsApp"))
243256
.willReturn(aResponse()

0 commit comments

Comments
 (0)