diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index a49a76a..74405df 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -23,7 +23,7 @@ on: jobs: build: - name: Build + name: Compile runs-on: ubuntu-latest steps: @@ -34,15 +34,15 @@ jobs: java-version: '19' distribution: 'temurin' cache: maven - - name: Build with Maven - run: mvn -B package --file pom.xml + - name: Compile with Maven + run: mvn -B clean compile # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive - name: Update dependency graph uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 sonar: - name: SonarCloud Scan + name: Publish to SonarCloud Scan runs-on: ubuntu-latest steps: @@ -53,7 +53,13 @@ jobs: java-version: '19' distribution: 'temurin' cache: maven + - name: Compile with Maven + run: mvn -B compile + - name: Unit Test with Maven + run: mvn -B test -Pcoverage + - name: Integration Test with Maven + run: mvn -B integration-test -Pintegration-test,coverage - name: SonarCloud Scan - run: mvn -B clean verify -Pcoverage,sonar -Dsonar.login=${{ secrets.SONAR_TOKEN }} + run: mvn -B verify -Pintegration-test,coverage,sonar -Dsonar.login=${{ secrets.SONAR_TOKEN }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/pom.xml b/pom.xml index ffb5db1..24b7e8f 100644 --- a/pom.xml +++ b/pom.xml @@ -16,17 +16,15 @@ - 3.9.1.2184 - 0.8.8 - 3.0.0-M7 + 3.9.1.2184 + 0.8.8 + 3.0.0-M7 19 - - **/com/event/manager/security/domain/exception/**/*, - **/com/event/manager/security/domain/**/*, - **/com/event/manager/security/EventManagerSecurityApplication.java - - target/site/jacoco/jacoco.xml + + false + ${skipTests} + true @@ -101,20 +99,20 @@ + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire-maven-plugin.version} + org.jacoco jacoco-maven-plugin - ${jacoco.version} + ${jacoco-maven-plugin.version} org.sonarsource.scanner.maven sonar-maven-plugin - ${sonar.version} - - - org.apache.maven.plugins - maven-surefire-plugin - ${surefire.version} + ${sonar-maven-plugin.version} @@ -176,32 +174,90 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + ${skipUTs} + + integration, system + + + + org.apache.maven.plugins + maven-failsafe-plugin + + ${skipITs} + integration + system + + **/*IntegrationTest.java + + + + + + integration-test + verify + + + + + + integration-test + + false + + coverage true + + + ${project.basedir}/target/jacoco.exec + ${project.basedir}/target/jacoco.xml + ${project.basedir}/target/jacoco-class-folders + org.jacoco jacoco-maven-plugin + + ${jacoco.binary.file} + + com/event/manager/** + + + **/generated/** + + prepare-agent + + ${jacoco.binary.file} + true + - report - test + jacoco-integration-initialize + pre-integration-test - report + prepare-agent-integration + + ${jacoco.binary.file} + true + @@ -211,12 +267,17 @@ sonar + ${jacoco.xml.file} + + **/com/event/manager/security/domain/exception/**/*, + **/com/event/manager/security/domain/**/*, + **/com/event/manager/security/EventManagerSecurityApplication.java + https://sonarcloud.io magicsoup EventManager_java-event-manager-security-app ${project.groupId}:${project.artifactId} ${code.coverage.exclusions} - ${jacoco.report.xml.path} false diff --git a/src/test/java/com/event/manager/security/EventManagerSecurityApplicationTests.java b/src/test/java/com/event/manager/security/EventManagerSecurityApplicationTests.java index 34e7a12..be98782 100644 --- a/src/test/java/com/event/manager/security/EventManagerSecurityApplicationTests.java +++ b/src/test/java/com/event/manager/security/EventManagerSecurityApplicationTests.java @@ -1,15 +1,12 @@ package com.event.manager.security; +import com.event.manager.security.annotations.DefaultSpringBootTest; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.jdbc.Sql; import static org.assertj.core.api.Assertions.assertThat; -@ActiveProfiles({"test"}) -@SpringBootTest +@DefaultSpringBootTest class EventManagerSecurityApplicationTests { @Value("${server.port}") diff --git a/src/test/java/com/event/manager/security/annotations/ControllerSetupSpringBootTest.java b/src/test/java/com/event/manager/security/annotations/ControllerSetupSpringBootTest.java new file mode 100644 index 0000000..e7eade2 --- /dev/null +++ b/src/test/java/com/event/manager/security/annotations/ControllerSetupSpringBootTest.java @@ -0,0 +1,18 @@ +package com.event.manager.security.annotations; + +import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.MOCK; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@AutoConfigureMockMvc +@DefaultSpringBootTest(webEnvironment = MOCK, exclude = {FlywayAutoConfiguration.class}) +public @interface ControllerSetupSpringBootTest { +} diff --git a/src/test/java/com/event/manager/security/annotations/DefaultSpringBootTest.java b/src/test/java/com/event/manager/security/annotations/DefaultSpringBootTest.java new file mode 100644 index 0000000..2d44ba3 --- /dev/null +++ b/src/test/java/com/event/manager/security/annotations/DefaultSpringBootTest.java @@ -0,0 +1,23 @@ +package com.event.manager.security.annotations; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.annotation.AliasFor; +import org.springframework.test.context.ActiveProfiles; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@SpringBootTest +@ActiveProfiles +@EnableAutoConfiguration +public @interface DefaultSpringBootTest { + @AliasFor(annotation = ActiveProfiles.class, attribute = "profiles") String[] activeProfile() default {"test"}; + @AliasFor(annotation = SpringBootTest.class, attribute = "webEnvironment") SpringBootTest.WebEnvironment webEnvironment() default SpringBootTest.WebEnvironment.NONE; + @AliasFor(annotation = SpringBootTest.class, attribute = "properties") String[] properties() default {}; + @AliasFor(annotation = EnableAutoConfiguration.class, attribute = "exclude") Class[] exclude() default {}; +} diff --git a/src/test/java/com/event/manager/security/controller/MemberControllerTest.java b/src/test/java/com/event/manager/security/controller/MemberControllerTest.java index 7f1b85e..a8202b5 100644 --- a/src/test/java/com/event/manager/security/controller/MemberControllerTest.java +++ b/src/test/java/com/event/manager/security/controller/MemberControllerTest.java @@ -1,16 +1,14 @@ package com.event.manager.security.controller; -import com.event.manager.security.domain.model.api.MemberDTO; +import com.event.manager.security.annotations.ControllerSetupSpringBootTest; import com.event.manager.security.domain.exception.notfound.MemberNotFoundException; +import com.event.manager.security.domain.model.api.MemberDTO; import com.event.manager.security.service.MemberService; import com.fasterxml.jackson.databind.ObjectMapper; 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.mock.web.MockHttpServletResponse; -import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; @@ -21,13 +19,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@ActiveProfiles({"test"}) -@SpringBootTest -@AutoConfigureMockMvc +@ControllerSetupSpringBootTest class MemberControllerTest { - private final static String API_BASE_URI = "/api/v1/member"; - @Autowired private MockMvc mockMvc; diff --git a/src/test/java/com/event/manager/security/controller/RoleControllerTest.java b/src/test/java/com/event/manager/security/controller/RoleControllerTest.java index d4e74ff..72b2ed2 100644 --- a/src/test/java/com/event/manager/security/controller/RoleControllerTest.java +++ b/src/test/java/com/event/manager/security/controller/RoleControllerTest.java @@ -1,19 +1,17 @@ package com.event.manager.security.controller; -import com.event.manager.security.domain.model.api.RoleDTO; +import com.event.manager.security.annotations.ControllerSetupSpringBootTest; import com.event.manager.security.domain.exception.notfound.RoleNotFoundException; import com.event.manager.security.domain.model.Role; +import com.event.manager.security.domain.model.api.RoleDTO; import com.event.manager.security.mapper.RoleMapper; import com.event.manager.security.service.RoleService; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; 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.mock.web.MockHttpServletResponse; -import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; @@ -28,9 +26,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@ActiveProfiles({"test"}) -@SpringBootTest -@AutoConfigureMockMvc +@ControllerSetupSpringBootTest class RoleControllerTest { private final static String API_BASE_URI = "/api/v1/role"; diff --git a/src/test/java/com/event/manager/security/service/das/MemberDASImplIntegrationTest.java b/src/test/java/com/event/manager/security/service/das/MemberDASImplIntegrationTest.java index 2c788ba..c11ea13 100644 --- a/src/test/java/com/event/manager/security/service/das/MemberDASImplIntegrationTest.java +++ b/src/test/java/com/event/manager/security/service/das/MemberDASImplIntegrationTest.java @@ -1,14 +1,15 @@ package com.event.manager.security.service.das; +import com.event.manager.security.annotations.DefaultSpringBootTest; import com.event.manager.security.domain.exception.notfound.MemberNotFoundException; import com.event.manager.security.domain.model.entity.MemberEntity; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Tags; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; import java.util.stream.Stream; @@ -17,8 +18,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.params.provider.Arguments.of; -@ActiveProfiles("test") -@SpringBootTest +@Tags({@Tag("integration")}) +@DefaultSpringBootTest class MemberDASImplIntegrationTest { @Autowired