@Override public String getStyle(Object itemId, Object propertyId) { if (propertyId == null) { return null; } Message message = messagesMap.get((Long) itemId); if (propertyId.equals("Status")) { if (message.getStatus().equals(Status.FAILED)) { return "red"; } } if (propertyId.equals("Cmd Status")) { int commandStatus = message.getProperty("commandStatus", Integer.class); if (commandStatus != 0) { return "red"; } } if (propertyId.equals("Receipt")) { String receiptStatus = message.getProperty("receiptStatus", String.class); if ("DELIVRD".equals(receiptStatus)) { return "green"; } else if (receiptStatus != null && !"".equals(receiptStatus)) { return "red"; } } return null; }
@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 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 shouldCopyPropertyAndDeleteFrom() throws Exception { CopyAction action = new CopyAction(); action.setFrom("prop-1"); action.setTo("prop-2"); action.setDeleteFrom(true); Message message = new Message(); message.setProperty("prop-1", "value"); action.execute(message); Assert.assertNull(message.getProperty("prop-1")); Assert.assertEquals(message.getProperty("prop-2"), "value"); }
@Test public void shouldAddSuffixIfFieldDoesntExists() throws Exception { AddSuffixAction action = new AddSuffixAction(); action.setField("to"); action.setSuffix("suf"); Message message = new Message(); action.execute(message); Assert.assertEquals(message.getProperty("to", String.class), "suf"); }
/** Cleans the table and reloads the data. */ public void loadData() { removeAllItems(); MessageCriteria criteria = new MessageCriteria() .direction(Direction.TO_CONNECTIONS) .orderBy("id") .orderType(OrderType.DOWNWARDS) .numRecords(2000); Collection<Message> messages = messageStore.list(criteria); messagesMap = new HashMap<Long, Message>(); for (Message message : messages) { messagesMap.put(message.getId(), message); } for (Message message : messages) { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); Timestamp receiptDate = message.getProperty("receiptTime", Timestamp.class); String strReceiptDate = ""; if (receiptDate != null) { strReceiptDate = sdf.format(receiptDate); } Object[] data = new Object[] { message.getId(), sdf.format(message.getCreationTime()), message.getSource(), message.getDestination(), message.getStatus().toString(), message.getProperty("to", String.class), message.getProperty("from", String.class), message.getProperty("sequenceNumber", Integer.class), message.getProperty("messageId", String.class), message.getProperty("commandStatus", Integer.class), message.getProperty("receiptStatus", String.class), strReceiptDate, message.getProperty("text", String.class) }; addItem(data, message.getId()); } }
@Override public Collection<Message> list(MessageCriteria criteria) throws StoreException { if (criteria != null && criteria.getProperties().get("smsc_messageid") != null) { Collection<Message> ret = new ArrayList<Message>(); // check messageId String messageId = (String) criteria.getProperties().get("smsc_messageid"); if (messageId != null) { for (Message message : messages) { String testId = message.getProperty("messageId", String.class); if (testId != null && messageId.equals(testId)) { ret.add(message); } } } return ret; } return messages; }