@Test public void testStatus() throws Exception { log.info("starting testStatus ... "); SmppConfiguration configuration = new SmppConfiguration(); configuration.setHost("localhost"); configuration.setPort(SERVER_PORT); configuration.setSystemId("test"); configuration.setPassword("test"); SmppConnector connector = new SmppConnector(configuration); injectResource(new MockProcessorContext(), connector); Assert.assertEquals(connector.getStatus(), Status.UNKNOWN); connector.doStart(); waitUntilStatus(connector, DEFAULT_TIMEOUT, Status.OK); try { stopSimulator(); waitUntilStatus(connector, DEFAULT_TIMEOUT, Status.FAILED); startSimulator(); waitUntilStatus(connector, DEFAULT_TIMEOUT, Status.OK); Assert.assertEquals(connector.getStatus(), Status.OK); } finally { connector.doStop(); } }
@Test public void testReceiveDeliveryReceipt() throws Exception { log.info("starting testReceiveDeliveryReceipt ... "); server.setPacketProcessor(new CustomPacketProcessor("12000")); SmppConfiguration configuration = new SmppConfiguration(); configuration.setHost("localhost"); configuration.setPort(SERVER_PORT); configuration.setSystemId("test"); configuration.setPassword("test"); MockMessageStore messageStore = new MockMessageStore(); MockMessageProducer messageProducer = new MockMessageProducer(); SmppConnector connector = createAndStartSmppConnector(configuration, messageStore, messageProducer); try { String from = "3542"; String to = "3002175604"; // send a message Message message = new Message(); message.setProperty("to", to); message.setProperty("from", from); message.setProperty("text", "This is the test"); message.setProperty("receiptDestination", "test"); sendMessage(connector, messageStore, message); // retrieve the session Assert.assertEquals(server.getSessions().size(), 1); SmppSession session = server.getSessions().iterator().next(); Assert.assertNotNull(session); DeliverSm deliverSM = new DeliverSm(); deliverSM.setEsmClass(SmppConstants.ESM_CLASS_MT_SMSC_DELIVERY_RECEIPT); deliverSM.setDestAddress(new Address((byte) 0, (byte) 0, from)); deliverSM.setSourceAddress(new Address((byte) 0, (byte) 0, to)); deliverSM.setShortMessage( "id:12000 sub:1 dlvrd:1 submit date:1101010000 done date:1101010000 stat:DELIVRD err:0 text:This is a ... " .getBytes()); session.sendRequest(deliverSM, DEFAULT_TIMEOUT); long timeout = 2000; if (!receiveMessage(messageProducer, timeout)) { Assert.fail("the delivery receipt was not received"); } Message receivedMessage = (Message) messageProducer.getMessage(0); Assert.assertEquals(from, receivedMessage.getProperty("to", String.class)); Assert.assertEquals(to, receivedMessage.getProperty("from", String.class)); Assert.assertEquals(receivedMessage.getProperty("messageId", String.class), 12000 + ""); Assert.assertEquals("DELIVRD", receivedMessage.getProperty("finalStatus", String.class)); } finally { connector.doStop(); } }
@Test public void shouldNotRouteDeliveryReceipt() throws Exception { MockMessageProducer messageProducer = new MockMessageProducer(); SmppConfiguration configuration = new SmppConfiguration(); configuration.setHost("localhost"); configuration.setPort(SERVER_PORT); configuration.setSystemId("test"); configuration.setPassword("test"); MessageStore messageStore = new MockMessageStore(); SmppConnector connector = new SmppConnector(configuration); injectResource(new MockProcessorContext(), connector); injectResource(messageStore, connector); injectResource(messageProducer, connector); connector.doStart(); waitUntilStatus(connector, DEFAULT_TIMEOUT, Status.OK); try { Message message = new Message(); message.setProperty("to", "3542"); message.setProperty("from", "3002175604"); message.setProperty("text", "This is the test"); message.setProperty("sequenceNumber", 1); message.setProperty("messageId", "12000"); message.setProperty("commandStatus", 0); messageStore.saveOrUpdate(message); DeliverSm deliverSm = new DeliverSm(); deliverSm.setEsmClass(SmppConstants.ESM_CLASS_MT_SMSC_DELIVERY_RECEIPT); deliverSm.setDestAddress(new Address((byte) 0, (byte) 0, "3002175604")); deliverSm.setSourceAddress(new Address((byte) 0, (byte) 0, "3542")); deliverSm.setShortMessage( "id:12000 sub:1 dlvrd:1 submit date:1101010000 done date:1101010000 stat:DELIVRD err:0 text:This is a ... " .getBytes()); // retrieve the session Assert.assertEquals(server.getSessions().size(), 1); SmppSession session = server.getSessions().iterator().next(); Assert.assertNotNull(session); // send the delivery receipt session.sendRequest(deliverSm, DEFAULT_TIMEOUT); long timeout = 2000; if (receiveMessage(messageProducer, timeout)) { Assert.fail("the message was received"); } } finally { connector.doStop(); } }
@Test public void testReceiveMessage() throws Exception { log.info("starting testReceiveMessage ... "); MockMessageProducer messageProducer = new MockMessageProducer(); SmppConfiguration configuration = new SmppConfiguration(); configuration.setHost("localhost"); configuration.setPort(SERVER_PORT); configuration.setSystemId("test"); configuration.setPassword("test"); SmppConnector connector = new SmppConnector(configuration); injectResource(new MockProcessorContext(), connector); injectResource(messageProducer, connector); connector.doStart(); waitUntilStatus(connector, DEFAULT_TIMEOUT, Status.OK); try { String to = "3542"; String from = "3002175604"; String text = "this is a test"; // retrieve the session Assert.assertEquals(server.getSessions().size(), 1); SmppSession session = server.getSessions().iterator().next(); Assert.assertNotNull(session); // create and send the request DeliverSm deliverSM = new DeliverSm(); deliverSM.setDestAddress(new Address((byte) 0, (byte) 0, to)); deliverSM.setSourceAddress(new Address((byte) 0, (byte) 0, from)); deliverSM.setShortMessage(text.getBytes()); session.sendRequest(deliverSM, DEFAULT_TIMEOUT); long timeout = 2000; if (!receiveMessage(messageProducer, timeout)) { Assert.fail("the message was not received"); } Message message = (Message) messageProducer.getMessage(0); Assert.assertEquals(to, message.getProperty("to", String.class)); Assert.assertEquals(from, message.getProperty("from", String.class)); Assert.assertEquals(text, message.getProperty("text", String.class)); } finally { connector.doStop(); } }
@Test public void testBindParameters() throws Exception { log.info("starting testBindParameters ... "); // set the mock packet processor MockPacketProcessor pp = new MockPacketProcessor(); server.setPacketProcessor(pp); SmppConfiguration configuration = new SmppConfiguration(); configuration.setHost("localhost"); configuration.setPort(SERVER_PORT); configuration.setSystemId("test"); configuration.setPassword("test"); configuration.setSystemType("test"); configuration.setBindNPI("1"); configuration.setBindTON("2"); SmppConnector connector = new SmppConnector(configuration); injectResource(new MockProcessorContext(), connector); connector.doStart(); waitUntilStatus(connector, DEFAULT_TIMEOUT, Status.OK); connector.doStop(); // validate the bind packet Bind bind = pp.getBindPacket(DEFAULT_TIMEOUT); Assert.assertNotNull(bind); Assert.assertEquals(bind.getCommandId(), SmppPacket.BIND_TRANSCEIVER); Assert.assertEquals(bind.getSystemId(), "test"); Assert.assertEquals(bind.getPassword(), "test"); Assert.assertEquals(bind.getSystemType(), "test"); Assert.assertEquals(bind.getAddressRange().getNpi(), 1); Assert.assertEquals(bind.getAddressRange().getTon(), 2); }
@Test public void testFailedConnectionOnStart() throws Exception { log.info("starting testFailedConnectionOnStart ... "); stopSimulator(); SmppConfiguration configuration = new SmppConfiguration(); configuration.setHost("localhost"); configuration.setPort(SERVER_PORT); configuration.setSystemId("test"); configuration.setPassword("test"); configuration.setInitialReconnectDelay(500); configuration.setReconnectDelay(500); SmppConnector connector = new SmppConnector(configuration); injectResource(new MockProcessorContext(), connector); connector.doStart(); waitUntilStatus(connector, 3000, Status.FAILED); startSimulator(); waitUntilStatus(connector, DEFAULT_TIMEOUT, Status.OK); connector.doStop(); }
@Test public void testFailedCommandStatuses() throws Exception { server.setPacketProcessor( new PacketProcessor() { @Override public void processPacket(SmppRequest packet, ResponseSender responseSender) { if (packet.getCommandId() == SmppPacket.SUBMIT_SM) { responseSender.send(Response.MESSAGE_QUEUE_FULL.withMessageId("12000")); return; } responseSender.send(Response.OK); } }); SmppConfiguration configuration = new SmppConfiguration(); configuration.setHost("localhost"); configuration.setPort(SERVER_PORT); configuration.setSystemId("test"); configuration.setPassword("test"); configuration.addFailedCommandStatus(Response.MESSAGE_QUEUE_FULL.getCommandStatus()); MockMessageStore messageStore = new MockMessageStore(); MockMessageProducer messageProducer = new MockMessageProducer(); SmppConnector connector = createAndStartSmppConnector(configuration, messageStore, messageProducer); try { // send a message Message message = new Message(); message.setProperty("to", "3542"); message.setProperty("from", "3002175604"); message.setProperty("text", "This is the test"); sendMessage(connector, messageStore, message); Assert.assertEquals(messageStore.messages.size(), 1); Message m1 = messageStore.messages.iterator().next(); Assert.assertNotNull(m1); waitMessageUntilStatus(m1, DEFAULT_TIMEOUT, Message.STATUS_FAILED); Assert.assertEquals(m1.getStatus(), Message.STATUS_FAILED); } finally { connector.doStop(); } }
@Test public void testProcessLongMessage() throws Exception { log.info("starting testProcessLongMessage ... "); MockPacketProcessor pp = new MockPacketProcessor( new PacketProcessor() { @Override public void processPacket(SmppRequest packet, ResponseSender responseSender) { if (packet.getCommandId() == SmppPacket.SUBMIT_SM) { responseSender.send(Response.OK.withMessageId("12000")); return; } responseSender.send(Response.OK); } }); server.setPacketProcessor(pp); MessageStore messageStore = Mockito.mock(MessageStore.class); SmppConfiguration configuration = new SmppConfiguration(); configuration.setHost("localhost"); configuration.setPort(SERVER_PORT); configuration.setSystemId("test"); configuration.setPassword("test"); configuration.setDataCoding(3); SmppConnector connector = new SmppConnector(configuration); injectResource(new MockProcessorContext(), connector); injectResource(messageStore, connector); connector.doStart(); waitUntilStatus(connector, DEFAULT_TIMEOUT, Status.OK); try { Message message = new Message(); message.setProperty("to", "3002175604"); message.setProperty("from", "3542"); message.setProperty( "text", "This is a long message to test how the smpp is working with long message splitting them by the 160 character and sending two messages. Finish the first message This is the second message."); connector.process(message); Assert.assertNotNull(message.getReference()); List<SmppPacket> packets = pp.getPackets(2, DEFAULT_TIMEOUT); Assert.assertNotNull(packets); Assert.assertEquals(packets.size(), 2); SmppPacket packet = packets.get(0); Assert.assertNotNull(packet); Assert.assertEquals(packet.getCommandId(), SmppPacket.SUBMIT_SM); SubmitSm submitSm = (SubmitSm) packet; Assert.assertEquals( submitSm.getShortMessage(), "This is a long message to test how the smpp is working with long message splitting them by the 160 character and sending two messages. Finish the first message "); Tlv totalTlv = submitSm.getOptionalParameter(SmppConstants.TAG_SAR_TOTAL_SEGMENTS); Assert.assertNotNull(totalTlv); Assert.assertEquals(ByteArrayUtil.toByte(totalTlv.getValue()), 2); Tlv segmentTlv = submitSm.getOptionalParameter(SmppConstants.TAG_SAR_SEGMENT_SEQNUM); Assert.assertNotNull(segmentTlv); Assert.assertEquals(ByteArrayUtil.toByte(segmentTlv.getValue()), 1); Tlv msgRefTlv = submitSm.getOptionalParameter(SmppConstants.TAG_SAR_MSG_REF_NUM); Assert.assertNotNull(msgRefTlv); packet = packets.get(1); Assert.assertNotNull(packet); Assert.assertEquals(packet.getCommandId(), SmppPacket.SUBMIT_SM); submitSm = (SubmitSm) packet; Assert.assertEquals(submitSm.getShortMessage(), "This is the second message."); totalTlv = submitSm.getOptionalParameter(SmppConstants.TAG_SAR_TOTAL_SEGMENTS); Assert.assertNotNull(totalTlv); Assert.assertEquals(ByteArrayUtil.toByte(totalTlv.getValue()), 2); segmentTlv = submitSm.getOptionalParameter(SmppConstants.TAG_SAR_SEGMENT_SEQNUM); Assert.assertNotNull(segmentTlv); Assert.assertEquals(ByteArrayUtil.toByte(segmentTlv.getValue()), 2); msgRefTlv = submitSm.getOptionalParameter(SmppConstants.TAG_SAR_MSG_REF_NUM); Assert.assertNotNull(msgRefTlv); } finally { connector.doStop(); } }
@Test public void testProcessMessage() throws Exception { log.info("starting testProcessMessage ... "); MockPacketProcessor pp = new MockPacketProcessor( new PacketProcessor() { @Override public void processPacket(SmppRequest packet, ResponseSender responseSender) { if (packet.getCommandId() == SmppPacket.SUBMIT_SM) { responseSender.send(Response.OK.withMessageId("12000")); return; } responseSender.send(Response.OK); } }); server.setPacketProcessor(pp); MessageStore messageStore = Mockito.mock(MessageStore.class); Message m = new Message(); m.setProperty("to", "3002175604"); m.setProperty("from", "3542"); Mockito.when(messageStore.list(Mockito.any(MessageCriteria.class))) .thenReturn(Collections.singletonList(m)); SmppConfiguration configuration = new SmppConfiguration(); configuration.setHost("localhost"); configuration.setPort(SERVER_PORT); configuration.setSystemId("test"); configuration.setPassword("test"); configuration.setDataCoding(3); SmppConnector connector = new SmppConnector(configuration); injectResource(new MockProcessorContext(), connector); injectResource(messageStore, connector); connector.doStart(); waitUntilStatus(connector, DEFAULT_TIMEOUT, Status.OK); try { Message message = new Message(); message.setProperty("to", "3002175604"); message.setProperty("from", "3542"); message.setProperty("text", "This is the test with ñ"); connector.process(message); Assert.assertNotNull(message.getReference()); Mockito.verify(messageStore, Mockito.timeout(1000)).saveOrUpdate(Mockito.any(Message.class)); List<SmppPacket> packets = pp.getPackets(1, DEFAULT_TIMEOUT); Assert.assertNotNull(packets); Assert.assertEquals(packets.size(), 1); SubmitSm submitSM = (SubmitSm) packets.get(0); Assert.assertNotNull(submitSM); Assert.assertEquals(submitSM.getDestAddress().getAddress(), "3002175604"); Assert.assertEquals(submitSM.getSourceAddress().getAddress(), "3542"); Assert.assertEquals(submitSM.getDataCoding(), 3); Assert.assertEquals(submitSM.getShortMessage(), "This is the test with ñ"); } finally { connector.doStop(); } }