Skip to content

Commit 14f43ad

Browse files
renovate[bot]stephenokeefekaren-hedges
authored
Update plugin org.springframework.boot to v3.5.4 (#2946)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: stephenokeefe <[email protected]> Co-authored-by: karen-hedges <[email protected]>
1 parent 47edfe0 commit 14f43ad

File tree

4 files changed

+250
-40
lines changed

4 files changed

+250
-40
lines changed

build.gradle

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@ buildscript {
55
}
66

77
plugins {
8-
id 'application'
9-
id 'checkstyle'
10-
id 'pmd'
11-
id 'jacoco'
12-
id 'idea'
13-
id 'io.spring.dependency-management' version '1.1.7'
14-
id 'org.springframework.boot' version '3.4.5'
15-
id 'org.owasp.dependencycheck' version '12.1.3'
16-
id 'com.github.ben-manes.versions' version '0.52.0'
17-
id 'org.sonarqube' version '6.2.0.5505'
18-
id "io.freefair.lombok" version "8.14"
19-
id "org.openapi.generator" version "7.13.0"
20-
id "org.flywaydb.flyway" version "11.11.0"
21-
id 'maven-publish'
22-
id("com.dorongold.task-tree") version "4.0.1"
8+
id 'application'
9+
id 'checkstyle'
10+
id 'pmd'
11+
id 'jacoco'
12+
id 'idea'
13+
id 'io.spring.dependency-management' version '1.1.7'
14+
id 'org.springframework.boot' version '3.5.4'
15+
id 'org.owasp.dependencycheck' version '12.1.3'
16+
id 'com.github.ben-manes.versions' version '0.52.0'
17+
id 'org.sonarqube' version '6.2.0.5505'
18+
id "io.freefair.lombok" version "8.14"
19+
id "org.openapi.generator" version "7.13.0"
20+
id "org.flywaydb.flyway" version "11.11.0"
21+
id 'maven-publish'
22+
id("com.dorongold.task-tree") version "4.0.1"
2323
}
2424

2525
jacoco {
2626
toolVersion = "0.8.13"
2727
reportsDirectory.set(layout.buildDirectory.dir("jacocoHtml"))
2828
}
2929

30-
def buildNumber = System.getenv("RELEASE_VERSION")?: "DEV-SNAPSHOT"
30+
def buildNumber = System.getenv("RELEASE_VERSION") ?: "DEV-SNAPSHOT"
3131

3232
group 'com.github.hmcts'
3333
version buildNumber
@@ -235,10 +235,10 @@ checkstyle {
235235
}
236236

237237
pmd {
238-
toolVersion = "7.16.0"
239-
reportsDir = file("$project.buildDir/reports/pmd")
240-
// https://github.com/pmd/pmd/issues/876
241-
ruleSets = []
238+
toolVersion = "7.16.0"
239+
reportsDir = file("$project.buildDir/reports/pmd")
240+
// https://github.com/pmd/pmd/issues/876
241+
ruleSets = []
242242
}
243243

244244

@@ -437,26 +437,26 @@ dependencies {
437437
implementation 'org.zalando:problem-spring-web-starter:0.29.1'
438438

439439
implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.8.9'
440-
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-openfeign', version: '4.2.1'
440+
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-openfeign', version: '4.3.0'
441441
implementation 'org.springframework.retry:spring-retry:2.0.12'
442442

443443
implementation 'net.javacrumbs.shedlock:shedlock-spring:6.9.2'
444444
implementation 'net.javacrumbs.shedlock:shedlock-provider-jdbc-template:6.9.2'
445445

446-
implementation group: 'com.github.hmcts.java-logging', name: 'logging', version: '6.1.9'
447-
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: log4JVersion
448-
implementation group: 'org.apache.logging.log4j', name: 'log4j-to-slf4j', version: log4JVersion
449-
implementation group: 'org.apache.commons', name: 'commons-exec', version: '1.5.0'
446+
implementation group: 'com.github.hmcts.java-logging', name: 'logging', version: '6.1.9'
447+
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: log4JVersion
448+
implementation group: 'org.apache.logging.log4j', name: 'log4j-to-slf4j', version: log4JVersion
449+
implementation group: 'org.apache.commons', name: 'commons-exec', version: '1.5.0'
450450
implementation group: 'org.apache.commons', name: 'commons-text', version: '1.14.0'
451451

452452
//CVE-2023-44487
453453
implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: tomcatEmbedVersion
454454
implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-websocket', version: tomcatEmbedVersion
455455

456456
implementation platform('com.azure:azure-sdk-bom:1.2.37')
457-
implementation 'com.azure:azure-storage-blob'
457+
implementation 'com.azure:azure-storage-blob'
458458

459-
implementation group: 'io.rest-assured', name: 'rest-assured'
459+
implementation group: 'io.rest-assured', name: 'rest-assured'
460460
implementation group: 'org.flywaydb', name: 'flyway-core', version: '11.11.0'
461461
implementation group: 'org.flywaydb', name: 'flyway-database-postgresql', version: '11.11.0'
462462
implementation group: 'io.hypersistence', name: 'hypersistence-utils-hibernate-63', version: '3.10.3'
@@ -500,7 +500,7 @@ dependencies {
500500
exclude group: 'junit', module: 'junit'
501501
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
502502
}
503-
testImplementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-contract-stub-runner', version: '4.2.1'
503+
testImplementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-contract-stub-runner', version: '4.3.0'
504504
testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
505505
testImplementation group: 'io.projectreactor', name: 'reactor-test', version: '3.7.9'
506506
testImplementation 'org.springframework.security:spring-security-test:6.5.2'
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
package uk.gov.hmcts.darts.common.repository;
2+
3+
import org.hamcrest.Matchers;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
import org.junit.jupiter.api.TestInstance;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.Arguments;
9+
import org.junit.jupiter.params.provider.MethodSource;
10+
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.data.domain.Sort;
12+
import uk.gov.hmcts.darts.common.entity.UserAccountEntity;
13+
import uk.gov.hmcts.darts.test.common.data.PersistableFactory;
14+
import uk.gov.hmcts.darts.testutils.PostgresIntegrationBase;
15+
import uk.gov.hmcts.darts.testutils.stubs.DartsPersistence;
16+
17+
import java.util.List;
18+
import java.util.stream.Stream;
19+
20+
import static org.hamcrest.MatcherAssert.assertThat;
21+
import static org.hamcrest.Matchers.containsInAnyOrder;
22+
import static org.hamcrest.Matchers.equalTo;
23+
24+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
25+
class UserAccountRepositoryTest extends PostgresIntegrationBase {
26+
27+
@Autowired
28+
private UserAccountRepository userAccountRepository;
29+
30+
@Autowired
31+
private DartsPersistence dartsPersistence;
32+
33+
private UserAccountEntity userAccountEntity1;
34+
35+
private UserAccountEntity userAccountEntity2;
36+
37+
private UserAccountEntity userAccountEntity3;
38+
39+
@BeforeEach
40+
void setUpData() {
41+
UserAccountEntity user1 = PersistableFactory.getUserAccountTestData().someMinimalBuilder()
42+
.emailAddress("[email protected]")
43+
.build()
44+
.getEntity();
45+
dartsPersistence.save(user1);
46+
47+
userAccountEntity1 = user1;
48+
49+
UserAccountEntity user2 = PersistableFactory.getUserAccountTestData().someMinimalBuilder()
50+
.emailAddress("[email protected]")
51+
.build()
52+
.getEntity();
53+
dartsPersistence.save(user2);
54+
55+
userAccountEntity2 = user2;
56+
57+
UserAccountEntity user3 = PersistableFactory.getUserAccountTestData().someMinimalBuilder()
58+
.emailAddress("[email protected]")
59+
.isSystemUser(true)
60+
.build()
61+
.getEntity();
62+
dartsPersistence.save(user3);
63+
64+
userAccountEntity3 = user3;
65+
66+
}
67+
68+
@Test
69+
void findUsers_shouldReturnUsers_WhenOnlyEmailProvided() {
70+
List<UserAccountEntity> users = userAccountRepository.findUsers(
71+
false, userAccountEntity1.getEmailAddress(), null, null
72+
);
73+
74+
assertThat(users, Matchers.hasSize(1));
75+
assertThat(users.get(0).getId(), equalTo(userAccountEntity1.getId()));
76+
}
77+
78+
@Test
79+
void findUsers_shouldReturnUser_WhenOnlyIdProvided() {
80+
List<UserAccountEntity> users = userAccountRepository.findUsers(
81+
false, null, List.of(userAccountEntity1.getId()), null
82+
);
83+
84+
assertThat(users, Matchers.hasSize(1));
85+
assertThat(users.get(0).getId(), equalTo(userAccountEntity1.getId()));
86+
}
87+
88+
@Test
89+
void findUsers_shouldReturnMultipleUsers_WhenOnlyIDsProvided() {
90+
List<UserAccountEntity> users = userAccountRepository.findUsers(
91+
false, null, List.of(userAccountEntity1.getId(), userAccountEntity2.getId()), null
92+
);
93+
assertThat(users, Matchers.hasSize(2));
94+
UserAccountEntity firstFoundUser = users.get(0);
95+
UserAccountEntity secondFoundUser = users.get(1);
96+
assertThat(firstFoundUser.getId(), equalTo(userAccountEntity1.getId()));
97+
assertThat(secondFoundUser.getId(), equalTo(userAccountEntity2.getId()));
98+
}
99+
100+
@Test
101+
void findUsers_shouldSortUsersByIdDesc_WhenSortSetToIdDesc() {
102+
List<UserAccountEntity> users = userAccountRepository.findUsers(
103+
false, null, List.of(userAccountEntity1.getId(), userAccountEntity2.getId()), Sort.by(Sort.Direction.DESC, "id")
104+
);
105+
assertThat(users, Matchers.hasSize(2));
106+
UserAccountEntity firstFoundUser = users.get(0);
107+
UserAccountEntity secondFoundUser = users.get(1);
108+
assertThat(firstFoundUser.getId(), equalTo(userAccountEntity2.getId()));
109+
assertThat(secondFoundUser.getId(), equalTo(userAccountEntity1.getId()));
110+
}
111+
112+
@Test
113+
void findUsers_shouldNotReturnUsers_WhenOnlyNonMatchingEmailProvided() {
114+
List<UserAccountEntity> users = userAccountRepository.findUsers(
115+
false, "[email protected]", null, null
116+
);
117+
118+
assertThat(users, Matchers.hasSize(0));
119+
}
120+
121+
@Test
122+
void findUsers_shouldNotReturnUsers_WhenOnlyNonMatchingIdProvided() {
123+
List<UserAccountEntity> users = userAccountRepository.findUsers(
124+
false, null, List.of(123), null
125+
);
126+
127+
assertThat(users, Matchers.hasSize(0));
128+
}
129+
130+
@Test
131+
void findUsers_shouldReturnUsers_WhenOptionalFieldsBlank() {
132+
List<UserAccountEntity> users = userAccountRepository.findUsers(
133+
false, null, null, null
134+
);
135+
136+
List<Integer> actualIds = users.stream()
137+
.map(UserAccountEntity::getId)
138+
.toList();
139+
140+
assertThat(actualIds, containsInAnyOrder(
141+
userAccountEntity1.getId(),
142+
userAccountEntity2.getId(),
143+
-99 // migration user added by flyway
144+
));
145+
}
146+
147+
@Test
148+
void findUsers_shouldReturnUser_WhenAllOptionalFieldsProvided() {
149+
List<UserAccountEntity> users = userAccountRepository.findUsers(
150+
false, userAccountEntity1.getEmailAddress(), List.of(userAccountEntity1.getId()), Sort.by(Sort.Direction.DESC, "id")
151+
);
152+
153+
assertThat(users, Matchers.hasSize(1));
154+
assertThat(users.get(0).getId(), equalTo(userAccountEntity1.getId()));
155+
}
156+
157+
@Test
158+
void findUsers_shouldNotReturnUser_WhenAllOptionalFieldsIncorrect() {
159+
List<UserAccountEntity> users = userAccountRepository.findUsers(
160+
false, "[email protected]", List.of(123), Sort.by(Sort.Direction.DESC, "id")
161+
);
162+
163+
assertThat(users, Matchers.hasSize(0));
164+
}
165+
166+
@Test
167+
void findUsers_shouldReturnSystemUser_WhenOnlyIdProvided() {
168+
List<UserAccountEntity> users = userAccountRepository.findUsers(
169+
true, null, List.of(userAccountEntity3.getId()), null
170+
);
171+
172+
assertThat(users, Matchers.hasSize(1));
173+
assertThat(users.get(0).getId(), equalTo(userAccountEntity3.getId()));
174+
}
175+
176+
@Test
177+
void findUsers_shouldReturnSystemUser_WhenOnlyEmailProvided() {
178+
List<UserAccountEntity> users = userAccountRepository.findUsers(
179+
true, userAccountEntity3.getEmailAddress(), null, null
180+
);
181+
182+
assertThat(users, Matchers.hasSize(1));
183+
assertThat(users.get(0).getId(), equalTo(userAccountEntity3.getId()));
184+
}
185+
186+
@ParameterizedTest
187+
@MethodSource("provideTestCombinations")
188+
void findUsers_shouldFailWithOneNonMatchingField_WhenOtherFieldsMatch(boolean includeSystemUsers, String emailAddress, List<Integer> userIds) {
189+
List<UserAccountEntity> users = userAccountRepository.findUsers(
190+
includeSystemUsers, emailAddress, userIds, null
191+
);
192+
193+
assertThat(users, Matchers.hasSize(0));
194+
}
195+
196+
private Stream<Arguments> provideTestCombinations() {
197+
return Stream.of(
198+
Arguments.of(false, userAccountEntity1.getEmailAddress(), List.of(123)), // Non-matching ID
199+
Arguments.of(false, "[email protected]", List.of(userAccountEntity1.getId())), // Non-matching Email
200+
Arguments.of(false, userAccountEntity3.getEmailAddress(), List.of(userAccountEntity3.getId())), // Include system user false
201+
Arguments.of(true, userAccountEntity3.getEmailAddress(), List.of(123)) // Include system user true, non-matching ID
202+
);
203+
}
204+
205+
}

src/main/java/uk/gov/hmcts/darts/common/repository/UserAccountRepository.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package uk.gov.hmcts.darts.common.repository;
22

3+
import org.springframework.data.domain.Sort;
34
import org.springframework.data.jpa.repository.JpaRepository;
45
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
56
import org.springframework.data.jpa.repository.Modifying;
@@ -73,4 +74,14 @@ AND securityRole.id IN (:roleIds)
7374
void updateLastLoginTime(Integer userId, OffsetDateTime now);
7475

7576
List<UserAccountEntity> findByIdInAndActive(List<Integer> userIds, Boolean active);
77+
78+
@Query("""
79+
select u
80+
from UserAccountEntity u
81+
where (:includeSystemUsers = true or u.isSystemUser = false)
82+
and (:emailAddress is null or u.emailAddress = :emailAddress)
83+
and ( :#{#userIds == null || #userIds.isEmpty()} = true or u.id in :userIds )
84+
""")
85+
List<UserAccountEntity> findUsers(boolean includeSystemUsers, String emailAddress, List<Integer> userIds, Sort sort
86+
);
7687
}

src/main/java/uk/gov/hmcts/darts/usermanagement/component/impl/UserManagementQueryImpl.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,13 @@
22

33
import lombok.RequiredArgsConstructor;
44
import org.springframework.data.domain.Sort;
5-
import org.springframework.data.jpa.domain.Specification;
65
import org.springframework.stereotype.Component;
76
import uk.gov.hmcts.darts.common.entity.UserAccountEntity;
87
import uk.gov.hmcts.darts.common.repository.UserAccountRepository;
98
import uk.gov.hmcts.darts.usermanagement.component.UserManagementQuery;
109

1110
import java.util.List;
1211

13-
import static org.springframework.data.domain.Sort.Direction.DESC;
14-
import static org.springframework.data.jpa.domain.Specification.where;
15-
import static uk.gov.hmcts.darts.usermanagement.component.impl.UserQuerySpecifications.hasEmailAddress;
16-
import static uk.gov.hmcts.darts.usermanagement.component.impl.UserQuerySpecifications.isInIds;
17-
import static uk.gov.hmcts.darts.usermanagement.component.impl.UserQuerySpecifications.notSystemUser;
18-
1912
@Component
2013
@RequiredArgsConstructor
2114
public class UserManagementQueryImpl implements UserManagementQuery {
@@ -24,10 +17,11 @@ public class UserManagementQueryImpl implements UserManagementQuery {
2417

2518
@Override
2619
public List<UserAccountEntity> getUsers(boolean includeSystemUsers, String emailAddress, List<Integer> userIds) {
27-
Specification<UserAccountEntity> spec = where(hasEmailAddress(emailAddress)).and(isInIds(userIds));
28-
if (!includeSystemUsers) {
29-
spec = spec.and(notSystemUser());
30-
}
31-
return userAccountRepository.findAll(spec, Sort.by(DESC, "id"));
20+
return userAccountRepository.findUsers(
21+
includeSystemUsers,
22+
emailAddress,
23+
userIds,
24+
Sort.by(Sort.Direction.DESC, "id")
25+
);
3226
}
3327
}

0 commit comments

Comments
 (0)