Skip to content

Commit

Permalink
feat(simulator-spring-boot): add MessageDirectionFilter and test
Browse files Browse the repository at this point in the history
  • Loading branch information
muellerfluri authored and bbortt committed Jan 21, 2025
1 parent bcb593c commit 48c563a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ protected Specification<ScenarioExecution> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -127,6 +131,7 @@ public int hashCode() {
.append(status)
.append(scenarioActionsId)
.append(scenarioMessagesId)
.append(scenarioMessagesDirection)
.append(scenarioParametersId)
.append(headers)
.append(scenarioMessagesPayload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 48c563a

Please sign in to comment.