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