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