Compare commits
8 Commits
8bf1594329
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 72c34f9b33 | |||
|
|
38a31b3e2b | ||
| 9b1af5029f | |||
|
|
9865e9dcc2 | ||
|
|
ca34df2af9 | ||
| b451ad2233 | |||
|
|
8a341c51ee | ||
|
|
b4555aa73f |
37
Jenkinsfile
vendored
37
Jenkinsfile
vendored
@@ -1,5 +1,8 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
tools {
|
||||||
|
maven 'maven-3.9'
|
||||||
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('Compilation') {
|
stage('Compilation') {
|
||||||
steps {
|
steps {
|
||||||
@@ -27,11 +30,35 @@ pipeline {
|
|||||||
}
|
}
|
||||||
stage('Déploiement') {
|
stage('Déploiement') {
|
||||||
steps {
|
steps {
|
||||||
echo "Démarrage de l'application Spring Boot..."
|
sh '''
|
||||||
// Arr\u00eater l'application si elle tourne d\u00e9j\u00e0 (pour ne pas dupliquer les instances)
|
echo "=== Déploiement simple sur le port 8081 ==="
|
||||||
sh 'pkill -f "java -jar" || echo "Aucune ancienne instance \u00e0 arr\u00eater"'
|
|
||||||
// D\u00e9marrer la nouvelle version en arri\u00e8re-plan
|
cd "$WORKSPACE"
|
||||||
sh 'nohup java -jar target/*.jar --server.port=8081 &'
|
|
||||||
|
# 1) Arrêter l'ancienne instance de CE jar (et pas tout java)
|
||||||
|
OLD_PIDS=$(pgrep -f "rock-paper-scissors-0.0.1-SNAPSHOT.jar" || true)
|
||||||
|
if [ -n "$OLD_PIDS" ]; then
|
||||||
|
echo "Arrêt des anciennes instances: $OLD_PIDS"
|
||||||
|
kill $OLD_PIDS || true
|
||||||
|
sleep 5
|
||||||
|
else
|
||||||
|
echo "Aucune ancienne instance à arrêter."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 2) Vérifier que le jar existe
|
||||||
|
JAR_FILE=target/rock-paper-scissors-0.0.1-SNAPSHOT.jar
|
||||||
|
if [ ! -f "$JAR_FILE" ]; then
|
||||||
|
echo "ERREUR : $JAR_FILE introuvable"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Jar sélectionné : $JAR_FILE"
|
||||||
|
|
||||||
|
# 3) Démarrer en arrière-plan, en évitant que Jenkins tue le process
|
||||||
|
echo "Démarrage de l'application..."
|
||||||
|
JENKINS_NODE_COOKIE=dontKillMe nohup java -jar "$JAR_FILE" --server.port=8081 > app.log 2>&1 &
|
||||||
|
|
||||||
|
echo "Déploiement terminé (process lancé en arrière-plan)."
|
||||||
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
177
README.md
Normal file
177
README.md
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
# Travaux Pratiques CI/CD
|
||||||
|
|
||||||
|
Le but de ce TP est d’utiliser un git déjà existant et d’y installer une multibranche pipeline Jenkins.
|
||||||
|
|
||||||
|
## Copier le git du TP sur son profil
|
||||||
|
Se rendre sur : https://grond.iut-fbleau.fr/pierront/rock-paper-scissors
|
||||||
|
|
||||||
|
Faire un fork
|
||||||
|
|
||||||
|
`/!\ ATTENTION NE PRENDRE QUE LA BRANCHE MAIN /!\`
|
||||||
|
|
||||||
|
## Créer la VM pour jenkins
|
||||||
|
### Créer la règle pare-feu pour accéder aux ports 8080 et 8081
|
||||||
|
Aller dans la section Pare-Feu
|
||||||
|
|
||||||
|
* Cliquer -> Créer une règle de pare-feu
|
||||||
|
* Nom : jenkins-rule
|
||||||
|
* Sens du trafic : Entrée
|
||||||
|
* Tag cibles : jenkins
|
||||||
|
* Plages IPv4 source : 0.0.0.0/0
|
||||||
|
* Cocher TCP
|
||||||
|
* Ports : 8080, 8081
|
||||||
|
* Puis créer
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
* Créer la VM
|
||||||
|
* Configuration de la machine
|
||||||
|
* Nom : jenkins
|
||||||
|
* Région : la plus proche
|
||||||
|
* Série : E2 / e2-medium
|
||||||
|
* Mise en réseau
|
||||||
|
* Cocher Autoriser le trafic HTTP
|
||||||
|
* Cocher Autoriser le trafic HTTPS
|
||||||
|
* Tags réseau : ajouter jenkins
|
||||||
|
* Créer la VM
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Installation de Jenkins sur la VM
|
||||||
|
|
||||||
|
Installer git
|
||||||
|
```bash
|
||||||
|
sudo apt install -y git
|
||||||
|
```
|
||||||
|
|
||||||
|
Installer Java
|
||||||
|
```bash
|
||||||
|
sudo apt install -y wget apt-transport-https gpg
|
||||||
|
wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/adoptium.gpg > /dev/null
|
||||||
|
echo "deb https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | sudo tee /etc/apt/sources.list.d/adoptium.list
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install temurin-21-jdk
|
||||||
|
```
|
||||||
|
|
||||||
|
Installer Jenkins
|
||||||
|
```bash
|
||||||
|
sudo wget -O /etc/apt/keyrings/jenkins-keyring.asc \
|
||||||
|
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
|
||||||
|
echo "deb [signed-by=/etc/apt/keyrings/jenkins-keyring.asc]" \
|
||||||
|
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
|
||||||
|
/etc/apt/sources.list.d/jenkins.list > /dev/null
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install jenkins
|
||||||
|
```
|
||||||
|
|
||||||
|
Verifier s'il a bien démarrer :
|
||||||
|
`systemctl status jenkins`
|
||||||
|
|
||||||
|
Se rendre sur l'adresse IP de la VM : http://<IP_EXTERNE_VM>:8080
|
||||||
|
|
||||||
|
Vous devriez voir la page d'accueil de Jenkins
|
||||||
|

|
||||||
|
|
||||||
|
* Suivre les instructions pour la creation de compte admin
|
||||||
|
* Selectionner : Install suggested plugins
|
||||||
|
* Créer un nouveau compte admin
|
||||||
|
* Voir cette page
|
||||||
|

|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Configuration de Jenkins avec Gitea
|
||||||
|
|
||||||
|
### Installer le plugin Gitea
|
||||||
|
* Aller dans la section Manage Jenkins **(roue crantée)** -> Plugins
|
||||||
|
* Rechercher Gitea
|
||||||
|
* Installer le plugin
|
||||||
|
|
||||||
|
### Configurer Maven
|
||||||
|
* Aller dans la section Manage Jenkins **(roue crantée)** -> Tools
|
||||||
|
* Add Maven
|
||||||
|
* Nom : maven-3.9
|
||||||
|
* Cocher Install automatically
|
||||||
|
* Version : 3.9.11
|
||||||
|
* Cliquer sur Save
|
||||||
|
|
||||||
|
### Récupérer un token Gitea
|
||||||
|
* Se rendre sur Gitea
|
||||||
|
* Cliquer sur profil -> Settings -> Applications -> Generate new token
|
||||||
|
* Nom du jeton : jenkins-token
|
||||||
|
* Avec ces options :
|
||||||
|

|
||||||
|
* Cliquer sur Generate token
|
||||||
|
* **Copier le token pour ne pas le perdre**
|
||||||
|
### Configurer Jenkins pour utiliser Gitea
|
||||||
|
* Aller dans la section Manage Jenkins -> System
|
||||||
|
* Add Gitea Server
|
||||||
|
* Choisir le nom du serveur (grond)
|
||||||
|
* Metter l'url du serveur : https://grond.iut-fbleau.fr
|
||||||
|
* Cocher Manage hooks
|
||||||
|
* Cliquer sur _Add +_
|
||||||
|
* Kind : Gitea Personal Access Token
|
||||||
|
* Token : celui copié dans la section précédente
|
||||||
|
* ID : gitea-token
|
||||||
|
* Cliquer sur Add
|
||||||
|
* Puis save
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Création d'un pipeline
|
||||||
|
* Aller sur l'accueil Jenkins -> New Item
|
||||||
|
* Nommer le projet : rock-paper-scissors
|
||||||
|
* Choisir le type de projet : Multibranch Pipeline
|
||||||
|
* Cliquer sur OK
|
||||||
|
* Add a source
|
||||||
|
* Gitea
|
||||||
|
* utiliser le jeton gitea-token
|
||||||
|
* owner : _<votre nom d'utilisateur gitea>_
|
||||||
|
* Choisir le projet : rock-paper-scissors
|
||||||
|
* Choisir le repository : https://grond.iut-fbleau.fr/pierront/rock-paper-scissors.git
|
||||||
|
* Cliquer sur Save
|
||||||
|
|
||||||
|
Voir que le scan se passe bien.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Tester le pipeline
|
||||||
|
* Aller dans la section Build History -> Build Now
|
||||||
|
* Voir que le pipeline se passe bien
|
||||||
|
|
||||||
|
|
||||||
|
Tester l'application via cette url : http://<IP_EXTERNE_VM>:8081/swagger-ui/index.html
|
||||||
|
---
|
||||||
|
|
||||||
|
## Gestion du Jenkinsfile
|
||||||
|
|
||||||
|
* Regarder les étapes pour comprendre ce que fait le Jenkinsfile
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Ajouter le puits dans le code java
|
||||||
|
|
||||||
|
Le puits bat la pierre et les ciseaux.
|
||||||
|
Le puits est battu par la feuille.
|
||||||
|
|
||||||
|
Grace à notre pipeline on peut voir le si le code fonctionne bien via les tests unitaires.
|
||||||
|
Puis on peut tester réelement grace au deploiement sur la VM de l'application java.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Sources :
|
||||||
|
* https://adoptium.net/installation/linux/#deb-installation-on-debian-or-ubuntu
|
||||||
|
* https://www.jenkins.io/doc/book/installing/linux/#debianubuntu
|
||||||
|
* https://plugins.jenkins.io/gitea/
|
||||||
|
* https://www.jenkins.io/doc/book/pipeline/jenkinsfile/
|
||||||
BIN
assets/gitea_token.png
Normal file
BIN
assets/gitea_token.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
BIN
assets/jenkins_home.png
Normal file
BIN
assets/jenkins_home.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
BIN
assets/jenkins_start.png
Normal file
BIN
assets/jenkins_start.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 78 KiB |
@@ -5,13 +5,14 @@ import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatBo
|
|||||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.spi.StatRepository;
|
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.spi.StatRepository;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Stub
|
@Stub
|
||||||
public record InMemoryStatRepository(Map<String, Integer> stats) implements StatRepository {
|
public record InMemoryStatRepository(Map<String, Integer> stats) implements StatRepository {
|
||||||
|
|
||||||
|
|
||||||
private final static HashMap<String, Integer> DEFAULT_STATS = new HashMap<>(Map.of("joe", 1,"eoj", 3));
|
private final static HashMap<String, Integer> DEFAULT_STATS = new LinkedHashMap<>(Map.of("joe", 1,"eoj", 3));
|
||||||
|
|
||||||
public InMemoryStatRepository() {
|
public InMemoryStatRepository() {
|
||||||
this(DEFAULT_STATS);
|
this(DEFAULT_STATS);
|
||||||
|
|||||||
@@ -2,13 +2,16 @@ package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.web;
|
|||||||
|
|
||||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatBoard;
|
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatBoard;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record StatBoardReponse(List<Stat> stats) {
|
public record StatBoardReponse(List<Stat> stats) {
|
||||||
|
|
||||||
public StatBoardReponse(StatBoard statBoard) {
|
public StatBoardReponse(StatBoard statBoard) {
|
||||||
this(statBoard.stats().entrySet().stream()
|
this(statBoard.stats().entrySet().stream()
|
||||||
.map(Stat::fromMap)
|
.map(Stat::fromMap)
|
||||||
.toList());
|
.sorted(Comparator.comparingInt(
|
||||||
}
|
stat -> -stat.wins()))
|
||||||
|
.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package fr.iut_fbleau.info.but3.automation.rock_paper_scissors;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.modulith.core.ApplicationModules;
|
import org.springframework.modulith.core.ApplicationModules;
|
||||||
|
|
||||||
public class ModulithStructureTests {
|
class ModulithStructureTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void verifyModularStructure() {
|
void verifyModularStructure() {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
webEnvironment = RANDOM_PORT
|
webEnvironment = RANDOM_PORT
|
||||||
)
|
)
|
||||||
@Import(FakeCpuConfiguration.class)
|
@Import(FakeCpuConfiguration.class)
|
||||||
public class RockPaperScissorsPlayApplicationTest {
|
class RockPaperScissorsPlayApplicationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TestRestTemplate restTemplate;
|
private TestRestTemplate restTemplate;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class MoveTest {
|
class MoveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void should_check_move_size(){
|
void should_check_move_size(){
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain;
|
package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.RockPaperScissorsPlay;
|
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.RockPaperScissorsPlay;
|
||||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.spi.FakeCpuPicker;
|
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.spi.FakeCpuPicker;
|
||||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatSaver;
|
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatSaver;
|
||||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.spi.stub.InMemoryStatRepository;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.mockito.Mockito.*;
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class RockPaperScissorsPlayTest {
|
public class RockPaperScissorsPlayTest {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
@ApplicationModuleTest(
|
@ApplicationModuleTest(
|
||||||
webEnvironment = RANDOM_PORT
|
webEnvironment = RANDOM_PORT
|
||||||
)
|
)
|
||||||
public class StatApplicationTest {
|
class StatApplicationTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
private TestRestTemplate restTemplate;
|
private TestRestTemplate restTemplate;
|
||||||
|
|
||||||
@@ -27,9 +27,9 @@ public class StatApplicationTest {
|
|||||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
|
||||||
assertThat(json.from(response.getBody())).extractingJsonPathArrayValue("@.stats").hasSize(2);
|
assertThat(json.from(response.getBody())).extractingJsonPathArrayValue("@.stats").hasSize(2);
|
||||||
assertThat(json.from(response.getBody())).extractingJsonPathStringValue("@.stats[0].name").isEqualTo("joe");
|
assertThat(json.from(response.getBody())).extractingJsonPathStringValue("@.stats[0].name").isEqualTo("eoj");
|
||||||
assertThat(json.from(response.getBody())).extractingJsonPathNumberValue("@.stats[0].wins").isEqualTo(1);
|
assertThat(json.from(response.getBody())).extractingJsonPathNumberValue("@.stats[0].wins").isEqualTo(3);
|
||||||
assertThat(json.from(response.getBody())).extractingJsonPathStringValue("@.stats[1].name").isEqualTo("eoj");
|
assertThat(json.from(response.getBody())).extractingJsonPathStringValue("@.stats[1].name").isEqualTo("joe");
|
||||||
assertThat(json.from(response.getBody())).extractingJsonPathNumberValue("@.stats[1].wins").isEqualTo(3);
|
assertThat(json.from(response.getBody())).extractingJsonPathNumberValue("@.stats[1].wins").isEqualTo(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat;
|
|||||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatBoard;
|
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatBoard;
|
||||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatBoardGetter;
|
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatBoardGetter;
|
||||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.spi.stub.InMemoryStatRepository;
|
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.spi.stub.InMemoryStatRepository;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -10,19 +11,20 @@ import java.util.HashMap;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
public class StatBoardGetterTest {
|
class StatBoardGetterTest {
|
||||||
@Test
|
|
||||||
public void should_get_stat_board() {
|
|
||||||
HashMap<String, Integer> stats = new HashMap<>();
|
|
||||||
stats.put("joe", 1);
|
|
||||||
stats.put("eoj", 5);
|
|
||||||
InMemoryStatRepository statRepository = new InMemoryStatRepository(stats);
|
|
||||||
|
|
||||||
StatBoardGet statBoardGet = new StatBoardGetter(statRepository);
|
@Test
|
||||||
|
void should_get_stat_board() {
|
||||||
|
HashMap<String, Integer> stats = new LinkedHashMap<>();
|
||||||
|
stats.put("eoj", 5);
|
||||||
|
stats.put("joe", 1);
|
||||||
|
InMemoryStatRepository statRepository = new InMemoryStatRepository(stats);
|
||||||
|
|
||||||
StatBoard statBoard = statBoardGet.board();
|
StatBoardGet statBoardGet = new StatBoardGetter(statRepository);
|
||||||
|
|
||||||
assertNotNull(statBoard);
|
StatBoard statBoard = statBoardGet.board();
|
||||||
assertEquals(stats, statBoard.stats());
|
|
||||||
}
|
assertNotNull(statBoard);
|
||||||
|
assertEquals(stats, statBoard.stats());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
|
|
||||||
@WebMvcTest(StatController.class)
|
@WebMvcTest(StatController.class)
|
||||||
@Import(StatConfiguration.class)
|
@Import(StatConfiguration.class)
|
||||||
public class StatControllerTest {
|
class StatControllerTest {
|
||||||
|
|
||||||
private static final String STAT_ENDPOINT = "/stat";
|
private static final String STAT_ENDPOINT = "/stat";
|
||||||
|
|
||||||
@@ -36,8 +36,8 @@ public class StatControllerTest {
|
|||||||
mockMvc.perform(get(STAT_ENDPOINT))
|
mockMvc.perform(get(STAT_ENDPOINT))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.stats").isArray())
|
.andExpect(jsonPath("$.stats").isArray())
|
||||||
.andExpect(jsonPath("$.stats[0].name").value("joe"))
|
.andExpect(jsonPath("$.stats[0].name").value("eoj"))
|
||||||
.andExpect(jsonPath("$.stats[0].wins").value(1));
|
.andExpect(jsonPath("$.stats[0].wins").value(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestConfiguration
|
@TestConfiguration
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class StatSaverTest {
|
class StatSaverTest {
|
||||||
@ParameterizedTest(name = "name = {0}, initial = {1}, expected = {2}")
|
@ParameterizedTest(name = "name = {0}, initial = {1}, expected = {2}")
|
||||||
@CsvSource({"joe,0,1", "eoj,2,3"})
|
@CsvSource({"joe,0,1", "eoj,2,3"})
|
||||||
void should_save(String name, int initial, int expected) {
|
void should_save(String name, int initial, int expected) {
|
||||||
|
|||||||
Reference in New Issue
Block a user