@Test public void testOnMessage() throws Exception { ReindexPatientMessageHandler handler = new ReindexPatientMessageHandler(); ISolrDao solrServiceMock = Mockito.mock(ISolrDao.class); IGenericPatientObjectDAO genericPatientRelatedDaoMock = Mockito.mock(IGenericPatientObjectDAO.class); handler.setSolrDao(solrServiceMock); handler.setGenericPatientRelatedDao(genericPatientRelatedDaoMock); LinkedHashMap<String, Object> allergyValues = new LinkedHashMap<String, Object>(2); allergyValues.put("pid", "3"); allergyValues.put("summary", "test"); Allergy al = new Allergy(allergyValues); Page<Allergy> page = new PageImpl(Collections.singletonList(al)); when(genericPatientRelatedDaoMock.findAllByPID(Allergy.class, "3", null)).thenReturn(page); LinkedHashMap<String, String> map1 = new LinkedHashMap<String, String>(1); map1.put("patientId", "3"); Session mockSession = Mockito.mock(Session.class); Message mockMessage = Mockito.mock(Message.class); SimpleMessageConverter converter = Mockito.mock(SimpleMessageConverter.class); handler.converter = converter; when(converter.fromMessage(mockMessage)).thenReturn(map1); handler.onMessage(mockMessage, mockSession); verify(genericPatientRelatedDaoMock, times(1)).findAllByPID(Allergy.class, "3", null); verify(solrServiceMock, times(1)).save(al); }
public void onMessage(Message message, Session session) { Map msg = null; try { msg = (Map) converter.fromMessage(message); final String pid = (String) msg.get(SyncMessageConstants.PATIENT_ID); Assert.hasText(pid, "[Assertion failed] - the 'pid' argument must have text; it must not be null, empty, or blank"); LOGGER.debug("Reindexing " + pid); for (String domain : UidUtils.getAllPatientDataDomains()) { Class domainClass = UidUtils.getDomainClass(domain); Page<IPatientObject> items = genericPatientRelatedDao.findAllByPID(domainClass, pid, null); if (items == null) continue; for (IPatientObject item : items) { try { solrDao.save(item); } catch (Exception e) { LOGGER.error("unable to reindex item " + String.valueOf(item), e); } } } } catch (Exception e) { LOGGER.error("Error synching patient data: " + e.getMessage(), e); try { errorDao.save(new SyncError(message, msg, e)); session.recover(); } catch (JMSException e1) { LOGGER.error("Exception saving sync error: " + e.getMessage(), e1); } } }
ReindexPatientMessageHandler implements SessionAwareMessageListener { public void onMessage(Message message, Session session) { Map msg = null; try { msg = (Map) converter.fromMessage(message); final String pid = (String) msg.get(SyncMessageConstants.PATIENT_ID); Assert.hasText(pid, "[Assertion failed] - the 'pid' argument must have text; it must not be null, empty, or blank"); LOGGER.debug("Reindexing " + pid); for (String domain : UidUtils.getAllPatientDataDomains()) { Class domainClass = UidUtils.getDomainClass(domain); Page<IPatientObject> items = genericPatientRelatedDao.findAllByPID(domainClass, pid, null); if (items == null) continue; for (IPatientObject item : items) { try { solrDao.save(item); } catch (Exception e) { LOGGER.error("unable to reindex item " + String.valueOf(item), e); } } } } catch (Exception e) { LOGGER.error("Error synching patient data: " + e.getMessage(), e); try { errorDao.save(new SyncError(message, msg, e)); session.recover(); } catch (JMSException e1) { LOGGER.error("Exception saving sync error: " + e.getMessage(), e1); } } } }
ReindexPatientMessageHandler implements SessionAwareMessageListener { public void onMessage(Message message, Session session) { Map msg = null; try { msg = (Map) converter.fromMessage(message); final String pid = (String) msg.get(SyncMessageConstants.PATIENT_ID); Assert.hasText(pid, "[Assertion failed] - the 'pid' argument must have text; it must not be null, empty, or blank"); LOGGER.debug("Reindexing " + pid); for (String domain : UidUtils.getAllPatientDataDomains()) { Class domainClass = UidUtils.getDomainClass(domain); Page<IPatientObject> items = genericPatientRelatedDao.findAllByPID(domainClass, pid, null); if (items == null) continue; for (IPatientObject item : items) { try { solrDao.save(item); } catch (Exception e) { LOGGER.error("unable to reindex item " + String.valueOf(item), e); } } } } catch (Exception e) { LOGGER.error("Error synching patient data: " + e.getMessage(), e); try { errorDao.save(new SyncError(message, msg, e)); session.recover(); } catch (JMSException e1) { LOGGER.error("Exception saving sync error: " + e.getMessage(), e1); } } }  }
ReindexPatientMessageHandler implements SessionAwareMessageListener { public void onMessage(Message message, Session session) { Map msg = null; try { msg = (Map) converter.fromMessage(message); final String pid = (String) msg.get(SyncMessageConstants.PATIENT_ID); Assert.hasText(pid, "[Assertion failed] - the 'pid' argument must have text; it must not be null, empty, or blank"); LOGGER.debug("Reindexing " + pid); for (String domain : UidUtils.getAllPatientDataDomains()) { Class domainClass = UidUtils.getDomainClass(domain); Page<IPatientObject> items = genericPatientRelatedDao.findAllByPID(domainClass, pid, null); if (items == null) continue; for (IPatientObject item : items) { try { solrDao.save(item); } catch (Exception e) { LOGGER.error("unable to reindex item " + String.valueOf(item), e); } } } } catch (Exception e) { LOGGER.error("Error synching patient data: " + e.getMessage(), e); try { errorDao.save(new SyncError(message, msg, e)); session.recover(); } catch (JMSException e1) { LOGGER.error("Exception saving sync error: " + e.getMessage(), e1); } } }  @Autowired void setErrorDao(IVprSyncErrorDao errorDao); ISolrDao getSolrDao(); @Autowired void setSolrDao(ISolrDao solrDao); IGenericPatientObjectDAO getGenericPatientRelatedDao(); @Autowired void setGenericPatientRelatedDao(IGenericPatientObjectDAO genericPatientRelatedDao); void onMessage(Message message, Session session); }
ReindexPatientMessageHandler implements SessionAwareMessageListener { public void onMessage(Message message, Session session) { Map msg = null; try { msg = (Map) converter.fromMessage(message); final String pid = (String) msg.get(SyncMessageConstants.PATIENT_ID); Assert.hasText(pid, "[Assertion failed] - the 'pid' argument must have text; it must not be null, empty, or blank"); LOGGER.debug("Reindexing " + pid); for (String domain : UidUtils.getAllPatientDataDomains()) { Class domainClass = UidUtils.getDomainClass(domain); Page<IPatientObject> items = genericPatientRelatedDao.findAllByPID(domainClass, pid, null); if (items == null) continue; for (IPatientObject item : items) { try { solrDao.save(item); } catch (Exception e) { LOGGER.error("unable to reindex item " + String.valueOf(item), e); } } } } catch (Exception e) { LOGGER.error("Error synching patient data: " + e.getMessage(), e); try { errorDao.save(new SyncError(message, msg, e)); session.recover(); } catch (JMSException e1) { LOGGER.error("Exception saving sync error: " + e.getMessage(), e1); } } }  @Autowired void setErrorDao(IVprSyncErrorDao errorDao); ISolrDao getSolrDao(); @Autowired void setSolrDao(ISolrDao solrDao); IGenericPatientObjectDAO getGenericPatientRelatedDao(); @Autowired void setGenericPatientRelatedDao(IGenericPatientObjectDAO genericPatientRelatedDao); void onMessage(Message message, Session session);  }