Skip to content

Commit 5d3e7e5

Browse files
committed
[frontend/backend] Add missing attributes and tests
1 parent 4471003 commit 5d3e7e5

File tree

6 files changed

+122
-7
lines changed

6 files changed

+122
-7
lines changed

openaev-api/src/main/java/io/openaev/rest/inject/output/InjectOutput.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ public class InjectOutput {
152152
@ArraySchema(schema = @Schema(type = "string", description = "Expectation of the inject"))
153153
private List<InjectExpectation> expectations = new ArrayList<>();
154154

155+
@JsonProperty("listened")
156+
@Schema(description = "Stream listener value of the inject")
157+
private boolean isListened;
158+
159+
@JsonProperty("header")
160+
@Schema(description = "Header of the inject")
161+
private String header;
162+
163+
@JsonProperty("footer")
164+
@Schema(description = "Footer of the inject")
165+
private String footer;
166+
155167
@JsonProperty("inject_users_number")
156168
@Schema(description = "Count of users targeted by the inject")
157169
public Long numberOfTargetUsers;

openaev-api/src/main/java/io/openaev/utils/mapper/InjectMapper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ public InjectOutput toInjectOutput(
174174
List<InjectDocument> documents,
175175
List<Communication> communications,
176176
List<InjectExpectation> expectations,
177+
boolean isListened,
178+
String header,
179+
String footer,
177180
Long numberOfTargetUsers,
178181
Instant date,
179182
Long communicationsNumber,
@@ -210,6 +213,9 @@ public InjectOutput toInjectOutput(
210213
injectOutput.setDocuments(documents);
211214
injectOutput.setCommunications(communications);
212215
injectOutput.setExpectations(expectations);
216+
injectOutput.setListened(isListened);
217+
injectOutput.setHeader(header);
218+
injectOutput.setFooter(footer);
213219
injectOutput.setNumberOfTargetUsers(numberOfTargetUsers);
214220
injectOutput.setDate(date);
215221
injectOutput.setCommunicationsNumber(communicationsNumber);
@@ -250,6 +256,9 @@ public InjectOutput toInjectOutput(Inject inject, List<HealthCheck> healthchecks
250256
inject.getDocuments(),
251257
inject.getCommunications(),
252258
inject.getExpectations(),
259+
inject.isListened(),
260+
inject.getHeader(),
261+
inject.getFooter(),
253262
inject.getNumberOfTargetUsers(),
254263
inject.getDate().orElse(null),
255264
inject.getCommunicationsNumber(),

openaev-api/src/test/java/io/openaev/rest/scenario/ScenarioInjectApiTest.java

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,12 @@
2020
import io.openaev.service.EndpointService;
2121
import io.openaev.service.ScenarioService;
2222
import io.openaev.utils.fixtures.*;
23-
import io.openaev.utils.fixtures.composers.AttackPatternComposer;
24-
import io.openaev.utils.fixtures.composers.InjectorContractComposer;
25-
import io.openaev.utils.fixtures.composers.PayloadComposer;
23+
import io.openaev.utils.fixtures.composers.*;
2624
import io.openaev.utils.fixtures.files.AttackPatternFixture;
2725
import io.openaev.utils.mockUser.WithMockUser;
2826
import jakarta.servlet.ServletException;
2927
import jakarta.transaction.Transactional;
30-
import java.util.ArrayList;
31-
import java.util.Arrays;
32-
import java.util.List;
33-
import java.util.Set;
28+
import java.util.*;
3429
import org.json.JSONArray;
3530
import org.junit.jupiter.api.*;
3631
import org.springframework.beans.factory.annotation.Autowired;
@@ -64,6 +59,13 @@ class ScenarioInjectApiTest extends IntegrationTest {
6459
@Autowired private ScenarioService scenarioService;
6560

6661
List<InjectorContractComposer.Composer> injectorContractWrapperComposers = new ArrayList<>();
62+
@Autowired private InjectComposer injectComposer;
63+
@Autowired private ScenarioComposer scenarioComposer;
64+
@Autowired private TeamComposer teamComposer;
65+
@Autowired private TagComposer tagComposer;
66+
@Autowired private EndpointComposer endpointComposer;
67+
@Autowired private AssetGroupComposer assetGroupComposer;
68+
@Autowired private ExerciseComposer exerciseComposer;
6769

6870
@BeforeAll
6971
void beforeAll() {
@@ -478,5 +480,81 @@ void given_TwoInjectByTTPNumber_should_createTwoInjects() throws Exception {
478480
assertEquals(2, jsonArray.length());
479481
assertEquals(2, injects.size());
480482
}
483+
484+
@DisplayName("Retrieve injects simple list for scenario with asset")
485+
@Test
486+
@Transactional
487+
@WithMockUser(isAdmin = true)
488+
void retrieveInjectSimpleForScenarioTestWithAsset() throws Exception {
489+
// -- PREPARE --
490+
ScenarioComposer.Composer composer =
491+
scenarioComposer
492+
.forScenario(ScenarioFixture.createDefaultCrisisScenario())
493+
.withInject(
494+
injectComposer
495+
.forInject(InjectFixture.getDefaultInject())
496+
.withTeam(teamComposer.forTeam(TeamFixture.getDefaultTeam()))
497+
.withExercise(
498+
exerciseComposer.forExercise(ExerciseFixture.createDefaultExercise()))
499+
.withTag(tagComposer.forTag(TagFixture.getTagWithText("test")))
500+
.withEndpoint(endpointComposer.forEndpoint(EndpointFixture.createEndpoint())))
501+
.persist();
502+
503+
// -- EXECUTE --
504+
String response =
505+
mvc.perform(
506+
get(SCENARIO_URI + "/" + composer.get().getId() + "/injects/simple")
507+
.accept(MediaType.APPLICATION_JSON))
508+
.andExpect(status().is2xxSuccessful())
509+
.andReturn()
510+
.getResponse()
511+
.getContentAsString();
512+
513+
// -- ASSERT --
514+
assertNotNull(response);
515+
assertEquals(composer.get().getId(), JsonPath.read(response, "$[0].inject_scenario"));
516+
517+
// -- CLEAN --
518+
composer.delete();
519+
}
520+
521+
@DisplayName("Retrieve injects simple list for scenario with asset group")
522+
@Test
523+
@Transactional
524+
@WithMockUser(isAdmin = true)
525+
void retrieveInjectSimpleForScenarioTestWithAssetGroup() throws Exception {
526+
// -- PREPARE --
527+
ScenarioComposer.Composer composer =
528+
scenarioComposer
529+
.forScenario(ScenarioFixture.createDefaultCrisisScenario())
530+
.withInject(
531+
injectComposer
532+
.forInject(InjectFixture.getDefaultInject())
533+
.withTeam(teamComposer.forTeam(TeamFixture.getDefaultTeam()))
534+
.withExercise(
535+
exerciseComposer.forExercise(ExerciseFixture.createDefaultExercise()))
536+
.withTag(tagComposer.forTag(TagFixture.getTagWithText("test")))
537+
.withAssetGroup(
538+
assetGroupComposer.forAssetGroup(
539+
AssetGroupFixture.createDefaultAssetGroup("test"))))
540+
.persist();
541+
542+
// -- EXECUTE --
543+
String response =
544+
mvc.perform(
545+
get(SCENARIO_URI + "/" + composer.get().getId() + "/injects/simple")
546+
.accept(MediaType.APPLICATION_JSON))
547+
.andExpect(status().is2xxSuccessful())
548+
.andReturn()
549+
.getResponse()
550+
.getContentAsString();
551+
552+
// -- ASSERT --
553+
assertNotNull(response);
554+
assertEquals(composer.get().getId(), JsonPath.read(response, "$[0].inject_scenario"));
555+
556+
// -- CLEAN --
557+
composer.delete();
558+
}
481559
}
482560
}

openaev-api/src/test/java/io/openaev/rest/scenario/ScenarioSimulationApiTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void beforeEach() {
5757
scenario = this.scenarioRepository.save(defaultScenario);
5858

5959
// Create exercises linked to the scenario
60+
exerciseRepository.deleteAll();
6061
Exercise exercise1 = ExerciseFixture.createDefaultCrisisExercise();
6162
exercise1.setScenario(scenario);
6263
exercise1FromScenario = this.exerciseRepository.save(exercise1);

openaev-api/src/test/java/io/openaev/utils/fixtures/composers/InjectComposer.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class Composer extends InnerComposerBase<Inject> {
2525
Optional.empty();
2626
private final List<DocumentComposer.Composer> documentComposers = new ArrayList<>();
2727
private final List<TeamComposer.Composer> teamComposers = new ArrayList<>();
28+
private final List<ExerciseComposer.Composer> exerciseComposers = new ArrayList<>();
2829
private final List<AssetGroupComposer.Composer> assetGroupComposers = new ArrayList<>();
2930
private final List<InjectExpectationComposer.Composer> expectationComposers = new ArrayList<>();
3031
private final List<FindingComposer.Composer> findingComposers = new ArrayList<>();
@@ -67,6 +68,12 @@ public Composer withTeam(TeamComposer.Composer teamComposer) {
6768
return this;
6869
}
6970

71+
public Composer withExercise(ExerciseComposer.Composer exerciseComposer) {
72+
this.exerciseComposers.add(exerciseComposer);
73+
this.inject.setExercise(exerciseComposer.get());
74+
return this;
75+
}
76+
7077
public Composer withId(String id) {
7178
this.inject.setId(id);
7279
return this;
@@ -142,6 +149,7 @@ public Composer persist() {
142149
endpointComposers.forEach(EndpointComposer.Composer::persist);
143150
tagComposers.forEach(TagComposer.Composer::persist);
144151
teamComposers.forEach(TeamComposer.Composer::persist);
152+
exerciseComposers.forEach(ExerciseComposer.Composer::persist);
145153
documentComposers.forEach(DocumentComposer.Composer::persist);
146154
injectRepository.save(inject);
147155
injectStatusComposers.ifPresent(InjectStatusComposer.Composer::persist);
@@ -160,6 +168,7 @@ public Composer delete() {
160168
assetGroupComposers.forEach(AssetGroupComposer.Composer::delete);
161169
injectStatusComposers.ifPresent(InjectStatusComposer.Composer::delete);
162170
teamComposers.forEach(TeamComposer.Composer::delete);
171+
exerciseComposers.forEach(ExerciseComposer.Composer::delete);
163172
injectorContractComposer.ifPresent(InjectorContractComposer.Composer::delete);
164173
findingComposers.forEach(FindingComposer.Composer::delete);
165174
expectationComposers.forEach(InjectExpectationComposer.Composer::delete);

openaev-front/src/utils/api-types.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2997,6 +2997,10 @@ export interface InjectInput {
29972997
}
29982998

29992999
export interface InjectOutput {
3000+
/** Footer of the inject */
3001+
footer?: string;
3002+
/** Header of the inject */
3003+
header?: string;
30003004
/** All teams value of the inject */
30013005
inject_all_teams?: boolean;
30023006
inject_asset_groups?: string[];
@@ -3087,6 +3091,8 @@ export interface InjectOutput {
30873091
* @format int64
30883092
*/
30893093
inject_users_number?: number;
3094+
/** Stream listener value of the inject */
3095+
listened?: boolean;
30903096
}
30913097

30923098
export interface InjectReceptionInput {

0 commit comments

Comments
 (0)