MessageInfoElement { public static OMElement createElement(final OMElement muElement, final IMessageUnit data) { final OMFactory f = muElement.getOMFactory(); final OMElement msginfo = f.createOMElement(Q_ELEMENT_NAME, muElement); final OMElement timestamp = f.createOMElement(Q_TIMESTAMP, msginfo); timestamp.setText(Utils.toXMLDateTime(data.getTimestamp())); final OMElement messageId = f.createOMElement(Q_MESSAGEID, msginfo); messageId.setText(data.getMessageId()); final String refToMsgId = data.getRefToMessageId(); if (!Utils.isNullOrEmpty(refToMsgId)) { final OMElement refToMsgIdElement = f.createOMElement(Q_REFTO_MESSAGEID, msginfo); refToMsgIdElement.setText(refToMsgId); } return msginfo; }  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 testCreateElementNoRefTo() throws Exception { UserMessage userMessage = new UserMessage(); userMessage.setMessageId(UUID.randomUUID().toString()); userMessage.setTimestamp(new Date()); OMElement miElement = MessageInfoElement.createElement(createParent(), userMessage); assertNotNull(miElement); assertEquals(MESSAGE_INFO_ELEMENT_NAME, miElement.getQName()); Iterator<OMElement> msgIdElems = miElement.getChildrenWithName(MESSAGE_ID_ELEMENT_NAME); assertFalse(Utils.isNullOrEmpty(msgIdElems)); assertEquals(userMessage.getMessageId(), msgIdElems.next().getText()); Iterator<OMElement> timestampElems = miElement.getChildrenWithName(TIMESTAMP_ELEMENT_NAME); assertFalse(Utils.isNullOrEmpty(timestampElems)); assertEquals(Utils.toXMLDateTime(userMessage.getTimestamp()), timestampElems.next().getText()); assertTrue(Utils.isNullOrEmpty(miElement.getChildrenWithName(REF_TO_MESSAGE_ID_ELEMENT_NAME))); }
@Test public void testCreateElementWithRefTo() throws Exception { Receipt receipt = new Receipt(); receipt.setMessageId(UUID.randomUUID().toString()); receipt.setTimestamp(new Date()); receipt.setRefToMessageId(UUID.randomUUID().toString()); OMElement miElement = MessageInfoElement.createElement(createParent(), receipt); assertNotNull(miElement); assertEquals(MESSAGE_INFO_ELEMENT_NAME, miElement.getQName()); Iterator<OMElement> msgIdElems = miElement.getChildrenWithName(MESSAGE_ID_ELEMENT_NAME); assertFalse(Utils.isNullOrEmpty(msgIdElems)); assertEquals(receipt.getMessageId(), msgIdElems.next().getText()); Iterator<OMElement> timestampElems = miElement.getChildrenWithName(TIMESTAMP_ELEMENT_NAME); assertFalse(Utils.isNullOrEmpty(timestampElems)); assertEquals(Utils.toXMLDateTime(receipt.getTimestamp()), timestampElems.next().getText()); Iterator<OMElement> refToElems = miElement.getChildrenWithName(REF_TO_MESSAGE_ID_ELEMENT_NAME); assertFalse(Utils.isNullOrEmpty(refToElems)); assertEquals(receipt.getRefToMessageId(), refToElems.next().getText()); }