-
Notifications
You must be signed in to change notification settings - Fork 84
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
da4a14d
commit c09fe52
Showing
9 changed files
with
63 additions
and
50 deletions.
There are no files selected for viewing
61 changes: 36 additions & 25 deletions
61
openbas-api/src/test/java/io/openbas/injects/InjectCrudTest.java
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 |
---|---|---|
@@ -1,50 +1,61 @@ | ||
package io.openbas.injects; | ||
|
||
import static io.openbas.injectors.email.EmailContract.EMAIL_DEFAULT; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import io.openbas.IntegrationTest; | ||
import io.openbas.database.model.Exercise; | ||
import io.openbas.database.model.Inject; | ||
import io.openbas.database.model.InjectorContract; | ||
import io.openbas.database.repository.ExerciseRepository; | ||
import io.openbas.database.repository.InjectRepository; | ||
import io.openbas.database.repository.InjectorContractRepository; | ||
import java.util.List; | ||
import io.openbas.rest.exercise.service.ExerciseService; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@SpringBootTest | ||
class InjectCrudTest { | ||
import static io.openbas.injectors.email.EmailContract.EMAIL_DEFAULT; | ||
import static io.openbas.utils.fixtures.ExerciseFixture.getExercise; | ||
import static io.openbas.utils.fixtures.InjectFixture.createDefaultInjectEmail; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; | ||
|
||
@Autowired private InjectRepository injectRepository; | ||
@TestInstance(PER_CLASS) | ||
class InjectCrudTest extends IntegrationTest { | ||
|
||
@Autowired private ExerciseRepository exerciseRepository; | ||
@Autowired | ||
private InjectorContractRepository injectorContractRepository; | ||
@Autowired | ||
private InjectRepository injectRepository; | ||
|
||
@Autowired private InjectorContractRepository injectorContractRepository; | ||
@Autowired | ||
private ExerciseService exerciseService; | ||
@Autowired | ||
private ExerciseRepository exerciseRepository; | ||
|
||
private static String EXERCISE_ID; | ||
private static String INJECT_ID; | ||
|
||
@AfterAll | ||
void afterAll() { | ||
this.exerciseRepository.deleteById(EXERCISE_ID); | ||
this.injectRepository.deleteById(INJECT_ID); | ||
} | ||
|
||
@DisplayName("Test inject creation with non null depends duration") | ||
@Test | ||
@Transactional | ||
void createInjectSuccess() { | ||
// -- PREPARE -- | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Exercise name"); | ||
exercise.setFrom("[email protected]"); | ||
exercise.setReplyTos(List.of("[email protected]")); | ||
Exercise exerciseCreated = this.exerciseRepository.save(exercise); | ||
Inject inject = new Inject(); | ||
inject.setTitle("test"); | ||
inject.setInjectorContract( | ||
this.injectorContractRepository.findById(EMAIL_DEFAULT).orElseThrow()); | ||
inject.setExercise(exerciseCreated); | ||
inject.setDependsDuration(0L); | ||
Exercise exercise = this.exerciseService.createExercise(getExercise()); | ||
EXERCISE_ID = exercise.getId(); | ||
InjectorContract contract = injectorContractRepository.findById(EMAIL_DEFAULT).orElseThrow(); | ||
Inject inject = createDefaultInjectEmail(contract); | ||
|
||
// -- EXECUTE -- | ||
Inject injectCreated = this.injectRepository.save(inject); | ||
INJECT_ID = injectCreated.getId(); | ||
assertNotNull(injectCreated); | ||
|
||
// -- CLEAN -- | ||
this.exerciseRepository.delete(exercise); | ||
this.injectRepository.delete(inject); | ||
} | ||
} |
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
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
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
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