From 3b45399d6d274e8d17b0d9678bb3b3b2ab4590f1 Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Fri, 26 Oct 2018 20:21:46 -0200 Subject: [PATCH] [RELEASE]merging 'release-1.2' into 'master' --- Jenkinsfile | 42 ++ otus-domain-business/pom.xml | 33 +- .../src/main/resources/META-INF/beans.xml | 12 +- otus-domain-ear/pom.xml | 49 +- otus-domain-persistence/pom.xml | 33 +- .../src/main/resources/META-INF/beans.xml | 12 +- otus-domain-rest/pom.xml | 32 +- .../security/AuthenticationResource.java | 87 ++-- .../src/main/webapp/WEB-INF/beans.xml | 12 +- .../src/main/webapp/WEB-INF/web.xml | 6 +- .../java/br/org/domain/rest/ResponseTest.java | 51 ++ .../br/org/domain/user/UserResourceTest.java | 57 +++ otus-domain-root/pom.xml | 437 ++++++++++-------- 13 files changed, 560 insertions(+), 303 deletions(-) create mode 100644 Jenkinsfile create mode 100644 otus-domain-rest/src/test/java/br/org/domain/rest/ResponseTest.java create mode 100644 otus-domain-rest/src/test/java/br/org/domain/user/UserResourceTest.java diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..750aa48 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,42 @@ +pipeline { + agent any + tools { + maven 'maven 3.5.0' + jdk 'Java8' + } + + stages { + stage('Build Aplication') { + steps { + sh 'mvn -f otus-domain-root/pom.xml clean install' + } + post { + always { + junit '**/target/surefire-reports/*.xml' + archive '**/target/surefire-reports/*.xml' + } + } + } + + stage('Publish artifact') { + steps { + sh 'mvn -f otus-domain-root/pom.xml deploy' + } + } + + stage('Sonar Update') { + steps { + sh 'mvn -f otus-domain-root/pom.xml sonar:sonar -Dsonar.host.url=${URL_SONAR} -Dsonar.password=${PWD_SONAR} -Dsonar.login=${USER_SONAR}' + } + } + + stage('Build - Development Server') { + steps { + echo "DEPLOY" + // sh 'mvn -f otus-domain-root/pom.xml clean install -Ddatabase.host=${DATABASE_DEV_HOST} -Ddatabase.username=${DATABASE_USER} -Ddatabase.password=${DATABASE_PWD}' + } + } + + } + + } diff --git a/otus-domain-business/pom.xml b/otus-domain-business/pom.xml index 1f5b517..a3aee1b 100644 --- a/otus-domain-business/pom.xml +++ b/otus-domain-business/pom.xml @@ -7,42 +7,49 @@ org.ccem.domain otus-domain-root - 1.1 + 1.2 ../otus-domain-root/pom.xml + org.ccem.domain otus-domain-persistence ${project.parent.version} provided + + org.ccem.owail + owail-sender + ${owail.sender.version} + provided + + + org.ccem.rep-tool + studio-repository-tool + ${studio.repository.version} + provided + br.org.tutty equalizer ${equalize.version} provided + + commons-io commons-io - 2.4 - - - org.ccem.owail - owail-sender - ${owail.sender.version} - - - org.ccem.rep-tool - studio-repository-tool - 1.0-SNAPSHOT + ${commons.io.version} + provided com.nimbusds nimbus-jose-jwt - 4.18 + ${nimbusds.version} + provided diff --git a/otus-domain-business/src/main/resources/META-INF/beans.xml b/otus-domain-business/src/main/resources/META-INF/beans.xml index ae0f4bf..b073abf 100644 --- a/otus-domain-business/src/main/resources/META-INF/beans.xml +++ b/otus-domain-business/src/main/resources/META-INF/beans.xml @@ -1,8 +1,6 @@ - - \ No newline at end of file + + diff --git a/otus-domain-ear/pom.xml b/otus-domain-ear/pom.xml index 99ae1e1..4769f2e 100644 --- a/otus-domain-ear/pom.xml +++ b/otus-domain-ear/pom.xml @@ -7,7 +7,7 @@ org.ccem.domain otus-domain-root - 1.1 + 1.2 ../otus-domain-root/pom.xml @@ -61,6 +61,7 @@ + org.ccem.domain otus-domain-business @@ -79,20 +80,56 @@ ${project.parent.version} war + + + + br.org.tutty + equalizer + ${equalize.version} + + + org.ccem.owail + owail-sender + ${owail.sender.version} + + + org.ccem.rep-tool + studio-repository-tool + ${studio.repository.version} + + + + + org.hibernate.javax.persistence + hibernate-jpa-2.1-api + ${hibernate.jpa.version} + org.hibernate.ogm hibernate-ogm-core - 5.0.0.Final + ${hibernate.core.version} org.hibernate.ogm hibernate-ogm-mongodb - 5.0.0.Final + ${hibernate.mongodb.version} + + - br.org.tutty - equalizer - ${equalize.version} + commons-io + commons-io + ${commons.io.version} + + + com.nimbusds + nimbus-jose-jwt + ${nimbusds.version} + + + com.google.code.gson + gson + ${gson.version} diff --git a/otus-domain-persistence/pom.xml b/otus-domain-persistence/pom.xml index e7654d6..8f90574 100644 --- a/otus-domain-persistence/pom.xml +++ b/otus-domain-persistence/pom.xml @@ -7,7 +7,7 @@ org.ccem.domain otus-domain-root - 1.1 + 1.2 ../otus-domain-root/pom.xml @@ -19,34 +19,45 @@ + + + br.org.tutty + equalizer + ${equalize.version} + provided + + + + + javax.validation + validation-api + 2.0.1.Final + provided + + + org.hibernate hibernate-core - 5.2.0.Final + ${hibernate.core.version} provided org.hibernate.javax.persistence hibernate-jpa-2.1-api - 1.0.0.Final + ${hibernate.jpa.version} provided org.hibernate.ogm hibernate-ogm-mongodb - 5.0.0.Final + ${hibernate.mongodb.version} provided org.hibernate.ogm hibernate-ogm-core - 5.0.0.Final - provided - - - br.org.tutty - equalizer - ${equalize.version} + ${hibernate.core.version} provided diff --git a/otus-domain-persistence/src/main/resources/META-INF/beans.xml b/otus-domain-persistence/src/main/resources/META-INF/beans.xml index ae0f4bf..b073abf 100644 --- a/otus-domain-persistence/src/main/resources/META-INF/beans.xml +++ b/otus-domain-persistence/src/main/resources/META-INF/beans.xml @@ -1,8 +1,6 @@ - - \ No newline at end of file + + diff --git a/otus-domain-rest/pom.xml b/otus-domain-rest/pom.xml index d932b83..7570dcc 100644 --- a/otus-domain-rest/pom.xml +++ b/otus-domain-rest/pom.xml @@ -6,32 +6,12 @@ org.ccem.domain otus-domain-root - 1.1 + 1.2 ../otus-domain-root/pom.xml - - org.jboss.resteasy - resteasy-jaxrs - 3.0.13.Final - - - org.jboss.resteasy - jaxrs-api - 3.0.12.Final - - - com.google.code.gson - gson - 2.3.1 - - - javax - javaee-web-api - 7.0 - provided - + org.ccem.domain otus-domain-business @@ -39,11 +19,13 @@ provided - org.jboss.resteasy - resteasy-cdi - 3.0.13.Final + com.google.code.gson + gson + ${gson.version} provided + + org.ccem.domain otus-domain-persistence diff --git a/otus-domain-rest/src/main/java/br/org/domain/security/AuthenticationResource.java b/otus-domain-rest/src/main/java/br/org/domain/security/AuthenticationResource.java index 02872fd..2ae179b 100644 --- a/otus-domain-rest/src/main/java/br/org/domain/security/AuthenticationResource.java +++ b/otus-domain-rest/src/main/java/br/org/domain/security/AuthenticationResource.java @@ -1,41 +1,46 @@ -package br.org.domain.security; - -import br.org.domain.rest.Response; -import br.org.domain.security.api.SecurityFacade; -import br.org.domain.security.dtos.AuthenticationDto; -import br.org.domain.user.dto.CurrentUserDto; - -import javax.inject.Inject; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; -import javax.ws.rs.*; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; - -@Path("/authentication") -public class AuthenticationResource { - @Inject - private SecurityFacade securityFacade; - - @Inject - private HttpSession httpSession; - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public String authenticate(AuthenticationDto authenticationDto, @Context HttpServletRequest request) { - authenticationDto.encrypt(); - String issuer = request.getRequestURL().toString(); - CurrentUserDto currentUser = securityFacade.authenticate(authenticationDto, issuer); - return new Response().buildSuccess(currentUser).toJson(); - } - - @POST - @Path("/invalidate") - public String invalidate(@Context HttpServletRequest request) { - String token = request.getHeader(HttpHeaders.AUTHORIZATION); - securityFacade.invalidateSession(token); - return new Response().buildSuccess().toJson(); - } -} +package br.org.domain.security; + +import br.org.domain.rest.Response; +import br.org.domain.security.api.SecurityFacade; +import br.org.domain.security.dtos.AuthenticationDto; +import br.org.domain.user.dto.CurrentUserDto; +import com.google.gson.Gson; + +import javax.inject.Inject; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; + +@Path("/authentication") +public class AuthenticationResource { + @Inject + private SecurityFacade securityFacade; + + @Inject + private HttpSession httpSession; + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public String authenticate(String authenticationJson, @Context HttpServletRequest request) { + AuthenticationDto authenticationDto = new Gson().fromJson(authenticationJson, AuthenticationDto.class); + authenticationDto.encrypt(); + String issuer = request.getRequestURL().toString(); + CurrentUserDto currentUser = securityFacade.authenticate(authenticationDto, issuer); + return new Response().buildSuccess(currentUser).toJson(); + } + + @POST + @Path("/invalidate") + public String invalidate(@Context HttpServletRequest request) { + String token = request.getHeader(HttpHeaders.AUTHORIZATION); + securityFacade.invalidateSession(token); + return new Response().buildSuccess().toJson(); + } +} diff --git a/otus-domain-rest/src/main/webapp/WEB-INF/beans.xml b/otus-domain-rest/src/main/webapp/WEB-INF/beans.xml index ae0f4bf..b073abf 100644 --- a/otus-domain-rest/src/main/webapp/WEB-INF/beans.xml +++ b/otus-domain-rest/src/main/webapp/WEB-INF/beans.xml @@ -1,8 +1,6 @@ - - \ No newline at end of file + + diff --git a/otus-domain-rest/src/main/webapp/WEB-INF/web.xml b/otus-domain-rest/src/main/webapp/WEB-INF/web.xml index 0f3715e..49db54c 100644 --- a/otus-domain-rest/src/main/webapp/WEB-INF/web.xml +++ b/otus-domain-rest/src/main/webapp/WEB-INF/web.xml @@ -1,6 +1,8 @@ - + resteasy.servlet.mapping.prefix diff --git a/otus-domain-rest/src/test/java/br/org/domain/rest/ResponseTest.java b/otus-domain-rest/src/test/java/br/org/domain/rest/ResponseTest.java new file mode 100644 index 0000000..fcf7bee --- /dev/null +++ b/otus-domain-rest/src/test/java/br/org/domain/rest/ResponseTest.java @@ -0,0 +1,51 @@ +package br.org.domain.rest; + +import br.org.domain.rest.Response; +import br.org.domain.user.dto.UserDto; +import com.google.gson.Gson; +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +public class ResponseTest { + + private UserDto user; + + @Before + public void setup() { + user = new UserDto(); + user.setEmail("emailValue"); + user.setName("nameValue"); + user.setPassword("passwordValue"); + user.setPhone("phoneValue"); + user.setSurname("surnameValue"); + } + + @Test + public void toString_should_return_a_json_with_value_of_data_equal_to_true() { + Response response = new Response(); + response.setData(true); + + Gson gson = new Gson(); + Response generatedJson = gson.fromJson(new Gson().toJson(response), Response.class); + assertThat(generatedJson.getData(), equalTo(Boolean.TRUE)); + } + + @Test + public void toString_should_return_a_json_with_value_of_data_equal_to_UserDto() { + Response response = new Response(); + response.setData(user); + + Gson gson = new Gson(); + UserDto generatedJson = gson.fromJson(new Gson().toJson(response.getData()), UserDto.class); + + assertThat(generatedJson.getEmail(), equalTo(user.getEmail())); + assertThat(generatedJson.getName(), equalTo(user.getName())); + assertThat(generatedJson.getPassword(), equalTo(user.getPassword())); + assertThat(generatedJson.getPhone(), equalTo(user.getPhone())); + assertThat(generatedJson.getSurname(), equalTo(user.getSurname())); + } + +} diff --git a/otus-domain-rest/src/test/java/br/org/domain/user/UserResourceTest.java b/otus-domain-rest/src/test/java/br/org/domain/user/UserResourceTest.java new file mode 100644 index 0000000..f5f474b --- /dev/null +++ b/otus-domain-rest/src/test/java/br/org/domain/user/UserResourceTest.java @@ -0,0 +1,57 @@ +package br.org.domain.user; + +import br.org.domain.email.validation.EmailConstraint; +import br.org.domain.rest.Response; +import br.org.domain.user.UserResource; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class UserResourceTest { + + @Mock + private EmailConstraint emailConstraint; + + @InjectMocks + private UserResource resource; + + private Response trueResponse; + private Response falseResponse; + + @Before + public void setup() { + trueResponse = new Response(); + trueResponse.setData(true); + + falseResponse = new Response(); + falseResponse.setData(false); + } + + @Test + public void userEmailExist_method_should_return_a_json_with_value_FALSE_for_property_data_when_email_is_unique() { + when(emailConstraint.isUnique(anyString())).thenReturn(false); + + String restReturn = resource.userEmailExists(anyString()); + + assertThat(trueResponse.toJson(), equalTo(restReturn)); + } + + @Test + public void userEmailExist_method_should_return_a_json_with_value_TRUE_for_property_data_when_email_is_not_unique() { + when(emailConstraint.isUnique(anyString())).thenReturn(true); + + String restReturn = resource.userEmailExists(anyString()); + + assertThat(falseResponse.toJson(), equalTo(restReturn)); + } + +} diff --git a/otus-domain-root/pom.xml b/otus-domain-root/pom.xml index 9528854..2776096 100644 --- a/otus-domain-root/pom.xml +++ b/otus-domain-root/pom.xml @@ -1,185 +1,254 @@ - 4.0.0 - org.ccem.domain - otus-domain-root - 1.1 - pom - otus-domain-api - - - ${project.build.directory}/endorsed - UTF-8 - - localhost - 9990 - admin - admin - - 1.0 - 2.0.2 - - - - ../otus-domain-rest - ../otus-domain-business - ../otus-domain-ear - ../otus-domain-persistence - - - - scm:git:git@github.com:ccem-dev/otus-domain.git - scm:git:git@github.com:ccem-dev/otus-domain.git - - - - - releases - http://ccem.ufrgs.br:8081/nexus/content/repositories/releases - - - snapshots - http://ccem.ufrgs.br:8081/nexus/content/repositories/snapshots - - true - - - - - - - releases - http://ccem.ufrgs.br:8081/nexus/content/repositories/releases - - - snapshots - http://ccem.ufrgs.br:8081/nexus/content/repositories/snapshots - - - - - - javax - javaee-web-api - 7.0 - provided - - - javax.mail - javax.mail-api - 1.5.4 - provided - - - junit - junit - 4.11 - test - - - org.mockito - mockito-all - 1.10.19 - test - - - org.powermock - powermock-module-junit4 - 1.6.3 - test - - - org.powermock - powermock-api-mockito - 1.6.3 - test - - - org.hamcrest - hamcrest-all - 1.3 - test - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.19.1 - - ${argLine} - - - - org.jacoco - jacoco-maven-plugin - 0.7.8 - - file - true - - - - jacoco-initialize - - prepare-agent - - - - jacoco-site - verify - - report - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-ejb-plugin - 2.3 - - 3.1 - - - - - external.atlassian.jgitflow - jgitflow-maven-plugin - 1.0-m5.1 - - true - - master - dev - feature- - release- - hotfix- - v - - true - [RELEASE] - - - - - + 4.0.0 + org.ccem.domain + otus-domain-root + 1.2 + pom + otus-domain-api + + + ${project.build.directory}/endorsed + UTF-8 + + localhost + 9990 + admin + admin + + 1.0 + 2.0.2 + 2.4 + 1.0 + 4.18 + 5.2.0.Final + 1.0.0.Final + 5.0.0.Final + 5.0.0.Final + 3.0.13.Final + 3.1.1.Final + 2.3.4 + 3.0.12.Final + 1.0.11 + 2.3.1 + 3.0.13.Final + + + + + ../otus-domain-rest + ../otus-domain-business + ../otus-domain-ear + ../otus-domain-persistence + + + + scm:git:git@github.com:ccem-dev/otus-domain.git + scm:git:git@github.com:ccem-dev/otus-domain.git + + + + + releases + http://nexus.inf.otus-solutions.com.br/repository/maven-releases/ + + + snapshots + http://nexus.inf.otus-solutions.com.br/repository/maven-snapshots/ + + true + + + + maven-restlet + Public online Restlet repository + http://maven.restlet.com + + + + + + releases + http://nexus.inf.otus-solutions.com.br/repository/maven-releases/ + + + snapshots + http://nexus.inf.otus-solutions.com.br/repository/maven-snapshots/ + + + + + + org.wildfly.bom + wildfly + 14.0.1.Final + pom + provided + + + + + commons-io + commons-io + ${commons.io.version} + provided + + + + + javax + javaee-web-api + 8.0 + provided + + + javax.mail + javax.mail-api + 1.5.4 + provided + + + + + + org.jboss.resteasy + resteasy-jaxrs + 4.0.0.Beta5 + provided + + + org.jboss.resteasy + jaxrs-api + 3.0.12.Final + provided + + + + + javax.enterprise + cdi-api + 2.0 + provided + + + + + junit + junit + 4.11 + test + + + org.mockito + mockito-all + 1.10.19 + test + + + org.powermock + powermock-module-junit4 + 1.6.3 + test + + + org.powermock + powermock-api-mockito + 1.6.3 + test + + + org.hamcrest + hamcrest-all + 1.3 + test + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + + ${argLine} + + + + org.jacoco + jacoco-maven-plugin + 0.7.8 + + file + true + + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + verify + + report + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-ejb-plugin + 2.3 + + 3.1 + + + + + external.atlassian.jgitflow + jgitflow-maven-plugin + 1.0-m5.1 + + true + + master + dev + feature- + release- + hotfix- + v + + true + [RELEASE] + + + + org.apache.maven.wagon + wagon-ssh + 2.12 + + + + + +