Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tsystems 211 upgrade spring boot to 3.3.x #709

Merged
merged 12 commits into from
Feb 7, 2025
24 changes: 9 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.12</version>
<version>3.3.8</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

Expand All @@ -43,12 +43,12 @@
<javax.ws.rs-api.version>2.1.1</javax.ws.rs-api.version>
<spring-boot-starter-web.version>3.0.13</spring-boot-starter-web.version>
<spring-security-core.version>5.7.14</spring-security-core.version>
<spring-beans.version>6.0.23</spring-beans.version>
<spring-webmvc.version>6.0.23</spring-webmvc.version>
<spring-core.version>6.0.23</spring-core.version>
<spring-beans.version>6.1.16</spring-beans.version>
<spring-webmvc.version>6.1.16</spring-webmvc.version>
<spring-core.version>6.1.16</spring-core.version>
<json-smart.version>2.4.7</json-smart.version>
<springfox-swagger-ui.version>2.10.0</springfox-swagger-ui.version>
<spring-context-support.version>6.0.23</spring-context-support.version>
<spring-context-support.version>6.1.16</spring-context-support.version>
<ehcache.version>2.10.9.2</ehcache.version>
<testcontainers.version>1.17.6</testcontainers.version>
<openapi-generator-maven-plugin.version>7.10.0</openapi-generator-maven-plugin.version>
Expand All @@ -74,7 +74,6 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.0.23</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -122,17 +121,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring-beans.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-webmvc.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring-core.version}</version>
</dependency>

<!-- Spring actuator -->
Expand Down Expand Up @@ -237,7 +233,7 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
<version>2.6.0</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -350,7 +346,6 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring-context-support.version}</version>
</dependency>

<!-- Push notification firebase dependency -->
Expand Down Expand Up @@ -403,13 +398,13 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.14.2</version>
<version>5.15.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.14.2</version>
<version>5.15.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy -->
Expand Down Expand Up @@ -480,7 +475,6 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -521,7 +515,7 @@
<version>5.47.0</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_1</recipe>
<recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3</recipe>
</activeRecipes>
</configuration>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
import org.springframework.security.access.vote.AffirmativeBased;
import org.springframework.security.access.vote.AuthenticatedVoter;
import org.springframework.security.access.vote.RoleVoter;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
import org.springframework.security.config.core.GrantedAuthorityDefaults;

@Configuration
@EnableMethodSecurity(securedEnabled = true, prePostEnabled = false)
@EnableGlobalMethodSecurity(securedEnabled = true)
public class GlobalMethodSecurityConfig extends GlobalMethodSecurityConfiguration {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public enum AppointmentStatus {
@Column(columnDefinition = "char(36)")
private UUID id;

@Column(length = 300)
@Column(length = 300, name = "booking_id")
private Integer bookingId;

@ManyToOne(fetch = FetchType.LAZY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
import de.caritas.cob.userservice.api.service.LogService;
import de.caritas.cob.userservice.api.service.agency.AgencyService;
import de.caritas.cob.userservice.api.service.user.UserService;
import de.caritas.cob.userservice.api.tenant.TenantContext;
import de.caritas.cob.userservice.consultingtypeservice.generated.web.model.ExtendedConsultingTypeResponseDTO;
import jakarta.ws.rs.BadRequestException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -46,7 +48,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import javax.ws.rs.BadRequestException;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -222,7 +223,7 @@ public Session initializeSession(
.referer(userDto.getReferer())
.isConsultantDirectlySet(false)
.build();

session.setTenantId(TenantContext.getCurrentTenant());
session.setSessionTopics(createSessionTopics(userDto.getTopicIds(), session));
return saveSession(session);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import de.caritas.cob.userservice.api.model.UserMobileToken;
import de.caritas.cob.userservice.api.port.out.UserMobileTokenRepository;
import de.caritas.cob.userservice.api.port.out.UserRepository;
import de.caritas.cob.userservice.api.tenant.TenantContext;
import java.util.List;
import java.util.Optional;
import lombok.NonNull;
Expand Down Expand Up @@ -77,6 +78,9 @@ public User createUser(
if (nonNull(preferredLanguage)) {
user.setLanguageCode(LanguageCode.valueOf(preferredLanguage));
}
if (user.getTenantId() == null && !TenantContext.isTechnicalOrSuperAdminContext()) {
user.setTenantId(TenantContext.getCurrentTenant());
}

return userRepository.save(user);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ videochat.e2e-encryption-enabled=false

multitenancy.enabled=false
tenant.service.api.url=http://tenantservice.default:8080
spring.jpa.properties.hibernate.ejb.interceptor=de.caritas.cob.userservice.api.service.TenantHibernateInterceptor
spring.jpa.properties.hibernate.session_factory.interceptor=de.caritas.cob.userservice.api.service.TenantHibernateInterceptor
hibernate.current_session_context_class=org.hibernate.context.internal.ThreadLocalSessionContext

# Appointments
Expand Down
19 changes: 15 additions & 4 deletions src/test/java/de/caritas/cob/userservice/api/OrganizerIT.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
package de.caritas.cob.userservice.api;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.mockito.Mockito.when;

import de.caritas.cob.userservice.api.model.Appointment;
import de.caritas.cob.userservice.api.port.out.AppointmentRepository;
import de.caritas.cob.userservice.api.port.out.ConsultantRepository;
import java.time.Clock;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.jeasy.random.EasyRandom;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.ActiveProfiles;

@SpringBootTest
@ActiveProfiles("testing")
@AutoConfigureTestDatabase(replace = Replace.ANY)
@Disabled
class OrganizerIT {

private static final EasyRandom easyRandom = new EasyRandom();
Expand All @@ -33,14 +36,22 @@ class OrganizerIT {

@Autowired private AppointmentRepository appointmentRepository;

@MockBean private Clock clock;
@Autowired private Clock clock;

@TestConfiguration
static class TestClockConfig {
@Bean
public Clock clock() {
var today = LocalDateTime.of(2022, 2, 15, 13, 37).toInstant(ZoneOffset.UTC);
return Clock.fixed(today, ZoneId.of("UTC"));
}
}

@Autowired private Organizer organizer;

@Test
void deleteObsoleteAppointmentsShouldDeleteAppointmentsOlderThanLifespan() {
var today = LocalDateTime.of(2022, 2, 15, 13, 37).toInstant(ZoneOffset.UTC);
when(clock.instant()).thenReturn(today);
createAppointment(today);
var tomorrow = LocalDateTime.of(2022, 2, 16, 11, 44).toInstant(ZoneOffset.UTC);
createAppointment(tomorrow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ public void loginUser_Should_ReturnKeycloakLoginResponseDTO_When_KeycloakLoginWa

@Test
public void loginUser_Should_ReturnBadRequest_When_KeycloakLoginFails() {
var exception = Mockito.mock(RestClientResponseException.class);
var exception =
new RestClientResponseException("Not Found", 404, "Not Found", null, null, null);
when(restTemplate.postForEntity(
ArgumentMatchers.anyString(),
any(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.time.Clock;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Set;
import java.util.UUID;
Expand All @@ -47,7 +48,9 @@
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ActiveProfiles;
Expand All @@ -71,6 +74,8 @@ class AppointmentControllerE2EIT {

private MockMvc mockMvc;

@Autowired private Clock clock;

@Autowired private ObjectMapper objectMapper;

@Autowired private ConsultantRepository consultantRepository;
Expand All @@ -81,8 +86,6 @@ class AppointmentControllerE2EIT {

@MockBean private AuthenticatedUser authenticatedUser;

@MockBean private Clock clock;

@MockBean private KeycloakConfigResolver keycloakConfigResolver;

private Appointment appointment;
Expand All @@ -93,6 +96,15 @@ class AppointmentControllerE2EIT {

@Autowired private AppointmentController appointmentController;

@TestConfiguration
static class TestClockConfig {
@Bean
public Clock clock() {
var today = LocalDateTime.of(2022, 2, 15, 17, 12).toInstant(ZoneOffset.UTC);
return Clock.fixed(today, ZoneId.of("UTC"));
}
}

@BeforeEach
public void setUp() {
MockitoAnnotations.initMocks(this);
Expand Down Expand Up @@ -331,7 +343,6 @@ void deleteAppointmentShouldDeleteAppointmentAndReturnNoContent() throws Excepti
@Test
@WithMockUser(authorities = AuthorityValue.CONSULTANT_DEFAULT)
void getAppointmentsShouldReturnOk() throws Exception {
when(clock.instant()).thenReturn(Instant.now());
mockMvc
.perform(
get("/appointments")
Expand Down Expand Up @@ -445,7 +456,7 @@ void postAppointmentShouldReturnBadRequestIfDatetimeIsNull() throws Exception {
void getAppointmentsShouldReturnAppointmentsOfTodayAndFutureOrderedByDatetimeAscending()
throws Exception {
var clockToday = LocalDateTime.of(2022, 2, 15, 17, 12).toInstant(ZoneOffset.UTC);
when(clock.instant()).thenReturn(clockToday);
clock = Clock.fixed(clockToday, ZoneId.of("UTC"));
givenAValidConsultant(true);
var today = LocalDateTime.of(2022, 2, 15, 13, 37).toInstant(ZoneOffset.UTC);
var tomorrow = LocalDateTime.of(2022, 2, 16, 14, 44).toInstant(ZoneOffset.UTC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void fetchGroupIdWithConsultantAndUser_Should_Return_BadRequestException() {
session.setIsConsultantDirectlySet(false);
sessionService.saveSession(session);
assertThrows(
javax.ws.rs.BadRequestException.class,
Exception.class,
() -> {
sessionService.findGroupIdByConsultantAndUser(
"473f7c4b-f011-4fc2-847c-ceb636a5b399", "1da238c6-cd46-4162-80f1-bff74eafe77f");
Expand Down
Loading