Skip to content

Commit

Permalink
[integration] Fix testing
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelHassine committed Jan 8, 2024
1 parent 143bd4c commit 988e25d
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 136 deletions.
26 changes: 14 additions & 12 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@ steps:
image: alpine/git
commands:
- git submodule update --init --recursive

- name: api-tests
image: maven:3.8.7-openjdk-18
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://pgsql:5432/openex
MINIO_ENDPOINT: minio
MINIO_PORT: 9000
MINIO_ACCESS-KEY: minioadmin
MINIO_ACCESS-SECRET: minioadmin
commands:
- mvn install
depends_on:
- submodules

- name: frontend-tests
image: node:20.10.0-alpine3.18
commands:
Expand All @@ -45,6 +42,12 @@ services:
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: minioadmin
command: [ server, /data ]
- name: pgsql
image: postgres:16-alpine
environment:
POSTGRES_USER: openex
POSTGRES_PASSWORD: openex
POSTGRES_DB: openex

---
kind: pipeline
Expand All @@ -62,17 +65,14 @@ steps:
image: alpine/git
commands:
- git submodule update --init --recursive

- name: api-tests
image: maven:3.8.7-openjdk-18
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://pgsql:5432/openex
MINIO_ENDPOINT: minio
MINIO_PORT: 9000
MINIO_ACCESS-KEY: minioadmin
MINIO_ACCESS-SECRET: minioadmin
commands:
- mvn install

- name: frontend-tests
image: node:20.10.0-alpine3.18
commands:
Expand All @@ -83,14 +83,12 @@ steps:
- yarn lint
- yarn i18n-checker
- NODE_OPTIONS=--max_old_space_size=8192 yarn test

- name: codecov
image: robertstettner/drone-codecov
settings:
token:
from_secret: CODECOV_TOKEN
files: openex-api/target/site/jacoco/jacoco.xml

- name: build-circleci
image: curlimages/curl
commands:
Expand All @@ -102,7 +100,6 @@ steps:
event:
exclude:
- tag

- name: build-circleci-release
image: curlimages/curl
commands:
Expand All @@ -113,7 +110,6 @@ steps:
when:
event:
- tag

- name: slack
image: plugins/slack
settings:
Expand All @@ -131,3 +127,9 @@ services:
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: minioadmin
command: [ server, /data ]
- name: pgsql
image: postgres:16-alpine
environment:
POSTGRES_USER: openex
POSTGRES_PASSWORD: openex
POSTGRES_DB: openex
137 changes: 70 additions & 67 deletions openex-api/src/test/java/io/openex/helper/InjectHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);

Expand Down
Loading

0 comments on commit 988e25d

Please sign in to comment.