-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
143bd4c
commit 988e25d
Showing
7 changed files
with
177 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,81 +10,84 @@ | |
|
||
import java.time.Instant; | ||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import static io.openex.database.model.Exercise.STATUS.RUNNING; | ||
import static io.openex.injects.email.EmailContract.EMAIL_DEFAULT; | ||
import static io.openex.injects.email.EmailContract.TYPE; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
@SpringBootTest | ||
public class InjectHelperTest { | ||
|
||
public static final String USER_EMAIL = "[email protected]"; | ||
@Autowired | ||
private InjectHelper injectHelper; | ||
|
||
@Autowired | ||
private TeamRepository teamRepository; | ||
|
||
@Autowired | ||
private ExerciseRepository exerciseRepository; | ||
|
||
@Autowired | ||
private ExerciseTeamUserRepository exerciseTeamUserRepository; | ||
|
||
@Autowired | ||
private InjectRepository injectRepository; | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@DisplayName("Retrieve simple inject to run") | ||
@Test | ||
void injectsToRunTest() { | ||
// -- PREPARE -- | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Exercice name"); | ||
exercise.setStart(Instant.now()); | ||
exercise.setStatus(RUNNING); | ||
Exercise exerciseSaved = this.exerciseRepository.save(exercise); | ||
List<Exercise> exercises = new ArrayList<>(); | ||
exercises.add(exerciseSaved); | ||
User user = new User(); | ||
user.setEmail(USER_EMAIL); | ||
this.userRepository.save(user); | ||
|
||
Team team = new Team(); | ||
team.setName("My team"); | ||
team.setExercises(exercises); | ||
team.setUsers(List.of(user)); | ||
this.teamRepository.save(team); | ||
|
||
ExerciseTeamUser exerciseTeamUser = new ExerciseTeamUser(); | ||
exerciseTeamUser.setExercise(exercise); | ||
exerciseTeamUser.setTeam(team); | ||
exerciseTeamUser.setUser(user); | ||
this.exerciseTeamUserRepository.save(exerciseTeamUser); | ||
|
||
// Executable Inject | ||
Inject inject = new Inject(); | ||
inject.setEnabled(true); | ||
InjectStatus status = new InjectStatus(); | ||
inject.setStatus(status); | ||
inject.setExercise(exerciseSaved); | ||
inject.setTeams(List.of(team)); | ||
inject.setDependsDuration(0L); | ||
this.injectRepository.save(inject); | ||
|
||
// -- EXECUTE -- | ||
List<ExecutableInject> executableInjects = this.injectHelper.getInjectsToRun(); | ||
|
||
// -- ASSERT -- | ||
assertFalse(executableInjects.isEmpty()); | ||
ExecutableInject executableInject = executableInjects.get(0); | ||
assertEquals(1, executableInject.getTeamSize()); | ||
assertEquals(1, executableInject.getUsers().size()); | ||
assertEquals(USER_EMAIL, executableInject.getUsers().get(0).getUser().getEmail()); | ||
} | ||
public static final String USER_EMAIL = "[email protected]"; | ||
@Autowired | ||
private InjectHelper injectHelper; | ||
|
||
@Autowired | ||
private TeamRepository teamRepository; | ||
|
||
@Autowired | ||
private ExerciseRepository exerciseRepository; | ||
|
||
@Autowired | ||
private ExerciseTeamUserRepository exerciseTeamUserRepository; | ||
|
||
@Autowired | ||
private InjectRepository injectRepository; | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@DisplayName("Retrieve simple inject to run") | ||
@Test | ||
void injectsToRunTest() { | ||
// -- PREPARE -- | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Exercice name"); | ||
exercise.setStart(Instant.now()); | ||
exercise.setReplyTo("[email protected]"); | ||
exercise.setStatus(RUNNING); | ||
Exercise exerciseSaved = this.exerciseRepository.save(exercise); | ||
List<Exercise> exercises = new ArrayList<>(); | ||
exercises.add(exerciseSaved); | ||
User user = new User(); | ||
user.setEmail(USER_EMAIL); | ||
this.userRepository.save(user); | ||
|
||
Team team = new Team(); | ||
team.setName("My team"); | ||
team.setExercises(exercises); | ||
team.setUsers(List.of(user)); | ||
this.teamRepository.save(team); | ||
|
||
ExerciseTeamUser exerciseTeamUser = new ExerciseTeamUser(); | ||
exerciseTeamUser.setExercise(exercise); | ||
exerciseTeamUser.setTeam(team); | ||
exerciseTeamUser.setUser(user); | ||
this.exerciseTeamUserRepository.save(exerciseTeamUser); | ||
|
||
// Executable Inject | ||
Inject inject = new Inject(); | ||
inject.setTitle("Test inject"); | ||
inject.setType(TYPE); | ||
inject.setContract(EMAIL_DEFAULT); | ||
inject.setEnabled(true); | ||
inject.setExercise(exerciseSaved); | ||
inject.setTeams(List.of(team)); | ||
inject.setDependsDuration(0L); | ||
this.injectRepository.save(inject); | ||
|
||
// -- EXECUTE -- | ||
List<ExecutableInject> executableInjects = this.injectHelper.getInjectsToRun(); | ||
|
||
// -- ASSERT -- | ||
assertFalse(executableInjects.isEmpty()); | ||
ExecutableInject executableInject = executableInjects.get(0); | ||
assertEquals(1, executableInject.getTeamSize()); | ||
assertEquals(1, executableInject.getUsers().size()); | ||
assertEquals(USER_EMAIL, executableInject.getUsers().get(0).getUser().getEmail()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
import javax.validation.ConstraintViolationException; | ||
import java.util.Set; | ||
|
||
import static io.openex.injects.email.EmailContract.EMAIL_DEFAULT; | ||
import static io.openex.injects.email.EmailContract.TYPE; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@SpringBootTest | ||
|
@@ -31,6 +33,7 @@ void createInjectFailed() { | |
// -- PREPARE -- | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Exercice name"); | ||
exercise.setReplyTo("[email protected]"); | ||
Exercise exerciseCreated = this.exerciseRepository.save(exercise); | ||
Inject inject = new Inject(); | ||
inject.setExercise(exerciseCreated); | ||
|
@@ -56,8 +59,12 @@ void createInjectSuccess() { | |
// -- PREPARE -- | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Exercice name"); | ||
exercise.setReplyTo("[email protected]"); | ||
Exercise exerciseCreated = this.exerciseRepository.save(exercise); | ||
Inject inject = new Inject(); | ||
inject.setTitle("test"); | ||
inject.setType(TYPE); | ||
inject.setContract(EMAIL_DEFAULT); | ||
inject.setExercise(exerciseCreated); | ||
inject.setDependsDuration(0L); | ||
|
||
|
Oops, something went wrong.