Skip to content

Commit 6a328c9

Browse files
author
Jamie Briggs
committed
CCMSPUI-529 Refactored NotificationSearchRepositoryIntegrationTest to use Oracle-Free instead of embedded H2 DB
Signed-off-by: Jamie Briggs <jamie.briggs@digital.justice.gov.uk>
1 parent aeafdea commit 6a328c9

File tree

10 files changed

+184
-84
lines changed

10 files changed

+184
-84
lines changed

data-service/src/integrationTest/java/uk/gov/laa/ccms/data/repository/NotificationSearchRepositoryIntegrationTest.java

+38-17
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,31 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertFalse;
55
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_CLASS;
7+
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_CLASS;
8+
import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE;
69

710
import jakarta.persistence.EntityManager;
811
import jakarta.persistence.PersistenceContext;
912
import java.time.LocalDate;
1013
import org.junit.jupiter.api.BeforeEach;
1114
import org.junit.jupiter.api.DisplayName;
1215
import org.junit.jupiter.api.Test;
13-
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
16+
import org.springframework.boot.test.context.SpringBootTest;
1417
import org.springframework.data.domain.Page;
1518
import org.springframework.data.domain.Pageable;
16-
import org.springframework.test.context.ActiveProfiles;
19+
import org.springframework.test.context.jdbc.Sql;
20+
import org.springframework.test.context.jdbc.SqlMergeMode;
21+
import org.springframework.transaction.annotation.Transactional;
22+
import uk.gov.laa.ccms.data.IntegrationTestInterface;
1723
import uk.gov.laa.ccms.data.entity.NotificationInfo;
1824

19-
@DataJpaTest
20-
@ActiveProfiles("h2-test")
25+
@SpringBootTest
26+
@SqlMergeMode(MERGE)
27+
@Sql(executionPhase=BEFORE_TEST_CLASS,scripts= "/sql/get_notif_info_create_schema.sql")
28+
@Sql(executionPhase=AFTER_TEST_CLASS,scripts= "/sql/get_notif_info_drop_schema.sql")
2129
@DisplayName("NotificationInfo Repository Integration Test")
22-
class NotificationSearchRepositoryIntegrationTest {
30+
class NotificationSearchRepositoryIntegrationTest implements IntegrationTestInterface {
2331

2432
private NotificationSearchRepository notificationRepository;
2533

@@ -29,35 +37,48 @@ class NotificationSearchRepositoryIntegrationTest {
2937
private NotificationInfo n1;
3038
private NotificationInfo n2;
3139

40+
@Transactional
3241
@BeforeEach
3342
void setUp() {
3443
notificationRepository = new NotificationSearchRepository(entityManager);
3544
// Insert test data into the in-memory database
3645
n1 = NotificationInfo.builder().notificationId(1L)
46+
.userId("test_user")
47+
.userLoginId("test_login")
3748
.providerFirmId(10L)
49+
.dateAssigned(LocalDate.of(2025, 1, 1))
50+
.subject("Subject")
51+
.dueDate(LocalDate.of(2027, 1, 1))
52+
.assignedTo("JBriggs")
53+
.status("open")
3854
.lscCaseRefReference("1001")
3955
.providerCaseReference("First Case Reference")
40-
.assignedTo("JBriggs")
56+
.clientName("Jamie Briggs")
57+
.feeEarner("Fee")
4158
.personLastName("Briggs")
4259
.feeEarnerPartyId(3001L)
43-
.isOpen(true)
4460
.actionNotificationInd("N")
45-
.dateAssigned(LocalDate.of(2025, 1, 1))
61+
.isOpen(true)
4662
.build();
4763
n2 = NotificationInfo.builder().notificationId(2L)
64+
.userId("test_user")
65+
.userLoginId("test_login")
4866
.providerFirmId(10L)
49-
.lscCaseRefReference("1002")
50-
.providerCaseReference("Second Case Reference")
67+
.dateAssigned(LocalDate.of(2026, 1, 1))
68+
.subject("Subject")
69+
.dueDate(LocalDate.of(2027, 1, 1))
5170
.assignedTo("SMonday")
71+
.status("open")
72+
.lscCaseRefReference("2100")
73+
.providerCaseReference("Second Case Reference")
74+
.clientName("Ski Monday")
75+
.feeEarner("Fee")
5276
.personLastName("Bri-Monday")
5377
.feeEarnerPartyId(3002L)
54-
.isOpen(false)
5578
.actionNotificationInd("O")
56-
.dateAssigned(LocalDate.of(2026, 1, 1))
79+
.isOpen(false)
5780
.build();
58-
// Use entityManager as NotificationRepository extends ReadOnlyRepository.
59-
entityManager.persist(n1);
60-
entityManager.persist(n2);
81+
6182
}
6283

6384
@Test
@@ -136,9 +157,9 @@ void shouldFilterBySimilarCaseReferenceNumber(){
136157
null,
137158
null, Pageable.ofSize(10).withPage(0));
138159
// Then
139-
assertEquals(2, result.getTotalElements());
140160
assertTrue(result.getContent().contains(n1));
141161
assertTrue(result.getContent().contains(n2));
162+
assertEquals(2, result.getTotalElements());
142163
}
143164

144165
@Test
@@ -398,7 +419,7 @@ void shouldFilterByDateToInclusive(){
398419
true,
399420
null,
400421
null,
401-
LocalDate.of(2026, 1, 1), Pageable.ofSize(10).withPage(0));
422+
LocalDate.of(2027, 1, 1), Pageable.ofSize(10).withPage(0));
402423
// Then
403424
assertEquals(2, result.getTotalElements());
404425
assertTrue(result.getContent().contains(n1));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
CREATE TABLE XXCCMS.XXCCMS_GET_NOTIF_INFO_V (
2+
NOTIFICATION_ID NUMBER NOT NULL PRIMARY KEY,
3+
USER_ID VARCHAR2(100),
4+
USER_LOGIN_ID VARCHAR2(100),
5+
PROVIDERFIRM_ID NUMBER NOT NULL,
6+
DATE_ASSIGNED DATE,
7+
SUBJECT VARCHAR2(320),
8+
DUE_DATE DATE,
9+
ASSIGNED_TO VARCHAR2(360),
10+
STATUS VARCHAR2(150),
11+
LSC_CASE_REF_REFERENCE VARCHAR2(360),
12+
PROVIDER_CASE_REFERENCE VARCHAR2(150),
13+
CLIENT_NAME VARCHAR2(301),
14+
FEE_EARNER VARCHAR2(360),
15+
PERSON_LAST_NAME VARCHAR2(150),
16+
FEE_EARNER_PARTY_ID NUMBER,
17+
ACTION_NOTIFICATION_IND VARCHAR2(150),
18+
IS_OPEN VARCHAR2(5));
19+
20+
21+
INSERT INTO XXCCMS.XXCCMS_GET_NOTIF_INFO_V (NOTIFICATION_ID,
22+
USER_ID,
23+
USER_LOGIN_ID,
24+
PROVIDERFIRM_ID,
25+
DATE_ASSIGNED,
26+
SUBJECT,
27+
DUE_DATE,
28+
ASSIGNED_TO,
29+
STATUS,
30+
LSC_CASE_REF_REFERENCE,
31+
PROVIDER_CASE_REFERENCE,
32+
CLIENT_NAME,
33+
FEE_EARNER,
34+
PERSON_LAST_NAME,
35+
FEE_EARNER_PARTY_ID,
36+
ACTION_NOTIFICATION_IND,
37+
IS_OPEN)
38+
VALUES (1, -- NOTIFICATION_ID
39+
'test_user', -- USER_ID
40+
'test_login', -- USER_LOGIN_ID
41+
10, -- PROVIDERFIRM_ID
42+
TO_DATE('2025-01-01', 'YYYY-MM-DD'), -- DATE_ASSIGNED
43+
'Subject', -- SUBJECT
44+
TO_DATE('2027-01-01', 'YYYY-MM-DD'), -- DUE_DATE
45+
'JBriggs', -- ASSIGNED_TO
46+
'open', -- STATUS
47+
'1001', -- LSC_CASE_REF_REFERENCE
48+
'First Case Reference', -- PROVIDER_CASE_REFERENCE
49+
'Jamie Briggs', -- CLIENT_NAME
50+
'Fee', -- FEE_EARNER
51+
'Briggs', -- PERSON_LAST_NAME
52+
3001, -- FEE_EARNER_PARTY_ID
53+
'N', -- ACTION_NOTIFICATION_IND
54+
'true' -- IS_OPEN
55+
);
56+
57+
INSERT INTO XXCCMS.XXCCMS_GET_NOTIF_INFO_V (NOTIFICATION_ID,
58+
USER_ID,
59+
USER_LOGIN_ID,
60+
PROVIDERFIRM_ID,
61+
DATE_ASSIGNED,
62+
SUBJECT,
63+
DUE_DATE,
64+
ASSIGNED_TO,
65+
STATUS,
66+
LSC_CASE_REF_REFERENCE,
67+
PROVIDER_CASE_REFERENCE,
68+
CLIENT_NAME,
69+
FEE_EARNER,
70+
PERSON_LAST_NAME,
71+
FEE_EARNER_PARTY_ID,
72+
ACTION_NOTIFICATION_IND,
73+
IS_OPEN)
74+
VALUES (2, -- NOTIFICATION_ID
75+
'test_user', -- USER_ID
76+
'test_login', -- USER_LOGIN_ID
77+
10, -- PROVIDERFIRM_ID
78+
TO_DATE('2026-01-01', 'YYYY-MM-DD'), -- DATE_ASSIGNED
79+
'Subject', -- SUBJECT
80+
TO_DATE('2027-01-01', 'YYYY-MM-DD'), -- DUE_DATE
81+
'SMonday', -- ASSIGNED_TO
82+
'open', -- STATUS
83+
'2100', -- LSC_CASE_REF_REFERENCE
84+
'Second Case Reference', -- PROVIDER_CASE_REFERENCE
85+
'Ski Monday', -- CLIENT_NAME
86+
'Fee', -- FEE_EARNER
87+
'Bri-Monday', -- PERSON_LAST_NAME
88+
3002, -- FEE_EARNER_PARTY_ID
89+
'O', -- ACTION_NOTIFICATION_IND
90+
'false' -- IS_OPEN
91+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE XXCCMS.XXCCMS_GET_NOTIF_INFO_V;

data-service/src/main/java/uk/gov/laa/ccms/data/entity/BooleanConverter.java data-service/src/main/java/uk/gov/laa/ccms/data/entity/BooleanCharConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* AttributeConverter class to handle the conversion to/from a Boolean value and 'Y' or 'N'.
99
*/
1010
@Converter(autoApply = true)
11-
public class BooleanConverter implements AttributeConverter<Boolean, Character> {
11+
public class BooleanCharConverter implements AttributeConverter<Boolean, Character> {
1212

1313
/**
1414
* Handle the conversion from a boolean value, to 'Y' or 'N'.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package uk.gov.laa.ccms.data.entity;
2+
3+
import jakarta.persistence.AttributeConverter;
4+
import jakarta.persistence.Converter;
5+
import java.util.Optional;
6+
7+
@Converter
8+
public class BooleanStringConverter implements AttributeConverter<Boolean, String> {
9+
10+
@Override
11+
public String convertToDatabaseColumn(Boolean aBoolean) {
12+
return Optional.ofNullable(aBoolean)
13+
.map(x -> x ? "true" : "false")
14+
.orElse(null);
15+
}
16+
17+
@Override
18+
public Boolean convertToEntityAttribute(String value) {
19+
return Optional.ofNullable(value)
20+
.map(d -> d.equalsIgnoreCase("true"))
21+
.orElse(null);
22+
}
23+
}

data-service/src/main/java/uk/gov/laa/ccms/data/entity/NotificationInfo.java

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package uk.gov.laa.ccms.data.entity;
22

33
import jakarta.persistence.Column;
4+
import jakarta.persistence.Convert;
45
import jakarta.persistence.Entity;
56
import jakarta.persistence.Id;
67
import jakarta.persistence.Table;
78
import java.time.LocalDate;
89
import lombok.AllArgsConstructor;
910
import lombok.Builder;
11+
import lombok.EqualsAndHashCode;
1012
import lombok.Getter;
1113
import lombok.RequiredArgsConstructor;
1214
import org.hibernate.annotations.Immutable;
@@ -28,6 +30,7 @@
2830
@Getter
2931
@Builder
3032
@Immutable
33+
@EqualsAndHashCode
3134
@AllArgsConstructor
3235
@RequiredArgsConstructor
3336
public class NotificationInfo {
@@ -81,23 +84,9 @@ public class NotificationInfo {
8184
private String actionNotificationInd;
8285

8386
@Column(name = "IS_OPEN")
87+
@Convert(converter = BooleanStringConverter.class)
8488
private Boolean isOpen;
8589

86-
87-
88-
/* @Column(name = "CLIENT_PARTY_ID")
89-
private Long clientPartyId;
90-
91-
@Column(name = "CATEGORY_OF_LAW", length = 150)
92-
private String categoryOfLaw;
93-
94-
@Column(name = "NOTIFICATION_SUBJECT", length = 320)
95-
private String notificationSubject;
96-
97-
@Column(name = "EVIDENCE_ALLOWED_IND", length = 5)
98-
private String evidenceAllowedInd;
99-
100-
@Column(name = "ASSIGNED_TO_PARTY_ID", precision = 15, scale = 0)
101-
private Long assignedToPartyId;*/
90+
10291

10392
}

data-service/src/main/java/uk/gov/laa/ccms/data/repository/NotificationRepository.java

-26
This file was deleted.

data-service/src/main/java/uk/gov/laa/ccms/data/repository/NotificationSearchRepository.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,17 @@ public final class NotificationSearchRepository {
4444
* @param feeEarnerId the ID of the fee earner to filter by
4545
* @param includeClosed whether to include closed notifications in the results
4646
* @param notificationType the type of notification to filter results by
47-
* @param dateFrom the start date for filtering notifications by assignment date
48-
* @param dateTo the end date for filtering notifications by assignment date
47+
* @param assignedDateFrom the start date for filtering notifications by assignment date
48+
* @param assignedDateTo the end date for filtering notifications by assignment date
4949
* @param pageable the pagination and sorting information
5050
* @return a paginated list of NotificationInfo entities matching the specified filters
5151
*/
5252
public Page<NotificationInfo> findAll(final long providerId,
5353
final String caseReferenceNumber, final String providerCaseReference,
5454
final String assignedToUserId, final String clientSurname, final Integer feeEarnerId,
5555
final Boolean includeClosed, final String notificationType,
56-
final LocalDate dateFrom, final LocalDate dateTo, final Pageable pageable) {
56+
final LocalDate assignedDateFrom, final LocalDate assignedDateTo,
57+
final Pageable pageable) {
5758

5859
final String searchNotificationQuery =
5960
"""
@@ -62,7 +63,7 @@ public Page<NotificationInfo> findAll(final long providerId,
6263
+
6364
getFilterSql(providerId, caseReferenceNumber, providerCaseReference,
6465
assignedToUserId, clientSurname, feeEarnerId, includeClosed,
65-
notificationType, dateFrom, dateTo)
66+
notificationType, assignedDateFrom, assignedDateTo)
6667
+
6768
"""
6869
OFFSET :offset ROWS FETCH NEXT :size ROWS ONLY
@@ -79,7 +80,7 @@ SELECT COUNT(*) FROM XXCCMS.XXCCMS_GET_NOTIF_INFO_V
7980
+
8081
getFilterSql(providerId, caseReferenceNumber, providerCaseReference,
8182
assignedToUserId, clientSurname, feeEarnerId, includeClosed,
82-
notificationType, dateFrom, dateTo);
83+
notificationType, assignedDateFrom, assignedDateTo);
8384

8485
Query countQuery = entityManager.createNativeQuery(notificationCount);
8586

@@ -93,7 +94,7 @@ SELECT COUNT(*) FROM XXCCMS.XXCCMS_GET_NOTIF_INFO_V
9394
private static String getFilterSql(Long providerId,
9495
String caseReferenceNumber, String providerCaseReference, String assignedToUser,
9596
String clientSurname, Integer feeEarnerId, Boolean includeClosed,
96-
String notificationType, LocalDate dateFrom, LocalDate dateTo) {
97+
String notificationType, LocalDate assignedDateFrom, LocalDate assignedDateTo) {
9798

9899
StringJoiner sj = new StringJoiner(" AND ");
99100
// Provider firm party id
@@ -125,11 +126,11 @@ private static String getFilterSql(Long providerId,
125126
if (stringNotEmpty(notificationType)) {
126127
sj.add("ACTION_NOTIFICATION_IND = '" + notificationType + "'");
127128
}
128-
if (Objects.nonNull(dateFrom)) {
129-
sj.add("DATE_ASSIGNED >= TO_DATE('" + dateFrom + "', 'YYYY-MM-DD')");
129+
if (Objects.nonNull(assignedDateFrom)) {
130+
sj.add("DATE_ASSIGNED >= TO_DATE('" + assignedDateFrom + "', 'YYYY-MM-DD')");
130131
}
131-
if (Objects.nonNull(dateTo)) {
132-
sj.add("DATE_ASSIGNED <= TO_DATE('" + dateTo + "', 'YYYY-MM-DD')");
132+
if (Objects.nonNull(assignedDateTo)) {
133+
sj.add("DATE_ASSIGNED <= TO_DATE('" + assignedDateTo + "', 'YYYY-MM-DD')");
133134
}
134135
return sj + " ";
135136
}

0 commit comments

Comments
 (0)