Ejemplo n.º 1
0
  @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();
    }
  }
Ejemplo n.º 2
0
  @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();
    }
  }