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); } }  FormatTS getAsyncMessageFormat(); void setAsyncMessageFormat(FormatTS asyncMessageFormat); C32DocumentEntityFactory getDocumentFactory(); void setDocumentFactory(C32DocumentEntityFactory documentFactory); void setWrapperResource(WrapperResource resource); @Override void onMessage(Message msg);  }
@Test public void onMessage_happyPath() { ptIdToAssert = "112233v10"; setupDocList(ptIdToAssert, ptIdToAssert); retriever.onMessage(new TestTextMessage("20120908070605:112233v10:fred")); Assert.assertEquals(0, insertedList.size()); Assert.assertEquals(1, updatedList.size()); Assert.assertEquals(returnXml, updatedList.get(0).getDocument()); Assert.assertEquals(ptIdToAssert, updatedList.get(0).getDocumentPatientId()); Assert.assertEquals(ptIdToAssert, updatedList.get(0).getIcn()); assertDatePartEqualsToday(updatedList.get(0).getCreateDate()); }
@Test public void onMessage_errorWrongPtId() { ptIdToAssert = "112233v01"; String docPtId = "112233v02"; setupDocList(ptIdToAssert, docPtId); retriever.onMessage(new TestTextMessage("20120908070605:112233v01:fred")); Assert.assertEquals(0, insertedList.size()); Assert.assertEquals(1, updatedList.size()); Assert.assertEquals(BlueButtonConstants.ERROR_PTID_STATUS_STRING, updatedList.get(0).getDocument()); Assert.assertEquals(docPtId, updatedList.get(0).getDocumentPatientId()); Assert.assertEquals(ptIdToAssert, updatedList.get(0).getIcn()); assertDatePartEqualsToday(updatedList.get(0).getCreateDate()); }
@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()); }
@Test public void onMessage_docNull() { ptIdToAssert = "998877v99"; setupDocList(ptIdToAssert, ptIdToAssert, null); 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()); }
@Test public void onMessage_error_nwhin() { nwhinError = true; ptIdToAssert = "998877vboom1"; setupDocList(ptIdToAssert, ptIdToAssert, "boom boom"); retriever.onMessage(new TestTextMessage("20120908070605:" + ptIdToAssert + ":fred")); Assert.assertEquals(0, insertedList.size()); Assert.assertEquals(1, updatedList.size()); Assert.assertEquals(BlueButtonConstants.ERROR_C32_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()); }
@Test public void onMessage_error_parsing() { parsingError = true; ptIdToAssert = "998877vboom2"; setupDocList(ptIdToAssert, ptIdToAssert, "boom boom #2"); retriever.onMessage(new TestTextMessage("20120908070605:" + ptIdToAssert + ":fred")); Assert.assertEquals(0, insertedList.size()); Assert.assertEquals(1, updatedList.size()); Assert.assertEquals(BlueButtonConstants.ERROR_C32_PARSE_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()); }