Skip to content

Commit

Permalink
[backend] fix exercise tests
Browse files Browse the repository at this point in the history
  • Loading branch information
isselparra committed Oct 7, 2024
1 parent 00ed6d3 commit f924f8d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]");
exercise.setReplyTos(List.of("[email protected]"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class InjectCrudTest {
void createInjectSuccess() {
// -- PREPARE --
Exercise exercise = new Exercise();
exercise.setName("Exercice name");
exercise.setName("Exercise name");
exercise.setFrom("[email protected]");
exercise.setReplyTos(List.of("[email protected]"));
Exercise exerciseCreated = this.exerciseRepository.save(exercise);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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("[email protected]");
exercise.setReplyTos(List.of("[email protected]"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class InjectTestStatusServiceTest {
@BeforeAll
void beforeAll() {
Exercise exercise = new Exercise();
exercise.setName("Exercice name");
exercise.setName("Exercise name");
exercise.setFrom("[email protected]");
exercise.setReplyTos(List.of("[email protected]"));
EXERCISE = this.exerciseRepository.save(exercise);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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("[email protected]");
exercise.setReplyTos(List.of("[email protected]"));
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("[email protected]");
exercise.setReplyTos(List.of("[email protected]"));
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);
Expand All @@ -60,7 +70,7 @@ void retrieveVariableTest() {
Variable variable = this.variableService.variable(VARIABLE_ID);
assertNotNull(variable);

List<Variable> variables = this.variableService.variablesFromExercise(EXERCISE_ID);
List<Variable> variables = this.variableService.variablesFromExercise(EXERCISE.getId());
assertNotNull(variable);
assertEquals(VARIABLE_ID, variables.get(0).getId());
}
Expand Down

0 comments on commit f924f8d

Please sign in to comment.