Skip to content

Commit

Permalink
Resolve PR commments
Browse files Browse the repository at this point in the history
  • Loading branch information
johanah29 committed Oct 18, 2024
1 parent 405fe6f commit 62bd5ae
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions openbas-api/src/test/java/io/openbas/rest/InjectApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ void deleteInjectsForScenarioTest() throws Exception {

@DisplayName("Add an inject for simulation")
@Test
@Order(9)
@WithMockPlannerUser
void addInjectForSimulationTest() throws Exception {
// -- PREPARE --
Expand All @@ -292,33 +291,31 @@ void addInjectForSimulationTest() throws Exception {

// -- ASSERT --
assertNotNull(response);
assertEquals("Test inject", JsonPath.read(response, "$.inject_title"));
EXERCISE_INJECT_ID = JsonPath.read(response, "$.inject_id");
response = mvc
.perform(get(EXERCISE_URI + "/" + EXERCISE.getId())
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().is2xxSuccessful())
.andReturn()
.getResponse()
.getContentAsString();
assertEquals(EXERCISE_INJECT_ID, JsonPath.read(response, "$.exercise_injects[0]"));

}

@DisplayName("Update inject for simulation")
@Test
@Order(10)
@WithMockPlannerUser
void updateInjectForSimulationTest() throws Exception {
// -- PREPARE --
Inject inject = injectRepository.findById(EXERCISE_INJECT_ID).orElseThrow();
InjectInput injectInput = new InjectInput();
injectInput.setTitle("Test inject");
injectInput.setDependsDuration(0L);
Inject inject = injectInput.toInject(injectorContractRepository.findById(EMAIL_DEFAULT).orElseThrow());
Inject savedInject = injectRepository.save(inject);

Inject injectToUpdate = injectRepository.findById(savedInject.getId()).orElseThrow();
InjectInput input = new InjectInput();
String injectTitle = "A new title";
input.setTitle(injectTitle);
input.setInjectorContract(inject.getInjectorContract().map(InjectorContract::getId).orElse(null));
input.setDependsDuration(inject.getDependsDuration());

// -- EXECUTE --
String response = mvc
.perform(put(INJECT_URI + "/" + EXERCISE.getId() + "/" + EXERCISE_INJECT_ID)
.perform(put(INJECT_URI + "/" + EXERCISE.getId() + "/" + injectToUpdate.getId())
.content(asJsonString(input))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
Expand Down

0 comments on commit 62bd5ae

Please sign in to comment.