-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Story(ccls-2166) delete opa assessments
- Loading branch information
1 parent
d728a70
commit 24b5b7d
Showing
13 changed files
with
481 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...ce/src/integrationTest/java/uk/gov/laa/ccms/caab/assessment/IntegrationTestInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
...ce/src/integrationTest/java/uk/gov/laa/ccms/caab/assessment/OracleContainerSingleton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
24 changes: 24 additions & 0 deletions
24
.../uk/gov/laa/ccms/caab/assessment/controller/AssessmentControllerIntegrationLocalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
.../java/uk/gov/laa/ccms/caab/assessment/controller/AssessmentControllerIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
158 changes: 158 additions & 0 deletions
158
...a/uk/gov/laa/ccms/caab/assessment/controller/BaseAssessmentControllerIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
||
|
||
|
||
} |
61 changes: 61 additions & 0 deletions
61
assessment-service/src/integrationTest/resources/sql/assessment_tables_create_schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); |
6 changes: 6 additions & 0 deletions
6
assessment-service/src/integrationTest/resources/sql/assessment_tables_drop_schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.