Skip to content

Commit

Permalink
feat(simulator-spring-boot): allow scenario execution filtering by me…
Browse files Browse the repository at this point in the history
…ssage payload
  • Loading branch information
bbortt committed Oct 10, 2024
1 parent a646c0f commit 1324fa3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ protected Specification<ScenarioExecution> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class ScenarioExecutionCriteria implements Serializable, Criteria {

private @Nullable String headers;

private @Nullable StringFilter scenarioMessagesPayload;

private @Nullable Boolean distinct;

public ScenarioExecutionCriteria() {
Expand All @@ -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;
}

Expand All @@ -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();
}
Expand All @@ -123,6 +128,8 @@ public int hashCode() {
.append(scenarioActionsId)
.append(scenarioMessagesId)
.append(scenarioParametersId)
.append(headers)
.append(scenarioMessagesPayload)
.append(distinct)
.toHashCode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -118,6 +120,7 @@ void beforeEachSetup() {
.addScenarioMessage(
MessageResourceIT.createEntityBuilder(entityManager)
.citrusMessageId("6eda9f2b-3a7a-423f-b19c-329ed3dd5ecc")
.payload("bar")
.build()
.addHeader(MessageHeader.builder()
.name(TRACEPARENT)
Expand Down Expand Up @@ -151,6 +154,7 @@ void beforeEachSetup() {
.addScenarioMessage(
MessageResourceIT.createEntityBuilder(entityManager)
.citrusMessageId("66666a09-7099-461b-aebb-260e776cd07f")
.payload("baz")
.build()
.addHeader(MessageHeader.builder()
.name("numeric")
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1324fa3

Please sign in to comment.