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 0038cef49..ebb60c736 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 @@ -209,6 +209,15 @@ protected Specification createSpecification(ScenarioExecution specification = specification.and(messageHeaderSpecification); } } + if (nonNull(criteria.getScenarioMessagesPayload())) { + specification = + specification.and( + buildSpecification( + criteria.getScenarioMessagesPayload(), + root -> root.join(ScenarioExecution_.scenarioMessages, JoinType.LEFT).get(Message_.payload) + ) + ); + } } return specification; } 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 7d7e39512..1ecea5e64 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 @@ -70,6 +70,8 @@ public class ScenarioExecutionCriteria implements Serializable, Criteria { private @Nullable String headers; + private @Nullable StringFilter scenarioMessagesPayload; + private @Nullable Boolean distinct; public ScenarioExecutionCriteria() { @@ -85,6 +87,7 @@ public ScenarioExecutionCriteria(ScenarioExecutionCriteria other) { this.scenarioMessagesId = other.scenarioMessagesId == null ? null : other.scenarioMessagesId.copy(); this.scenarioParametersId = other.scenarioParametersId == null ? null : other.scenarioParametersId.copy(); this.headers = other.headers; + this.scenarioMessagesPayload = other.scenarioMessagesPayload; this.distinct = other.distinct; } @@ -108,6 +111,8 @@ public boolean equals(Object o) { .append(scenarioActionsId, scenarioExecutionCriteria.scenarioActionsId) .append(scenarioMessagesId, scenarioExecutionCriteria.scenarioMessagesId) .append(scenarioParametersId, scenarioExecutionCriteria.scenarioParametersId) + .append(headers, scenarioExecutionCriteria.headers) + .append(scenarioMessagesPayload, scenarioExecutionCriteria.scenarioMessagesPayload) .append(distinct, scenarioExecutionCriteria.distinct) .isEquals(); } @@ -123,6 +128,8 @@ public int hashCode() { .append(scenarioActionsId) .append(scenarioMessagesId) .append(scenarioParametersId) + .append(headers) + .append(scenarioMessagesPayload) .append(distinct) .toHashCode(); } diff --git a/simulator-spring-boot/src/test/java/org/citrusframework/simulator/service/ScenarioExecutionQueryServiceIT.java b/simulator-spring-boot/src/test/java/org/citrusframework/simulator/service/ScenarioExecutionQueryServiceIT.java index 580617506..974b6888d 100644 --- a/simulator-spring-boot/src/test/java/org/citrusframework/simulator/service/ScenarioExecutionQueryServiceIT.java +++ b/simulator-spring-boot/src/test/java/org/citrusframework/simulator/service/ScenarioExecutionQueryServiceIT.java @@ -29,6 +29,7 @@ import org.citrusframework.simulator.service.criteria.ScenarioExecutionCriteria; import org.citrusframework.simulator.service.filter.IntegerFilter; import org.citrusframework.simulator.service.filter.LongFilter; +import org.citrusframework.simulator.service.filter.StringFilter; import org.citrusframework.simulator.web.rest.MessageResourceIT; import org.citrusframework.simulator.web.rest.ScenarioActionResourceIT; import org.citrusframework.simulator.web.rest.ScenarioExecutionResourceIT; @@ -93,6 +94,7 @@ void beforeEachSetup() { scenarioAction = ScenarioActionResourceIT.createEntity(entityManager); message = MessageResourceIT.createEntityBuilder(entityManager) .citrusMessageId("e4d560c9-720f-4283-ac89-8f28b1d0f277") + .payload("foo") .build() .addHeader(MessageHeader.builder() .name(TRACEPARENT) @@ -118,6 +120,7 @@ void beforeEachSetup() { .addScenarioMessage( MessageResourceIT.createEntityBuilder(entityManager) .citrusMessageId("6eda9f2b-3a7a-423f-b19c-329ed3dd5ecc") + .payload("bar") .build() .addHeader(MessageHeader.builder() .name(TRACEPARENT) @@ -151,6 +154,7 @@ void beforeEachSetup() { .addScenarioMessage( MessageResourceIT.createEntityBuilder(entityManager) .citrusMessageId("66666a09-7099-461b-aebb-260e776cd07f") + .payload("baz") .build() .addHeader(MessageHeader.builder() .name("numeric") @@ -227,6 +231,14 @@ void selectWithJoinToMessages() { assertThatScenarioExecutionAtIndexSelectedByCriteria(scenarioExecutionCriteria, 1); } + @Test + void selectWithJoinToMessagesPayload() { + var scenarioExecutionCriteria = new ScenarioExecutionCriteria(); + scenarioExecutionCriteria.setScenarioMessagesPayload((StringFilter) new StringFilter().setEquals(message.getPayload())); + + assertThatScenarioExecutionAtIndexSelectedByCriteria(scenarioExecutionCriteria, 1); + } + @Test void selectWithJoinToScenarioParameters() { var scenarioExecutionCriteria = new ScenarioExecutionCriteria(); diff --git a/simulator-spring-boot/src/test/java/org/citrusframework/simulator/web/rest/MessageResourceIT.java b/simulator-spring-boot/src/test/java/org/citrusframework/simulator/web/rest/MessageResourceIT.java index 70f1d1dff..b135d692d 100644 --- a/simulator-spring-boot/src/test/java/org/citrusframework/simulator/web/rest/MessageResourceIT.java +++ b/simulator-spring-boot/src/test/java/org/citrusframework/simulator/web/rest/MessageResourceIT.java @@ -53,8 +53,8 @@ public class MessageResourceIT { private static final Message.Direction DEFAULT_DIRECTION = Message.Direction.INBOUND; // Integer value: 1 private static final Message.Direction UPDATED_DIRECTION = Message.Direction.OUTBOUND; // Integer value: 2 - private static final String DEFAULT_PAYLOAD = "AAAAAAAAAA"; - private static final String UPDATED_PAYLOAD = "BBBBBBBBBB"; + static final String DEFAULT_PAYLOAD = "AAAAAAAAAA"; + static final String UPDATED_PAYLOAD = "BBBBBBBBBB"; private static final String DEFAULT_CITRUS_MESSAGE_ID = "AAAAAAAAAA"; private static final String UPDATED_CITRUS_MESSAGE_ID = "BBBBBBBBBB"; 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 ac81ff1a6..89081b492 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 @@ -50,6 +50,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.citrusframework.simulator.model.TestResult.Status.FAILURE; import static org.citrusframework.simulator.model.TestResult.Status.SUCCESS; +import static org.citrusframework.simulator.web.rest.MessageResourceIT.DEFAULT_PAYLOAD; +import static org.citrusframework.simulator.web.rest.MessageResourceIT.UPDATED_PAYLOAD; import static org.hamcrest.Matchers.hasItem; import static org.springframework.http.HttpStatus.OK; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -464,6 +466,28 @@ void getAllScenarioExecutionsByScenarioMessagesIsEqualToSomething() throws Excep defaultScenarioExecutionShouldNotBeFound("scenarioMessagesId.equals=" + (scenarioMessagesId + 1)); } + @Test + @Transactional + void getAllScenarioExecutionsByScenarioMessagesPayloadIsEqualToSomething() 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); + } + entityManager.persist(scenarioMessages); + entityManager.flush(); + scenarioExecution.addScenarioMessage(scenarioMessages); + scenarioExecutionRepository.saveAndFlush(scenarioExecution); + + // Get all the scenarioExecutionList where payload equals the default payload + defaultScenarioExecutionShouldBeFound("scenarioMessagesPayload.equals=" + DEFAULT_PAYLOAD); + + // Get all the scenarioExecutionList where payload equals another payload + defaultScenarioExecutionShouldNotBeFound("scenarioMessagesPayload.equals=" + UPDATED_PAYLOAD); + } + @Test @Transactional void getAllScenarioExecutionsByScenarioParametersIsEqualToSomething() throws Exception {