@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; }
private void waitMessageUntilStatus(Message message, long timeout, byte status) { boolean isValid = false; long startTime = new Date().getTime(); long actualTime = new Date().getTime(); while (!isValid && (actualTime - startTime) <= timeout) { if (message.getStatus() == status) { isValid = true; } else { synchronized (this) { try { this.wait(200); } catch (Exception e) { } } } actualTime = new Date().getTime(); } Assert.assertEquals(message.getStatus(), status); }
@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(); } }
/** 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()); } }