diff --git a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/service/ScenarioExecutionQueryService.java b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/service/ScenarioExecutionQueryService.java index afb0416f..9fc0363a 100644 --- a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/service/ScenarioExecutionQueryService.java +++ b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/service/ScenarioExecutionQueryService.java @@ -258,6 +258,15 @@ protected Specification createSpecification(ScenarioExecution ) ); } + if (nonNull(criteria.getScenarioMessagesDirection())) { + specification = + specification.and( + buildSpecification( + criteria.getScenarioMessagesDirection(), + root -> root.join(ScenarioExecution_.scenarioMessages, JoinType.LEFT).get(Message_.direction) + ) + ); + } if (nonNull(criteria.getScenarioParametersId())) { specification = specification.and( diff --git a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/service/criteria/ScenarioExecutionCriteria.java b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/service/criteria/ScenarioExecutionCriteria.java index 1ecea5e6..0a8370d3 100644 --- a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/service/criteria/ScenarioExecutionCriteria.java +++ b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/service/criteria/ScenarioExecutionCriteria.java @@ -66,6 +66,8 @@ public class ScenarioExecutionCriteria implements Serializable, Criteria { private @Nullable LongFilter scenarioMessagesId; + private @Nullable IntegerFilter scenarioMessagesDirection; + private @Nullable LongFilter scenarioParametersId; private @Nullable String headers; @@ -85,6 +87,7 @@ public ScenarioExecutionCriteria(ScenarioExecutionCriteria other) { this.status = other.status == null ? null : other.status.copy(); this.scenarioActionsId = other.scenarioActionsId == null ? null : other.scenarioActionsId.copy(); this.scenarioMessagesId = other.scenarioMessagesId == null ? null : other.scenarioMessagesId.copy(); + this.scenarioMessagesDirection = other.scenarioMessagesDirection == null ? null : other.scenarioMessagesDirection.copy(); this.scenarioParametersId = other.scenarioParametersId == null ? null : other.scenarioParametersId.copy(); this.headers = other.headers; this.scenarioMessagesPayload = other.scenarioMessagesPayload; @@ -110,6 +113,7 @@ public boolean equals(Object o) { .append(status, scenarioExecutionCriteria.status) .append(scenarioActionsId, scenarioExecutionCriteria.scenarioActionsId) .append(scenarioMessagesId, scenarioExecutionCriteria.scenarioMessagesId) + .append(scenarioMessagesDirection, scenarioExecutionCriteria.scenarioMessagesDirection) .append(scenarioParametersId, scenarioExecutionCriteria.scenarioParametersId) .append(headers, scenarioExecutionCriteria.headers) .append(scenarioMessagesPayload, scenarioExecutionCriteria.scenarioMessagesPayload) @@ -127,6 +131,7 @@ public int hashCode() { .append(status) .append(scenarioActionsId) .append(scenarioMessagesId) + .append(scenarioMessagesDirection) .append(scenarioParametersId) .append(headers) .append(scenarioMessagesPayload) diff --git a/simulator-spring-boot/src/test/java/org/citrusframework/simulator/web/rest/ScenarioExecutionResourceIT.java b/simulator-spring-boot/src/test/java/org/citrusframework/simulator/web/rest/ScenarioExecutionResourceIT.java index 39464588..3c228e52 100644 --- a/simulator-spring-boot/src/test/java/org/citrusframework/simulator/web/rest/ScenarioExecutionResourceIT.java +++ b/simulator-spring-boot/src/test/java/org/citrusframework/simulator/web/rest/ScenarioExecutionResourceIT.java @@ -20,12 +20,8 @@ import jakarta.persistence.EntityManager; import org.assertj.core.data.TemporalUnitLessThanOffset; import org.citrusframework.simulator.IntegrationTest; -import org.citrusframework.simulator.model.Message; -import org.citrusframework.simulator.model.ScenarioAction; -import org.citrusframework.simulator.model.ScenarioExecution; +import org.citrusframework.simulator.model.*; import org.citrusframework.simulator.model.ScenarioExecution.ScenarioExecutionBuilder; -import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.TestResult; import org.citrusframework.simulator.repository.ScenarioExecutionRepository; import org.citrusframework.simulator.scenario.AbstractSimulatorScenario; import org.citrusframework.simulator.scenario.Scenario; @@ -57,9 +53,7 @@ import static org.hamcrest.Matchers.hasSize; import static org.springframework.http.HttpStatus.OK; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; /** * Integration tests for the {@link ScenarioExecutionResource} REST controller. @@ -398,6 +392,30 @@ void getAllScenarioExecutionsByScenarioMessagesIsEqualToSomething() throws Excep defaultScenarioExecutionShouldNotBeFound("scenarioMessagesId.equals=" + (scenarioMessagesId + 1)); } + @Test + @Transactional + void getAllScenarioExecutionsByScenarioMessageDirectionIsEqualToSomething() throws Exception { + Message scenarioMessages; + if (TestUtil.findAll(entityManager, Message.class).isEmpty()) { + scenarioExecutionRepository.saveAndFlush(scenarioExecution); + scenarioMessages = MessageResourceIT.createEntity(entityManager); + } else { + scenarioMessages = TestUtil.findAll(entityManager, Message.class).get(0); + } + scenarioMessages.setDirection(Message.Direction.INBOUND); + entityManager.persist(scenarioMessages); + entityManager.flush(); + scenarioExecution.addScenarioMessage(scenarioMessages); + scenarioExecutionRepository.saveAndFlush(scenarioExecution); + int scenarioMessageDirection = scenarioMessages.getDirection().getId(); + System.out.printf(String.valueOf(scenarioMessageDirection)); + // Get all the scenarioExecutionList where scenarioMessagesDirection equals to scenarioMessagesDirection + defaultScenarioExecutionShouldBeFound("scenarioMessagesDirection.equals=" + scenarioMessageDirection); + + // Get all the scenarioExecutionList where scenarioMessagesDirection equals to (scenarioMessagesDirection + 1) + defaultScenarioExecutionShouldNotBeFound("scenarioMessagesDirection.equals=" + (Message.Direction.UNKNOWN.getId())); + } + @Test @Transactional void getAllScenarioExecutionsByScenarioMessagesPayloadIsEqualToSomething() throws Exception {