TelestaxDlrParser implements DlrParser { @Override public DLRPayload parseMessage(String message) { DLRPayload dlr = new DLRPayload(); final String messageId = parseTagValue(message, ID_TAG); dlr.setId(messageId); final String submit_date = parseTagValue(message, SUBMIT_TAG); DateTime parsedDate = parseDate(submit_date); dlr.setSubmitDate(parsedDate); final String done_date = parseTagValue(message, DONE_TAG); DateTime doneDate = parseDate(done_date); dlr.setDoneDate(doneDate); final String stat = parseTagValue(message, STAT_TAG); Status parsedStatus = parseRestcommStatus(stat); dlr.setStat(parsedStatus); final String err = parseTagValue(message, ERR_TAG); MessageError parsedError = parseRestcommErrorCode(err); dlr.setErr(parsedError); final String sub = parseTagValue(message, SUB_TAG); dlr.setSub(sub); final String dlv = parseTagValue(message, DLVRD_TAG); dlr.setDlvrd(dlv); if (logger.isDebugEnabled()) { logger.debug("Parsed DLR is:" + dlr); } return dlr; }  @Override DLRPayload parseMessage(String message);  }
@Test public void parseInvalidDLR() { final String pduMessage = "submit date:invaliddate stat:invalidStat"; DlrParser parser = new TelestaxDlrParser(); DLRPayload dlrMap = parser.parseMessage(pduMessage); Assert.assertNull(dlrMap.getId()); }
@Test public void parseDLRMessageTest() { final String pduMessage = "id:0000058049 sub:001 dlvrd:001 submit date:1805170144 done date:1805170144 stat:DELIVRD err:000 text:none "; DlrParser parser = new TelestaxDlrParser(); DLRPayload dlrMap = parser.parseMessage(pduMessage); Assert.assertEquals("0000058049", dlrMap.getId()); Assert.assertEquals("001", dlrMap.getSub()); Assert.assertEquals("001", dlrMap.getDlvrd()); Assert.assertNull(dlrMap.getErr()); Assert.assertEquals(Status.DELIVERED, dlrMap.getStat()); Assert.assertEquals(2018, dlrMap.getDoneDate().getYear()); Assert.assertEquals(2018, dlrMap.getSubmitDate().getYear()); }