Search in sources :

Example 1 with JsonContent

use of org.springframework.boot.test.json.JsonContent 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");
}
Also used : SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) GetEvents(uk.gov.justice.hmpps.prison.repository.v1.storedprocs.EventProcs.GetEvents) Events(uk.gov.justice.hmpps.prison.api.model.v1.Events) JsonContent(org.springframework.boot.test.json.JsonContent) EventSP(uk.gov.justice.hmpps.prison.repository.v1.model.EventSP) Test(org.junit.jupiter.api.Test) ResourceTest(uk.gov.justice.hmpps.prison.api.resource.impl.ResourceTest)

Example 2 with JsonContent

use of org.springframework.boot.test.json.JsonContent in project prison-api by ministryofjustice.

the class NomisApiV1ResourceIntTest method getLiveRoll.

@Test
public void getLiveRoll() {
    final var requestEntity = createHttpEntityWithBearerAuthorisation("ITAG_USER", List.of("ROLE_NOMIS_API_V1"), null);
    final var roll = List.of(new LiveRollSP("A12345B"), new LiveRollSP("B23456C"));
    final var captor = ArgumentCaptor.forClass(SqlParameterSource.class);
    when(getLiveRoll.execute(captor.capture())).thenReturn(Map.of(P_ROLL_CSR, roll));
    final var responseEntity = testRestTemplate.exchange("/api/v1/prison/MDI/live_roll", HttpMethod.GET, requestEntity, String.class);
    assertThat(captor.getValue().getValue(P_AGY_LOC_ID)).isEqualTo("MDI");
    // noinspection ConstantConditions
    assertThat(new JsonContent<LiveRoll>(getClass(), forType(LiveRoll.class), responseEntity.getBody())).isEqualToJson("roll.json");
}
Also used : LiveRoll(uk.gov.justice.hmpps.prison.api.model.v1.LiveRoll) GetLiveRoll(uk.gov.justice.hmpps.prison.repository.v1.storedprocs.PrisonProcs.GetLiveRoll) JsonContent(org.springframework.boot.test.json.JsonContent) LiveRollSP(uk.gov.justice.hmpps.prison.repository.v1.model.LiveRollSP) Test(org.junit.jupiter.api.Test) ResourceTest(uk.gov.justice.hmpps.prison.api.resource.impl.ResourceTest)

Example 3 with JsonContent

use of org.springframework.boot.test.json.JsonContent 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");
}
Also used : GetEvents(uk.gov.justice.hmpps.prison.repository.v1.storedprocs.EventProcs.GetEvents) Events(uk.gov.justice.hmpps.prison.api.model.v1.Events) JsonContent(org.springframework.boot.test.json.JsonContent) EventSP(uk.gov.justice.hmpps.prison.repository.v1.model.EventSP) Test(org.junit.jupiter.api.Test) ResourceTest(uk.gov.justice.hmpps.prison.api.resource.impl.ResourceTest)

Example 4 with JsonContent

use of org.springframework.boot.test.json.JsonContent in project prison-api by ministryofjustice.

the class NomisApiV1ResourceIntTest method getHoldsWithClientReference.

@Test
public void getHoldsWithClientReference() {
    final var requestEntity = createHttpEntityWithBearerAuthorisation("ITAG_USER_ADM", List.of("ROLE_NOMIS_API_V1"), Map.of("X-Client-Name", "some-client"));
    final var holds = List.of(new HoldSP(3L, "ref", "12345", "entry", null, new BigDecimal("123.45"), null), new HoldSP(4L, "some-client-ref2", "12346", "entry2", LocalDate.of(2019, 1, 2), new BigDecimal("123.46"), LocalDate.of(2018, 12, 30)));
    final var captor = ArgumentCaptor.forClass(SqlParameterSource.class);
    when(getHolds.execute(captor.capture())).thenReturn(Map.of(P_HOLDS_CSR, holds));
    final var responseEntity = testRestTemplate.exchange("/api/v1/prison/CKI/offenders/G1408GC/holds?client_unique_ref=some-reference", HttpMethod.GET, requestEntity, String.class);
    // noinspection ConstantConditions
    assertThat(new JsonContent<Hold>(getClass(), forType(Hold.class), responseEntity.getBody())).isEqualToJson("holds.json");
    assertThat(captor.getValue().getValue(P_CLIENT_UNIQUE_REF)).isEqualTo("some-client-some-reference");
}
Also used : HoldSP(uk.gov.justice.hmpps.prison.repository.v1.model.HoldSP) JsonContent(org.springframework.boot.test.json.JsonContent) Hold(uk.gov.justice.hmpps.prison.api.model.v1.Hold) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test) ResourceTest(uk.gov.justice.hmpps.prison.api.resource.impl.ResourceTest)

Example 5 with JsonContent

use of org.springframework.boot.test.json.JsonContent in project prison-api by ministryofjustice.

the class NomisApiV1ResourceIntTest method getHolds.

@Test
public void getHolds() {
    final var requestEntity = createHttpEntityWithBearerAuthorisation("ITAG_USER", List.of("ROLE_NOMIS_API_V1"), null);
    final var holds = List.of(new HoldSP(3L, "ref", "12345", "entry", null, new BigDecimal("123.45"), null), new HoldSP(4L, "ref2", "12346", "entry2", LocalDate.of(2019, 1, 2), new BigDecimal("123.46"), LocalDate.of(2018, 12, 30)));
    when(getHolds.execute(any(SqlParameterSource.class))).thenReturn(Map.of(P_HOLDS_CSR, holds));
    final var responseEntity = testRestTemplate.exchange("/api/v1/prison/CKI/offenders/G1408GC/holds", HttpMethod.GET, requestEntity, String.class);
    // noinspection ConstantConditions
    assertThat(new JsonContent<Hold>(getClass(), forType(Hold.class), responseEntity.getBody())).isEqualToJson("holds.json");
}
Also used : SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) HoldSP(uk.gov.justice.hmpps.prison.repository.v1.model.HoldSP) JsonContent(org.springframework.boot.test.json.JsonContent) Hold(uk.gov.justice.hmpps.prison.api.model.v1.Hold) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test) ResourceTest(uk.gov.justice.hmpps.prison.api.resource.impl.ResourceTest)

Aggregations

Test (org.junit.jupiter.api.Test)5 JsonContent (org.springframework.boot.test.json.JsonContent)5 ResourceTest (uk.gov.justice.hmpps.prison.api.resource.impl.ResourceTest)5 BigDecimal (java.math.BigDecimal)2 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)2 Events (uk.gov.justice.hmpps.prison.api.model.v1.Events)2 Hold (uk.gov.justice.hmpps.prison.api.model.v1.Hold)2 EventSP (uk.gov.justice.hmpps.prison.repository.v1.model.EventSP)2 HoldSP (uk.gov.justice.hmpps.prison.repository.v1.model.HoldSP)2 GetEvents (uk.gov.justice.hmpps.prison.repository.v1.storedprocs.EventProcs.GetEvents)2 LiveRoll (uk.gov.justice.hmpps.prison.api.model.v1.LiveRoll)1 LiveRollSP (uk.gov.justice.hmpps.prison.repository.v1.model.LiveRollSP)1 GetLiveRoll (uk.gov.justice.hmpps.prison.repository.v1.storedprocs.PrisonProcs.GetLiveRoll)1