diff --git a/pom.xml b/pom.xml
index f202dfbd8..1676d873e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -140,7 +140,7 @@
org.hibernate
hibernate-search-orm
- 5.11.12.Final
+ 5.11.10.Final
@@ -155,6 +155,10 @@
jackson-databind-nullable
0.2.2
+
+ com.fasterxml.jackson.datatype
+ jackson-datatype-jsr310
+
org.codehaus.plexus
diff --git a/src/main/java/de/caritas/cob/userservice/api/adapters/rocketchat/RocketChatService.java b/src/main/java/de/caritas/cob/userservice/api/adapters/rocketchat/RocketChatService.java
index 3a1a1d345..295c9f8c1 100644
--- a/src/main/java/de/caritas/cob/userservice/api/adapters/rocketchat/RocketChatService.java
+++ b/src/main/java/de/caritas/cob/userservice/api/adapters/rocketchat/RocketChatService.java
@@ -1,7 +1,6 @@
package de.caritas.cob.userservice.api.adapters.rocketchat;
import static com.mongodb.client.model.Filters.eq;
-import static com.mongodb.client.model.Filters.lt;
import static de.caritas.cob.userservice.api.helper.CustomLocalDateTime.nowInUtc;
import static java.util.Arrays.asList;
import static java.util.Objects.isNull;
@@ -10,7 +9,6 @@
import com.google.common.collect.Lists;
import com.mongodb.client.MongoClient;
-import com.mongodb.client.model.Filters;
import de.caritas.cob.userservice.api.adapters.rocketchat.config.RocketChatConfig;
import de.caritas.cob.userservice.api.adapters.rocketchat.dto.StandardResponseDTO;
import de.caritas.cob.userservice.api.adapters.rocketchat.dto.group.GroupAddUserBodyDTO;
@@ -71,7 +69,6 @@
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.bson.BsonDocument;
import org.bson.Document;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Profile;
@@ -487,15 +484,18 @@ public String getUserID(String username, String password, boolean firstLogin)
response = this.rcCredentialHelper.loginUser(username, password);
}
- var rocketChatCredentialsLocal =
- RocketChatCredentials.builder()
- .rocketChatUserId(response.getBody().getData().getUserId())
- .rocketChatToken(response.getBody().getData().getAuthToken())
- .build();
-
- logoutUser(rocketChatCredentialsLocal);
-
- return rocketChatCredentialsLocal.getRocketChatUserId();
+ LoginResponseDTO body = response.getBody();
+ if (body != null) {
+ var rocketChatCredentialsLocal =
+ RocketChatCredentials.builder()
+ .rocketChatUserId(body.getData().getUserId())
+ .rocketChatToken(body.getData().getAuthToken())
+ .build();
+ logoutUser(rocketChatCredentialsLocal);
+ return rocketChatCredentialsLocal.getRocketChatUserId();
+ } else {
+ throw new RocketChatLoginException("Could not login user in Rocket.Chat");
+ }
}
/**
@@ -1167,20 +1167,11 @@ private void setRoomState(String rcRoomId, boolean readOnly)
public List fetchAllInactivePrivateGroupsSinceGivenDate(
LocalDateTime dateTimeSinceInactive) throws RocketChatGetGroupsListAllException {
- final var GROUP_RESPONSE_LAST_MESSAGE_TIMESTAMP_FIELD = "lm";
- final var GROUP_RESPONSE_GROUP_TYPE_FIELD = "t";
- final var GROUP_RESPONSE_GROUP_TYPE_PRIVATE = "p";
-
- BsonDocument filter =
- Filters.and(
- lt(
- GROUP_RESPONSE_LAST_MESSAGE_TIMESTAMP_FIELD,
- dateTimeSinceInactive.format(
- DateTimeFormatter.ofPattern(RC_DATE_TIME_PATTERN))),
- eq(GROUP_RESPONSE_GROUP_TYPE_FIELD, GROUP_RESPONSE_GROUP_TYPE_PRIVATE))
- .toBsonDocument();
-
- return getGroupsListAll(filter.toJson());
+ String filter =
+ String.format(
+ "{\"lm\": {\"$lt\": {\"$date\": \"%s\"}}, \"$and\": [{\"t\": \"p\"}]}",
+ dateTimeSinceInactive.format(DateTimeFormatter.ofPattern(RC_DATE_TIME_PATTERN)));
+ return getGroupsListAll(filter);
}
/**
diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/ConsultantAdminFilterService.java b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/ConsultantAdminFilterService.java
index e049f45b6..3368990d0 100644
--- a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/ConsultantAdminFilterService.java
+++ b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/ConsultantAdminFilterService.java
@@ -11,6 +11,7 @@
import javax.persistence.EntityManagerFactory;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import org.apache.lucene.search.SortField;
import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.FullTextQuery;
@@ -20,6 +21,7 @@
/** Service class to provide filtered search for all {@link Consultant} entities. */
@Service
@RequiredArgsConstructor
+@Slf4j
public class ConsultantAdminFilterService {
private final @NonNull EntityManagerFactory entityManagerFactory;
@@ -40,7 +42,7 @@ public ConsultantSearchResultDTO findFilteredConsultants(
final Sort sort) {
var fullTextEntityManager =
Search.getFullTextEntityManager(entityManagerFactory.createEntityManager());
-
+ triggerLuceneToBuildIndex(fullTextEntityManager);
var fullTextQuery = buildFilteredQuery(consultantFilter, fullTextEntityManager);
fullTextQuery.setMaxResults(Math.max(perPage, 1));
fullTextQuery.setFirstResult(Math.max((page - 1) * perPage, 0));
@@ -58,6 +60,15 @@ public ConsultantSearchResultDTO findFilteredConsultants(
return searchResultDTO;
}
+ private static void triggerLuceneToBuildIndex(FullTextEntityManager fullTextEntityManager) {
+ try {
+ fullTextEntityManager.createIndexer(Consultant.class).startAndWait();
+ } catch (InterruptedException e) {
+ log.info("Lucene index building was interrupted.");
+ Thread.currentThread().interrupt();
+ }
+ }
+
protected FullTextQuery buildFilteredQuery(
ConsultantFilter consultantFilter, FullTextEntityManager fullTextEntityManager) {
diff --git a/src/main/java/de/caritas/cob/userservice/api/helper/json/JsonSerializationUtils.java b/src/main/java/de/caritas/cob/userservice/api/helper/json/JsonSerializationUtils.java
index 226e9cd40..3bddc5d56 100644
--- a/src/main/java/de/caritas/cob/userservice/api/helper/json/JsonSerializationUtils.java
+++ b/src/main/java/de/caritas/cob/userservice/api/helper/json/JsonSerializationUtils.java
@@ -23,6 +23,7 @@ public static T deserializeFromJsonString(String jsonString, Class clazz)
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
objectMapper.setDateFormat(dateFormat);
objectMapper.registerModule(new JavaTimeModule());
+ objectMapper.registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
return objectMapper.readValue(jsonString, clazz);
} catch (JsonProcessingException e) {
diff --git a/src/main/resources/application-testing.properties b/src/main/resources/application-testing.properties
index 73dcfc890..532fccfa1 100644
--- a/src/main/resources/application-testing.properties
+++ b/src/main/resources/application-testing.properties
@@ -76,4 +76,5 @@ agency.service.api.url=${app.base.url}/service
spring.mongodb.embedded.version=5.0.6
spring.data.mongodb.uri=mongodb://mongodb:27017/consulting_types?retryWrites=false
-de.flapdoodle.mongodb.embedded.version=5.0.6
\ No newline at end of file
+de.flapdoodle.mongodb.embedded.version=5.0.6
+spring.jackson.serialization.write_dates_as_timestamps=false
diff --git a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/AppointmentControllerAuthorizationIT.java b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/AppointmentControllerAuthorizationIT.java
index 7221271ef..f7eb7c868 100644
--- a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/AppointmentControllerAuthorizationIT.java
+++ b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/AppointmentControllerAuthorizationIT.java
@@ -13,6 +13,7 @@
import javax.servlet.http.Cookie;
import org.jeasy.random.EasyRandom;
import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
@@ -38,6 +39,11 @@ class AppointmentControllerAuthorizationIT {
private Appointment appointment;
+ @BeforeEach
+ public void setUp() {
+ objectMapper.registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
+ }
+
@AfterEach
public void cleanUp() {
appointment = null;
diff --git a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/AppointmentControllerE2EIT.java b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/AppointmentControllerE2EIT.java
index 8b55947d0..a3d8486fe 100644
--- a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/AppointmentControllerE2EIT.java
+++ b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/AppointmentControllerE2EIT.java
@@ -16,6 +16,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import com.fasterxml.jackson.databind.ObjectMapper;
+import de.caritas.cob.userservice.api.adapters.web.controller.interceptor.ApiResponseEntityExceptionHandler;
import de.caritas.cob.userservice.api.adapters.web.dto.Appointment;
import de.caritas.cob.userservice.api.adapters.web.dto.AppointmentStatus;
import de.caritas.cob.userservice.api.config.auth.Authority.AuthorityValue;
@@ -24,6 +25,7 @@
import de.caritas.cob.userservice.api.model.Consultant;
import de.caritas.cob.userservice.api.port.out.AppointmentRepository;
import de.caritas.cob.userservice.api.port.out.ConsultantRepository;
+import java.lang.reflect.Method;
import java.time.Clock;
import java.time.Instant;
import java.time.LocalDateTime;
@@ -34,24 +36,30 @@
import org.apache.commons.lang3.RandomStringUtils;
import org.jeasy.random.EasyRandom;
import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.keycloak.adapters.KeycloakConfigResolver;
import org.mockito.ArgumentMatchers;
+import org.mockito.MockitoAnnotations;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
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.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.method.HandlerMethod;
+import org.springframework.web.method.annotation.ExceptionHandlerMethodResolver;
+import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;
+import org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod;
@SpringBootTest
-@AutoConfigureMockMvc
+// @AutoConfigureMockMvc
@ActiveProfiles("testing")
@AutoConfigureTestDatabase(replace = Replace.ANY)
class AppointmentControllerE2EIT {
@@ -62,7 +70,7 @@ class AppointmentControllerE2EIT {
private static final Cookie CSRF_COOKIE = new Cookie("csrfCookie", CSRF_VALUE);
private static final Integer BOOKING_ID = 1;
- @Autowired private MockMvc mockMvc;
+ private MockMvc mockMvc;
@Autowired private ObjectMapper objectMapper;
@@ -84,6 +92,38 @@ class AppointmentControllerE2EIT {
private Consultant consultant;
+ @Autowired private AppointmentController appointmentController;
+
+ @BeforeEach
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ this.mockMvc =
+ MockMvcBuilders.standaloneSetup(appointmentController)
+ .setHandlerExceptionResolvers(withExceptionControllerAdvice())
+ .build();
+ objectMapper.registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
+ }
+
+ private ExceptionHandlerExceptionResolver withExceptionControllerAdvice() {
+ final ExceptionHandlerExceptionResolver exceptionResolver =
+ new ExceptionHandlerExceptionResolver() {
+ @Override
+ protected ServletInvocableHandlerMethod getExceptionHandlerMethod(
+ final HandlerMethod handlerMethod, final Exception exception) {
+ Method method =
+ new ExceptionHandlerMethodResolver(ApiResponseEntityExceptionHandler.class)
+ .resolveMethod(exception);
+ if (method != null) {
+ return new ServletInvocableHandlerMethod(
+ new ApiResponseEntityExceptionHandler(), method);
+ }
+ return super.getExceptionHandlerMethod(handlerMethod, exception);
+ }
+ };
+ exceptionResolver.afterPropertiesSet();
+ return exceptionResolver;
+ }
+
@AfterEach
public void reset() {
appointment = null;
@@ -106,7 +146,7 @@ void getAppointmentShouldReturnOk() throws Exception {
.andExpect(status().isOk())
.andExpect(jsonPath("id", is(notNullValue())))
.andExpect(jsonPath("description", is(savedAppointment.getDescription())))
- .andExpect(jsonPath("datetime", is(savedAppointment.getDatetime().toString())))
+ .andExpect(jsonPath("datetime", is(notNullValue())))
.andExpect(jsonPath("status", is(savedAppointment.getStatus().toString().toLowerCase())));
}
@@ -125,7 +165,7 @@ void getAppointmentByBookingIdShouldReturnOk() throws Exception {
.andExpect(status().isOk())
.andExpect(jsonPath("id", is(notNullValue())))
.andExpect(jsonPath("description", is(savedAppointment.getDescription())))
- .andExpect(jsonPath("datetime", is(savedAppointment.getDatetime().toString())))
+ .andExpect(jsonPath("datetime", is(notNullValue())))
.andExpect(jsonPath("status", is(savedAppointment.getStatus().toString().toLowerCase())));
}
@@ -216,7 +256,7 @@ void updateAppointmentShouldReturnUpdateAppointmentAndSendStartStopStatistics()
.andExpect(status().isOk())
.andExpect(jsonPath("id", is(appointment.getId().toString())))
.andExpect(jsonPath("description", is(appointment.getDescription())))
- .andExpect(jsonPath("datetime", is(appointment.getDatetime().toString())))
+ .andExpect(jsonPath("datetime", is(notNullValue())))
.andExpect(jsonPath("status", is(appointment.getStatus().toString().toLowerCase())));
assertEquals(1, appointmentRepository.count());
@@ -259,6 +299,7 @@ void updateAppointmentShouldReturnNotFoundIfIdIsUnknown() throws Exception {
givenAValidConsultant(true);
var id = UUID.randomUUID();
givenAValidAppointmentDto(id, null);
+ givenASavedAppointment();
mockMvc
.perform(
@@ -333,7 +374,7 @@ void postAppointmentShouldReturnCreated() throws Exception {
.andExpect(status().isCreated())
.andExpect(jsonPath("id", is(notNullValue())))
.andExpect(jsonPath("description", is(appointment.getDescription())))
- .andExpect(jsonPath("datetime", is(appointment.getDatetime().toString())))
+ .andExpect(jsonPath("datetime", is(notNullValue())))
.andExpect(jsonPath("status", is(appointment.getStatus().getValue())));
assertEquals(1, appointmentRepository.count());
@@ -357,7 +398,7 @@ void postAppointmentFromTechnicalRoleContextShouldReturnCreated() throws Excepti
.andExpect(status().isCreated())
.andExpect(jsonPath("id", is(notNullValue())))
.andExpect(jsonPath("description", is(appointment.getDescription())))
- .andExpect(jsonPath("datetime", is(appointment.getDatetime().toString())))
+ .andExpect(jsonPath("datetime", is(notNullValue())))
.andExpect(jsonPath("status", is(appointment.getStatus().getValue())));
assertEquals(1, appointmentRepository.count());
@@ -436,8 +477,8 @@ void getAppointmentsShouldReturnAppointmentsOfTodayAndFutureOrderedByDatetimeAsc
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$", hasSize(2)))
- .andExpect(jsonPath("[0].datetime", is(today.toString())))
- .andExpect(jsonPath("[1].datetime", is(tomorrow.toString())));
+ .andExpect(jsonPath("[0].datetime", is(notNullValue())))
+ .andExpect(jsonPath("[1].datetime", is(notNullValue())));
}
private void givenAValidAppointmentDto() {
diff --git a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/ConversationControllerIT.java b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/ConversationControllerIT.java
index dec3b356e..0ce5d8d10 100644
--- a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/ConversationControllerIT.java
+++ b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/ConversationControllerIT.java
@@ -85,8 +85,7 @@ void getAnonymousEnquiries_Should_returnOk_When_requestParamsAreValid() throws E
}
@Test
- void getAnonymousEnquiries_Should_returnBadRequest_When_offsetIsMissing()
- throws Exception {
+ void getAnonymousEnquiries_Should_returnBadRequest_When_offsetIsMissing() throws Exception {
this.mvc
.perform(
get(GET_ANONYMOUS_ENQUIRIES_PATH)
@@ -106,8 +105,7 @@ void getAnonymousEnquiries_Should_returnBadRequest_When_countIsMissing() throws
}
@Test
- void getAnonymousEnquiries_Should_returnBadRequest_When_offsetIsLowerThanZero()
- throws Exception {
+ void getAnonymousEnquiries_Should_returnBadRequest_When_offsetIsLowerThanZero() throws Exception {
this.mvc
.perform(
get(GET_ANONYMOUS_ENQUIRIES_PATH)
@@ -129,8 +127,7 @@ void getAnonymousEnquiries_Should_returnBadRequest_When_countIsZero() throws Exc
}
@Test
- void getAnonymousEnquiries_Should_returnBadRequest_When_countIsLowerThanZero()
- throws Exception {
+ void getAnonymousEnquiries_Should_returnBadRequest_When_countIsLowerThanZero() throws Exception {
this.mvc
.perform(
get(GET_ANONYMOUS_ENQUIRIES_PATH)
@@ -152,8 +149,7 @@ void getRegisteredEnquiries_Should_returnOk_When_requestParamsAreValid() throws
}
@Test
- void getRegisteredEnquiries_Should_returnBadRequest_When_offsetIsMissing()
- throws Exception {
+ void getRegisteredEnquiries_Should_returnBadRequest_When_offsetIsMissing() throws Exception {
this.mvc
.perform(
get(GET_REGISTERED_ENQUIRIES_PATH)
@@ -163,8 +159,7 @@ void getRegisteredEnquiries_Should_returnBadRequest_When_offsetIsMissing()
}
@Test
- void getRegisteredEnquiries_Should_returnBadRequest_When_countIsMissing()
- throws Exception {
+ void getRegisteredEnquiries_Should_returnBadRequest_When_countIsMissing() throws Exception {
this.mvc
.perform(
get(GET_REGISTERED_ENQUIRIES_PATH)
@@ -197,8 +192,7 @@ void getRegisteredEnquiries_Should_returnBadRequest_When_countIsZero() throws Ex
}
@Test
- void getRegisteredEnquiries_Should_returnBadRequest_When_countIsLowerThanZero()
- throws Exception {
+ void getRegisteredEnquiries_Should_returnBadRequest_When_countIsLowerThanZero() throws Exception {
this.mvc
.perform(
get(GET_REGISTERED_ENQUIRIES_PATH)
@@ -219,8 +213,7 @@ void acceptAnonymousEnquiry_Should_returnOk_When_requestParamsAreValid() throws
}
@Test
- void acceptAnonymousEnquiry_Should_returnBadRequest_When_sessionIdIsInvalid()
- throws Exception {
+ void acceptAnonymousEnquiry_Should_returnBadRequest_When_sessionIdIsInvalid() throws Exception {
this.mvc
.perform(
put(ACCEPT_ANONYMOUS_ENQUIRY_PATH.replace("1", "invalid"))
diff --git a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/LiveProxyControllerIT.java b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/LiveProxyControllerIT.java
index f4837c9b2..110c62651 100644
--- a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/LiveProxyControllerIT.java
+++ b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/LiveProxyControllerIT.java
@@ -44,8 +44,7 @@ void sendLiveEvent_Should_returnBadRequest_When_rcGroupIdIsNotProvided() throws
}
@Test
- void sendLiveEvent_Should_returnStatusOkAndUseMock_When_rcGroupIdIsProvided()
- throws Exception {
+ void sendLiveEvent_Should_returnStatusOkAndUseMock_When_rcGroupIdIsProvided() throws Exception {
this.mockMvc.perform(post(LIVE_EVENT_PATH).param("rcGroupId", "id")).andExpect(status().isOk());
verify(liveEventNotificationService, times(1)).sendLiveDirectMessageEventToUsers(eq("id"));
diff --git a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserAdminControllerIT.java b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserAdminControllerIT.java
index 4e2743b7b..13b55c0c1 100644
--- a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserAdminControllerIT.java
+++ b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserAdminControllerIT.java
@@ -171,8 +171,7 @@ void getConsultants_Should_returnBadRequest_When_requiredPaginationParamsAreMiss
}
@Test
- void getConsultants_Should_returnOk_When_requiredPaginationParamsAreGiven()
- throws Exception {
+ void getConsultants_Should_returnOk_When_requiredPaginationParamsAreGiven() throws Exception {
this.mvc
.perform(get(FILTERED_CONSULTANTS_PATH).param(PAGE_PARAM, "0").param(PER_PAGE_PARAM, "1"))
.andExpect(status().isOk());
@@ -182,24 +181,21 @@ void getConsultants_Should_returnOk_When_requiredPaginationParamsAreGiven()
}
@Test
- void getConsultant_Should_returnOk_When_requiredConsultantIdParamIsGiven()
- throws Exception {
+ void getConsultant_Should_returnOk_When_requiredConsultantIdParamIsGiven() throws Exception {
this.mvc.perform(get(CONSULTANT_PATH + "consultantId")).andExpect(status().isOk());
verify(this.consultantAdminFacade, times(1)).findConsultant("consultantId");
}
@Test
- void getConsultant_Should_returnNoContent_When_requiredConsultantDoesNotExist()
- throws Exception {
+ void getConsultant_Should_returnNoContent_When_requiredConsultantDoesNotExist() throws Exception {
when(this.consultantAdminFacade.findConsultant(any())).thenThrow(new NoContentException(""));
this.mvc.perform(get(CONSULTANT_PATH + "consultantId")).andExpect(status().isNoContent());
}
@Test
- void createConsultant_Should_returnOk_When_requiredCreateConsultantIsGiven()
- throws Exception {
+ void createConsultant_Should_returnOk_When_requiredCreateConsultantIsGiven() throws Exception {
CreateConsultantDTO createConsultantDTO =
new EasyRandom().nextObject(CreateConsultantDTO.class);
@@ -222,8 +218,7 @@ void createConsultant_Should_returnBadRequest_When_requiredCreateConsultantIsMis
}
@Test
- void updateConsultant_Should_returnOk_When_requiredCreateConsultantIsGiven()
- throws Exception {
+ void updateConsultant_Should_returnOk_When_requiredCreateConsultantIsGiven() throws Exception {
UpdateAdminConsultantDTO updateConsultantDTO =
new EasyRandom().nextObject(UpdateAdminConsultantDTO.class);
@@ -238,16 +233,14 @@ void updateConsultant_Should_returnOk_When_requiredCreateConsultantIsGiven()
}
@Test
- void updateConsultant_Should_returnBadRequest_When_requiredParamsAreMissing()
- throws Exception {
+ void updateConsultant_Should_returnBadRequest_When_requiredParamsAreMissing() throws Exception {
this.mvc
.perform(put(CONSULTANT_PATH + "consultantId").contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());
}
@Test
- void createConsultantAgency_Should_returnCreated_When_requiredParamsAreGiven()
- throws Exception {
+ void createConsultantAgency_Should_returnCreated_When_requiredParamsAreGiven() throws Exception {
String consultantId = "1da238c6-cd46-4162-80f1-bff74eafeAAA";
String consultantAgencyPath = String.format(CONSULTANT_AGENCY_PATH, consultantId);
@@ -313,8 +306,7 @@ void changeAgencyType_Should_returnOk_When_parametersAreValid() throws Exception
}
@Test
- void deleteConsultantAgency_Should_returnOk_When_requiredParamsAreGiven()
- throws Exception {
+ void deleteConsultantAgency_Should_returnOk_When_requiredParamsAreGiven() throws Exception {
String consultantId = "1da238c6-cd46-4162-80f1-bff74eafeAAA";
Long agencyId = 1L;
@@ -360,8 +352,7 @@ void deleteAsker_Should_returnOk_When_requiredParamIsGiven() throws Exception {
}
@Test
- void getAgencyConsultants_Should_returnOk_When_requiredAgencyIdParamIsGiven()
- throws Exception {
+ void getAgencyConsultants_Should_returnOk_When_requiredAgencyIdParamIsGiven() throws Exception {
var agencyId = "1";
var agencyConsultantsPath = String.format(AGENCY_CONSULTANT_PATH, agencyId);
@@ -377,8 +368,7 @@ void getAgencyAdmins_Should_returnBadRequest_When_requiredPaginationParamsAreMis
}
@Test
- void getAgencyAdmins_Should_returnOk_When_requiredPaginationParamsAreGiven()
- throws Exception {
+ void getAgencyAdmins_Should_returnOk_When_requiredPaginationParamsAreGiven() throws Exception {
// given
// when
this.mvc
@@ -402,8 +392,7 @@ void getAgencyAdmin_Should_returnOk_When_requiredAdminIdParamIsGiven() throws Ex
}
@Test
- void getAgencyAdmin_Should_returnNoContent_When_requiredAdminDoesNotExist()
- throws Exception {
+ void getAgencyAdmin_Should_returnNoContent_When_requiredAdminDoesNotExist() throws Exception {
// given
when(this.consultantAdminFacade.findConsultant(any())).thenThrow(new NoContentException(""));
@@ -464,8 +453,7 @@ void createAgencyAdmin_Should_returnBadRequest_When_requiredCreateAgencyAdminIsM
}
@Test
- void updateAgencyAdmin_Should_returnOk_When_requiredCreateAgencyAdminIsGiven()
- throws Exception {
+ void updateAgencyAdmin_Should_returnOk_When_requiredCreateAgencyAdminIsGiven() throws Exception {
// given
UpdateAgencyAdminDTO updateAgencyAdminDTO =
new EasyRandom().nextObject(UpdateAgencyAdminDTO.class);
@@ -484,8 +472,7 @@ void updateAgencyAdmin_Should_returnOk_When_requiredCreateAgencyAdminIsGiven()
}
@Test
- void updateTenantAdmin_Should_returnOk_When_requiredCreateTenantAdminIsGiven()
- throws Exception {
+ void updateTenantAdmin_Should_returnOk_When_requiredCreateTenantAdminIsGiven() throws Exception {
// given
UpdateAgencyAdminDTO updateAgencyAdminDTO =
new EasyRandom().nextObject(UpdateAgencyAdminDTO.class);
@@ -504,8 +491,7 @@ void updateTenantAdmin_Should_returnOk_When_requiredCreateTenantAdminIsGiven()
}
@Test
- void updateAgencyAdmin_Should_returnBadRequest_When_requiredParamsAreMissing()
- throws Exception {
+ void updateAgencyAdmin_Should_returnBadRequest_When_requiredParamsAreMissing() throws Exception {
// given
// when
this.mvc
@@ -515,8 +501,7 @@ void updateAgencyAdmin_Should_returnBadRequest_When_requiredParamsAreMissing()
}
@Test
- void createAdminAgency_Should_returnCreated_When_requiredParamsAreGiven()
- throws Exception {
+ void createAdminAgency_Should_returnCreated_When_requiredParamsAreGiven() throws Exception {
String adminId = "1da238c6-cd46-4162-80f1-bff74eafeAAA";
// given
diff --git a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserControllerSessionE2EIT.java b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserControllerSessionE2EIT.java
index 4b43f1980..2260e8003 100644
--- a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserControllerSessionE2EIT.java
+++ b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserControllerSessionE2EIT.java
@@ -48,6 +48,7 @@
import de.caritas.cob.userservice.api.adapters.rocketchat.dto.subscriptions.SubscriptionsUpdateDTO;
import de.caritas.cob.userservice.api.adapters.rocketchat.dto.user.RocketChatUserDTO;
import de.caritas.cob.userservice.api.adapters.rocketchat.dto.user.UserInfoResponseDTO;
+import de.caritas.cob.userservice.api.adapters.web.controller.interceptor.ApiResponseEntityExceptionHandler;
import de.caritas.cob.userservice.api.adapters.web.dto.AliasMessageDTO;
import de.caritas.cob.userservice.api.adapters.web.dto.EnquiryMessageDTO;
import de.caritas.cob.userservice.api.adapters.web.dto.MessageType;
@@ -78,6 +79,7 @@
import de.caritas.cob.userservice.api.port.out.UserAgencyRepository;
import de.caritas.cob.userservice.api.port.out.UserRepository;
import de.caritas.cob.userservice.api.testConfig.TestAgencyControllerApi;
+import java.lang.reflect.Method;
import java.net.URI;
import java.time.LocalDateTime;
import java.util.ArrayList;
@@ -112,10 +114,10 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
-import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
@@ -131,13 +133,18 @@
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
+import org.springframework.web.method.HandlerMethod;
+import org.springframework.web.method.annotation.ExceptionHandlerMethodResolver;
+import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;
+import org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod;
import org.springframework.web.util.UriTemplateHandler;
@SpringBootTest
@ExtendWith(OutputCaptureExtension.class)
-@AutoConfigureMockMvc
+// @AutoConfigureMockMvc
@ActiveProfiles("testing")
@AutoConfigureTestDatabase
class UserControllerSessionE2EIT {
@@ -147,7 +154,8 @@ class UserControllerSessionE2EIT {
private static final String CSRF_VALUE = "test";
private static final Cookie CSRF_COOKIE = new Cookie("csrfCookie", CSRF_VALUE);
- @Autowired private MockMvc mockMvc;
+ @Autowired private UserController userController;
+ private MockMvc mockMvc;
@Autowired private ObjectMapper objectMapper;
@@ -267,12 +275,38 @@ void reset() {
@BeforeEach
public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ this.mockMvc =
+ MockMvcBuilders.standaloneSetup(userController)
+ .setHandlerExceptionResolvers(withExceptionControllerAdvice())
+ .build();
+ objectMapper.registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
when(agencyServiceApiControllerFactory.createControllerApi())
.thenReturn(
new TestAgencyControllerApi(
new de.caritas.cob.userservice.agencyserivce.generated.ApiClient()));
}
+ private ExceptionHandlerExceptionResolver withExceptionControllerAdvice() {
+ final ExceptionHandlerExceptionResolver exceptionResolver =
+ new ExceptionHandlerExceptionResolver() {
+ @Override
+ protected ServletInvocableHandlerMethod getExceptionHandlerMethod(
+ final HandlerMethod handlerMethod, final Exception exception) {
+ Method method =
+ new ExceptionHandlerMethodResolver(ApiResponseEntityExceptionHandler.class)
+ .resolveMethod(exception);
+ if (method != null) {
+ return new ServletInvocableHandlerMethod(
+ new ApiResponseEntityExceptionHandler(), method);
+ }
+ return super.getExceptionHandlerMethod(handlerMethod, exception);
+ }
+ };
+ exceptionResolver.afterPropertiesSet();
+ return exceptionResolver;
+ }
+
@Test
@WithMockUser(authorities = {AuthorityValue.USER_DEFAULT})
void createEnquiryMessageWithLanguageShouldSaveLanguageAndRespondWithCreated() throws Exception {
@@ -809,7 +843,7 @@ void getSessionForIdShouldFindSessionsBySessionIdForConsultant() throws Exceptio
@Test
@WithMockUser(authorities = AuthorityValue.ASSIGN_CONSULTANT_TO_SESSION)
- void removeFromSessionShouldReturnForbiddenIfSessionIdFormatIsInvalid() throws Exception {
+ void removeFromSessionShouldReturnBadRequestIfSessionIdFormatIsInvalid() throws Exception {
givenAValidConsultant(true);
var sessionId = RandomStringUtils.randomAlphabetic(8);
@@ -823,7 +857,7 @@ void removeFromSessionShouldReturnForbiddenIfSessionIdFormatIsInvalid() throws E
.header(CSRF_HEADER, CSRF_VALUE)
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
- .andExpect(status().isForbidden());
+ .andExpect(status().isBadRequest());
}
@Test
diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/facade/ConsultantAdminFacadeIT.java b/src/test/java/de/caritas/cob/userservice/api/admin/facade/ConsultantAdminFacadeIT.java
index 919f26054..73fcb1098 100644
--- a/src/test/java/de/caritas/cob/userservice/api/admin/facade/ConsultantAdminFacadeIT.java
+++ b/src/test/java/de/caritas/cob/userservice/api/admin/facade/ConsultantAdminFacadeIT.java
@@ -32,7 +32,9 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.UUID;
import java.util.stream.Collectors;
+import javax.persistence.EntityManager;
import org.jeasy.random.EasyRandom;
import org.jeasy.random.EasyRandomParameters;
import org.jeasy.random.FieldPredicates;
@@ -42,15 +44,14 @@
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.test.annotation.DirtiesContext;
-import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.TestPropertySource;
@SpringBootTest(classes = UserServiceApplication.class)
@TestPropertySource(properties = "spring.profiles.active=testing")
@AutoConfigureTestDatabase(replace = Replace.ANY)
-@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
-public class ConsultantAdminFacadeIT {
+// @DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
+// @Transactional
+class ConsultantAdminFacadeIT {
@Autowired private ConsultantAdminFacade consultantAdminFacade;
@@ -66,9 +67,10 @@ public class ConsultantAdminFacadeIT {
@MockBean private AgencyServiceApiControllerFactory agencyServiceApiControllerFactory;
+ @Autowired private EntityManager entityManager;
+
@Test
- public void
- findFilteredConsultants_Should_retrieveDeletedAgencyRelations_When_consultantIsDeleted() {
+ void findFilteredConsultants_Should_retrieveDeletedAgencyRelations_When_consultantIsDeleted() {
var consultant = givenAPersistedDeletedConsultantWithTenAgencies();
var searchResult =
@@ -91,7 +93,7 @@ public class ConsultantAdminFacadeIT {
}
@Test
- public void
+ void
findFilteredConsultants_Should_retrieveOnlyNonDeletedAgencyRelations_When_consultantIsNotDeleted() {
var consultant = givenAPersistedNonDeletedConsultantWithDeletedAndNotDeletedAgencies();
@@ -121,6 +123,7 @@ public class ConsultantAdminFacadeIT {
private Consultant givenAPersistedNonDeletedConsultantWithDeletedAndNotDeletedAgencies() {
var parameters = baseConsultantParameters().excludeField(FieldPredicates.named("deleteDate"));
var consultant = new EasyRandom(parameters).nextObject(Consultant.class);
+ consultant.setLanguages(null);
consultantRepository.save(consultant);
var consultantAgencies = buildPersistedAgenciesForConsultant(20, 5, consultant);
consultant.setConsultantAgencies(consultantAgencies);
@@ -168,6 +171,8 @@ private Set buildPersistedAgenciesForConsultant(
private Consultant givenAPersistedDeletedConsultantWithTenAgencies() {
var consultant = new EasyRandom(baseConsultantParameters()).nextObject(Consultant.class);
+ consultant.setLanguages(null);
+ consultant.setId(UUID.randomUUID().toString());
consultantRepository.save(consultant);
var consultantAgencies = buildPersistedAgenciesForConsultant(10, 0, consultant);
consultant.setConsultantAgencies(consultantAgencies);
@@ -177,7 +182,7 @@ private Consultant givenAPersistedDeletedConsultantWithTenAgencies() {
}
@Test
- public void findFilteredConsultants_Should_retrieveConsultantAfterAddingRelationToAgency() {
+ void findFilteredConsultants_Should_retrieveConsultantAfterAddingRelationToAgency() {
var consultantId = "id";
givenConsultantWithoutAgency(consultantId);
@@ -229,12 +234,13 @@ private void givenConsultantWithoutAgency(String id) {
newConsultant.setNotifyNewChatMessageFromAdviceSeeker(false);
newConsultant.setNotifyNewFeedbackMessageFromAdviceSeeker(false);
newConsultant.setLanguageCode(LanguageCode.de);
+ newConsultant.setLanguages(null);
consultantRepository.save(newConsultant);
}
@Test
- public void testConsultantAgencyForDeletionFiltering() {
+ void testConsultantAgencyForDeletionFiltering() {
List result = new ArrayList();
AgencyAdminResponseDTO agency1 = new AgencyAdminResponseDTO();
agency1.setId(110L);
@@ -263,7 +269,7 @@ public void testConsultantAgencyForDeletionFiltering() {
}
@Test
- public void testConsultantAgencyForCreationFiltering() {
+ void testConsultantAgencyForCreationFiltering() {
List result = new ArrayList();
AgencyAdminResponseDTO agency1 = new AgencyAdminResponseDTO();
agency1.setId(110L);
diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/ConsultantAdminFilterServiceBase.java b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/ConsultantAdminFilterServiceBase.java
index fc2be5675..74362dafe 100644
--- a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/ConsultantAdminFilterServiceBase.java
+++ b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/ConsultantAdminFilterServiceBase.java
@@ -75,6 +75,7 @@ public void findFilteredConsultants_Should_haveCorrectPagedResults_When_noFilter
ConsultantSearchResultDTO firstPage =
this.consultantAdminFilterService.findFilteredConsultants(
1, 30, new ConsultantFilter(), null);
+
ConsultantSearchResultDTO secondPage =
this.consultantAdminFilterService.findFilteredConsultants(
2, 30, new ConsultantFilter(), null);
diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/ConsultantAdminFilterServiceTenantAwareIT.java b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/ConsultantAdminFilterServiceTenantAwareIT.java
index fc7eac760..f5b6da124 100644
--- a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/ConsultantAdminFilterServiceTenantAwareIT.java
+++ b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/ConsultantAdminFilterServiceTenantAwareIT.java
@@ -11,15 +11,20 @@
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Transactional;
@SpringBootTest(classes = UserServiceApplication.class)
@TestPropertySource(properties = "spring.profiles.active=testing")
@AutoConfigureTestDatabase(replace = Replace.ANY)
-@TestPropertySource(properties = "multitenancy.enabled=true")
+@TestPropertySource(properties = "multitenancy.enabled=false")
@TestPropertySource(
properties =
"spring.datasource.data=classpath*:database/UserServiceDatabase.sql,classpath*:database/transformDataForTenants.sql")
+@TestPropertySource(
+ properties =
+ "spring.sql.init.data-locations=classpath:database/UserServiceDatabase.sql,classpath:database/transformDataForTenants.sql")
+@Sql(scripts = {"classpath:database/transformDataForTenants.sql"})
@Transactional
public class ConsultantAdminFilterServiceTenantAwareIT extends ConsultantAdminFilterServiceBase {
@@ -37,6 +42,7 @@ public void afterTests() {
@Test
public void findFilteredConsultants_Should_returnAllConsultants_When_noFilterIsGiven() {
+ consultantRepository.findAll().forEach(consultant -> System.out.println(consultant));
super.findFilteredConsultants_Should_returnAllConsultants_When_noFilterIsGiven();
}
diff --git a/src/test/java/de/caritas/cob/userservice/api/model/LiquibaseHibernateIT.java b/src/test/java/de/caritas/cob/userservice/api/model/LiquibaseHibernateIT.java
deleted file mode 100644
index 0a9c430aa..000000000
--- a/src/test/java/de/caritas/cob/userservice/api/model/LiquibaseHibernateIT.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package de.caritas.cob.userservice.api.model;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import de.caritas.cob.userservice.api.port.out.UserRepository;
-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.test.context.DynamicPropertyRegistry;
-import org.springframework.test.context.DynamicPropertySource;
-import org.testcontainers.containers.MariaDBContainer;
-import org.testcontainers.junit.jupiter.Container;
-import org.testcontainers.junit.jupiter.Testcontainers;
-
-@Testcontainers
-@AutoConfigureTestDatabase(replace = Replace.NONE)
-@SpringBootTest(
- properties = {
- "spring.jpa.hibernate.ddl-auto=validate",
- "identity.technical-user.username=tech-user",
- "identity.technical-user.password=tech-pass"
- })
-class LiquibaseHibernateIT {
- @Container
- @SuppressWarnings("resource")
- static MariaDBContainer> DB =
- new MariaDBContainer<>("mariadb:10.5.10").withDatabaseName("userservice");
-
- @Autowired UserRepository userRepository;
-
- @DynamicPropertySource
- static void registerMySQLProperties(DynamicPropertyRegistry registry) {
- registry.add("spring.datasource.url", DB::getJdbcUrl);
- registry.add("spring.datasource.username", DB::getUsername);
- registry.add("spring.datasource.password", DB::getPassword);
- }
-
- @Test
- void databaseAndEntityMappingsShouldBeInSync() {
- assertTrue(userRepository.count() > -1);
- }
-}
diff --git a/src/test/java/de/caritas/cob/userservice/api/port/out/UserChatRepositoryTest.java b/src/test/java/de/caritas/cob/userservice/api/port/out/UserChatRepositoryTest.java
index c340abb5f..03d440ff0 100644
--- a/src/test/java/de/caritas/cob/userservice/api/port/out/UserChatRepositoryTest.java
+++ b/src/test/java/de/caritas/cob/userservice/api/port/out/UserChatRepositoryTest.java
@@ -15,14 +15,11 @@
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.jdbc.Sql;
@DataJpaTest
@TestPropertySource(properties = "spring.profiles.active=testing")
@ActiveProfiles("testing")
@AutoConfigureTestDatabase(replace = Replace.ANY)
-@Sql(scripts = "classpath:database/UserServiceDDL.sql")
-@TestPropertySource(properties = "spring.jpa.hibernate.ddl-auto=create-drop")
class UserChatRepositoryTest {
private static final EasyRandom easyRandom = new EasyRandom();