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
18 changes: 18 additions & 0 deletions .m2/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<settings>
<pluginGroups>
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>
http://localhost:9000
</sonar.host.url>
</properties>
</profile>
</profiles>
</settings>
71 changes: 70 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,72 @@
# Dépôt des sources JAVA pour cours CICD

Sources accompagnant le cours "Continuous Integration, Continuous Delivery"
1/ Création des configurations par profil

Port:

DEV: 8090 (par défaut)
UAT : 8091
PROD : 8092

Avec Spring-boot, les propriétés propres au profil se définissent dans des fichiers: application-<profile name>.yml

application-uat.yml
application-prod.yml


Démarrer l'application en CMD et démontrer qu'en fonction de l'environnement défini, on démarre sur un port différent:

mvn clean package -DskipTests

java -jar -Dspring.profiles.active=dev|uat|prod target\calculator.jar


2/ Déploiement manuel pour chaque environnement


a/ Configuration de Docker

Pas de serveurs donc nous allons utiliser des containers (Pas des machines virtuelles)

Overview Dockerfile

Configuration de l'image Docker via le Dockerfile


Externaliser entrypoint.sh afin d'avoir plus de maléabilité


Lancer l'application pour chaque environnement



Sur la branche actuelle: m1ch3

mvn sonar:sonar -s .m2/settings.xml -Dsonar.login=<token> ==> est ce OK ?

Empaquetter l'application a containeuriser

docker build -t calculator-demo:1.0.0 .

docker run --name calculator-demo --env SPRING_ACTIVE_PROFILES=dev calculator-demo:dev



Si tout est OK, on fait une fusion avec la branche ready et l'on contruit/exécute l'image pour l'uat

mvn sonar:sonar -s .m2/settings.xml -Dsonar.login=<token> ==> est ce OK ?

docker build -t calculator-demo:uat

docker run --name calculator-demo --env SPRING_ACTIVE_PROFILES=uat calculator-demo:uat




si tout est OK, on fait une fusion avec main et l'on construit exécute l'image pour la PROD

mvn sonar:sonar -s .m2/settings.xml -Dsonar.login=<toke> ==> est ce OK ?

docker build -t calculator-demo:prod

docker run --name calculator-prod --env SPRING_ACTIVE_PROFILES=prod calculator-demo:prod
30 changes: 30 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.7.1</version>
</dependency>
</dependencies>
<build>
<finalName>calculator</finalName>
Expand All @@ -92,6 +102,26 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import java.util.Set;

import javax.inject.Named;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Named
public class Calculator {

Logger logger = LoggerFactory.getLogger(Calculator.class);

public int add(int a, int b) {
return a + b;
}
Expand Down Expand Up @@ -54,12 +58,12 @@ public void longCalculation() {
try {
Thread.sleep(500);
} catch (final InterruptedException e) {
e.printStackTrace();
logger.debug("Thread has been interrupted", e);
}
}

public Set<Integer> digitsSet(int number) {
final Set<Integer> integers = new HashSet<Integer>();
final Set<Integer> integers = new HashSet<>();
final String numberString = String.valueOf(number);

for (int i = 0; i < numberString.length(); i++) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/templates/calculator.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ <h2>
</div>
<div class="row">
<div class="col">
<input type="text" th:field="*{leftArgument}" class="form-control" placeholder="First Value">
<input id="left" type="text" th:field="*{leftArgument}" class="form-control" placeholder="First Value">
</div>
<div class="col">
<select th:field="*{calculationType}" class="form-control form-control-lg">
<select id="type" th:field="*{calculationType}" class="form-control form-control-lg">
<option value="ADDITION" selected="true"> + </option>
<option value="SUBTRACTION" selected="true"> - </option>
<option value="MULTIPLICATION"> x </option>
<option value="DIVISION"> / </option>
</select>
</div>
<div class="col">
<input type="text" th:field="*{rightArgument}" class="form-control" placeholder="Second Value">
<input id="right" type="text" th:field="*{rightArgument}" class="form-control" placeholder="Second Value">
</div>
</div>
<div class="row">
<div class="col">
<button type="submit" class="btn btn-primary">=</button>
<button id="submit" type="submit" class="btn btn-primary">=</button>

</div>
<div class="text-danger validation-summary-valid" data-valmsg-summary="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@WebMvcTest(controllers = { CalculatorController.class, CalculatorService.class })
@ExtendWith(SpringExtension.class)
public class CalculatorControllerSIT {
class CalculatorControllerSIT {

@Inject
private MockMvc mockMvc;
Expand All @@ -34,7 +34,7 @@ public class CalculatorControllerSIT {
private Calculator calculator;

@Test
public void givenACalculatorApp_whenRequestToAdd_thenSolutionIsShown() throws Exception {
void givenACalculatorApp_whenRequestToAdd_thenSolutionIsShown() throws Exception {
// GIVEN
when(calculator.add(2, 3)).thenReturn(5);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.junit.jupiter.params.provider.ValueSource;

@ExtendWith(LoggingExtension.class)
public class CalculatorTest {
class CalculatorTest {

private static Instant startedAt;

Expand All @@ -40,33 +40,33 @@ public void setLogger(Logger logger) {
}

@BeforeEach
public void initCalculator() {
void initCalculator() {
logger.info("Appel avant chaque test");
calculatorUnderTest = new Calculator();
}

@AfterEach
public void undefCalculator() {
void undefCalculator() {
logger.info("Appel après chaque test");
calculatorUnderTest = null;
}

@BeforeAll
public static void initStartingTime() {
static void initStartingTime() {
System.out.println("Appel avant tous les tests");
startedAt = Instant.now();
}

@AfterAll
public static void showTestDuration() {
static void showTestDuration() {
System.out.println("Appel après tous les tests");
final Instant endedAt = Instant.now();
final long duration = Duration.between(startedAt, endedAt).toMillis();
System.out.println(MessageFormat.format("Durée des tests : {0} ms", duration));
}

@Test
public void testAddTwoPositiveNumbers() {
void testAddTwoPositiveNumbers() {
// Arrange
final int a = 2;
final int b = 3;
Expand All @@ -80,7 +80,7 @@ public void testAddTwoPositiveNumbers() {
}

@Test
public void multiply_shouldReturnTheProduct_ofTwoIntegers() {
void multiply_shouldReturnTheProduct_ofTwoIntegers() {
// Arrange
final int a = 42;
final int b = 11;
Expand All @@ -94,7 +94,7 @@ public void multiply_shouldReturnTheProduct_ofTwoIntegers() {

@ParameterizedTest(name = "{0} x 0 doit être égal à 0")
@ValueSource(ints = { 1, 2, 42, 1011, 5089 })
public void multiply_shouldReturnZero_ofZeroWithMultipleIntegers(int arg) {
void multiply_shouldReturnZero_ofZeroWithMultipleIntegers(int arg) {
// Arrange -- Tout est prêt !

// Act -- Multiplier par zéro
Expand All @@ -106,7 +106,7 @@ public void multiply_shouldReturnZero_ofZeroWithMultipleIntegers(int arg) {

@ParameterizedTest(name = "{0} + {1} doit être égal à {2}")
@CsvSource({ "1,1,2", "2,3,5", "42,57,99" })
public void add_shouldReturnTheSum_ofMultipleIntegers(int arg1, int arg2, int expectResult) {
void add_shouldReturnTheSum_ofMultipleIntegers(int arg1, int arg2, int expectResult) {
// Arrange -- Tout est prêt !

// Act
Expand All @@ -118,7 +118,7 @@ public void add_shouldReturnTheSum_ofMultipleIntegers(int arg1, int arg2, int ex

@Timeout(1)
@Test
public void longCalcul_shouldComputeInLessThan1Second() {
void longCalcul_shouldComputeInLessThan1Second() {
// Arrange

// Act
Expand All @@ -129,7 +129,7 @@ public void longCalcul_shouldComputeInLessThan1Second() {
}

@Test
public void listDigits_shouldReturnsTheListOfDigits_ofPositiveInteger() {
void listDigits_shouldReturnsTheListOfDigits_ofPositiveInteger() {
// GIVEN
final int number = 95897;

Expand All @@ -143,22 +143,22 @@ public void listDigits_shouldReturnsTheListOfDigits_ofPositiveInteger() {
}

@Test
public void listDigits_shouldReturnsTheListOfDigits_ofNegativeInteger() {
void listDigits_shouldReturnsTheListOfDigits_ofNegativeInteger() {
final int number = -124432;
final Set<Integer> actualDigits = calculatorUnderTest.digitsSet(number);
assertThat(actualDigits).containsExactlyInAnyOrder(1, 2, 3, 4);
}

@Test
public void listDigits_shouldReturnsTheListOfZero_ofZero() {
void listDigits_shouldReturnsTheListOfZero_ofZero() {
final int number = 0;
final Set<Integer> actualDigits = calculatorUnderTest.digitsSet(number);
assertThat(actualDigits).containsExactly(0);
}

@Disabled("Stoppé car cela échoue tous les mardis")
@Test
public void testDate() {
void testDate() {
// GIVEN
final LocalDateTime dateTime = LocalDateTime.now();

Expand All @@ -169,7 +169,7 @@ public void testDate() {
}

@Test
public void fact12_shouldReturnsTheCorrectAnswer() {
void fact12_shouldReturnsTheCorrectAnswer() {
// GIVEN
final int number = 12;

Expand All @@ -182,7 +182,7 @@ public void fact12_shouldReturnsTheCorrectAnswer() {
}

@Test
public void digitsSetOfFact12_shouldReturnsTheCorrectAnswser() {
void digitsSetOfFact12_shouldReturnsTheCorrectAnswser() {
// GIVEN
final int cacheFactorial = 479001600;

Expand All @@ -194,7 +194,7 @@ public void digitsSetOfFact12_shouldReturnsTheCorrectAnswser() {
}

@Test
public void multiplyAndDivide_shouldBeIdentity() {
void multiplyAndDivide_shouldBeIdentity() {
// GIVEN
final Random r = new Random();
final int a = 1 + r.nextInt(100);
Expand Down
Loading