Skip to content

Commit

Permalink
Story(ccls-2166) delete opa assessments
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilDigitalJustice committed Apr 30, 2024
1 parent d728a70 commit 24b5b7d
Show file tree
Hide file tree
Showing 13 changed files with 481 additions and 7 deletions.
42 changes: 37 additions & 5 deletions assessment-api/open-api-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,42 @@ paths:
description: 'Not found'
'500':
description: 'Internal server error'
delete:
tags:
- assessments
summary: 'delete assessments'
operationId: 'deleteAssessments'
parameters:
- $ref: '#/components/parameters/requiredUserLoginId'
- $ref: '#/components/parameters/assessmentType'
- name: 'provider-id'
required: true
in: 'query'
schema:
type: 'string'
example: '1234567890'
- name: 'case-reference-number'
required: true
in: 'query'
schema:
type: 'string'
example: '1234567890'
- name: 'status'
in: 'query'
schema:
type: 'string'
example: 'INCOMPLETE'
responses:
'204':
description: 'Successful deletion'
'400':
description: 'Bad request'
'401':
description: 'Unauthorized'
'404':
description: 'Not found'
'500':
description: 'Internal server error'
/assessments/{assessment-id}:
get:
tags:
Expand Down Expand Up @@ -91,12 +127,8 @@ paths:
example: '1234567890'
- $ref: '#/components/parameters/requiredUserLoginId'
responses:
'200':
'204':
description: 'Successful operation'
content:
application/json:
schema:
$ref: "#/components/schemas/assessmentDetail"
'400':
description: 'Bad request'
'401':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package uk.gov.laa.ccms.caab.assessment;

import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.junit.jupiter.Testcontainers;

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@Testcontainers
@DirtiesContext
public interface IntegrationTestInterface {

OracleContainerSingleton oracleContainerSingleton = OracleContainerSingleton.getInstance();

@DynamicPropertySource
static void properties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", oracleContainerSingleton.getOracleContainer()::getJdbcUrl);
registry.add("spring.datasource.username", oracleContainerSingleton.getOracleContainer()::getUsername);
registry.add("spring.datasource.password", oracleContainerSingleton.getOracleContainer()::getPassword);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package uk.gov.laa.ccms.caab.assessment;

import org.testcontainers.containers.OracleContainer;

public class OracleContainerSingleton {

private static OracleContainerSingleton instance;
private final OracleContainer oracleContainer;

private OracleContainerSingleton() {
oracleContainer = new OracleContainer("gvenzl/oracle-xe:21-slim-faststart");
oracleContainer.start();
}

public static synchronized OracleContainerSingleton getInstance() {
if (instance == null) {
instance = new OracleContainerSingleton();
}
return instance;
}

public OracleContainer getOracleContainer() {
return oracleContainer;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package uk.gov.laa.ccms.caab.assessment.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.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlMergeMode;
import uk.gov.laa.ccms.caab.assessment.AssessmentApplication;

@SpringBootTest(classes = AssessmentApplication.class)
@SqlMergeMode(MERGE)
@ActiveProfiles("local")
@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/delete_data.sql")
@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/delete_data.sql")
public class AssessmentControllerIntegrationLocalTest
extends BaseAssessmentControllerIntegrationTest{

//this runs all tests in BaseAssessmentControllerIntegrationTest, do not add anything here
//this is an easy way to run the tests if you have the containerised database running locally already

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package uk.gov.laa.ccms.caab.assessment.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.SqlMergeMode;
import uk.gov.laa.ccms.caab.assessment.AssessmentApplication;
import uk.gov.laa.ccms.caab.assessment.IntegrationTestInterface;

@SpringBootTest(classes = AssessmentApplication.class)
@SqlMergeMode(MERGE)
@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/assessment_tables_create_schema.sql")
@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/assessment_tables_drop_schema.sql")
public class AssessmentControllerIntegrationTest
extends BaseAssessmentControllerIntegrationTest
implements IntegrationTestInterface {

//this runs all tests in BaseAssessmentControllerIntegrationTest, do not add anything here
//running this class takes longer than the local version, but it is used for running tests in a pipeline

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package uk.gov.laa.ccms.caab.assessment.controller;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;

import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.jdbc.Sql;
import uk.gov.laa.ccms.caab.assessment.model.AssessmentDetail;
import uk.gov.laa.ccms.caab.assessment.model.AssessmentDetails;
import uk.gov.laa.ccms.caab.assessment.model.AssessmentEntityTypeDetail;
import uk.gov.laa.ccms.caab.assessment.model.PatchAssessmentDetail;

public abstract class BaseAssessmentControllerIntegrationTest {

@Autowired
private AssessmentController assessmentController;

//get by id expect 200
@Test
@Sql(scripts = "/sql/assessments_insert.sql")
public void testGetAssessment_expect200() {
final Long id = 26L;
ResponseEntity<AssessmentDetail> response = assessmentController.getAssessment(id);
assertEquals(HttpStatus.OK, response.getStatusCode());
}

private static Stream<Arguments> getAssessmentsArguments() {

return Stream.of(
Arguments.of(List.of("assessment1"), "owner1", "1234567890", "status1"),
Arguments.of(List.of("assessment1"), null, null, null),
Arguments.of(null, "owner1", null, null),
Arguments.of(null, null, "1234567890", null),
Arguments.of(null, null, null, "status1"),
Arguments.of(null, null, null, null)
);
}

@ParameterizedTest
@MethodSource("getAssessmentsArguments")
@Sql(scripts = "/sql/assessments_insert.sql")
public void testGetAssessments_expect200(
final List<String> names,
final String providerId,
final String caseReferenceNumber,
final String status) {

ResponseEntity<AssessmentDetails> response =
assessmentController.getAssessments(names, providerId, caseReferenceNumber, status);

assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(1, response.getBody().getContent().size());
}

private static Stream<Arguments> getAssessmentsEmptyArguments() {

return Stream.of(
Arguments.of(List.of("assessment2"), "owner2", "1234567891", "status2"),
Arguments.of(List.of("assessment2"), null, null, null),
Arguments.of(null, "owner2", null, null),
Arguments.of(null, null, "1234567891", null),
Arguments.of(null, null, null, "status2")
);
}

@ParameterizedTest
@MethodSource("getAssessmentsEmptyArguments")
@Sql(scripts = "/sql/assessments_insert.sql")
public void testGetAssessments_expect200_empty(
final List<String> names,
final String providerId,
final String caseReferenceNumber,
final String status) {

ResponseEntity<AssessmentDetails> response =
assessmentController.getAssessments(names, providerId, caseReferenceNumber, status);

assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(0, response.getBody().getContent().size());
}

@Test
@Sql(scripts = "/sql/assessments_insert.sql")
public void testGetAssessments_expect200_empty() {
final String providerId = "owner1";
final String caseReferenceNumber = "1234567890";

ResponseEntity<AssessmentDetails> beforeDeleteResponse =
assessmentController.getAssessments(null, null , null, null);

ResponseEntity<Void> response = assessmentController.deleteAssessments(
"test", providerId, caseReferenceNumber, null, null);

ResponseEntity<AssessmentDetails> afterDeleteResponse =
assessmentController.getAssessments(null, null , null, null);

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

int beforeSize = beforeDeleteResponse.getBody().getContent().size();
int afterSize = afterDeleteResponse.getBody().getContent().size();

assertTrue(beforeSize > afterSize);
}

@Test
@Sql(scripts = "/sql/assessments_insert.sql")
public void testPatchAssessments_expect200_empty() {

final Long id = 26L;
ResponseEntity<AssessmentDetail> beforePatchResponse = assessmentController.getAssessment(id);

PatchAssessmentDetail patch = new PatchAssessmentDetail()
.caseReferenceNumber("9876543210")
.name("assessment2")
.status("status2");

ResponseEntity<Void> response =
assessmentController.updateAssessment(26L, "testUser", patch);

ResponseEntity<AssessmentDetail> afterPatchResponse = assessmentController.getAssessment(id);

assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
String beforeCaseReferenceNumber = beforePatchResponse.getBody().getCaseReferenceNumber();
String afterCaseReferenceNumber = afterPatchResponse.getBody().getCaseReferenceNumber();
String beforeName = beforePatchResponse.getBody().getName();
String afterName = afterPatchResponse.getBody().getName();
String beforeStatus = beforePatchResponse.getBody().getStatus();
String afterStatus = afterPatchResponse.getBody().getStatus();

//check patching amended values
assertNotEquals(beforeCaseReferenceNumber, afterCaseReferenceNumber);
assertNotEquals(beforeName, afterName);
assertNotEquals(beforeStatus, afterStatus);

//check patching did not amend values
String beforeProviderId = beforePatchResponse.getBody().getProviderId();
String afterProviderId = afterPatchResponse.getBody().getProviderId();
List<AssessmentEntityTypeDetail> beforeEntityTypes = beforePatchResponse.getBody().getEntityTypes();
List<AssessmentEntityTypeDetail> afterEntityTypes = afterPatchResponse.getBody().getEntityTypes();

assertEquals(beforeProviderId, afterProviderId);
assertEquals(beforeEntityTypes, afterEntityTypes);
}




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
CREATE TABLE XXCCMS_OPA_SESSION (
ID NUMBER(19, 0) NOT NULL,
OWNER_ID VARCHAR2(255 CHAR) NOT NULL,
TARGET_ID VARCHAR2(255 CHAR) NOT NULL,
ASSESSMENT VARCHAR2(255 CHAR) NOT NULL,
STATUS VARCHAR2(20 CHAR),
CREATED DATE DEFAULT SYSDATE,
MODIFIED DATE DEFAULT SYSDATE,
CREATED_BY VARCHAR2(255 CHAR),
MODIFIED_BY VARCHAR2(255 CHAR),
PRIMARY KEY (ID)
);

CREATE TABLE XXCCMS_OPA_LISTENTITY (
ID NUMBER(19, 0) NOT NULL,
FK_OPA_SESSION NUMBER(19, 0),
ENTITY_TYPE VARCHAR2(255 CHAR) NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (FK_OPA_SESSION) REFERENCES XXCCMS_OPA_SESSION(ID)
);

CREATE TABLE XXCCMS_OPA_ENTITY (
ID NUMBER(19, 0) NOT NULL,
FK_OPA_LIST_ENTITY NUMBER(19, 0) NOT NULL,
FK_OPA_SESSION NUMBER(19, 0) NOT NULL,
ENTITY_ID VARCHAR2(255 CHAR),
PREPOPULATED NUMBER(1, 0),
COMPLETED NUMBER(1, 0),
PRIMARY KEY (ID),
FOREIGN KEY (FK_OPA_LIST_ENTITY) REFERENCES XXCCMS_OPA_LISTENTITY(ID),
FOREIGN KEY (FK_OPA_SESSION) REFERENCES XXCCMS_OPA_SESSION(ID)
);

CREATE TABLE XXCCMS_OPA_ATTRIBUTE (
ID NUMBER(19, 0) NOT NULL,
FK_OPA_ENTITY NUMBER(19, 0) NOT NULL,
ATTRIBUTE_ID VARCHAR2(100 CHAR) NOT NULL,
ATTRIBUTE_TYPE VARCHAR2(255 CHAR) NOT NULL,
ATTRIBUTE_VALUE CLOB,
INFERENCING_TYPE VARCHAR2(255 CHAR),
PREPOPULATED NUMBER(1, 0) NOT NULL,
ASKED NUMBER(1, 0),
PRIMARY KEY (ID),
FOREIGN KEY (FK_OPA_ENTITY) REFERENCES XXCCMS_OPA_ENTITY(ID)
);

CREATE TABLE XXCCMS_OPA_RELATIONSHIP (
ID NUMBER(19, 0) NOT NULL,
FK_OPA_ENTITY NUMBER(19, 0) NOT NULL,
NAME VARCHAR2(255 CHAR),
PREPOPULATED NUMBER(1, 0),
PRIMARY KEY (ID),
FOREIGN KEY (FK_OPA_ENTITY) REFERENCES XXCCMS_OPA_ENTITY(ID)
);

CREATE TABLE XXCCMS_OPA_RELSHIPTARGET (
ID NUMBER(19, 0) NOT NULL,
TARGET_ENTITY_ID VARCHAR2(255 CHAR) NOT NULL,
FK_OPA_RELATIONSHIP NUMBER(19, 0),
PRIMARY KEY (ID)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP TABLE XXCCMS_OPA_RELSHIPTARGET;
DROP TABLE XXCCMS_OPA_RELATIONSHIP;
DROP TABLE XXCCMS_OPA_ATTRIBUTE;
DROP TABLE XXCCMS_OPA_ENTITY;
DROP TABLE XXCCMS_OPA_LISTENTITY;
DROP TABLE XXCCMS_OPA_SESSION;
Loading

0 comments on commit 24b5b7d

Please sign in to comment.