From 3d16c0e4db8daac3f357350470bbd795ee956515 Mon Sep 17 00:00:00 2001 From: Timon Borter Date: Fri, 8 Sep 2023 20:17:47 +0200 Subject: [PATCH] feat(#166): auditted entities all entities which do not have any timing informatin (e.g. `startDate` or `endDate`) did now receive `createdDate` as well as `lastModifiedDate` information. --- .../controller/ActivityController.java | 14 ++- .../model/AbstractAuditingEntity.java | 57 +++++++++++ .../simulator/model/Message.java | 99 +++++++++---------- .../simulator/model/MessageFilter.java | 8 +- .../simulator/model/MessageHeader.java | 36 ++++--- .../simulator/model/ScenarioAction.java | 65 ++++++------ .../simulator/model/ScenarioExecution.java | 82 ++++++++------- .../simulator/model/ScenarioParameter.java | 64 +++++++----- .../ScenarioExecutionRepository.java | 4 +- .../ScenarioExecutionRepositoryImpl.java | 13 +-- .../simulator/service/ActivityService.java | 98 +++++++++--------- .../simulator/service/MessageService.java | 13 +-- .../service/QueryFilterAdapterFactory.java | 32 +++--- .../service/MessageRepositoryTest.java | 14 ++- .../simulator/service/MessageServiceTest.java | 6 +- .../ScenarioExecutionRepositoryTest.java | 70 ++++++++----- 16 files changed, 395 insertions(+), 280 deletions(-) create mode 100644 simulator-starter/src/main/java/org/citrusframework/simulator/model/AbstractAuditingEntity.java diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/controller/ActivityController.java b/simulator-starter/src/main/java/org/citrusframework/simulator/controller/ActivityController.java index 50b2d8c75..7cfceea9d 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/controller/ActivityController.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/controller/ActivityController.java @@ -20,9 +20,15 @@ import org.citrusframework.simulator.model.ScenarioExecutionFilter; import org.citrusframework.simulator.service.ActivityService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.time.Instant; import java.util.Collection; -import java.util.Date; @RestController @RequestMapping("api/activity") @@ -33,8 +39,8 @@ public class ActivityController { @RequestMapping(method = RequestMethod.GET) public Collection getScenarioExecutions( - @RequestParam(value = "fromDate", required = false) Date fromDate, - @RequestParam(value = "toDate", required = false) Date toDate, + @RequestParam(value = "fromDate", required = false) Instant fromDate, + @RequestParam(value = "toDate", required = false) Instant toDate, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size ) { diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/model/AbstractAuditingEntity.java b/simulator-starter/src/main/java/org/citrusframework/simulator/model/AbstractAuditingEntity.java new file mode 100644 index 000000000..96e4f8720 --- /dev/null +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/model/AbstractAuditingEntity.java @@ -0,0 +1,57 @@ +package org.citrusframework.simulator.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import jakarta.persistence.Column; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.io.Serializable; +import java.time.Instant; + +/** + * Base abstract class for entities which will hold definitions for created and last modified by attributes. + */ +@MappedSuperclass +@EntityListeners({ AuditingEntityListener.class }) +@JsonIgnoreProperties(value = { "createdDate", "lastModifiedDate" }, allowGetters = true) +public abstract class AbstractAuditingEntity implements Serializable { + + private static final long serialVersionUID = 1L; + + @CreatedDate + @Column(name = "created_date", nullable = false, updatable = false) + private Instant createdDate = Instant.now(); + + @LastModifiedDate + @Column(name = "last_modified_date") + private Instant lastModifiedDate = Instant.now(); + + public Instant getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Instant createdDate) { + this.createdDate = createdDate; + } + + public T createdDate(Instant createdDate) { + setCreatedDate(createdDate); + return (T) this; + } + + public Instant getLastModifiedDate() { + return lastModifiedDate; + } + + public void setLastModifiedDate(Instant lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; + } + + public T lastModifiedDate(Instant lastModifiedDate) { + setLastModifiedDate(lastModifiedDate); + return (T) this; + } +} diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/model/Message.java b/simulator-starter/src/main/java/org/citrusframework/simulator/model/Message.java index 2d9f61bbf..4f013eec0 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/model/Message.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/model/Message.java @@ -16,20 +16,31 @@ package org.citrusframework.simulator.model; -import com.fasterxml.jackson.annotation.JsonIgnore; - -import jakarta.persistence.*; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OrderBy; + +import java.io.Serial; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; /** * JPA entity for representing inbound and outbound messages */ @Entity -public class Message implements Serializable { - private static final long serialVersionUID = -4858126051234255084L; +public class Message extends AbstractAuditingEntity implements Serializable { + + @Serial + private static final long serialVersionUID = 2L; public enum Direction { INBOUND, @@ -38,31 +49,26 @@ public enum Direction { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "MESSAGE_ID") private Long messageId; - @JsonIgnore - @ManyToOne - private ScenarioExecution scenarioExecution; - @Column(nullable = false) private Direction direction; - @Column(nullable = false) - @Temporal(TemporalType.TIMESTAMP) - private Date date; - - @Column(columnDefinition = "CLOB") @Lob + @Column(columnDefinition = "CLOB") private String payload; @Column(unique = true) private String citrusMessageId; - @OneToMany(mappedBy = "message", cascade = CascadeType.ALL, orphanRemoval = true) @OrderBy("name ASC") + @OneToMany(mappedBy = "message", cascade = CascadeType.ALL, orphanRemoval = true) private Collection headers = new ArrayList<>(); + @ManyToOne + @JsonIgnoreProperties(value = { "scenarioParameters", "scenarioActions", "scenarioMessages" }, allowSetters = true) + private ScenarioExecution scenarioExecution; + public Long getMessageId() { return messageId; } @@ -75,32 +81,6 @@ public ScenarioExecution getScenarioExecution() { return scenarioExecution; } - public void setScenarioExecution(ScenarioExecution scenarioExecution) { - this.scenarioExecution = scenarioExecution; - } - - public Long getScenarioExecutionId() { - if (scenarioExecution != null) { - return scenarioExecution.getExecutionId(); - } - return null; - } - - public String getScenarioName() { - if (scenarioExecution != null) { - return scenarioExecution.getScenarioName(); - } - return null; - } - - public Date getDate() { - return date; - } - - public void setDate(Date date) { - this.date = date; - } - public Direction getDirection() { return direction; } @@ -139,18 +119,35 @@ public Collection getHeaders() { return headers; } + public void setScenarioExecution(ScenarioExecution scenarioExecution) { + this.scenarioExecution = scenarioExecution; + } + + public Long getScenarioExecutionId() { + if (scenarioExecution != null) { + return scenarioExecution.getExecutionId(); + } + return null; + } + + public String getScenarioName() { + if (scenarioExecution != null) { + return scenarioExecution.getScenarioName(); + } + return null; + } + @Override public String toString() { return "Message{" + - "date=" + date + - ", messageId=" + messageId + - ", direction=" + direction + - ", payload='" + payload + '\'' + - ", citrusMessageId=" + citrusMessageId + - ", scenarioExecutionId=" + getScenarioExecutionId() + - ", scenarioName=" + getScenarioName() + - ", headers=" + headers + + "messageId='" + getMessageId() + "'" + + ", createdDate='" + getCreatedDate() + "'" + + ", direction='" + getDirection() + "'" + + ", payload='" + getPayload() + "'" + + ", citrusMessageId='" + getCitrusMessageId() + "'" + + ", headers='" + getHeaders() + "'" + + ", scenarioExecution='" + getScenarioExecution() + "'" + '}'; } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/model/MessageFilter.java b/simulator-starter/src/main/java/org/citrusframework/simulator/model/MessageFilter.java index c2371a50f..cdeea8b97 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/model/MessageFilter.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/model/MessageFilter.java @@ -16,16 +16,17 @@ package org.citrusframework.simulator.model; -import java.util.Date; import lombok.Data; +import java.time.Instant; + /** * Filter for filtering {@link Message}s */ @Data public class MessageFilter { - private Date fromDate; - private Date toDate; + private Instant fromDate; + private Instant toDate; private Integer pageNumber; private Integer pageSize; private Boolean directionInbound; @@ -42,5 +43,4 @@ public class MessageFilter { * filter. */ private String headerFilter; - } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/model/MessageHeader.java b/simulator-starter/src/main/java/org/citrusframework/simulator/model/MessageHeader.java index aa20e274d..4c643cd2a 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/model/MessageHeader.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/model/MessageHeader.java @@ -15,9 +15,17 @@ */ package org.citrusframework.simulator.model; -import com.fasterxml.jackson.annotation.JsonIgnore; - -import jakarta.persistence.*; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.validation.constraints.NotNull; + +import java.io.Serial; import java.io.Serializable; /** @@ -26,14 +34,13 @@ * @author Georgi Todorov */ @Entity -public class MessageHeader implements Serializable { +public class MessageHeader extends AbstractAuditingEntity implements Serializable { - private static final long serialVersionUID = 6645135139541485915L; + @Serial + private static final long serialVersionUID = 2L; - @JsonIgnore @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "HEADER_ID") private Long headerId; @Column(nullable = false) @@ -42,8 +49,10 @@ public class MessageHeader implements Serializable { @Column(nullable = false, name = "`value`") private String value; - @JsonIgnore - @ManyToOne + @NotNull + @ManyToOne(optional = false) + @JoinColumn(nullable = false) + @JsonIgnoreProperties(value = { "headers", "scenarioExecution" }, allowSetters = true) private Message message; public MessageHeader() { @@ -89,10 +98,11 @@ public void setMessage(Message message) { @Override public String toString() { return "MessageHeader{" + - "headerId=" + headerId + - ", name='" + name + '\'' + - ", value='" + value + '\'' + + "headerId='" + getHeaderId() + "'" + + ", createdDate='" + getCreatedDate() + "'" + + ", name='" + getName() + "'" + + ", value='" + getValue() + "'" + + ", message='" + getMessage() + "'" + '}'; } - } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/model/ScenarioAction.java b/simulator-starter/src/main/java/org/citrusframework/simulator/model/ScenarioAction.java index 595ad3f48..e9debecc6 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/model/ScenarioAction.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/model/ScenarioAction.java @@ -16,11 +16,17 @@ package org.citrusframework.simulator.model; -import com.fasterxml.jackson.annotation.JsonIgnore; - -import jakarta.persistence.*; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; + +import java.io.Serial; import java.io.Serializable; -import java.util.Date; +import java.time.Instant; /** * JPA entity for representing a scenario action @@ -28,23 +34,23 @@ @Entity public class ScenarioAction implements Serializable { + @Serial + private static final long serialVersionUID = 2L; + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "ACTION_ID") private Long actionId; - @JsonIgnore - @ManyToOne - private ScenarioExecution scenarioExecution; - @Column(nullable = false) private String name; - @Temporal(TemporalType.TIMESTAMP) - private Date startDate; + private Instant startDate; + + private Instant endDate; - @Temporal(TemporalType.TIMESTAMP) - private Date endDate; + @ManyToOne + @JsonIgnoreProperties(value = { "scenarioParameters", "scenarioActions", "scenarioMessages" }, allowSetters = true) + private ScenarioExecution scenarioExecution; public Long getActionId() { return actionId; @@ -54,45 +60,46 @@ public void setActionId(Long actionId) { this.actionId = actionId; } - public ScenarioExecution getScenarioExecution() { - return scenarioExecution; + public String getName() { + return name; } - public void setScenarioExecution(ScenarioExecution scenarioExecution) { - this.scenarioExecution = scenarioExecution; + public void setName(String name) { + this.name = name; } - public Date getStartDate() { + public Instant getStartDate() { return startDate; } - public void setStartDate(Date startDate) { + public void setStartDate(Instant startDate) { this.startDate = startDate; } - public Date getEndDate() { + public Instant getEndDate() { return endDate; } - public void setEndDate(Date endDate) { + public void setEndDate(Instant endDate) { this.endDate = endDate; } - public String getName() { - return name; + public ScenarioExecution getScenarioExecution() { + return scenarioExecution; } - public void setName(String name) { - this.name = name; + public void setScenarioExecution(ScenarioExecution scenarioExecution) { + this.scenarioExecution = scenarioExecution; } @Override public String toString() { return "ScenarioAction{" + - "actionId=" + actionId + - ", name='" + name + '\'' + - ", startDate=" + startDate + - ", endDate=" + endDate + + "actionId='" + getActionId() + "'" + + ", name='" + getName() + "'" + + ", startDate='" + getStartDate() + "'" + + ", endDate='" + getEndDate() + "'" + + ", scenarioExecution='" + getScenarioExecution() + "'" + '}'; } } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/model/ScenarioExecution.java b/simulator-starter/src/main/java/org/citrusframework/simulator/model/ScenarioExecution.java index 57ab224d6..e4d29432f 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/model/ScenarioExecution.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/model/ScenarioExecution.java @@ -16,15 +16,22 @@ package org.citrusframework.simulator.model; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OrderBy; import org.springframework.util.StringUtils; -import jakarta.persistence.*; +import java.io.Serial; import java.io.Serializable; +import java.time.Instant; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.List; /** @@ -32,27 +39,20 @@ */ @Entity public class ScenarioExecution implements Serializable { - private static final Logger LOG = LoggerFactory.getLogger(ScenarioExecution.class); - public static final String EXECUTION_ID = "scenarioExecutionId"; + @Serial + private static final long serialVersionUID = 2L; - public enum Status { - ACTIVE, - SUCCESS, - FAILED - } + public static final String EXECUTION_ID = "scenarioExecutionId"; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "EXECUTION_ID") private Long executionId; - @Temporal(TemporalType.TIMESTAMP) @Column(nullable = false) - private Date startDate; + private Instant startDate; - @Temporal(TemporalType.TIMESTAMP) - private Date endDate; + private Instant endDate; @Column(nullable = false) private String scenarioName; @@ -63,16 +63,18 @@ public enum Status { @Column(length = 1000) private String errorMessage; - @OneToMany(mappedBy = "scenarioExecution", cascade = CascadeType.ALL, orphanRemoval = true) @OrderBy("name ASC") + @OneToMany(mappedBy = "scenarioExecution", cascade = CascadeType.ALL, orphanRemoval = true) + @JsonIgnoreProperties(value = { "scenarioExecution" }, allowSetters = true) private List scenarioParameters = new ArrayList<>(); - @OneToMany(mappedBy = "scenarioExecution", cascade = CascadeType.ALL, orphanRemoval = true) @OrderBy("actionId ASC") + @OneToMany(mappedBy = "scenarioExecution", cascade = CascadeType.ALL, orphanRemoval = true) private List scenarioActions = new ArrayList<>(); - @OneToMany(mappedBy = "scenarioExecution", cascade = CascadeType.ALL, orphanRemoval = true) @OrderBy("messageId ASC") + @OneToMany(mappedBy = "scenarioExecution", cascade = CascadeType.ALL, orphanRemoval = true) + @JsonIgnoreProperties(value = { "headers", "scenarioExecution" }, allowSetters = true) private List scenarioMessages = new ArrayList<>(); public Long getExecutionId() { @@ -83,19 +85,19 @@ public void setExecutionId(Long executionId) { this.executionId = executionId; } - public Date getEndDate() { + public Instant getEndDate() { return endDate; } - public void setEndDate(Date endDate) { + public void setEndDate(Instant endDate) { this.endDate = endDate; } - public Date getStartDate() { + public Instant getStartDate() { return startDate; } - public void setStartDate(Date startDate) { + public void setStartDate(Instant startDate) { this.startDate = startDate; } @@ -119,7 +121,7 @@ public String getErrorMessage() { return errorMessage; } - public void setErrorMessage(String errorMessage) { + public void setErrorMessage(String errorMessage) throws ErrorMessageTruncationException { this.errorMessage = errorMessage; if(StringUtils.hasLength(this.errorMessage)) { try { @@ -129,7 +131,7 @@ public void setErrorMessage(String errorMessage) { this.errorMessage = this.errorMessage.substring(0, size); } } catch (SecurityException | NoSuchFieldException ex) { - LOG.error(String.format("Error truncating error message", errorMessage), ex); + throw new ErrorMessageTruncationException(String.format("Error truncating error message '%s'!", errorMessage), ex); } } } @@ -179,15 +181,27 @@ public void removeScenarioMessage(Message scenarioMessage) { @Override public String toString() { return "ScenarioExecution{" + - "endDate=" + endDate + - ", executionId=" + executionId + - ", startDate=" + startDate + - ", scenarioName='" + scenarioName + '\'' + - ", status=" + status + - ", errorMessage='" + errorMessage + '\'' + - ", scenarioParameters=" + scenarioParameters + - ", scenarioActions=" + scenarioActions + - ", scenarioMessages=" + scenarioMessages + + "executionId='" + getExecutionId() + "'" + + ", startDate='" + getStartDate() + "'" + + ", endDate='" + getEndDate() + "'" + + ", scenarioName='" + getScenarioName() + "'" + + ", status='" + getStatus() + "'" + + ", errorMessage='" + getErrorMessage() + "'" + + ", scenarioParameters='" + getScenarioParameters() + "'" + + ", scenarioActions='" + getScenarioActions() + "'" + + ", scenarioMessages='" + getScenarioMessages() + "'" + '}'; } + + public enum Status { + ACTIVE, + SUCCESS, + FAILED + } + + public class ErrorMessageTruncationException extends Throwable { + public ErrorMessageTruncationException(String errorMessage, Exception exception) { + super(errorMessage, exception); + } + } } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/model/ScenarioParameter.java b/simulator-starter/src/main/java/org/citrusframework/simulator/model/ScenarioParameter.java index a0402f4e2..55d1b6e38 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/model/ScenarioParameter.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/model/ScenarioParameter.java @@ -18,7 +18,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import jakarta.persistence.*; + +import java.io.Serial; import java.io.Serializable; import java.util.List; @@ -26,32 +29,31 @@ * JPA entity for representing a scenario parameter */ @Entity -public class ScenarioParameter implements Serializable { - public enum ControlType { - TEXTBOX, - TEXTAREA, - DROPDOWN - } +public class ScenarioParameter extends AbstractAuditingEntity implements Serializable { + + @Serial + private static final long serialVersionUID = 2L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "PARAMETER_ID") private Long parameterId; - @JsonIgnore - @ManyToOne - private ScenarioExecution scenarioExecution; - @Column(nullable = false) private String name; @Column(nullable = false) private ControlType controlType; - @Column(columnDefinition = "CLOB", name = "`value`") @Lob + @Column(columnDefinition = "CLOB", name = "`value`") private String value; + + @ManyToOne + @JsonIgnoreProperties(value = { "scenarioParameters", "scenarioActions", "scenarioMessages" }, allowSetters = true) + private ScenarioExecution scenarioExecution; + private boolean required; + private String label; @Transient @@ -65,14 +67,6 @@ public void setParameterId(Long parameterId) { this.parameterId = parameterId; } - public ScenarioExecution getScenarioExecution() { - return scenarioExecution; - } - - public void setScenarioExecution(ScenarioExecution scenarioExecution) { - this.scenarioExecution = scenarioExecution; - } - public String getLabel() { return label; } @@ -113,6 +107,14 @@ public void setValue(String value) { this.value = value; } + public ScenarioExecution getScenarioExecution() { + return scenarioExecution; + } + + public void setScenarioExecution(ScenarioExecution scenarioExecution) { + this.scenarioExecution = scenarioExecution; + } + public boolean isRequired() { return required; } @@ -124,13 +126,21 @@ public void setRequired(boolean required) { @Override public String toString() { return "ScenarioParameter{" + - "controlType=" + controlType + - ", parameterId=" + parameterId + - ", name='" + name + '\'' + - ", value='" + value + '\'' + - ", required=" + required + - ", label='" + label + '\'' + - ", options=" + options + + ", parameterId='" + getParameterId() + + ", createdDate='" + getCreatedDate() + + ", name='" + getName() + '\'' + + ", controlType='" + getControlType() + + ", value='" + getValue() + '\'' + + ", options='" + getScenarioExecution() + + ", required='" + isRequired() + + ", label='" + getLabel() + + ", options='" + getOptions() + '}'; } + + public enum ControlType { + TEXTBOX, + TEXTAREA, + DROPDOWN + } } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/repository/ScenarioExecutionRepository.java b/simulator-starter/src/main/java/org/citrusframework/simulator/repository/ScenarioExecutionRepository.java index f43aefa21..ff5f4ae77 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/repository/ScenarioExecutionRepository.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/repository/ScenarioExecutionRepository.java @@ -22,7 +22,7 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import java.util.Date; +import java.time.Instant; import java.util.List; /** @@ -34,5 +34,5 @@ public interface ScenarioExecutionRepository extends CrudRepository findByStatusOrderByStartDateDesc(@Param("status") ScenarioExecution.Status status); - List findByStartDateBetweenOrderByStartDateDesc(@Param("fromDate") Date fromDate, @Param("toDate") Date toDate, Pageable pageable); + List findByStartDateBetweenOrderByStartDateDesc(@Param("fromDate") Instant fromDate, @Param("toDate") Instant toDate, Pageable pageable); } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/repository/ScenarioExecutionRepositoryImpl.java b/simulator-starter/src/main/java/org/citrusframework/simulator/repository/ScenarioExecutionRepositoryImpl.java index 0c9ccb821..05aea5d87 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/repository/ScenarioExecutionRepositoryImpl.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/repository/ScenarioExecutionRepositoryImpl.java @@ -22,12 +22,11 @@ public class ScenarioExecutionRepositoryImpl extends AbstractRepository implements ScenarioExecutionRepositoryCustom { @Autowired - private EntityManager em; + private EntityManager entityManager; @Override public List find(ScenarioExecutionFilter filter) { - - CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder(); + CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery criteriaQuery = criteriaBuilder.createQuery(ScenarioExecution.class); Root scenarioExecution = criteriaQuery.from(ScenarioExecution.class); @@ -41,7 +40,7 @@ public List find(ScenarioExecutionFilter filter) { criteriaQuery.orderBy(criteriaBuilder.desc(scenarioExecution.get("startDate"))); - TypedQuery messageQuery = em.createQuery(criteriaQuery.distinct(true)); + TypedQuery messageQuery = entityManager.createQuery(criteriaQuery.distinct(true)); addPagingRestrictions(filter, messageQuery); return messageQuery.getResultList(); @@ -143,15 +142,13 @@ private void addPayloadPredicate(ScenarioExecutionFilter filter, CriteriaBuilder * @param predicates */ private void addDatePredicates(ScenarioExecutionFilter filter, CriteriaBuilder criteriaBuilder, - Root scenarioExecution, List predicates) { + Root scenarioExecution, List predicates) { if (filter.getFromDate() != null) { - predicates.add( - criteriaBuilder.greaterThanOrEqualTo(scenarioExecution.get("startDate"), filter.getFromDate())); + predicates.add(criteriaBuilder.greaterThanOrEqualTo(scenarioExecution.get("startDate"), filter.getFromDate())); } if (filter.getToDate() != null) { predicates.add(criteriaBuilder.lessThanOrEqualTo(scenarioExecution.get("endDate"), filter.getToDate())); } } - } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/service/ActivityService.java b/simulator-starter/src/main/java/org/citrusframework/simulator/service/ActivityService.java index 6f0911317..6e8a64b82 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/service/ActivityService.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/service/ActivityService.java @@ -16,20 +16,6 @@ package org.citrusframework.simulator.service; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.ZoneOffset; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; - import jakarta.transaction.Transactional; import org.citrusframework.TestAction; import org.citrusframework.TestCase; @@ -40,11 +26,27 @@ import org.citrusframework.simulator.model.ScenarioExecutionFilter; import org.citrusframework.simulator.model.ScenarioParameter; import org.citrusframework.simulator.repository.ScenarioExecutionRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; + /** * Service for persisting and retrieving {@link ScenarioExecution} data. */ @@ -52,6 +54,8 @@ @Transactional public class ActivityService { + private static final Logger logger = LoggerFactory.getLogger(ActivityService.class); + @Autowired private QueryFilterAdapterFactory queryFilterAdapterFactory; @@ -72,19 +76,19 @@ public ActivityService(ScenarioExecutionRepository scenarioExecutionRepository, * @return the new {@link ScenarioExecution} */ public ScenarioExecution createExecutionScenario(String scenarioName, Collection scenarioParameters) { - ScenarioExecution ts = new ScenarioExecution(); - ts.setScenarioName(scenarioName); - ts.setStartDate(getTimeNow()); - ts.setStatus(ScenarioExecution.Status.ACTIVE); + ScenarioExecution scenarioExecution = new ScenarioExecution(); + scenarioExecution.setScenarioName(scenarioName); + scenarioExecution.setStartDate(getTimeNow()); + scenarioExecution.setEndDate(getTimeNow()); + scenarioExecution.setStatus(ScenarioExecution.Status.ACTIVE); if (scenarioParameters != null) { for (ScenarioParameter tp : scenarioParameters) { - ts.addScenarioParameter(tp); + scenarioExecution.addScenarioParameter(tp); } } - ts = scenarioExecutionRepository.save(ts); - return ts; + return scenarioExecutionRepository.save(scenarioExecution); } public void completeScenarioExecutionSuccess(TestCase testCase) { @@ -114,7 +118,7 @@ public ScenarioExecution getScenarioExecutionById(Long id) { /** * Persists the message along with the scenario execution details. With the help of the {@code citrusMessageId} * a check is made to determine whether the message has already been persisted. If it has then there's nothing - * to be done and the the persisted message is simply returned. + * to be done and the persisted message is simply returned. * * @param executionId the scenario execution id * @param direction the direction of the message @@ -124,8 +128,8 @@ public ScenarioExecution getScenarioExecutionById(Long id) { * @return the already or newly persisted message */ public Message saveScenarioMessage(Long executionId, Message.Direction direction, String payload, String citrusMessageId, Map headers) { - final ScenarioExecution se = getScenarioExecutionById(executionId); - Collection messages = se.getScenarioMessages(); + final ScenarioExecution scenarioExecution = getScenarioExecutionById(executionId); + Collection messages = scenarioExecution.getScenarioMessages(); if (messages != null) { Optional message = messages.stream() .filter(scenarioMessage -> scenarioMessage.getCitrusMessageId().equalsIgnoreCase(citrusMessageId)) @@ -136,7 +140,7 @@ public Message saveScenarioMessage(Long executionId, Message.Direction direction } } final Message message = messageService.saveMessage(direction, payload, citrusMessageId, headers); - se.addScenarioMessage(message); + scenarioExecution.addScenarioMessage(message); return message; } @@ -144,14 +148,14 @@ public void clearScenarioExecutions() { scenarioExecutionRepository.deleteAll(); } - public Collection getScenarioExecutionsByStartDate(Date fromDate, Date toDate, Integer page, Integer size) { - Date calcFromDate = fromDate; + public Collection getScenarioExecutionsByStartDate(Instant fromDate, Instant toDate, Integer page, Integer size) { + Instant calcFromDate = fromDate; if (calcFromDate == null) { - calcFromDate = Date.from(LocalDate.now().atStartOfDay().toInstant(ZoneOffset.UTC)); + calcFromDate = LocalDate.now().atStartOfDay().toInstant(ZoneOffset.UTC); } - Date calcToDate = toDate; + Instant calcToDate = toDate; if (calcToDate == null) { - calcToDate = Date.from(LocalDate.now().plusDays(1).atStartOfDay().toInstant(ZoneOffset.UTC)); + calcToDate = LocalDate.now().plusDays(1).atStartOfDay().toInstant(ZoneOffset.UTC); } Integer calcPage = page; @@ -170,14 +174,19 @@ public Collection getScenarioExecutionsByStartDate(Date fromD } private void completeScenarioExecution(ScenarioExecution.Status status, TestCase testCase, Throwable cause) { - ScenarioExecution te = lookupScenarioExecution(testCase); - te.setEndDate(getTimeNow()); - te.setStatus(status); + ScenarioExecution scenarioExecution = lookupScenarioExecution(testCase); + scenarioExecution.setEndDate(getTimeNow()); + scenarioExecution.setStatus(status); if (cause != null) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - cause.printStackTrace(pw); - te.setErrorMessage(sw.toString()); + StringWriter stringWriter = new StringWriter(); + PrintWriter printWriter = new PrintWriter(stringWriter); + cause.printStackTrace(printWriter); + + try { + scenarioExecution.setErrorMessage(stringWriter.toString()); + } catch (ScenarioExecution.ErrorMessageTruncationException e) { + logger.error("Error completing scenario execution!", e); + } } } @@ -186,11 +195,11 @@ public void createTestAction(TestCase testCase, TestAction testAction) { return; } - ScenarioExecution te = lookupScenarioExecution(testCase); - ScenarioAction ta = new ScenarioAction(); - ta.setName(testAction.getName()); - ta.setStartDate(getTimeNow()); - te.addScenarioAction(ta); + ScenarioExecution scenarioExecution = lookupScenarioExecution(testCase); + ScenarioAction scenarioAction = new ScenarioAction(); + scenarioAction.setName(testAction.getName()); + scenarioAction.setStartDate(getTimeNow()); + scenarioExecution.addScenarioAction(scenarioAction); } public void completeTestAction(TestCase testCase, TestAction testAction) { @@ -228,8 +237,7 @@ private long lookupScenarioExecutionId(TestCase testCase) { return Long.parseLong(testCase.getVariableDefinitions().get(ScenarioExecution.EXECUTION_ID).toString()); } - private Date getTimeNow() { - return Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant()); + private Instant getTimeNow() { + return LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant(); } - } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/service/MessageService.java b/simulator-starter/src/main/java/org/citrusframework/simulator/service/MessageService.java index cfe76efb8..5fd0355b3 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/service/MessageService.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/service/MessageService.java @@ -16,8 +16,9 @@ package org.citrusframework.simulator.service; -import org.citrusframework.exceptions.CitrusRuntimeException; +import jakarta.transaction.Transactional; import org.apache.commons.lang3.StringUtils; +import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.simulator.model.Message; import org.citrusframework.simulator.model.MessageFilter; import org.citrusframework.simulator.model.MessageHeader; @@ -25,10 +26,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import jakarta.transaction.Transactional; -import java.time.LocalDateTime; -import java.time.ZoneOffset; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -52,7 +49,6 @@ public MessageService(MessageRepository messageRepository, QueryFilterAdapterFac public Message saveMessage(Message.Direction direction, String payload, String citrusMessageId, Map headers) { Message message = new Message(); - message.setDate(now()); message.setDirection(direction); message.setPayload(payload); message.setCitrusMessageId(citrusMessageId); @@ -80,9 +76,4 @@ public List getMessagesMatchingFilter(MessageFilter filter) { public void clearMessages() { messageRepository.deleteAll(); } - - private Date now() { - return Date.from(LocalDateTime.now().atZone(ZoneOffset.UTC).toInstant()); - } - } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/service/QueryFilterAdapterFactory.java b/simulator-starter/src/main/java/org/citrusframework/simulator/service/QueryFilterAdapterFactory.java index c659a55bc..3e88154a1 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/service/QueryFilterAdapterFactory.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/service/QueryFilterAdapterFactory.java @@ -1,16 +1,16 @@ package org.citrusframework.simulator.service; -import org.citrusframework.simulator.config.SimulatorConfigurationProperties; -import org.citrusframework.simulator.model.MessageFilter; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.citrusframework.simulator.config.SimulatorConfigurationProperties; +import org.citrusframework.simulator.model.MessageFilter; import org.springframework.aop.framework.ProxyFactory; + +import java.time.Instant; import java.time.LocalDate; import java.time.ZoneOffset; -import java.util.Date; import java.util.Optional; - /** * Factory for filters that provide default values. */ @@ -21,7 +21,7 @@ public class QueryFilterAdapterFactory { public QueryFilterAdapterFactory(SimulatorConfigurationProperties simulatorConfiguration) { this.simulatorConfiguration = simulatorConfiguration; } - + /** * Creates a filter that provides reasonable default values for the following certain filter attributes:
* @@ -46,19 +46,18 @@ public T getQueryAdapter(T delegate) { proxyFactory.addAdvice(new DefaultValuesQueryAdvice(delegate)); return (T)proxyFactory.getProxy(); } - + private class DefaultValuesQueryAdvice implements MethodInterceptor { - + private final T delegate; public DefaultValuesQueryAdvice(T delegate) { super(); this.delegate = delegate; } - + @Override public Object invoke(MethodInvocation invocation) throws Throwable { - if ("getFromDate".equals(invocation.getMethod().getName())) { return Optional.ofNullable(invocation.getMethod().invoke(delegate)).orElse(startOfDay()); } else if ("getToDate".equals(invocation.getMethod().getName())) { @@ -71,18 +70,17 @@ public Object invoke(MethodInvocation invocation) throws Throwable { return Optional.ofNullable(delegate.getDirectionInbound()).orElse(true); } else if ("getDirectionOutbound".equals(invocation.getMethod().getName())) { return Optional.ofNullable(delegate.getDirectionOutbound()).orElse(true); - } + } + return invocation.getMethod().invoke(delegate, invocation.getArguments()); } - - private Date startOfDay() { - return Date.from(LocalDate.now().atStartOfDay().plusDays(-simulatorConfiguration.getFilterStartDayShift()) - .toInstant(ZoneOffset.UTC)); + + private Instant startOfDay() { + return LocalDate.now().atStartOfDay().minusDays(simulatorConfiguration.getFilterStartDayShift()).toInstant(ZoneOffset.UTC); } - private Date endOfDay() { - return Date.from(LocalDate.now().plusDays(1).atStartOfDay() - .toInstant(ZoneOffset.UTC)); + private Instant endOfDay() { + return LocalDate.now().plusDays(1).atStartOfDay().toInstant(ZoneOffset.UTC); } } } diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/service/MessageRepositoryTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/service/MessageRepositoryTest.java index ff5ea75b2..68b750640 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/service/MessageRepositoryTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/service/MessageRepositoryTest.java @@ -13,9 +13,13 @@ import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.testng.Assert; +import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneOffset; -import java.util.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; @DataJpaTest @ContextConfiguration(classes = { SimulatorAutoConfiguration.class }) @@ -134,9 +138,9 @@ void testFindByPayload() { @Test void testFindByAllParams() { - Date startSavingDate = now(); + Instant startSavingDate = now(); String uid = createTestMessage(); - Date endSavingDate = now(); + Instant endSavingDate = now(); // Filter by all valid MessageFilter filter = new MessageFilter(); @@ -172,8 +176,8 @@ void testPaging() { Assert.assertEquals(33, result.size()); } - private Date now() { - return Date.from(LocalDateTime.now().toInstant(ZoneOffset.UTC)); + private Instant now() { + return LocalDateTime.now().toInstant(ZoneOffset.UTC); } private String createTestMessage() { diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/service/MessageServiceTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/service/MessageServiceTest.java index 9c11f81a3..adca5d9eb 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/service/MessageServiceTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/service/MessageServiceTest.java @@ -28,9 +28,9 @@ import org.testng.Assert; import org.testng.annotations.AfterMethod; +import java.time.Instant; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.List; import static org.mockito.Mockito.when; @@ -76,8 +76,8 @@ public void shouldGetMessagesUsingDefaults() throws Exception { @Test public void shouldGetMessagesUsingNoDefaults() throws Exception { - Date dateFrom = new Date(); - Date dateTo = new Date(); + Instant dateFrom = Instant.now(); + Instant dateTo = Instant.now(); int pageNumber = 10; int pageSize = 1000; String text = "abc"; diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/service/ScenarioExecutionRepositoryTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/service/ScenarioExecutionRepositoryTest.java index d1c514cab..362aee182 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/service/ScenarioExecutionRepositoryTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/service/ScenarioExecutionRepositoryTest.java @@ -15,6 +15,7 @@ */ package org.citrusframework.simulator.service; +import jakarta.persistence.EntityManager; import org.citrusframework.DefaultTestCase; import org.citrusframework.simulator.SimulatorAutoConfiguration; import org.citrusframework.simulator.config.SimulatorConfigurationProperties; @@ -27,10 +28,16 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; -import org.testng.Assert; import org.testng.annotations.Test; -import java.util.*; +import java.time.Instant; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import static org.testng.AssertJUnit.assertEquals; @DataJpaTest @ContextConfiguration(classes = {SimulatorAutoConfiguration.class}) @@ -53,6 +60,9 @@ public class ScenarioExecutionRepositoryTest extends AbstractTestNGSpringContext @Autowired private ActivityService activityService; + @Autowired + private EntityManager entityManager; + @Autowired private ScenarioExecutionRepository scenarioExecutionRepository; @@ -69,7 +79,7 @@ void testFindByScenarioName() { ScenarioExecutionFilter queryFilter = queryFilterAdapterFactory.getQueryAdapter(scenarioExecutionFilter); - Assert.assertEquals(1, scenarioExecutionRepository.find(queryFilter).size()); + assertEquals(1, scenarioExecutionRepository.find(queryFilter).size()); } @Test @@ -87,8 +97,8 @@ void testFindByScenarioStatus() { ScenarioExecutionFilter queryFilter = queryFilterAdapterFactory.getQueryAdapter(scenarioExecutionFilter); List result = scenarioExecutionRepository.find(queryFilter); - Assert.assertEquals(1, result.size()); - Assert.assertEquals(failedScenarioExecutionId, result.get(0).getExecutionId()); + assertEquals(1, result.size()); + assertEquals(failedScenarioExecutionId, result.get(0).getExecutionId()); } @Test @@ -103,11 +113,11 @@ void testFindByHeader() { ScenarioExecutionFilter queryFilter = queryFilterAdapterFactory.getQueryAdapter(scenarioExecutionFilter); - Assert.assertEquals(1, scenarioExecutionRepository.find(queryFilter).size()); + assertEquals(1, scenarioExecutionRepository.find(queryFilter).size()); scenarioExecutionFilter.setHeaderFilter(IN_HEADER_NAME1 + ":" + inUid + "mod"); - Assert.assertEquals(0, scenarioExecutionRepository.find(queryFilter).size()); + assertEquals(0, scenarioExecutionRepository.find(queryFilter).size()); } @Test @@ -121,11 +131,11 @@ void testFindByHeaderMulti() { ScenarioExecutionFilter queryFilter = queryFilterAdapterFactory.getQueryAdapter(scenarioExecutionFilter); - Assert.assertEquals(1, scenarioExecutionRepository.find(queryFilter).size()); + assertEquals(1, scenarioExecutionRepository.find(queryFilter).size()); scenarioExecutionFilter.setHeaderFilter(IN_HEADER_NAME1 + ":" + inUid + ";" + IN_HEADER_NAME2 + ":" + inUid + "_3"); - Assert.assertEquals(0, scenarioExecutionRepository.find(queryFilter).size()); + assertEquals(0, scenarioExecutionRepository.find(queryFilter).size()); } @Test @@ -142,26 +152,26 @@ void testFindByPayload() { ScenarioExecutionFilter queryFilter = queryFilterAdapterFactory.getQueryAdapter(scenarioExecutionFilter); scenarioExecutionFilter.setContainingText(inPayload); - Assert.assertEquals(1, scenarioExecutionRepository.find(queryFilter).size()); + assertEquals(1, scenarioExecutionRepository.find(queryFilter).size()); scenarioExecutionFilter.setContainingText(inPayload + "mod"); - Assert.assertEquals(0, scenarioExecutionRepository.find(queryFilter).size()); + assertEquals(0, scenarioExecutionRepository.find(queryFilter).size()); scenarioExecutionFilter.setDirectionInbound(false); scenarioExecutionFilter.setContainingText(inPayload); - Assert.assertEquals(0, scenarioExecutionRepository.find(queryFilter).size()); + assertEquals(0, scenarioExecutionRepository.find(queryFilter).size()); scenarioExecutionFilter.setDirectionInbound(true); scenarioExecutionFilter.setContainingText(inPayload); - Assert.assertEquals(1, scenarioExecutionRepository.find(queryFilter).size()); + assertEquals(1, scenarioExecutionRepository.find(queryFilter).size()); scenarioExecutionFilter.setDirectionOutbound(true); scenarioExecutionFilter.setContainingText(outPayload); - Assert.assertEquals(1, scenarioExecutionRepository.find(queryFilter).size()); + assertEquals(1, scenarioExecutionRepository.find(queryFilter).size()); scenarioExecutionFilter.setDirectionOutbound(false); scenarioExecutionFilter.setContainingText(outPayload); - Assert.assertEquals(0, scenarioExecutionRepository.find(queryFilter).size()); + assertEquals(0, scenarioExecutionRepository.find(queryFilter).size()); } @Test @@ -178,25 +188,32 @@ void testPaging() { ScenarioExecutionFilter queryFilter = queryFilterAdapterFactory.getQueryAdapter(scenarioExecutionFilter); List result = scenarioExecutionRepository.find(queryFilter); - Assert.assertEquals(33, result.size()); + assertEquals(result.size(), 33); } @Test void testFindByDate() { + String uniquePayload = "FindByDatePayload" + UUID.randomUUID(); - Date t1 = new Date(); - String uniquePayload = "FindByDatePayload" + UUID.randomUUID().toString(); - for (int i = 0; i < 100; i++) { + Instant t1 = Instant.now(); + + int batch1Size = 100; + for (int i = 0; i < batch1Size; i++) { createTestScenarioExecution(UUID.randomUUID().toString(), uniquePayload + "-in", UUID.randomUUID().toString(), uniquePayload + "-out"); } - Date t2 = new Date(); + entityManager.flush(); + + Instant t2 = Instant.now(); - for (int i = 0; i < 50; i++) { + int batch2Size = 50; + for (int i = 0; i < batch2Size; i++) { createTestScenarioExecution(UUID.randomUUID().toString(), uniquePayload + "-in", UUID.randomUUID().toString(), uniquePayload + "-out"); } - Date t3 = new Date(); + entityManager.flush(); + + Instant t3 = Instant.now(); ScenarioExecutionFilter scenarioExecutionFilter = new ScenarioExecutionFilter(); scenarioExecutionFilter.setPageNumber(0); @@ -206,15 +223,15 @@ void testFindByDate() { scenarioExecutionFilter.setFromDate(t1); scenarioExecutionFilter.setToDate(t2); - Assert.assertEquals(100, scenarioExecutionRepository.find(queryFilter).size()); + assertEquals(batch1Size, scenarioExecutionRepository.find(queryFilter).size()); scenarioExecutionFilter.setFromDate(t1); scenarioExecutionFilter.setToDate(t3); - Assert.assertEquals(150, scenarioExecutionRepository.find(queryFilter).size()); + assertEquals(batch1Size + batch2Size, scenarioExecutionRepository.find(queryFilter).size()); scenarioExecutionFilter.setFromDate(t2); scenarioExecutionFilter.setToDate(t3); - Assert.assertEquals(50, scenarioExecutionRepository.find(queryFilter).size()); + assertEquals(batch2Size, scenarioExecutionRepository.find(queryFilter).size()); } private Long createTestScenarioExecution(String inUid, String inPayload, String outUid, String outPayload) { @@ -222,8 +239,7 @@ private Long createTestScenarioExecution(String inUid, String inPayload, String } private Long createTestScenarioExecution(String scenarioName, String inUid, String inPayload, String outUid, String outPayload, Status status) { - - Map inHeaders = new HashMap(); + Map inHeaders = new HashMap<>(); inHeaders.put(IN_HEADER_NAME1, inUid); inHeaders.put(IN_HEADER_NAME2, inUid + "_2");