diff --git a/.github/workflows/dockerImage.yml b/.github/workflows/dockerImage.yml
index 1fe48e9..ec4013b 100644
--- a/.github/workflows/dockerImage.yml
+++ b/.github/workflows/dockerImage.yml
@@ -65,7 +65,7 @@ jobs:
push_to_registry:
strategy:
matrix:
- registry: ["docker.pkg.github.com", "ghcr.io"]
+ registry: ["ghcr.io"]
needs: [test]
name: Push Docker image to GitHub Packages
runs-on: ubuntu-latest
diff --git a/pom.xml b/pom.xml
index 4663cb2..1a14054 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,7 +16,7 @@
org.springframework.boot
spring-boot-starter-parent
- 2.5.12
+ 2.7.18
@@ -30,7 +30,7 @@
6.2.1
3.0.0
3.3.5
- 5.7.5
+ 5.7.12
2.10.9.2
@@ -64,6 +64,7 @@
org.springframework.boot
spring-boot-starter-data-mongodb
+ 2.7.5
org.springframework.data
@@ -73,7 +74,6 @@
org.hibernate.validator
hibernate-validator
- 6.1.6.Final
@@ -104,13 +104,6 @@
4.3.1
-
-
- io.springfox
- springfox-boot-starter
- ${springfox-boot-starter.version}
-
-
org.keycloak
@@ -150,7 +143,6 @@
org.apache.commons
commons-lang3
- 3.11
@@ -168,7 +160,6 @@
org.springframework.boot
spring-boot-autoconfigure
- 2.3.5.RELEASE
@@ -195,23 +186,23 @@
+
- powermock-module-junit4
- org.powermock
+ de.flapdoodle.embed
+ de.flapdoodle.embed.mongo
+ 4.13.0
test
- 2.0.2
- powermock-api-mockito2
- org.powermock
- test
- 2.0.2
+ de.flapdoodle.embed
+ de.flapdoodle.embed.mongo.spring26x
+ 4.13.0
- de.flapdoodle.embed
- de.flapdoodle.embed.mongo
- test
+ commons-io
+ commons-io
+ 2.16.1
@@ -237,6 +228,24 @@
spring-boot-maven-plugin
+
+ org.openrewrite.maven
+ rewrite-maven-plugin
+ 5.30.0
+
+
+ org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_7
+
+
+
+
+ org.openrewrite.recipe
+ rewrite-spring
+ 5.9.0
+
+
+
+
org.openapitools
diff --git a/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java b/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java
index 184e804..39c5405 100644
--- a/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java
+++ b/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java
@@ -6,11 +6,6 @@
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class StatisticsServiceApplication {
-
- static {
- System.setProperty("os.arch", "i686_64");
- }
-
public static void main(String[] args) {
SpringApplication.run(StatisticsServiceApplication.class, args);
}
diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/controller/CustomSwaggerUIApiResourceController.java b/src/main/java/de/caritas/cob/statisticsservice/api/controller/CustomSwaggerUIApiResourceController.java
deleted file mode 100644
index 144f217..0000000
--- a/src/main/java/de/caritas/cob/statisticsservice/api/controller/CustomSwaggerUIApiResourceController.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package de.caritas.cob.statisticsservice.api.controller;
-
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import springfox.documentation.annotations.ApiIgnore;
-import springfox.documentation.swagger.web.ApiResourceController;
-import springfox.documentation.swagger.web.SwaggerResourcesProvider;
-
-@Controller
-@ApiIgnore
-@RequestMapping(value = "${springfox.docuPath}" + "/swagger-resources")
-public class CustomSwaggerUIApiResourceController extends ApiResourceController {
-
- public static final String SWAGGER_UI_BASE_URL = "/statistics/docs";
-
- public CustomSwaggerUIApiResourceController(SwaggerResourcesProvider swaggerResources) {
- super(swaggerResources, SWAGGER_UI_BASE_URL);
- }
-
-}
diff --git a/src/main/java/de/caritas/cob/statisticsservice/config/AppConfig.java b/src/main/java/de/caritas/cob/statisticsservice/config/AppConfig.java
index 58f0389..c0a8f9a 100644
--- a/src/main/java/de/caritas/cob/statisticsservice/config/AppConfig.java
+++ b/src/main/java/de/caritas/cob/statisticsservice/config/AppConfig.java
@@ -1,5 +1,7 @@
package de.caritas.cob.statisticsservice.config;
+import org.keycloak.adapters.KeycloakConfigResolver;
+import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
@@ -25,4 +27,14 @@ public LocalValidatorFactoryBean validator(MessageSource messageSource) {
return validatorFactoryBean;
}
+ /**
+ * Use the KeycloakSpringBootConfigResolver to be able to save the Keycloak settings in the spring
+ * application properties.
+ */
+ @Bean
+ public KeycloakConfigResolver keyCloakConfigResolver() {
+ return new KeycloakSpringBootConfigResolver();
+ }
+
+
}
diff --git a/src/main/java/de/caritas/cob/statisticsservice/config/CustomSwaggerUIPathWebMvcConfigurer.java b/src/main/java/de/caritas/cob/statisticsservice/config/CustomSwaggerUIPathWebMvcConfigurer.java
deleted file mode 100644
index 49a4399..0000000
--- a/src/main/java/de/caritas/cob/statisticsservice/config/CustomSwaggerUIPathWebMvcConfigurer.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package de.caritas.cob.statisticsservice.config;
-
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-
-@Component
-public class CustomSwaggerUIPathWebMvcConfigurer implements WebMvcConfigurer {
-
- @Value("${springfox.docuPath}")
- private String docuPath;
-
- @Override
- public void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.addResourceHandler(docuPath + "/swagger-ui/**")
- .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
- registry.addResourceHandler(docuPath + "/**")
- .addResourceLocations("classpath:/META-INF/resources/");
- }
-
-}
diff --git a/src/main/java/de/caritas/cob/statisticsservice/config/SecurityConfig.java b/src/main/java/de/caritas/cob/statisticsservice/config/SecurityConfig.java
index 7886f37..f60ce96 100644
--- a/src/main/java/de/caritas/cob/statisticsservice/config/SecurityConfig.java
+++ b/src/main/java/de/caritas/cob/statisticsservice/config/SecurityConfig.java
@@ -93,14 +93,6 @@ protected void configure(HttpSecurity http) throws Exception {
.anyRequest().denyAll();
}
- /**
- * Use the KeycloakSpringBootConfigResolver to be able to save the Keycloak settings in the spring
- * application properties.
- */
- @Bean
- public KeycloakConfigResolver keyCloakConfigResolver() {
- return new KeycloakSpringBootConfigResolver();
- }
/**
* Change springs authentication strategy to be stateless (no session is being created).
diff --git a/src/main/java/de/caritas/cob/statisticsservice/config/SpringFoxConfig.java b/src/main/java/de/caritas/cob/statisticsservice/config/SpringFoxConfig.java
deleted file mode 100644
index cad6032..0000000
--- a/src/main/java/de/caritas/cob/statisticsservice/config/SpringFoxConfig.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package de.caritas.cob.statisticsservice.config;
-
-import static java.util.Collections.singletonList;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
-import springfox.documentation.builders.PathSelectors;
-import springfox.documentation.builders.RequestHandlerSelectors;
-import springfox.documentation.service.ApiInfo;
-import springfox.documentation.service.ApiKey;
-import springfox.documentation.service.AuthorizationScope;
-import springfox.documentation.service.Contact;
-import springfox.documentation.service.SecurityReference;
-import springfox.documentation.service.SecurityScheme;
-import springfox.documentation.spi.DocumentationType;
-import springfox.documentation.spi.service.contexts.SecurityContext;
-import springfox.documentation.spring.web.plugins.Docket;
-
-/**
- * Provides the SpringFox (API documentation generation) configuration.
- *
- */
-@Configuration
-@Import(BeanValidatorPluginsConfiguration.class)
-public class SpringFoxConfig {
-
- @Value("${springfox.docuTitle}")
- private String docuTitle;
- @Value("${springfox.docuDescription}")
- private String docuDescription;
- @Value("${springfox.docuVersion}")
- private String docuVersion;
- @Value("${springfox.docuTermsUrl}")
- private String docuTermsUrl;
- @Value("${springfox.docuContactName}")
- private String docuContactName;
- @Value("${springfox.docuContactUrl}")
- private String docuContactUrl;
- @Value("${springfox.docuContactEmail}")
- private String docuContactEmail;
- @Value("${springfox.docuLicense}")
- private String docuLicense;
- @Value("${springfox.docuLicenseUrl}")
- private String docuLicenseUrl;
-
- @Bean
- public Docket apiDocket() {
- return new Docket(DocumentationType.SWAGGER_2).select()
- .apis(RequestHandlerSelectors.basePackage("de.caritas.cob.statisticsservice.api")).build()
- .consumes(getContentTypes()).produces(getContentTypes()).apiInfo(getApiInfo())
- .useDefaultResponseMessages(false).protocols(protocols()).securitySchemes(securitySchemes())
- .securityContexts(securityContexts());
- }
-
- private List securityContexts() {
- return singletonList(SecurityContext.builder()
- .forPaths(PathSelectors.any()).securityReferences(securityReferences()).build());
- }
-
- private List securityReferences() {
- return singletonList(
- SecurityReference.builder().reference("token").scopes(new AuthorizationScope[0]).build());
- }
-
- private List securitySchemes() {
- return singletonList(new ApiKey("Bearer", "Authorization", "header"));
- }
-
- /**
- * Returns the API protocols (for documentation).
- *
- * @return the supported protocols
- */
- private Set protocols() {
- Set protocols = new HashSet<>();
- protocols.add("https");
- return protocols;
- }
-
- /**
- * Returns all content types which should be consumed/produced.
- *
- * @return the supported content types
- */
- private Set getContentTypes() {
- Set contentTypes = new HashSet<>();
- contentTypes.add("application/json");
- return contentTypes;
- }
-
- /**
- * Returns the API information (defined in application.properties).
- *
- * @return api information
- */
- private ApiInfo getApiInfo() {
- return new ApiInfo(docuTitle, docuDescription, docuVersion, docuTermsUrl,
- new Contact(docuContactName, docuContactUrl, docuContactEmail), docuLicense, docuLicenseUrl,
- Collections.emptyList());
- }
-
-}
diff --git a/src/main/resources/application-testing.properties b/src/main/resources/application-testing.properties
index c3d440b..e444b9f 100644
--- a/src/main/resources/application-testing.properties
+++ b/src/main/resources/application-testing.properties
@@ -22,4 +22,8 @@ csrf.header.property=X-CSRF-TOKEN
csrf.cookie.property=CSRF-TOKEN
consulting.type.service.api.url=
+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
+
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 04a1950..4d07972 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -11,7 +11,7 @@ spring.data.jpa.repositories.bootstrap-mode=default
# General app settings
server.port=8080
-spring.mvc.locale=de_DE
+spring.web.locale=de_DE
spring.jackson.time-zone=Europe/Berlin
# Logging: SLF4J (via Lombok)
@@ -75,6 +75,6 @@ tenant.service.api.url=http://tenantservice:8080
management.endpoint.health.enabled=true
management.endpoint.health.show-details=never
management.endpoints.web.exposure.include=health
-management.health.probes.enabled=true
+management.endpoint.health.probes.enabled=true
management.metrics.mongo.command.enabled=false
management.metrics.mongo.connectionpool.enabled=false
\ No newline at end of file
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/authorization/AuthorityTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/authorization/AuthorityTest.java
index 0ffe01b..970e98e 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/authorization/AuthorityTest.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/authorization/AuthorityTest.java
@@ -7,7 +7,7 @@
import static org.hamcrest.Matchers.nullValue;
import de.caritas.cob.statisticsservice.api.authorization.Authority.AuthorityValue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class AuthorityTest {
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/authorization/RoleAuthorizationAuthorityMapperTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/authorization/RoleAuthorizationAuthorityMapperTest.java
index 644bf58..385e7e6 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/authorization/RoleAuthorizationAuthorityMapperTest.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/authorization/RoleAuthorizationAuthorityMapperTest.java
@@ -10,7 +10,8 @@
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import org.junit.Test;
+
+import org.junit.jupiter.api.Test;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerAuthorizationIT.java b/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerAuthorizationIT.java
index ca55e9b..ca17be0 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerAuthorizationIT.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerAuthorizationIT.java
@@ -9,9 +9,9 @@
import de.caritas.cob.statisticsservice.api.authorization.Authority.AuthorityValue;
import de.caritas.cob.statisticsservice.api.statistics.repository.StatisticsEventRepository;
import de.caritas.cob.statisticsservice.api.statistics.repository.StatisticsEventTenantAwareRepository;
+import org.junit.jupiter.api.Test;
+
import javax.servlet.http.Cookie;
-import org.junit.Test;
-import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
@@ -24,10 +24,8 @@
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
-@RunWith(SpringRunner.class)
@TestPropertySource(properties = "spring.profiles.active=testing")
@SpringBootTest(classes = {StatisticsServiceApplication.class})
@EnableAutoConfiguration(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerIT.java b/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerIT.java
index 711aa61..ed1847d 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerIT.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerIT.java
@@ -9,7 +9,6 @@
import static de.caritas.cob.statisticsservice.api.testhelper.TestConstants.DATE_TO;
import static de.caritas.cob.statisticsservice.api.testhelper.TestConstants.DATE_TO_FORMATTED;
import static org.mockito.Mockito.when;
-import static org.powermock.reflect.Whitebox.setInternalState;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@@ -18,15 +17,13 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
-import de.caritas.cob.statisticsservice.StatisticsServiceApplication;
import de.caritas.cob.statisticsservice.api.authorization.RoleAuthorizationAuthorityMapper;
import de.caritas.cob.statisticsservice.api.authorization.StatisticsFeatureAuthorisationService;
import de.caritas.cob.statisticsservice.api.service.LogService;
import de.caritas.cob.statisticsservice.api.statistics.service.RegistrationStatisticsService;
import de.caritas.cob.statisticsservice.api.statistics.service.StatisticsService;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.keycloak.adapters.KeycloakConfigResolver;
import org.mockito.Mock;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -35,15 +32,13 @@
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.http.MediaType;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MockMvc;
-@RunWith(SpringRunner.class)
@WebMvcTest(StatisticsController.class)
@AutoConfigureMockMvc(addFilters = false)
-@ContextConfiguration(classes = StatisticsServiceApplication.class)
-public class StatisticsControllerIT {
+@TestPropertySource(properties = "spring.profiles.active=testing")
+class StatisticsControllerIT {
@Autowired
private MockMvc mvc;
@@ -60,16 +55,14 @@ public class StatisticsControllerIT {
@MockBean
StatisticsFeatureAuthorisationService statisticsFeatureAuthorisationService;
+ @MockBean
+ KeycloakConfigResolver keycloakConfigResolver;
+
@Mock
private Logger logger;
- @Before
- public void setup() {
- setInternalState(LogService.class, "LOGGER", logger);
- }
-
@Test
- public void getConsultantStatistics_Should_ReturnStatisticsDataAndOk() throws Exception {
+ void getConsultantStatistics_Should_ReturnStatisticsDataAndOk() throws Exception {
when(statisticsService.fetchStatisticsData(DATE_FROM, DATE_TO)).thenReturn(CONSULTANT_STATISTICS_RESPONSE_DTO);
@@ -81,7 +74,7 @@ public void getConsultantStatistics_Should_ReturnStatisticsDataAndOk() throws Ex
}
@Test
- public void getRegistrationStatistics_Should_ReturnStatisticsDataAndOk() throws Exception {
+ void getRegistrationStatistics_Should_ReturnStatisticsDataAndOk() throws Exception {
when(registrationStatisticsService.fetchRegistrationStatisticsData()).thenReturn(REGISTRATION_STATISTICS_LIST_RESPONSE_DTO);
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/helper/AuthenticatedUserTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/helper/AuthenticatedUserTest.java
index 0e5afbd..103f770 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/helper/AuthenticatedUserTest.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/helper/AuthenticatedUserTest.java
@@ -1,26 +1,34 @@
package de.caritas.cob.statisticsservice.api.helper;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-@RunWith(MockitoJUnitRunner.class)
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
public class AuthenticatedUserTest {
- @Test(expected = NullPointerException.class)
+ @Test
public void AuthenticatedUser_Should_ThrowNullPointerExceptionWhenArgumentsAreNull() {
- new AuthenticatedUser(null, null, null);
+ assertThrows(NullPointerException.class, () -> {
+ new AuthenticatedUser(null, null, null);
+ });
}
- @Test(expected = NullPointerException.class)
+ @Test
public void AuthenticatedUser_Should_ThrowNullPointerExceptionWhenUserIdIsNull() {
- AuthenticatedUser authenticatedUser = new AuthenticatedUser();
- authenticatedUser.setUserId(null);
+ assertThrows(NullPointerException.class, () -> {
+ AuthenticatedUser authenticatedUser = new AuthenticatedUser();
+ authenticatedUser.setUserId(null);
+ });
}
- @Test(expected = NullPointerException.class)
+ @Test
public void AuthenticatedUser_Should_ThrowNullPointerExceptionWhenUsernameIsNull() {
- AuthenticatedUser authenticatedUser = new AuthenticatedUser();
- authenticatedUser.setUsername(null);
+ assertThrows(NullPointerException.class, () -> {
+ AuthenticatedUser authenticatedUser = new AuthenticatedUser();
+ authenticatedUser.setUsername(null);
+ });
}
}
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/service/LogServiceTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/service/LogServiceTest.java
deleted file mode 100644
index a7b4a64..0000000
--- a/src/test/java/de/caritas/cob/statisticsservice/api/service/LogServiceTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package de.caritas.cob.statisticsservice.api.service;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.verify;
-import static org.powermock.reflect.Whitebox.setInternalState;
-
-import java.io.PrintWriter;
-import javax.ws.rs.BadRequestException;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.slf4j.Logger;
-import org.springframework.http.HttpStatus;
-
-@RunWith(MockitoJUnitRunner.class)
-public class LogServiceTest {
-
- @Mock
- Exception exception;
-
- @Mock
- BadRequestException badRequestException;
-
- @Mock
- NumberFormatException numberFormatException;
-
- @Mock
- private Logger logger;
-
- @Before
- public void setup() {
- setInternalState(LogService.class, "LOGGER", logger);
- }
-
- @Test
- public void logDatabaseError_Should_LogExceptionStackTrace() {
-
- LogService.logDatabaseError(exception);
- verify(exception, atLeastOnce()).printStackTrace(any(PrintWriter.class));
- }
-
- @Test
- public void logBadRequestException_Should_LogExceptionStackTrace() {
-
- LogService.logBadRequestException(badRequestException);
- verify(badRequestException, atLeastOnce()).printStackTrace(any(PrintWriter.class));
- }
-
- @Test
- public void logNumberFormatException_Should_LogExceptionStackTrace() {
-
- LogService.logNumberFormatException(numberFormatException);
- verify(numberFormatException, atLeastOnce()).printStackTrace(any(PrintWriter.class));
- }
-
- @Test
- public void logInfo_Should_LogInfoMessage() {
-
- LogService.logInfo("info message");
- verify(logger, atLeastOnce()).info("info message");
- }
-
- @Test
- public void logWarning_Should_LogWarnMessage_When_onlyExceptionIsProvided() {
-
- LogService.logWarning(exception);
- verify(logger, atLeastOnce()).warn(eq("StatisticsService API: {}"), anyString());
- verify(exception, atLeastOnce()).printStackTrace(any(PrintWriter.class));
- }
-
- @Test
- public void logWarning_Should_LogWarnMessage_When_onlyExceptionAndStatusProvided() {
-
- LogService.logWarning(HttpStatus.MULTI_STATUS, exception);
- verify(logger, atLeastOnce()).warn(eq("StatisticsService API: {}: {}"),
- eq("Multi-Status"), anyString());
- verify(exception, atLeastOnce()).printStackTrace(any(PrintWriter.class));
- }
-
- @Test
- public void logInternalServerError_Should_LogError() {
-
- LogService.logInternalServerError(exception);
- verify(logger, atLeastOnce()).error(eq("StatisticsService API: 500 Internal Server Error: {}"),
- anyString());
- verify(exception, atLeastOnce()).printStackTrace(any(PrintWriter.class));
- }
-
- @Test
- public void logError_Should_LogError() {
- LogService.logError(exception);
- verify(logger, atLeastOnce()).error(eq("StatisticsService API: {}"), anyString());
- verify(exception, atLeastOnce()).printStackTrace(any(PrintWriter.class));
- }
-
-}
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/service/UserStatisticsServiceTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/service/UserStatisticsServiceTest.java
index a71cabc..e07b4c1 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/service/UserStatisticsServiceTest.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/service/UserStatisticsServiceTest.java
@@ -9,16 +9,19 @@
import de.caritas.cob.statisticsservice.api.service.securityheader.SecurityHeaderSupplier;
import de.caritas.cob.statisticsservice.api.service.securityheader.TenantHeaderSupplier;
+import de.caritas.cob.statisticsservice.config.apiclient.UserStatisticsApiControllerFactory;
import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.UserStatisticsControllerApi;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpHeaders;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
-@RunWith(SpringRunner.class)
-public class UserStatisticsServiceTest {
+@ExtendWith(MockitoExtension.class)
+class UserStatisticsServiceTest {
@InjectMocks
UserStatisticsService userStatisticsService;
@@ -29,8 +32,16 @@ public class UserStatisticsServiceTest {
@Mock
TenantHeaderSupplier tenantHeaderSupplier;
+ @Mock
+ UserStatisticsApiControllerFactory userStatisticsApiControllerFactory;
+
+ @BeforeEach
+ void setup() {
+ when(userStatisticsApiControllerFactory.createControllerApi()).thenReturn(userStatisticsControllerApi);
+ }
+
@Test
- public void retrieveSessionViaRcGroupId_Should_RetrieveSessionViaUserStatisticsControllerApi() {
+ void retrieveSessionViaRcGroupId_Should_RetrieveSessionViaUserStatisticsControllerApi() {
var headers = new HttpHeaders();
when(securityHeaderSupplier.getCsrfHttpHeaders()).thenReturn(headers);
@@ -40,7 +51,7 @@ public void retrieveSessionViaRcGroupId_Should_RetrieveSessionViaUserStatisticsC
}
@Test
- public void retrieveSessionViaSessionId_Should_RetrieveSessionViaUserStatisticsControllerApi() {
+ void retrieveSessionViaSessionId_Should_RetrieveSessionViaUserStatisticsControllerApi() {
var headers = new HttpHeaders();
when(securityHeaderSupplier.getCsrfHttpHeaders()).thenReturn(headers);
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/service/securityheader/TenantHeaderSupplierTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/service/securityheader/TenantHeaderSupplierTest.java
index 6ad62d7..cd7373e 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/service/securityheader/TenantHeaderSupplierTest.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/service/securityheader/TenantHeaderSupplierTest.java
@@ -7,7 +7,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
-import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpHeaders;
import org.springframework.test.util.ReflectionTestUtils;
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveOrDeleteSessionListenerTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveOrDeleteSessionListenerTest.java
index 7e57a23..af89bbe 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveOrDeleteSessionListenerTest.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveOrDeleteSessionListenerTest.java
@@ -18,17 +18,18 @@
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent;
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.ArchiveMetaData;
import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.model.SessionStatisticsResultDTO;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
import java.time.OffsetDateTime;
-import org.junit.Test;
-import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
public class ArchiveOrDeleteSessionListenerTest {
@InjectMocks
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/AssignSessionListenerTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/AssignSessionListenerTest.java
index 8aeb246..58cfcc8 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/AssignSessionListenerTest.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/AssignSessionListenerTest.java
@@ -7,14 +7,15 @@
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent;
import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.model.SessionStatisticsResultDTO;
import org.apache.commons.lang3.RandomStringUtils;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.time.OffsetDateTime;
import java.util.Map;
@@ -32,8 +33,8 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-@RunWith(SpringRunner.class)
-public class AssignSessionListenerTest {
+@ExtendWith(SpringExtension.class)
+class AssignSessionListenerTest {
@InjectMocks
AssignSessionListener assignSessionListener;
@@ -42,7 +43,7 @@ public class AssignSessionListenerTest {
@Captor ArgumentCaptor statisticsEventCaptor;
@Test
- public void receiveMessage_Should_saveFullEventToMongoDb() {
+ void receiveMessage_Should_saveFullEventToMongoDb() {
// given
SessionStatisticsResultDTO sessionStatisticsResultDTO = buildResultDto();
when(userStatisticsService.retrieveSessionViaSessionId(SESSION_ID))
@@ -77,7 +78,7 @@ public void receiveMessage_Should_saveFullEventToMongoDb() {
}
@Test
- public void receiveMessage_Should_savePartialEventToMongoDb() {
+ void receiveMessage_Should_savePartialEventToMongoDb() {
var sessionStatisticsResultDTO = buildResultDto();
when(userStatisticsService.retrieveSessionViaSessionId(SESSION_ID))
.thenReturn(sessionStatisticsResultDTO);
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListenerTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListenerTest.java
index 70c2802..5bef18d 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListenerTest.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListenerTest.java
@@ -17,17 +17,18 @@
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent;
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.CreateMessageMetaData;
import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.model.SessionStatisticsResultDTO;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
import java.time.OffsetDateTime;
-import org.junit.Test;
-import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
public class CreateMessageListenerTest {
@InjectMocks
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListenerTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListenerTest.java
index 25273ed..8d44a6c 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListenerTest.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListenerTest.java
@@ -18,18 +18,19 @@
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent;
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.RegistrationMetaData;
import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.model.SessionStatisticsResultDTO;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
import java.time.OffsetDateTime;
import java.util.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
public class RegistrationListenerTest {
@InjectMocks
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListenerTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListenerTest.java
index 33fbd25..3c86644 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListenerTest.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListenerTest.java
@@ -8,14 +8,14 @@
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.StartVideoCallMetaData;
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.VideoCallStatus;
import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.model.SessionStatisticsResultDTO;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
@@ -32,7 +32,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
public class StartVideoCallListenerTest {
@InjectMocks
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StopVideoCallListenerTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StopVideoCallListenerTest.java
index 9a46404..7ccfbf5 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StopVideoCallListenerTest.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StopVideoCallListenerTest.java
@@ -8,9 +8,9 @@
import static de.caritas.cob.statisticsservice.api.testhelper.TestConstants.VIDEO_CALL_UUID;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
-import static org.powermock.api.mockito.PowerMockito.when;
import de.caritas.cob.statisticsservice.api.model.EventType;
import de.caritas.cob.statisticsservice.api.model.StopVideoCallStatisticsEventMessage;
@@ -21,14 +21,15 @@
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.User;
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.StartVideoCallMetaData;
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.VideoCallStatus;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
import java.time.Duration;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
@@ -37,9 +38,9 @@
import org.springframework.amqp.AmqpException;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
public class StopVideoCallListenerTest {
@InjectMocks
@@ -52,7 +53,7 @@ public class StopVideoCallListenerTest {
@Test
public void receiveMessage_Should_saveEventToMongoDb() {
// given
- when(mongoTemplate.find(Mockito.any(Query.class), eq(StatisticsEvent.class)))
+ Mockito.when(mongoTemplate.find(Mockito.any(Query.class), Mockito.eq(StatisticsEvent.class)))
.thenReturn(buildMongoResultWithOneStatisticsEvent());
StopVideoCallStatisticsEventMessage stopVideoCallStatisticsEventMessage = buildEventMessage();
@@ -91,28 +92,32 @@ public void receiveMessage_Should_saveEventToMongoDb() {
assertThat(startVideoCallMetaData.getDuration(), is(duration));
}
- @Test(expected = AmqpException.class)
+ @Test
public void receiveMessage_Should_ThrowAmqpException_WhenMoreThanOneStartVideoCallEventWasFound() {
- // given
- when(mongoTemplate.find(Mockito.any(Query.class), eq(StatisticsEvent.class)))
- .thenReturn(buildMongoResultWithTwoStatisticsEvent());
+ assertThrows(AmqpException.class, () -> {
+ // given
+ Mockito.when(mongoTemplate.find(Mockito.any(Query.class), eq(StatisticsEvent.class)))
+ .thenReturn(buildMongoResultWithTwoStatisticsEvent());
- StopVideoCallStatisticsEventMessage stopVideoCallStatisticsEventMessage = buildEventMessage();
+ StopVideoCallStatisticsEventMessage stopVideoCallStatisticsEventMessage = buildEventMessage();
- // when, then
- stopVideoCallListener.receiveMessage(stopVideoCallStatisticsEventMessage);
+ // when, then
+ stopVideoCallListener.receiveMessage(stopVideoCallStatisticsEventMessage);
+ });
}
- @Test(expected = AmqpException.class)
+ @Test
public void receiveMessage_Should_ThrowAmqpException_WhenNoStartVideoCallEventWasFound() {
- // given
- when(mongoTemplate.find(Mockito.any(Query.class), eq(StatisticsEvent.class)))
- .thenReturn(Collections.emptyList());
+ assertThrows(AmqpException.class, () -> {
+ // given
+ Mockito.when(mongoTemplate.find(Mockito.any(Query.class), eq(StatisticsEvent.class)))
+ .thenReturn(Collections.emptyList());
- StopVideoCallStatisticsEventMessage stopVideoCallStatisticsEventMessage = buildEventMessage();
+ StopVideoCallStatisticsEventMessage stopVideoCallStatisticsEventMessage = buildEventMessage();
- // when, then
- stopVideoCallListener.receiveMessage(stopVideoCallStatisticsEventMessage);
+ // when, then
+ stopVideoCallListener.receiveMessage(stopVideoCallStatisticsEventMessage);
+ });
}
public List buildMongoResultWithOneStatisticsEvent() {
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/model/StatisticsEventBuilderTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/model/StatisticsEventBuilderTest.java
index 9736ce8..4b041c4 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/model/StatisticsEventBuilderTest.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/model/StatisticsEventBuilderTest.java
@@ -7,10 +7,10 @@
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEventBuilder;
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.CreateMessageMetaData;
import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.model.SessionStatisticsResultDTO;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import java.time.Instant;
@@ -23,85 +23,96 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
+@ExtendWith(MockitoExtension.class)
public class StatisticsEventBuilderTest {
@Mock UserStatisticsService userStatisticsService;
- @Test(expected = NullPointerException.class)
+ @Test
public void build_Should_ThrowNullPointerException_WhenEventTypeIsNull() {
-
- StatisticsEventBuilder builder =
- StatisticsEventBuilder.getInstance(
- () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID));
- builder
- .withTimestamp(Instant.now())
- .withUserId(CONSULTANT_ID)
- .withUserRole(UserRole.CONSULTANT)
- .build();
+ assertThrows(NullPointerException.class, () -> {
+
+ StatisticsEventBuilder builder =
+ StatisticsEventBuilder.getInstance(
+ () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID));
+ builder
+ .withTimestamp(Instant.now())
+ .withUserId(CONSULTANT_ID)
+ .withUserRole(UserRole.CONSULTANT)
+ .build();
+ });
}
- @Test(expected = NullPointerException.class)
+ @Test
public void build_Should_ThrowNullPointerException_WhenTimestampIsNull() {
-
- StatisticsEventBuilder builder =
- StatisticsEventBuilder.getInstance(
- () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID));
- builder
- .withEventType(EventType.ASSIGN_SESSION)
- .withUserId(CONSULTANT_ID)
- .withUserRole(UserRole.CONSULTANT)
- .build();
+ assertThrows(NullPointerException.class, () -> {
+
+ StatisticsEventBuilder builder =
+ StatisticsEventBuilder.getInstance(
+ () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID));
+ builder
+ .withEventType(EventType.ASSIGN_SESSION)
+ .withUserId(CONSULTANT_ID)
+ .withUserRole(UserRole.CONSULTANT)
+ .build();
+ });
}
- @Test(expected = NullPointerException.class)
+ @Test
public void build_Should_ThrowNullPointerException_WhenUserIdIsNull() {
-
- StatisticsEventBuilder builder =
- StatisticsEventBuilder.getInstance(
- () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID));
- builder
- .withEventType(EventType.ASSIGN_SESSION)
- .withTimestamp(Instant.now())
- .withUserRole(UserRole.CONSULTANT)
- .build();
+ assertThrows(NullPointerException.class, () -> {
+
+ StatisticsEventBuilder builder =
+ StatisticsEventBuilder.getInstance(
+ () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID));
+ builder
+ .withEventType(EventType.ASSIGN_SESSION)
+ .withTimestamp(Instant.now())
+ .withUserRole(UserRole.CONSULTANT)
+ .build();
+ });
}
- @Test(expected = NullPointerException.class)
+ @Test
public void build_Should_ThrowNullPointerException_WhenUserRoleIsNull() {
-
- StatisticsEventBuilder builder =
- StatisticsEventBuilder.getInstance(
- () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID));
- builder
- .withEventType(EventType.ASSIGN_SESSION)
- .withTimestamp(Instant.now())
- .withUserId(CONSULTANT_ID)
- .build();
+ assertThrows(NullPointerException.class, () -> {
+
+ StatisticsEventBuilder builder =
+ StatisticsEventBuilder.getInstance(
+ () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID));
+ builder
+ .withEventType(EventType.ASSIGN_SESSION)
+ .withTimestamp(Instant.now())
+ .withUserId(CONSULTANT_ID)
+ .build();
+ });
}
- @Test(expected = NullPointerException.class)
+ @Test
public void build_Should_ThrowNullPointerException_WhenRetrievedSessionHasNoId() {
-
- SessionStatisticsResultDTO session = buildSessionStatisticsResultDto();
- session.id(null);
-
- when(userStatisticsService.retrieveSessionViaSessionId(SESSION_ID))
- .thenReturn(session);
-
- StatisticsEventBuilder builder =
- StatisticsEventBuilder.getInstance(
- () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID));
- builder
- .withEventType(EventType.ASSIGN_SESSION)
- .withTimestamp(Instant.now())
- .withUserId(CONSULTANT_ID)
- .withUserRole(UserRole.CONSULTANT)
- .build();
+ assertThrows(NullPointerException.class, () -> {
+
+ SessionStatisticsResultDTO session = buildSessionStatisticsResultDto();
+ session.id(null);
+
+ when(userStatisticsService.retrieveSessionViaSessionId(SESSION_ID))
+ .thenReturn(session);
+
+ StatisticsEventBuilder builder =
+ StatisticsEventBuilder.getInstance(
+ () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID));
+ builder
+ .withEventType(EventType.ASSIGN_SESSION)
+ .withTimestamp(Instant.now())
+ .withUserId(CONSULTANT_ID)
+ .withUserRole(UserRole.CONSULTANT)
+ .build();
+ });
}
@Test
@@ -185,15 +196,17 @@ public void buildShouldNotRequestSessionFromUserServiceOnStartVideoCallEvent() {
verifyNoInteractions(userStatisticsService);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void buildShouldIllegalArgExceptionOnMissingSessionAndNotStartVideoCallEvent() {
- StatisticsEventBuilder.getInstance()
- .withEventType(EventType.ASSIGN_SESSION)
- .withTimestamp(Instant.now())
- .withUserId(CONSULTANT_ID)
- .withUserRole(UserRole.CONSULTANT)
- .withMetaData(new Object())
- .build();
+ assertThrows(IllegalArgumentException.class, () -> {
+ StatisticsEventBuilder.getInstance()
+ .withEventType(EventType.ASSIGN_SESSION)
+ .withTimestamp(Instant.now())
+ .withUserId(CONSULTANT_ID)
+ .withUserRole(UserRole.CONSULTANT)
+ .withMetaData(new Object())
+ .build();
+ });
}
private SessionStatisticsResultDTO buildSessionStatisticsResultDto() {
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepositoryIT.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepositoryIT.java
index 12d1695..733a7e1 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepositoryIT.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepositoryIT.java
@@ -22,24 +22,22 @@
import java.time.ZoneOffset;
import java.util.List;
import org.bson.Document;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+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.data.mongo.DataMongoTest;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.junit4.SpringRunner;
@DataMongoTest()
@ContextConfiguration(classes = StatisticsServiceApplication.class)
-@RunWith(SpringRunner.class)
@TestPropertySource(properties = "spring.profiles.active=testing")
public class StatisticsEventRepositoryIT {
+
public static final String MONGODB_STATISTICS_EVENTS_JSON_FILENAME =
"mongodb/StatisticsEvents.json";
private final Instant dateFromConverted =
@@ -52,7 +50,7 @@ public class StatisticsEventRepositoryIT {
@Autowired
MongoTemplate mongoTemplate;
- @Before
+ @BeforeEach
public void preFillMongoDb() throws IOException {
mongoTemplate.dropCollection(MONGO_COLLECTION_NAME);
ObjectMapper objectMapper = new ObjectMapper();
@@ -139,7 +137,7 @@ public void getAllArchiveSessionEvents_Should_ReturnArchiveSessionEvents() {
}
@Test
- @Ignore("For some reason this test is failing in this test scenario caused by the event.0.startTime and event.0.endTime filters.")
+ @Disabled("For some reason this test is failing in this test scenario caused by the event.0.startTime and event.0.endTime filters.")
public void calculateNumberOfDoneAppointmentsForConsultant_Should_ReturnCorrectNumberOfAppointments() {
Count count = statisticsEventRepository.calculateNumbersOfDoneAppointments(CONSULTANT_ID,
dateFromConverted, dateToConverted, dateToConverted);
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepositoryIT.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepositoryIT.java
index 3b47815..dfb49c7 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepositoryIT.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepositoryIT.java
@@ -10,20 +10,17 @@
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent;
import java.io.IOException;
import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+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.data.mongo.DataMongoTest;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.junit4.SpringRunner;
@DataMongoTest()
@ContextConfiguration(classes = StatisticsServiceApplication.class)
-@RunWith(SpringRunner.class)
@TestPropertySource(properties = "spring.profiles.active=testing")
@TestPropertySource(properties = "multitenancy.enabled=true")
public class StatisticsEventTenantAwareRepositoryIT {
@@ -40,7 +37,7 @@ public class StatisticsEventTenantAwareRepositoryIT {
@Autowired
MongoTemplate mongoTemplate;
- @Before
+ @BeforeEach
public void preFillMongoDb() throws IOException {
mongoTemplate.dropCollection(MONGO_COLLECTION_NAME);
ObjectMapper objectMapper = new ObjectMapper();
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java
index 5129040..5641b17 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java
@@ -7,7 +7,6 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/StatisticsServiceTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/StatisticsServiceTest.java
index 329af89..e56e4c4 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/StatisticsServiceTest.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/StatisticsServiceTest.java
@@ -5,6 +5,7 @@
import static de.caritas.cob.statisticsservice.api.testhelper.TestConstants.DATE_TO;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
@@ -17,18 +18,19 @@
import de.caritas.cob.statisticsservice.api.statistics.repository.StatisticsEventRepository;
import de.caritas.cob.statisticsservice.api.statistics.repository.StatisticsEventRepository.Count;
import de.caritas.cob.statisticsservice.api.statistics.repository.StatisticsEventRepository.Duration;
+import org.junit.jupiter.api.Test;
+
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
-@RunWith(MockitoJUnitRunner.class)
+@ExtendWith(MockitoExtension.class)
public class StatisticsServiceTest {
@InjectMocks
@@ -38,9 +40,11 @@ public class StatisticsServiceTest {
@Mock
AuthenticatedUser authenticatedUser;
- @Test(expected = BadRequestException.class)
+ @Test
public void fetchStatisticsData_Should_ThrowBadRequestException_WhenDateFromIsAfterDateTo() {
- statisticsService.fetchStatisticsData(DATE_TO, DATE_FROM);
+ assertThrows(BadRequestException.class, () -> {
+ statisticsService.fetchStatisticsData(DATE_TO, DATE_FROM);
+ });
}
@Test
diff --git a/src/test/java/de/caritas/cob/statisticsservice/config/resttemplate/CustomResponseErrorHandlerTest.java b/src/test/java/de/caritas/cob/statisticsservice/config/resttemplate/CustomResponseErrorHandlerTest.java
index 60432bc..0cbf7a8 100644
--- a/src/test/java/de/caritas/cob/statisticsservice/config/resttemplate/CustomResponseErrorHandlerTest.java
+++ b/src/test/java/de/caritas/cob/statisticsservice/config/resttemplate/CustomResponseErrorHandlerTest.java
@@ -2,13 +2,14 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.net.URI;
-import org.junit.Test;
+
+import org.junit.jupiter.api.Test;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpResponse;