Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Story/ccls 2159 case outcome #35

Merged
merged 12 commits into from
May 14, 2024
361 changes: 275 additions & 86 deletions caab-api/open-api-specification.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static uk.gov.laa.ccms.caab.api.audit.AuditorAwareImpl.currentUserHolder;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -83,7 +84,8 @@ public static boolean areAllFieldsEqual(Object obj1, Object obj2, Class<?> clazz
* @param jsonFilePath The path to the JSON file to load
*/
protected <T> T loadObjectFromJson(String jsonFilePath, Class<T> objectType) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
ObjectMapper objectMapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
ClassPathResource resource = new ClassPathResource(jsonFilePath);
return objectMapper.readValue(resource.getInputStream(), objectType);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package uk.gov.laa.ccms.data.api.controller;

import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD;
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD;
import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE;

import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlConfig;
import org.springframework.test.context.jdbc.SqlConfig.ErrorMode;
import org.springframework.test.context.jdbc.SqlConfig.TransactionMode;
import org.springframework.test.context.jdbc.SqlMergeMode;
import uk.gov.laa.ccms.caab.api.CaabApiApplication;
import uk.gov.laa.ccms.data.api.IntegrationTestInterface;

@SpringBootTest(classes = CaabApiApplication.class)
@SqlMergeMode(MERGE)
@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/application_tables_create_schema.sql")
@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/application_tables_drop_schema.sql")
@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/application_tables_drop_schema.sql", config = @SqlConfig(transactionMode = TransactionMode.ISOLATED, errorMode = ErrorMode.CONTINUE_ON_ERROR))
@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/application_tables_create_schema.sql", config = @SqlConfig(transactionMode = TransactionMode.ISOLATED))
public class ApplicationControllerIntegrationTest extends BaseApplicationControllerIntegrationTest implements
IntegrationTestInterface {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
import uk.gov.laa.ccms.caab.api.service.ApplicationService;
import uk.gov.laa.ccms.caab.model.ApplicationDetail;
import uk.gov.laa.ccms.caab.model.ApplicationDetails;
import uk.gov.laa.ccms.caab.model.BaseApplication;
import uk.gov.laa.ccms.caab.model.BaseClient;
import uk.gov.laa.ccms.caab.model.LinkedCase;
import uk.gov.laa.ccms.caab.model.Opponent;
import uk.gov.laa.ccms.caab.model.PriorAuthority;
import uk.gov.laa.ccms.caab.model.Proceeding;
import uk.gov.laa.ccms.caab.model.ScopeLimitation;
import uk.gov.laa.ccms.caab.model.BaseApplicationDetail;
import uk.gov.laa.ccms.caab.model.BaseClientDetail;
import uk.gov.laa.ccms.caab.model.LinkedCaseDetail;
import uk.gov.laa.ccms.caab.model.OpponentDetail;
import uk.gov.laa.ccms.caab.model.PriorAuthorityDetail;
import uk.gov.laa.ccms.caab.model.ProceedingDetail;
import uk.gov.laa.ccms.caab.model.ReferenceDataItemDetail;
import uk.gov.laa.ccms.caab.model.ScopeLimitationDetail;

public abstract class BaseApplicationControllerIntegrationTest
extends AbstractControllerIntegrationTest {
Expand Down Expand Up @@ -212,37 +213,45 @@ private void updateExpectedBooleans(ApplicationDetail applicationDetail) {
private void nullModelIds(ApplicationDetail applicationDetail) {
applicationDetail.setId(null);

if (applicationDetail.getCorrespondenceAddress() != null) {
applicationDetail.getCorrespondenceAddress().setId(null);
}

if (applicationDetail.getLinkedCases() != null) {
for (LinkedCase linkedCase : applicationDetail.getLinkedCases()) {
for (LinkedCaseDetail linkedCase : applicationDetail.getLinkedCases()) {
linkedCase.setId(null);
}
}

if (applicationDetail.getProceedings() != null) {
for (Proceeding proceeding : applicationDetail.getProceedings()) {
for (ProceedingDetail proceeding : applicationDetail.getProceedings()) {
proceeding.setId(null);
if (proceeding.getScopeLimitations() != null) {
for (ScopeLimitation scopeLimitation : proceeding.getScopeLimitations()) {
for (ScopeLimitationDetail scopeLimitation : proceeding.getScopeLimitations()) {
scopeLimitation.setId(null);
}
}
}
}

if (applicationDetail.getPriorAuthorities() != null) {
for (uk.gov.laa.ccms.caab.model.PriorAuthority priorAuthority : applicationDetail.getPriorAuthorities()) {
for (PriorAuthorityDetail priorAuthority : applicationDetail.getPriorAuthorities()) {
priorAuthority.setId(null);
if (priorAuthority.getItems() != null) {
for (uk.gov.laa.ccms.caab.model.ReferenceDataItem referenceDataItem : priorAuthority.getItems()) {
for (ReferenceDataItemDetail referenceDataItem : priorAuthority.getItems()) {
referenceDataItem.setId(null);
}
}
}
}

if (applicationDetail.getOpponents() != null) {
for (uk.gov.laa.ccms.caab.model.Opponent opponent : applicationDetail.getOpponents()) {
for (OpponentDetail opponent : applicationDetail.getOpponents()) {
opponent.setId(null);

if (opponent.getAddress() != null) {
opponent.getAddress().setId(null);
}
}
}
}
Expand Down Expand Up @@ -280,7 +289,7 @@ public void testGetApplications_caseref_returnsdata() {
assertNotNull(responseEntity.getBody());
assertNotNull(responseEntity.getBody().getContent());
assertEquals(1, responseEntity.getBody().getSize());
BaseApplication result = responseEntity.getBody().getContent().get(0);
BaseApplicationDetail result = responseEntity.getBody().getContent().get(0);
assertEquals(caseRef, result.getCaseReferenceNumber());
assertEquals(Integer.parseInt(providerId), result.getProviderDetails().getProvider().getId());
assertEquals(provCaseRef, result.getProviderDetails().getProviderCaseReference());
Expand Down Expand Up @@ -324,7 +333,7 @@ public void testGetApplications_allfields_returnsdata() {
assertNotNull(responseEntity.getBody());
assertNotNull(responseEntity.getBody().getContent());
assertEquals(1, responseEntity.getBody().getSize());
BaseApplication result = responseEntity.getBody().getContent().get(0);
BaseApplicationDetail result = responseEntity.getBody().getContent().get(0);
assertEquals(caseRef, result.getCaseReferenceNumber());
assertEquals(Integer.parseInt(providerId), result.getProviderDetails().getProvider().getId());
assertEquals(provCaseRef, result.getProviderDetails().getProviderCaseReference());
Expand Down Expand Up @@ -375,19 +384,19 @@ public void testGetApplications_allfields_nomatch() {
public void addApplicationProceedings() throws IOException {
Long caseRef = 41L;

Proceeding proceeding = loadObjectFromJson("/json/proceeding_new.json", Proceeding.class);
ProceedingDetail proceeding = loadObjectFromJson("/json/proceeding_new.json", ProceedingDetail.class);
ResponseEntity<Void> response = applicationController.addApplicationProceeding(
caseRef, caabUserLoginId, proceeding);

assertEquals(HttpStatus.CREATED, response.getStatusCode());

ResponseEntity<List<Proceeding>> responseEntity =
ResponseEntity<List<ProceedingDetail>> responseEntity =
applicationController.getApplicationProceedings(caseRef);

assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
assertNotNull(responseEntity.getBody());

List<Proceeding> proceedings = responseEntity.getBody();
List<ProceedingDetail> proceedings = responseEntity.getBody();
assertEquals(1, proceedings.size());
}

Expand All @@ -396,12 +405,12 @@ public void addApplicationProceedings() throws IOException {
public void getApplicationProceedings() {
Long caseRef = 41L;

ResponseEntity<List<Proceeding>> responseEntity = applicationController.getApplicationProceedings(caseRef);
ResponseEntity<List<ProceedingDetail>> responseEntity = applicationController.getApplicationProceedings(caseRef);

assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
assertNotNull(responseEntity.getBody());

List<Proceeding> proceedings = responseEntity.getBody();
List<ProceedingDetail> proceedings = responseEntity.getBody();
assertEquals(1, proceedings.size());
}

Expand All @@ -410,21 +419,21 @@ public void getApplicationProceedings() {
public void addLinkedCase() throws IOException {
Long caseRef = 41L; // Assuming this is the ID of an application

LinkedCase newLinkedCase = loadObjectFromJson("/json/linked_cases_new.json", LinkedCase.class);
LinkedCaseDetail newLinkedCase = loadObjectFromJson("/json/linked_cases_new.json", LinkedCaseDetail.class);

ResponseEntity<Void> response =
applicationController.addApplicationLinkedCase(caseRef, caabUserLoginId,
newLinkedCase);

assertEquals(HttpStatus.CREATED, response.getStatusCode());

ResponseEntity<List<LinkedCase>> responseEntity =
ResponseEntity<List<LinkedCaseDetail>> responseEntity =
applicationController.getApplicationLinkedCases(caseRef);

assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
assertNotNull(responseEntity.getBody());

List<LinkedCase> linkedCases = responseEntity.getBody();
List<LinkedCaseDetail> linkedCases = responseEntity.getBody();
assertEquals(1, linkedCases.size());
}

Expand All @@ -433,12 +442,12 @@ public void addLinkedCase() throws IOException {
public void getLinkedCase() {
Long caseRef = 41L;

ResponseEntity<List<LinkedCase>> responseEntity = applicationController.getApplicationLinkedCases(caseRef);
ResponseEntity<List<LinkedCaseDetail>> responseEntity = applicationController.getApplicationLinkedCases(caseRef);

assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
assertNotNull(responseEntity.getBody());

List<LinkedCase> linkedCases = responseEntity.getBody();
List<LinkedCaseDetail> linkedCases = responseEntity.getBody();
assertEquals(1, linkedCases.size());
}

Expand All @@ -447,8 +456,8 @@ public void getLinkedCase() {
public void addPriorAuthority() throws IOException {
Long caseRef = 41L;

PriorAuthority
priorAuthority = loadObjectFromJson("/json/prior_authority_new.json", PriorAuthority.class);
PriorAuthorityDetail
priorAuthority = loadObjectFromJson("/json/prior_authority_new.json", PriorAuthorityDetail.class);

ResponseEntity<Void> response = applicationController.addApplicationPriorAuthority(caseRef, caabUserLoginId, priorAuthority);

Expand All @@ -460,12 +469,12 @@ public void addPriorAuthority() throws IOException {
public void getPriorAuthority() {
Long caseRef = 41L;

ResponseEntity<List<PriorAuthority>> responseEntity = applicationController.getApplicationPriorAuthorities(caseRef);
ResponseEntity<List<PriorAuthorityDetail>> responseEntity = applicationController.getApplicationPriorAuthorities(caseRef);

assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
assertNotNull(responseEntity.getBody());

List<PriorAuthority> priorAuthorities = responseEntity.getBody();
List<PriorAuthorityDetail> priorAuthorities = responseEntity.getBody();
assertEquals(1, priorAuthorities.size());
}

Expand All @@ -475,7 +484,7 @@ public void updateClient() throws IOException {
Long caseRef = 41L;
String clientReferenceId = "62595640";

BaseClient baseClient = loadObjectFromJson("/json/base_client_new.json", BaseClient.class);
BaseClientDetail baseClient = loadObjectFromJson("/json/base_client_new.json", BaseClientDetail.class);

ResponseEntity<Void> response = applicationController.updateApplicationClient(clientReferenceId,caabUserLoginId, baseClient);
assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
Expand All @@ -499,7 +508,7 @@ public void updateClient() throws IOException {
public void addOpponentToApplication() throws IOException {
Long applicationId = 41L;

Opponent opponent = loadObjectFromJson("/json/opponent_new.json", Opponent.class);
OpponentDetail opponent = loadObjectFromJson("/json/opponent_new.json", OpponentDetail.class);

ResponseEntity<Void> response = applicationController.addApplicationOpponent(applicationId, caabUserLoginId, opponent);

Expand All @@ -513,12 +522,12 @@ public void addOpponentToApplication() throws IOException {
public void getOpponentsForApplication() {
Long applicationId = 41L;

ResponseEntity<List<Opponent>> responseEntity = applicationController.getApplicationOpponents(applicationId);
ResponseEntity<List<OpponentDetail>> responseEntity = applicationController.getApplicationOpponents(applicationId);

assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
assertNotNull(responseEntity.getBody());

List<Opponent> opponents = responseEntity.getBody();
List<OpponentDetail> opponents = responseEntity.getBody();
assertFalse(opponents.isEmpty());
}

Expand Down
Loading
Loading