MessageInfoElement { public static void readElement(final OMElement miElement, final MessageUnit msgUnit) { if (miElement == null) return; try { msgUnit.setTimestamp(Utils.fromXMLDateTime(miElement.getFirstChildWithName(Q_TIMESTAMP).getText())); } catch (final OMException | ParseException e) { msgUnit.setTimestamp(null); } final OMElement messageId = miElement.getFirstChildWithName(Q_MESSAGEID); if (messageId != null && !Utils.isNullOrEmpty(messageId.getText())) msgUnit.setMessageId(messageId.getText()); else msgUnit.setMessageId(null); final OMElement refToMsgId = miElement.getFirstChildWithName(Q_REFTO_MESSAGEID); if (refToMsgId != null && !Utils.isNullOrEmpty(refToMsgId.getText())) msgUnit.setRefToMessageId(refToMsgId.getText()); }  static OMElement createElement(final OMElement muElement, final IMessageUnit data); static OMElement getElement(final OMElement piElement); static void readElement(final OMElement miElement, final MessageUnit msgUnit); static final QName Q_ELEMENT_NAME; }
@Test public void testReadElement() throws Exception { String msgId = UUID.randomUUID().toString(); Date timestamp = new Date(); String refToMsgId = UUID.randomUUID().toString(); UserMessage msgUnit = new UserMessage(); MessageInfoElement.readElement(createXML( "<eb3:MessageInfo xmlns:eb3=\"http: " <eb3:Timestamp>" + Utils.toXMLDateTime(timestamp) + "</eb3:Timestamp>\n" + " <eb3:MessageId>" + msgId + "</eb3:MessageId>\n" + " <eb3:RefToMessageId>" + refToMsgId + "</eb3:RefToMessageId>\n" + "</eb3:MessageInfo>"), msgUnit); assertEquals(msgId, msgUnit.getMessageId()); assertEquals(timestamp, msgUnit.getTimestamp()); assertEquals(refToMsgId, msgUnit.getRefToMessageId()); }