class NwhinDataRetriever extends AbstractC32DaoAware implements MessageListener {

	@Override
	public void onMessage(Message msg) {
		TextMessage tMsg = (TextMessage)msg;
		AsyncRetrieveMessage aMsg = null;
		
		try {
			aMsg = (AsyncRetrieveMessage)getAsyncMessageFormat().parse(tMsg.getText());
		}
		catch (Exception ex) {
			logger.error("message parsing error for " + msg + ": USER CANNOT BE NOTIFIED (users info is not known)", ex);
			return;
		}
		
		C32DocumentEntity doc = getC32Document(aMsg);

		try {
			if (logger.isDebugEnabled()) {
				logger.debug("Attempting to Persist Domain XML for: " + aMsg.getPatientId());
			}
			updateDocumentWithNewDocument(aMsg.getPatientId(), doc);
		}
		catch (Exception ex) {
			logger.error("error saving c32 document: USER NOT NOTIFIED:" + msg, ex);
		}
	}

}

class NwhinDataRetrieverTest extends AbstractC32DaoAware implements MessageListener {

	 NwhinDataRetriever retriever;
	 List<C32DocumentEntity> insertedList;
	 List<C32DocumentEntity> updatedList;
	 List<C32DocumentEntity> docList;
	 String returnXml;
	 String ptNameToAssert;
	 String ptIdToAssert;
	 boolean nwhinError;
	 boolean parsingError;

	@Test
	public void onMessage_docEmpty() {

		ptIdToAssert = "998877v99";
		setupDocList(ptIdToAssert, ptIdToAssert, "");
		retriever.onMessage(new TestTextMessage("20120908070605:998877v99:fred"));
		Assert.assertEquals(0, insertedList.size());
		Assert.assertEquals(1, updatedList.size());
		Assert.assertEquals(BlueButtonConstants.UNAVAILABLE_STATUS_STRING, updatedList.get(0).getDocument());
		Assert.assertEquals(ptIdToAssert, updatedList.get(0).getDocumentPatientId());
		Assert.assertEquals(ptIdToAssert, updatedList.get(0).getIcn());
		assertDatePartEqualsToday(updatedList.get(0).getCreateDate());
	}

}