use of se.inera.intyg.infra.logmessages.PdlLogMessage in project webcert by sklintyg.
the class LogServiceImplTest method serviceSendsDocumentAndIdForCreate.
@Test
public void serviceSendsDocumentAndIdForCreate() throws Exception {
when(userService.getUser()).thenReturn(createUser());
ArgumentCaptor<MessageCreator> messageCreatorCaptor = ArgumentCaptor.forClass(MessageCreator.class);
LogRequest logRequest = new LogRequest();
logRequest.setIntygId("abc123");
logRequest.setPatientId(createPnr("19121212-1212"));
logRequest.setPatientName("Hans Olof van der Test");
logService.logReadIntyg(logRequest);
verify(template, only()).send(messageCreatorCaptor.capture());
MessageCreator messageCreator = messageCreatorCaptor.getValue();
Session session = mock(Session.class);
ArgumentCaptor<String> intygReadMessageCaptor = ArgumentCaptor.forClass(String.class);
when(session.createTextMessage(intygReadMessageCaptor.capture())).thenReturn(null);
messageCreator.createMessage(session);
String body = intygReadMessageCaptor.getValue();
PdlLogMessage intygReadMessage = objectMapper.readValue(body, PdlLogMessage.class);
assertNotNull(intygReadMessage.getLogId());
assertEquals(ActivityType.READ, intygReadMessage.getActivityType());
assertEquals(ActivityPurpose.CARE_TREATMENT, intygReadMessage.getPurpose());
assertEquals("Intyg", intygReadMessage.getPdlResourceList().get(0).getResourceType());
assertEquals("abc123", intygReadMessage.getActivityLevel());
assertEquals("HSAID", intygReadMessage.getUserId());
assertEquals("Markus Gran", intygReadMessage.getUserName());
assertEquals("Läkare på vårdcentralen", intygReadMessage.getUserAssignment());
assertEquals("Överläkare", intygReadMessage.getUserTitle());
assertEquals("VARDENHET_ID", intygReadMessage.getUserCareUnit().getEnhetsId());
assertEquals("Vårdenheten", intygReadMessage.getUserCareUnit().getEnhetsNamn());
assertEquals("VARDGIVARE_ID", intygReadMessage.getUserCareUnit().getVardgivareId());
assertEquals("Vårdgivaren", intygReadMessage.getUserCareUnit().getVardgivareNamn());
assertEquals("191212121212", intygReadMessage.getPdlResourceList().get(0).getPatient().getPatientId());
assertEquals("Hans Olof van der Test", intygReadMessage.getPdlResourceList().get(0).getPatient().getPatientNamn());
assertTrue(intygReadMessage.getTimestamp().minusSeconds(DELAY).isBefore(now()));
assertTrue(intygReadMessage.getTimestamp().plusSeconds(DELAY).isAfter(now()));
assertEquals("webcert", intygReadMessage.getSystemId());
assertEquals("WebCert", intygReadMessage.getSystemName());
}
Aggregations