diff --git a/Jenkinsfile b/Jenkinsfile index 57d3199..13136a7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,15 +1,15 @@ -def CONTAINER_NAME = "calculator" def ENV_NAME = getEnvName(env.BRANCH_NAME) +def CONTAINER_NAME = "calculator-" +ENV_NAME def CONTAINER_TAG = getTag(env.BUILD_NUMBER, env.BRANCH_NAME) def HTTP_PORT = getHTTPPort(env.BRANCH_NAME) -def EMAIL_RECIPIENTS = "philippe.guemkamsimo@gmail.com" +def EMAIL_RECIPIENTS = "nesrine.dridi@esprit.tn" node { try { stage('Initialize') { - def dockerHome = tool 'DockerLatest' - def mavenHome = tool 'MavenLatest' + def dockerHome = tool 'dockerlatest' + def mavenHome = tool 'mavenlatest' env.PATH = "${dockerHome}/bin:${mavenHome}/bin:${env.PATH}" } @@ -21,9 +21,10 @@ node { sh "mvn clean install" } + stage('Sonarqube Analysis') { - withSonarQubeEnv('SonarQubeLocalServer') { + withSonarQubeEnv('localhost_sonarqube') { sh " mvn sonar:sonar -Dintegration-tests.skip=true -Dmaven.test.failure.ignore=true" } timeout(time: 1, unit: 'MINUTES') { @@ -43,13 +44,13 @@ node { } stage('Push to Docker Registry') { - withCredentials([usernamePassword(credentialsId: 'DockerhubCredentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { + withCredentials([usernamePassword(credentialsId: 'dockerhubcredentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { pushToImage(CONTAINER_NAME, CONTAINER_TAG, USERNAME, PASSWORD) } } stage('Run App') { - withCredentials([usernamePassword(credentialsId: 'DockerhubCredentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { + withCredentials([usernamePassword(credentialsId: 'dockerhubcredentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { runApp(CONTAINER_NAME, CONTAINER_TAG, USERNAME, HTTP_PORT, ENV_NAME) } @@ -96,22 +97,22 @@ def sendEmail(recipients) { } String getEnvName(String branchName) { - if (branchName == 'main') { + if (branchName == 'master') { return 'prod' } return (branchName == 'develop') ? 'uat' : 'dev' } String getHTTPPort(String branchName) { - if (branchName == 'main') { + if (branchName == 'master') { return '9003' } return (branchName == 'develop') ? '9002' : '9001' } String getTag(String buildNumber, String branchName) { - if (branchName == 'main') { - return buildNumber + '-unstable' + if (branchName == 'master') { + return buildNumber + '-stable' } - return buildNumber + '-stable' + return buildNumber + '-unstable' } diff --git a/pom.xml b/pom.xml index 1b16bd0..cc8ec87 100644 --- a/pom.xml +++ b/pom.xml @@ -1,128 +1,127 @@ - 4.0.0 - tech.zerofiltre.testing - calculator - 0.0.1-SNAPSHOT - - 5.5.2 - UTF-8 - 11 - ${maven.compiler.source} - 4.3.1 - 2.2.0.RELEASE - tech.zerofiltre.testing:calculator - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + com.openclassrooms.testing + calculator + 0.0.1-SNAPSHOT + + 5.5.2 + UTF-8 + 11 + ${maven.compiler.source} + 4.3.1 + 2.2.0.RELEASE + - - org.springframework.boot - spring-boot-starter-parent - 2.2.0.RELEASE - + + org.springframework.boot + spring-boot-starter-parent + 2.2.0.RELEASE + - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-test - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - org.springframework.boot - spring-boot-devtools - runtime - - - org.webjars - bootstrap - ${bootstrap.version} - - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter - test - - - org.mockito - mockito-junit-jupiter - test - - - org.assertj - assertj-core - test - - - org.apache.logging.log4j - log4j-core - - - javax.inject - javax.inject - 1 - - - org.seleniumhq.selenium - selenium-java - test - - - io.github.bonigarcia - webdrivermanager - 3.7.1 - - - - calculator - - - org.springframework.boot - spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - integration-test - verify - - - - - - org.jacoco - jacoco-maven-plugin - 0.8.2 - - - - prepare-agent - - - - - report - test - - report - - - - - - + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-devtools + runtime + + + org.webjars + bootstrap + ${bootstrap.version} + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter + test + + + org.mockito + mockito-junit-jupiter + test + + + org.assertj + assertj-core + test + + + org.apache.logging.log4j + log4j-core + + + javax.inject + javax.inject + 1 + + + org.seleniumhq.selenium + selenium-java + test + + + io.github.bonigarcia + webdrivermanager + 3.7.1 + + + + calculator + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + org.jacoco + jacoco-maven-plugin + 0.8.2 + + + + prepare-agent + + + + + report + test + + report + + + + + + \ No newline at end of file diff --git a/src/main/java/tech/zerofiltre/testing/calcul/domain/Calculator.java b/src/main/java/tech/zerofiltre/testing/calcul/domain/Calculator.java index afe011e..9716920 100644 --- a/src/main/java/tech/zerofiltre/testing/calcul/domain/Calculator.java +++ b/src/main/java/tech/zerofiltre/testing/calcul/domain/Calculator.java @@ -54,14 +54,16 @@ public int fact(int a) { return a * fact(a - 1); } - public void longCalculation() { + public void longCalculation() { try { Thread.sleep(500); - } catch (final InterruptedException e) { + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); // Réinterruption logger.debug("Thread has been interrupted", e); } } + public Set digitsSet(int number) { final Set integers = new HashSet<>(); final String numberString = String.valueOf(number);