From 714e4dfa24e91fe2bee5f7813371dcdd480c8341 Mon Sep 17 00:00:00 2001 From: tillias Date: Mon, 2 Nov 2020 22:39:26 +0100 Subject: [PATCH] Unit tests cleanup #79 --- .../github/microcatalog/MockMvcWithUser.java | 18 ++++++++++++++++++ .../ImpactAnalysisCustomResourceTest.java | 7 ++++--- .../custom/ReleasePathCustomResourceTest.java | 9 +++------ 3 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 src/test/java/com/github/microcatalog/MockMvcWithUser.java diff --git a/src/test/java/com/github/microcatalog/MockMvcWithUser.java b/src/test/java/com/github/microcatalog/MockMvcWithUser.java new file mode 100644 index 0000000..8566c3d --- /dev/null +++ b/src/test/java/com/github/microcatalog/MockMvcWithUser.java @@ -0,0 +1,18 @@ +package com.github.microcatalog; + +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc; +import org.springframework.security.test.context.support.WithMockUser; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@AutoConfigureWebMvc +@AutoConfigureMockMvc +@WithMockUser +public @interface MockMvcWithUser { +} diff --git a/src/test/java/com/github/microcatalog/web/rest/custom/ImpactAnalysisCustomResourceTest.java b/src/test/java/com/github/microcatalog/web/rest/custom/ImpactAnalysisCustomResourceTest.java index 0037ede..928193a 100644 --- a/src/test/java/com/github/microcatalog/web/rest/custom/ImpactAnalysisCustomResourceTest.java +++ b/src/test/java/com/github/microcatalog/web/rest/custom/ImpactAnalysisCustomResourceTest.java @@ -1,11 +1,13 @@ package com.github.microcatalog.web.rest.custom; +import com.github.microcatalog.MockMvcWithUser; import com.github.microcatalog.domain.custom.impact.analysis.Result; import com.github.microcatalog.service.custom.ImpactAnalysisService; import com.github.microcatalog.utils.MicroserviceBuilder; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; @@ -18,9 +20,8 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -@SpringBootTest -@AutoConfigureMockMvc -@WithMockUser +@SpringBootTest(classes = ImpactAnalysisCustomResource.class) +@MockMvcWithUser class ImpactAnalysisCustomResourceTest { @Autowired diff --git a/src/test/java/com/github/microcatalog/web/rest/custom/ReleasePathCustomResourceTest.java b/src/test/java/com/github/microcatalog/web/rest/custom/ReleasePathCustomResourceTest.java index 90794f2..3e6fd4f 100644 --- a/src/test/java/com/github/microcatalog/web/rest/custom/ReleasePathCustomResourceTest.java +++ b/src/test/java/com/github/microcatalog/web/rest/custom/ReleasePathCustomResourceTest.java @@ -1,15 +1,14 @@ package com.github.microcatalog.web.rest.custom; +import com.github.microcatalog.MockMvcWithUser; import com.github.microcatalog.domain.custom.ReleasePath; import com.github.microcatalog.service.custom.ReleasePathCustomService; import com.github.microcatalog.utils.MicroserviceBuilder; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -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.web.servlet.MockMvc; import java.util.Optional; @@ -17,11 +16,9 @@ import static org.mockito.BDDMockito.given; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -@SpringBootTest -@AutoConfigureMockMvc -@WithMockUser +@SpringBootTest(classes = ReleasePathCustomResource.class) +@MockMvcWithUser class ReleasePathCustomResourceTest { @Autowired