Skip to content

Commit

Permalink
UPDATE: mock data for processor testing and logic for getting process…
Browse files Browse the repository at this point in the history
…or data
  • Loading branch information
JeremiahUy committed Oct 31, 2024
1 parent ae9ac3e commit 0560881
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,28 @@ public class BehandlingService {

private final BkatClient bkatClient;

private List<DataBehandler> getDatabehandlerForBehandling(BkatProcess process) {
List<DataBehandler> dataBehandlerList = new ArrayList<>();
if(!process.getDataProcessing().getProcessors().isEmpty()) {
process.getDataProcessing().getProcessors().forEach(databehandlerId -> {
DataBehandler databehandler = getDataBehandler(databehandlerId);
if(databehandler != null) {
dataBehandlerList.add(databehandler);
}
});
}
return dataBehandlerList;
}

public Behandling getBehandling(String id) {
BkatProcess process = bkatClient.getProcess(id);
if (process == null) {
return null;
}

Behandling behandling = process.convertToBehandling();
List<DataBehandler> dataBehandlerList = new ArrayList<>();
if(!process.getDataProcessing().getProcessors().isEmpty()) {
process.getDataProcessing().getProcessors().forEach(databehandlerId -> {
DataBehandler databehandler = getDataBehandler(databehandlerId);
dataBehandlerList.add(databehandler);
});
}
List<DataBehandler> dataBehandlerList = getDatabehandlerForBehandling(process);
behandling.setDataBehandlerList(dataBehandlerList);

return behandling;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public Behandling convertToBehandling() {
.policies(policies.stream().map(BkatPolicy::convertToPolyResponse).toList())
.automatiskBehandling(automaticProcessing)
.profilering(profiling)
.dataBehandlerList(List.of())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import no.nav.data.etterlevelse.common.domain.ExternalCode;
import no.nav.data.integration.behandling.BehandlingController.BehandlingPage;
import no.nav.data.integration.behandling.dto.Behandling;
import no.nav.data.integration.behandling.dto.DataProsessering;
import no.nav.data.integration.behandling.dto.DataBehandler;
import no.nav.data.integration.behandling.dto.PolicyResponse;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
Expand All @@ -22,7 +22,7 @@ void getBehandling() {
.getForEntity("/behandling/{Id}", Behandling.class, "74288ec1-c45d-4b9f-b799-33539981a690");
assertThat(behandling.getBody()).isNotNull();
assertThat(behandling.getStatusCode()).isEqualTo(HttpStatus.OK);
assertResponse(behandling.getBody());
assertResponse(behandling.getBody(),false);
}

@Test
Expand All @@ -32,11 +32,11 @@ void searchBehandling() {
assertThat(behandlinger.getBody()).isNotNull();
assertThat(behandlinger.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(behandlinger.getBody().getContent()).hasSize(1);
assertResponse(behandlinger.getBody().getContent().get(0));
assertResponse(behandlinger.getBody().getContent().get(0),true);
}

private void assertResponse(Behandling behandling) {
assertThat(behandling).isEqualTo(Behandling.builder()
private void assertResponse(Behandling behandling, boolean searchResponse) {
Behandling behandlingToCompare = Behandling.builder()
.id("74288ec1-c45d-4b9f-b799-33539981a690")
.navn("process name")
.nummer(101)
Expand All @@ -46,15 +46,21 @@ private void assertResponse(Behandling behandling) {
.linje(ExternalCode.builder().list("LINJE").code("LIN").shortName("Lin").description("desc").external(true).build())
.system(ExternalCode.builder().list("SYSTEM").code("SYS").shortName("Sys").description("desc").external(true).build())
.team("team")
.dataBehandlerList(List.of())
.policies(List.of(PolicyResponse.builder()
.id("test policy")
.opplysningsTypeId("test information type")
.opplysningsTypeNavn("test information type")
.sensitivity(ExternalCode.builder().list("SENSITIVITY").code("POL").shortName("pol").description("desc").external(true).build())
.behandlingId(behandling.getId())
.personKategorier(List.of(ExternalCode.builder().list("SUBJECT_CATEGORY").code("BRUKER").shortName("Bruker").description("desc").external(true).build()))
.build()))
.dataProsessering(DataProsessering.builder().benyttesDataBehandlere(true).dataBehandlerIds(List.of("processor_1")).build())
.build());
.id("test policy")
.opplysningsTypeId("test information type")
.opplysningsTypeNavn("test information type")
.sensitivity(ExternalCode.builder().list("SENSITIVITY").code("POL").shortName("pol").description("desc").external(true).build())
.behandlingId(behandling.getId())
.personKategorier(List.of(ExternalCode.builder().list("SUBJECT_CATEGORY").code("BRUKER").shortName("Bruker").description("desc").external(true).build()))
.build()))
.build();

if(!searchResponse) {
behandlingToCompare.setDataBehandlerList(List.of(DataBehandler.builder().id("processor_1").navn("processor_1").build()));
}

assertThat(behandling).isEqualTo(behandlingToCompare);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import no.nav.data.integration.behandling.dto.BkatInformationTypeShort;
import no.nav.data.integration.behandling.dto.BkatPolicy;
import no.nav.data.integration.behandling.dto.BkatProcess;
import no.nav.data.integration.behandling.dto.BkatProcessor;

import java.util.List;

Expand All @@ -20,6 +21,7 @@ public class BkatMocks {

public static void mock() {
stubFor(get("/bkat/process/74288ec1-c45d-4b9f-b799-33539981a690").willReturn(okJson(toJson(processMockResponse()))));
stubFor(get("/bkat/processor/processor_1").willReturn(okJson(toJson(processorMockResponse()))));
stubFor(get("/bkat/process?pageNumber=0&pageSize=20").willReturn(okJson(toJson(new RestResponsePage<>(List.of(processMockResponse()))))));
stubFor(post("/bkat/process/shortbyid").willReturn(okJson(toJson(new RestResponsePage<>(List.of(processMockResponse()))))));
stubFor(get("/bkat/process/search/name?includePurpose=true").willReturn(okJson(toJson(new RestResponsePage<>(List.of(processMockResponse()))))));
Expand All @@ -29,6 +31,13 @@ public static BkatProcess processMockResponse() {
return processMockResponse("74288ec1-c45d-4b9f-b799-33539981a690", 101);
}

public static BkatProcessor processorMockResponse () {
return BkatProcessor.builder()
.id("processor_1")
.name("processor_1")
.build();
}

public static BkatProcess stubProcess(String id, int num) {
var resp = processMockResponse(id, num);
stubFor(get("/bkat/process/%s".formatted(id)).willReturn(okJson(toJson(resp))));
Expand Down

0 comments on commit 0560881

Please sign in to comment.