use of uk.gov.justice.hmpps.prison.repository.v1.model.EventSP in project prison-api by ministryofjustice.
the class NomisApiV1ResourceIntTest method getEvents_WithSpacesBetweenEventData.
@Test
public void getEvents_WithSpacesBetweenEventData() {
final var requestEntity = createHttpEntityWithBearerAuthorisation("ITAG_USER", List.of("ROLE_NOMIS_API_V1"), null);
final var events = List.of(new EventSP(3L, LocalDateTime.parse("2019-03-31T00:01:00.12456"), "LEI", "AB1256B", "ALERT", "{\"case_note\":{\"id\":47004657,\"contact_datetime\":\"2019-03-31 ", null, "00:00:00\"\n" + ",\"source\":{\"code\":\"AUTO\"\n" + ",\"desc\":\"System\"\n" + "},\"type\":{\"code\":\"ALERT\"\n" + ",\"desc\":\"Alert\"\n" + "},\"sub_type\":{\"code\":\"INACTIVE\"\n" + ",\"desc\":\"Made Inactive\"\n" + "},\"staff_member\":{\"id\":1,\"name\":\"Cnomis, Admin&Onb\"\n" + ",\"userid\":\"\"\n" + "},\"text\":\"Alert Other and Charged under Harassment Act made inactive.\"\n" + ",\"amended\":false}}"), new EventSP(4L, LocalDateTime.parse("2019-04-30T00:00:01.234567"), "MDI", "BC1256B", "INTERNAL_LOCATION_CHANGED", "{\"account\":{\"code\":\"REG\"\n" + ",\"desc\":\"Private", " Cash\"\n" + "},\"balance\":0}", null), new EventSP(5L, LocalDateTime.parse("2019-03-31T00:00:01"), "MDI", "CD1256B", "PERSONAL_DETAILS_CHANGED", null, null, null));
when(getEvents.execute(any(SqlParameterSource.class))).thenReturn(Map.of(P_EVENTS_CSR, events));
final var responseEntity = testRestTemplate.exchange("/api/v1/offenders/events?prison_id=MDI&offender_id=A1492AE&event_type=e&from_datetime=2019-07-07 07:15:20.090&limit=100", HttpMethod.GET, requestEntity, String.class);
// noinspection ConstantConditions
assertThat(new JsonContent<Events>(getClass(), forType(Events.class), responseEntity.getBody())).isEqualToJson("events.json");
}
use of uk.gov.justice.hmpps.prison.repository.v1.model.EventSP in project prison-api by ministryofjustice.
the class NomisApiV1ServiceTest method getEventsCopesWithAllNull.
@Test
public void getEventsCopesWithAllNull() {
final var date = LocalDateTime.parse("2020-01-02T03:02:01");
when(eventsV1Repository.getEvents(anyString(), isNull(), anyLong(), isNull(), anyString(), any(), anyLong())).thenReturn(List.of(new EventSP(5L, date, "MDI", "A1234", "ETYPE", null, null, null)));
final var events = service.getEvents("prison", new OffenderIdentifier("12345"), "type", LocalDateTime.now(), 5L);
assertThat(events).containsExactly(new Event("ETYPE", 5L, "A1234", "MDI", date, "{}"));
}
use of uk.gov.justice.hmpps.prison.repository.v1.model.EventSP in project prison-api by ministryofjustice.
the class NomisApiV1ServiceTest method getEventsCopesWithSomeNull.
@Test
public void getEventsCopesWithSomeNull() {
final var date = LocalDateTime.parse("2020-01-02T03:02:01");
when(eventsV1Repository.getEvents(anyString(), isNull(), anyLong(), isNull(), anyString(), any(), anyLong())).thenReturn(List.of(new EventSP(5L, date, "MDI", "A1234", "ETYPE", null, " a value ", null)));
final var events = service.getEvents("prison", new OffenderIdentifier("12345"), "type", LocalDateTime.now(), 5L);
assertThat(events).containsExactly(new Event("ETYPE", 5L, "A1234", "MDI", date, " a value "));
}
use of uk.gov.justice.hmpps.prison.repository.v1.model.EventSP in project prison-api by ministryofjustice.
the class NomisApiV1ServiceTest method getEvents.
@Test
public void getEvents() {
final var date = LocalDateTime.parse("2020-01-02T03:02:01");
when(eventsV1Repository.getEvents(anyString(), isNull(), anyLong(), isNull(), anyString(), any(), anyLong())).thenReturn(List.of(new EventSP(5L, date, "MDI", "A1234", "ETYPE", "Event ", "Data 2", " and 3")));
final var events = service.getEvents("prison", new OffenderIdentifier("12345"), "type", LocalDateTime.now(), 5L);
assertThat(events).containsExactly(new Event("ETYPE", 5L, "A1234", "MDI", date, "Event Data 2 and 3"));
}
use of uk.gov.justice.hmpps.prison.repository.v1.model.EventSP in project prison-api by ministryofjustice.
the class NomisApiV1ResourceIntTest method getEvents.
@Test
public void getEvents() {
final var requestEntity = createHttpEntityWithBearerAuthorisation("ITAG_USER", List.of("ROLE_NOMIS_API_V1"), null);
final var events = List.of(new EventSP(3L, LocalDateTime.parse("2019-03-31T00:01:00.12456"), "LEI", "AB1256B", "ALERT", null, null, "{\"case_note\":{\"id\":47004657,\"contact_datetime\":\"2019-03-31 00:00:00\"\n" + ",\"source\":{\"code\":\"AUTO\"\n" + ",\"desc\":\"System\"\n" + "},\"type\":{\"code\":\"ALERT\"\n" + ",\"desc\":\"Alert\"\n" + "},\"sub_type\":{\"code\":\"INACTIVE\"\n" + ",\"desc\":\"Made Inactive\"\n" + "},\"staff_member\":{\"id\":1,\"name\":\"Cnomis, Admin&Onb\"\n" + ",\"userid\":\"\"\n" + "},\"text\":\"Alert Other and Charged under Harassment Act made inactive.\"\n" + ",\"amended\":false}}"), new EventSP(4L, LocalDateTime.parse("2019-04-30T00:00:01.234567"), "MDI", "BC1256B", "INTERNAL_LOCATION_CHANGED", null, "{\"account\":{\"code\":\"REG\"\n" + ",\"desc\":\"Private Cash\"\n" + "},\"balance\":0}", null), new EventSP(5L, LocalDateTime.parse("2019-03-31T00:00:01"), "MDI", "CD1256B", "PERSONAL_DETAILS_CHANGED", null, null, null));
final var captor = ArgumentCaptor.forClass(SqlParameterSource.class);
when(getEvents.execute(captor.capture())).thenReturn(Map.of(P_EVENTS_CSR, events));
final var responseEntity = testRestTemplate.exchange("/api/v1/offenders/events?prison_id=MDI&offender_id=A1492AE&event_type=e&from_datetime=2019-07-07 07:15:20.090&limit=100", HttpMethod.GET, requestEntity, String.class);
assertThat(captor.getValue().getValue(P_AGY_LOC_ID)).isEqualTo("MDI");
assertThat(captor.getValue().getValue(P_NOMS_ID)).isEqualTo("A1492AE");
assertThat(captor.getValue().getValue(P_ROOT_OFFENDER_ID)).isNull();
assertThat(captor.getValue().getValue(P_SINGLE_OFFENDER_ID)).isNull();
assertThat(captor.getValue().getValue(P_EVENT_TYPE)).isEqualTo("e");
assertThat(captor.getValue().getValue(P_FROM_TS)).isEqualTo(LocalDateTime.parse("2019-07-07T07:15:20.090"));
assertThat(captor.getValue().getValue(P_LIMIT)).isEqualTo(100L);
// noinspection ConstantConditions
assertThat(new JsonContent<Events>(getClass(), forType(Events.class), responseEntity.getBody())).isEqualToJson("events.json");
}
Aggregations