generated from hmcts/spring-boot-template
-
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.
* Added hibernate, postgres, lombok and flyway. Set java version to 17. * Updated Open API config * Added local docker compose to generate local db * Updated application.yaml with settings for hibernate and flyway * Added placeholder code for variables needed from key vault * Added SQL script to generate the database via flyway * Updated values.yaml to get correct environment variables from key vault * Fixed environment vars in docker-compose-local.yml * Updated README with details for running local docker image * Hibernate and rest controller for recording * checkstyle fix * Remove old code for old db + created enums for new db types * Remove old db schema * Fix Application.java re-added * Add updated hibernate entities * Add updated hibernate repositories * Move id field out of each entity into base entity class * Remove unused imports * Remove setting fields to false * Fix Class cannot have field of same name * Add PMD suppressing on the enums * Fix spacing * Fix editInstruction column with type json * Add tests for each of the entities and a helper class to generate entities * Fix checkstyle and pmd * Added hibernate, postgres, lombok and flyway. Set java version to 17. * Updated Open API config * Added local docker compose to generate local db * Updated application.yaml with settings for hibernate and flyway * Added placeholder code for variables needed from key vault * Added SQL script to generate the database via flyway * Fixed environment vars in docker-compose-local.yml * Updated README with details for running local docker image * Hibernate and rest controller for recording * checkstyle fix * removed duplicate flyway gradle tasks * Bumping chart version/ fixing aliases * Remove old code for old db * Remove old code for old db * Fix Enum types work correctly now * Remove BookingParticipant entity and replaced with many to many * Update entities to match new schema changes * Update entities to match new schema changes (deleted -> deleted_at) * Fix Tests for updated entities * Styling * Styling * Update entities to match new schema changes (capture session, recording) * Revert readme changes * Update build.gradle * Move schema file db.migrations -> db.migration * Revert springboot version to fix enum errors * Move tests to integration testing * Remove timezone setting * Add comment for downgraded spring plugin * Add default test user to entity factory * Capitalize enums in db and code * Update column definition default --------- Co-authored-by: Jason Paige <[email protected]> Co-authored-by: hmcts-jenkins-cnp <60659747+hmcts-jenkins-cnp[bot]@users.noreply.github.com> Co-authored-by: Jason Paige <[email protected]>
- Loading branch information
1 parent
6a93fed
commit 5c171a5
Showing
64 changed files
with
1,978 additions
and
9 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
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
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
66 changes: 66 additions & 0 deletions
66
src/integrationTest/java/uk/gov/hmcts/reform/preapi/entities/AppAccessTest.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,66 @@ | ||
package uk.gov.hmcts.reform.preapi.entities; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.transaction.Transactional; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import uk.gov.hmcts.reform.preapi.Application; | ||
import uk.gov.hmcts.reform.preapi.enums.CourtType; | ||
|
||
import java.sql.Date; | ||
import java.sql.Timestamp; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@SpringBootTest(classes = Application.class) | ||
class AppAccessTest { | ||
|
||
@Autowired | ||
private EntityManager entityManager; | ||
|
||
@Test | ||
@Transactional | ||
public void testSaveAndRetrieveAppAccess() { //NOPMD - suppressed JUnit5TestShouldBePackagePrivate | ||
User user = HelperFactory.createUser( | ||
"Test", | ||
"User", | ||
"[email protected]", | ||
new Timestamp(System.currentTimeMillis()), | ||
null, | ||
null | ||
); | ||
entityManager.persist(user); | ||
|
||
Court court = HelperFactory.createCourt(CourtType.CROWN, "Test Court", "Test123"); | ||
entityManager.persist(court); | ||
|
||
Role role = HelperFactory.createRole("TestRole"); | ||
entityManager.persist(role); | ||
|
||
AppAccess appAccess = HelperFactory.createAppAccess( | ||
user, | ||
court, | ||
role, | ||
true, | ||
new Timestamp(System.currentTimeMillis()), | ||
new Date(System.currentTimeMillis()) | ||
); | ||
|
||
entityManager.persist(appAccess); | ||
entityManager.flush(); | ||
|
||
AppAccess retrievedAppAccess = entityManager.find(AppAccess.class, appAccess.getId()); | ||
|
||
assertEquals(appAccess.getId(), retrievedAppAccess.getId(), "Ids should match"); | ||
assertEquals(appAccess.getUser(), retrievedAppAccess.getUser(), "Users should match"); | ||
assertEquals(appAccess.getCourt(), retrievedAppAccess.getCourt(), "Courts should match"); | ||
assertEquals(appAccess.getRole(), retrievedAppAccess.getRole(), "Roles should match"); | ||
assertEquals(appAccess.getLastAccess(), retrievedAppAccess.getLastAccess(), "Last access should match"); | ||
assertEquals(appAccess.isActive(), retrievedAppAccess.isActive(), "Active status should match"); | ||
assertEquals(appAccess.getDeletedAt(), retrievedAppAccess.getDeletedAt(), "Deleted at should match"); | ||
assertEquals(appAccess.getCreatedAt(), retrievedAppAccess.getCreatedAt(), "Created at should match"); | ||
assertEquals(appAccess.getModifiedAt(), retrievedAppAccess.getModifiedAt(), "Modified at should match"); | ||
} | ||
} | ||
|
56 changes: 56 additions & 0 deletions
56
src/integrationTest/java/uk/gov/hmcts/reform/preapi/entities/AuditTest.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,56 @@ | ||
package uk.gov.hmcts.reform.preapi.entities; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.transaction.Transactional; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import uk.gov.hmcts.reform.preapi.Application; | ||
import uk.gov.hmcts.reform.preapi.enums.AuditLogSource; | ||
import uk.gov.hmcts.reform.preapi.enums.AuditLogType; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@SpringBootTest(classes = Application.class) | ||
class AuditTest { | ||
|
||
@Autowired | ||
private EntityManager entityManager; | ||
|
||
@Test | ||
@Transactional | ||
public void testSaveAndRetrieveAudit() { //NOPMD - suppressed JUnit5TestShouldBePackagePrivate | ||
Audit audit = new Audit(); | ||
audit.setTableName("TestTable"); | ||
audit.setTableRecordId(UUID.randomUUID()); | ||
audit.setSource(AuditLogSource.PORTAL); | ||
audit.setType(AuditLogType.CREATE); | ||
audit.setCategory("TestCategory"); | ||
audit.setActivity("TestActivity"); | ||
audit.setFunctionalArea("TestFunctionalArea"); | ||
audit.setAuditDetails("TestAuditDetails"); | ||
audit.setCreatedBy("TestUser"); | ||
audit.setUpdatedAt(new Timestamp(System.currentTimeMillis())); | ||
entityManager.persist(audit); | ||
entityManager.flush(); | ||
|
||
Audit retrievedAudit = entityManager.find(Audit.class, audit.getId()); | ||
|
||
assertEquals(audit.getId(), retrievedAudit.getId(), "Id should match"); | ||
assertEquals(audit.getTableName(), retrievedAudit.getTableName(), "Table names should match"); | ||
assertEquals(audit.getTableRecordId(), retrievedAudit.getTableRecordId(), "Record ids should match"); | ||
assertEquals(audit.getSource(), retrievedAudit.getSource(), "Source should match"); | ||
assertEquals(audit.getType(), retrievedAudit.getType(), "Type should match"); | ||
assertEquals(audit.getCategory(), retrievedAudit.getCategory(), "Category should match"); | ||
assertEquals(audit.getActivity(), retrievedAudit.getActivity(), "Activity should match"); | ||
assertEquals(audit.getFunctionalArea(), retrievedAudit.getFunctionalArea(), "Functional area should match"); | ||
assertEquals(audit.getAuditDetails(), retrievedAudit.getAuditDetails(), "Audit details should match"); | ||
assertEquals(audit.getCreatedBy(), retrievedAudit.getCreatedBy(), "Created by should match"); | ||
assertEquals(audit.getCreatedAt(), retrievedAudit.getCreatedAt(), "Created at should match"); | ||
assertEquals(audit.getUpdatedAt(), retrievedAudit.getUpdatedAt(), "Updated at should match"); | ||
assertEquals(audit.getDeletedAt(), retrievedAudit.getDeletedAt(), "Deleted at should match"); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/integrationTest/java/uk/gov/hmcts/reform/preapi/entities/BookingTest.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,45 @@ | ||
package uk.gov.hmcts.reform.preapi.entities; | ||
|
||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.transaction.Transactional; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import uk.gov.hmcts.reform.preapi.Application; | ||
import uk.gov.hmcts.reform.preapi.enums.CourtType; | ||
|
||
import java.sql.Timestamp; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@SpringBootTest(classes = Application.class) | ||
class BookingTest { | ||
|
||
@Autowired | ||
private EntityManager entityManager; | ||
|
||
@Test | ||
@Transactional | ||
public void testSaveAndRetrieveBooking() { //NOPMD - suppressed JUnit5TestShouldBePackagePrivate | ||
Timestamp now = new Timestamp(System.currentTimeMillis()); | ||
Court court = HelperFactory.createCourt(CourtType.CROWN, "Test Court", null); | ||
entityManager.persist(court); | ||
|
||
Case testCase = HelperFactory.createCase(court, "ref1234", true, now); | ||
entityManager.persist(testCase); | ||
|
||
Booking booking = HelperFactory.createBooking(testCase, now, now); | ||
entityManager.persist(booking); | ||
entityManager.flush(); | ||
|
||
Booking retrievedBooking = entityManager.find(Booking.class, booking.getId()); | ||
|
||
assertEquals(booking.getId(), retrievedBooking.getId(), "Id should match"); | ||
assertEquals(booking.getCaseId(), retrievedBooking.getCaseId(), "Case should match"); | ||
assertEquals(booking.getScheduledFor(), retrievedBooking.getScheduledFor(), "Scheduled for should match"); | ||
assertEquals(booking.getDeletedAt(), retrievedBooking.getDeletedAt(), "Deleted at should match"); | ||
assertEquals(booking.getCreatedAt(), retrievedBooking.getCreatedAt(), "Created at should match"); | ||
assertEquals(booking.getModifiedAt(), retrievedBooking.getModifiedAt(), "Modified at should match"); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
src/integrationTest/java/uk/gov/hmcts/reform/preapi/entities/CaptureSessionTest.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,92 @@ | ||
package uk.gov.hmcts.reform.preapi.entities; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.transaction.Transactional; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import uk.gov.hmcts.reform.preapi.Application; | ||
import uk.gov.hmcts.reform.preapi.enums.CourtType; | ||
import uk.gov.hmcts.reform.preapi.enums.RecordingOrigin; | ||
import uk.gov.hmcts.reform.preapi.enums.RecordingStatus; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.LocalDateTime; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@SpringBootTest(classes = Application.class) | ||
class CaptureSessionTest { | ||
|
||
@Autowired | ||
private EntityManager entityManager; | ||
|
||
@Test | ||
@Transactional | ||
public void testSaveAndRetrieveCaptureSession() { //NOPMD - suppressed JUnit5TestShouldBePackagePrivate | ||
Court court = HelperFactory.createCourt(CourtType.CROWN, "Test Court", null); | ||
entityManager.persist(court); | ||
|
||
Case testCase = HelperFactory.createCase(court, "ref1234", true, new Timestamp(System.currentTimeMillis())); | ||
entityManager.persist(testCase); | ||
|
||
Booking booking = HelperFactory.createBooking( | ||
testCase, | ||
Timestamp.valueOf(LocalDateTime.now()), | ||
new Timestamp(System.currentTimeMillis()) | ||
); | ||
entityManager.persist(booking); | ||
|
||
User user = HelperFactory.createDefaultTestUser(); | ||
entityManager.persist(user); | ||
|
||
CaptureSession captureSession = HelperFactory.createCaptureSession( | ||
booking, | ||
RecordingOrigin.PRE, | ||
"TestIngrestAddress", | ||
"TestLiveOutputAddress", | ||
new Timestamp(System.currentTimeMillis()), | ||
user, | ||
new Timestamp(System.currentTimeMillis()), | ||
user, | ||
RecordingStatus.FINISHED, | ||
new Timestamp(System.currentTimeMillis()) | ||
); | ||
entityManager.persist(captureSession); | ||
entityManager.flush(); | ||
|
||
CaptureSession retrievedCaptureSession = entityManager.find(CaptureSession.class, captureSession.getId()); | ||
|
||
assertEquals(captureSession.getId(), retrievedCaptureSession.getId(), "Id should match"); | ||
assertEquals(captureSession.getBooking(), retrievedCaptureSession.getBooking(), "Booking should match"); | ||
assertEquals(captureSession.getOrigin(), retrievedCaptureSession.getOrigin(), "Origin should match"); | ||
assertEquals( | ||
captureSession.getIngestAddress(), | ||
retrievedCaptureSession.getIngestAddress(), | ||
"Ingest address should match" | ||
); | ||
assertEquals( | ||
captureSession.getLiveOutputUrl(), | ||
retrievedCaptureSession.getLiveOutputUrl(), | ||
"Live output url should match" | ||
); | ||
assertEquals(captureSession.getStartedAt(), retrievedCaptureSession.getStartedAt(), "Started at should match"); | ||
assertEquals( | ||
captureSession.getStartedByUser(), | ||
retrievedCaptureSession.getStartedByUser(), | ||
"Started by by user should match" | ||
); | ||
assertEquals( | ||
captureSession.getFinishedAt(), | ||
retrievedCaptureSession.getFinishedAt(), | ||
"Finished at should match" | ||
); | ||
assertEquals( | ||
captureSession.getFinishedByUserId(), | ||
retrievedCaptureSession.getFinishedByUserId(), | ||
"Finished by user should match" | ||
); | ||
assertEquals(captureSession.getStatus(), retrievedCaptureSession.getStatus(), "Status should match"); | ||
assertEquals(captureSession.getDeletedAt(), retrievedCaptureSession.getDeletedAt(), "Deleted at should match"); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/integrationTest/java/uk/gov/hmcts/reform/preapi/entities/CaseTest.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,41 @@ | ||
package uk.gov.hmcts.reform.preapi.entities; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.transaction.Transactional; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import uk.gov.hmcts.reform.preapi.Application; | ||
import uk.gov.hmcts.reform.preapi.enums.CourtType; | ||
|
||
import java.sql.Timestamp; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@SpringBootTest(classes = Application.class) | ||
class CaseTest { | ||
|
||
@Autowired | ||
private EntityManager entityManager; | ||
|
||
@Test | ||
@Transactional | ||
public void testSaveAndRetrieveCase() { //NOPMD - suppressed JUnit5TestShouldBePackagePrivate | ||
Court court = HelperFactory.createCourt(CourtType.CROWN, "Test Court", null); | ||
entityManager.persist(court); | ||
|
||
Case testCase = HelperFactory.createCase(court, "ref1234", true, new Timestamp(System.currentTimeMillis())); | ||
entityManager.persist(testCase); | ||
entityManager.flush(); | ||
|
||
Case retrievedCase = entityManager.find(Case.class, testCase.getId()); | ||
|
||
assertEquals(testCase.getId(), retrievedCase.getId(), "Id should match"); | ||
assertEquals(testCase.getCourt(), retrievedCase.getCourt(), "Court should match"); | ||
assertEquals(testCase.getReference(), retrievedCase.getReference(), "Case reference should match"); | ||
assertEquals(testCase.isTest(), retrievedCase.isTest(), "Test status should match"); | ||
assertEquals(testCase.getDeletedAt(), retrievedCase.getDeletedAt(), "Deleted at should match"); | ||
assertEquals(testCase.getCreatedAt(), retrievedCase.getCreatedAt(), "Created at should match"); | ||
assertEquals(testCase.getModifiedAt(), retrievedCase.getModifiedAt(), "Modified at should match"); | ||
} | ||
} |
Oops, something went wrong.