Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:

jobs:
build:
name: Build
name: Compile
runs-on: ubuntu-latest

steps:
Expand All @@ -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:
Expand All @@ -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 }}
101 changes: 81 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@
<properties>
<!-- libs version -->
<!-- plugins version -->
<sonar.version>3.9.1.2184</sonar.version>
<jacoco.version>0.8.8</jacoco.version>
<surefire.version>3.0.0-M7</surefire.version>
<sonar-maven-plugin.version>3.9.1.2184</sonar-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.8</jacoco-maven-plugin.version>
<surefire-maven-plugin.version>3.0.0-M7</surefire-maven-plugin.version>
<!-- global -->
<java.version>19</java.version>
<code.coverage.exclusions>
**/com/event/manager/security/domain/exception/**/*,
**/com/event/manager/security/domain/**/*,
**/com/event/manager/security/EventManagerSecurityApplication.java
</code.coverage.exclusions>
<jacoco.report.xml.path>target/site/jacoco/jacoco.xml</jacoco.report.xml.path>
<!-- global test config -->
<skipTests>false</skipTests>
<skipUTs>${skipTests}</skipUTs>
<skipITs>true</skipITs>
</properties>
<dependencies>
<!-- Spring boot dependencies -->
Expand Down Expand Up @@ -101,20 +99,20 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<version>${jacoco-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${sonar.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<version>${sonar-maven-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down Expand Up @@ -176,32 +174,90 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${skipUTs}</skipTests>
<!-- All tests except ones below-->
<excludedGroups>integration, system</excludedGroups>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skipITs>${skipITs}</skipITs>
<groups>integration</groups>
<excludedGroups>system</excludedGroups>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>integration-test</id>
<properties>
<skipITs>false</skipITs>
</properties>
</profile>
<profile>
<id>coverage</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- for multi-module projects, override those properties replacing ${project.basedir} by ${maven.multiModuleProjectDirectory} -->
<jacoco.binary.file>${project.basedir}/target/jacoco.exec</jacoco.binary.file>
<jacoco.xml.file>${project.basedir}/target/jacoco.xml</jacoco.xml.file>
<jacoco-class-folders>${project.basedir}/target/jacoco-class-folders</jacoco-class-folders>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<dataFile>${jacoco.binary.file}</dataFile>
<includes>
<include>com/event/manager/**</include>
</includes>
<excludes>
<exclude>**/generated/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${jacoco.binary.file}</destFile>
<append>true</append>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<id>jacoco-integration-initialize</id>
<phase>pre-integration-test</phase>
<goals>
<goal>report</goal>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${jacoco.binary.file}</destFile>
<append>true</append>
</configuration>
</execution>
</executions>
</plugin>
Expand All @@ -211,12 +267,17 @@
<profile>
<id>sonar</id>
<properties>
<sonar.coverage.jacoco.xmlReportPaths>${jacoco.xml.file}</sonar.coverage.jacoco.xmlReportPaths>
<code.coverage.exclusions>
**/com/event/manager/security/domain/exception/**/*,
**/com/event/manager/security/domain/**/*,
**/com/event/manager/security/EventManagerSecurityApplication.java
</code.coverage.exclusions>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.organization>magicsoup</sonar.organization>
<sonar.projectKey>EventManager_java-event-manager-security-app</sonar.projectKey>
<sonar.moduleKey>${project.groupId}:${project.artifactId}</sonar.moduleKey>
<sonar.exclusions>${code.coverage.exclusions}</sonar.exclusions>
<sonar.report>${jacoco.report.xml.path}</sonar.report>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
Expand Down
Original file line number Diff line number Diff line change
@@ -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}")
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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 {};
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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
Expand Down