From f924f8d2559fb4c5b13520126dbb19a7e023d832 Mon Sep 17 00:00:00 2001 From: Issel Parra <14161286+isselparra@users.noreply.github.com> Date: Mon, 7 Oct 2024 20:10:58 +0200 Subject: [PATCH] [backend] fix exercise tests --- .../io/openbas/helper/InjectHelperTest.java | 2 +- .../io/openbas/injects/InjectCrudTest.java | 2 +- .../ExerciseExpectationServiceTest.java | 12 ++++---- .../service/InjectTestStatusServiceTest.java | 2 +- .../openbas/service/VariableServiceTest.java | 28 +++++++++++++------ 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/openbas-api/src/test/java/io/openbas/helper/InjectHelperTest.java b/openbas-api/src/test/java/io/openbas/helper/InjectHelperTest.java index be910f9241..50c6ad45e5 100644 --- a/openbas-api/src/test/java/io/openbas/helper/InjectHelperTest.java +++ b/openbas-api/src/test/java/io/openbas/helper/InjectHelperTest.java @@ -49,7 +49,7 @@ public class InjectHelperTest { void injectsToRunTest() { // -- PREPARE -- Exercise exercise = new Exercise(); - exercise.setName("Exercice name"); + exercise.setName("Exercise name"); exercise.setStart(Instant.now()); exercise.setFrom("test@test.com"); exercise.setReplyTos(List.of("test@test.com")); diff --git a/openbas-api/src/test/java/io/openbas/injects/InjectCrudTest.java b/openbas-api/src/test/java/io/openbas/injects/InjectCrudTest.java index afb8fcad12..b4db64de5a 100644 --- a/openbas-api/src/test/java/io/openbas/injects/InjectCrudTest.java +++ b/openbas-api/src/test/java/io/openbas/injects/InjectCrudTest.java @@ -32,7 +32,7 @@ class InjectCrudTest { void createInjectSuccess() { // -- PREPARE -- Exercise exercise = new Exercise(); - exercise.setName("Exercice name"); + exercise.setName("Exercise name"); exercise.setFrom("test@test.com"); exercise.setReplyTos(List.of("test@test.com")); Exercise exerciseCreated = this.exerciseRepository.save(exercise); diff --git a/openbas-api/src/test/java/io/openbas/service/ExerciseExpectationServiceTest.java b/openbas-api/src/test/java/io/openbas/service/ExerciseExpectationServiceTest.java index 0cbdb257dd..ec83dbfe50 100644 --- a/openbas-api/src/test/java/io/openbas/service/ExerciseExpectationServiceTest.java +++ b/openbas-api/src/test/java/io/openbas/service/ExerciseExpectationServiceTest.java @@ -7,10 +7,7 @@ import io.openbas.database.repository.*; import io.openbas.rest.exercise.form.ExpectationUpdateInput; import io.openbas.utils.fixtures.InjectExpectationFixture; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -57,6 +54,11 @@ void beforeAll() { getInjectExpectation(injectCreated, teamCreated, exerciseCreated); } + @AfterAll + void afterAll() { + this.exerciseRepository.deleteById(EXERCISE_ID); + } + @DisplayName("Retrieve inject expectations") @Test void retrieveInjectExpectations() { @@ -86,7 +88,7 @@ void updateInjectExpectation() { protected Exercise getExercise() { Exercise exercise = new Exercise(); - exercise.setName("Exercice name"); + exercise.setName("Exercise name"); exercise.setStatus(SCHEDULED); exercise.setFrom("test@test.com"); exercise.setReplyTos(List.of("test@test.com")); diff --git a/openbas-api/src/test/java/io/openbas/service/InjectTestStatusServiceTest.java b/openbas-api/src/test/java/io/openbas/service/InjectTestStatusServiceTest.java index b43e71b564..06e15c0a69 100644 --- a/openbas-api/src/test/java/io/openbas/service/InjectTestStatusServiceTest.java +++ b/openbas-api/src/test/java/io/openbas/service/InjectTestStatusServiceTest.java @@ -59,7 +59,7 @@ public class InjectTestStatusServiceTest { @BeforeAll void beforeAll() { Exercise exercise = new Exercise(); - exercise.setName("Exercice name"); + exercise.setName("Exercise name"); exercise.setFrom("test@test.com"); exercise.setReplyTos(List.of("test@test.com")); EXERCISE = this.exerciseRepository.save(exercise); diff --git a/openbas-api/src/test/java/io/openbas/service/VariableServiceTest.java b/openbas-api/src/test/java/io/openbas/service/VariableServiceTest.java index 9056dab713..0092a89d00 100644 --- a/openbas-api/src/test/java/io/openbas/service/VariableServiceTest.java +++ b/openbas-api/src/test/java/io/openbas/service/VariableServiceTest.java @@ -12,8 +12,10 @@ import java.util.NoSuchElementException; import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; @SpringBootTest +@TestInstance(PER_CLASS) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class VariableServiceTest { @@ -23,24 +25,32 @@ public class VariableServiceTest { @Autowired private ExerciseRepository exerciseRepository; - static String EXERCISE_ID; + static Exercise EXERCISE; static String VARIABLE_ID; + @BeforeAll + void beforeAll() { + Exercise exercise = new Exercise(); + exercise.setName("Exercise name"); + exercise.setFrom("test@test.com"); + exercise.setReplyTos(List.of("test@test.com")); + EXERCISE = this.exerciseRepository.save(exercise); + } + + @AfterAll + void afterAll() { + this.exerciseRepository.deleteById(EXERCISE.getId()); + } + @DisplayName("Create variable") @Test @Order(1) void createVariableTest() { // -- PREPARE -- - Exercise exercise = new Exercise(); - exercise.setName("Exercice name"); - exercise.setFrom("test@test.com"); - exercise.setReplyTos(List.of("test@test.com")); - Exercise exerciseCreated = this.exerciseRepository.save(exercise); - EXERCISE_ID = exerciseCreated.getId(); Variable variable = new Variable(); String variableKey = "key"; variable.setKey(variableKey); - variable.setExercise(exerciseCreated); + variable.setExercise(EXERCISE); // -- EXECUTE -- Variable variableCreated = this.variableService.createVariable(variable); @@ -60,7 +70,7 @@ void retrieveVariableTest() { Variable variable = this.variableService.variable(VARIABLE_ID); assertNotNull(variable); - List variables = this.variableService.variablesFromExercise(EXERCISE_ID); + List variables = this.variableService.variablesFromExercise(EXERCISE.getId()); assertNotNull(variable); assertEquals(VARIABLE_ID, variables.get(0).getId()); }