diff --git a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/Message.java b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/Message.java index 8f1b6c5ca..89ec6d83d 100644 --- a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/Message.java +++ b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/Message.java @@ -24,16 +24,18 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.Index; import jakarta.persistence.Lob; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.OrderBy; +import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; import lombok.ToString; -import org.apache.commons.lang3.StringUtils; import java.io.Serial; import java.io.Serializable; @@ -44,6 +46,7 @@ import static java.util.Arrays.stream; import static lombok.AccessLevel.NONE; +import static org.apache.commons.lang3.StringUtils.isNotEmpty; /** * JPA entity for representing inbound and outbound messages @@ -51,6 +54,16 @@ @Getter @Setter @Entity +@Table( + name = "message", + indexes = { + @Index(name = "idx_message_direction", columnList = "direction"), + @Index(name = "idx_message_scenario_execution_execution_id", columnList = "scenario_execution_execution_id") + }, + uniqueConstraints = { + @UniqueConstraint(name = "uk_citrus_message_id", columnNames = {"citrus_message_id"}) + } +) @ToString public class Message extends AbstractAuditingEntity implements Serializable { @@ -106,9 +119,10 @@ public void setDirection(Direction direction) { this.direction = direction.id; } - public void addHeader(MessageHeader messageHeader) { + public Message addHeader(MessageHeader messageHeader) { headers.add(messageHeader); messageHeader.setMessage(this); + return this; } public Long getScenarioExecutionId() { @@ -197,7 +211,7 @@ public MessageBuilder headers(Map headers) { headers.entrySet().stream() .map(header -> { if (header.getValue() != null - && StringUtils.isNotEmpty(header.getValue().toString())) { + && isNotEmpty(header.getValue().toString())) { return new MessageHeader(header.getKey(), header.getValue().toString()); } else { return null; diff --git a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/MessageHeader.java b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/MessageHeader.java index 4834a77cc..023c7a20a 100644 --- a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/MessageHeader.java +++ b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/MessageHeader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2023 the original author or authors. + * Copyright 2006-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,10 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.Index; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import lombok.Getter; @@ -43,6 +45,14 @@ @Getter @Setter @Entity +@Table( + name = "message_header", + indexes = { + @Index(name = "idx_message_header_name", columnList = "name"), + @Index(name = "idx_message_header_value", columnList = "header_value"), + @Index(name = "idx_message_id", columnList = "message_id") + } +) @ToString public class MessageHeader extends AbstractAuditingEntity implements Serializable { @@ -66,7 +76,7 @@ public class MessageHeader extends AbstractAuditingEntity i @NotNull @ToString.Exclude @ManyToOne(optional = false) - @JoinColumn(nullable = false) + @JoinColumn(name = "message_id", nullable = false) @JsonIgnoreProperties(value = {"headers", "scenarioExecution"}, allowSetters = true) private Message message; diff --git a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/ScenarioAction.java b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/ScenarioAction.java index aaacd06eb..292786ec3 100644 --- a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/ScenarioAction.java +++ b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/ScenarioAction.java @@ -22,7 +22,9 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.Index; import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import jakarta.validation.constraints.NotEmpty; import lombok.Getter; import lombok.Setter; @@ -40,6 +42,12 @@ @Getter @Setter @Entity +@Table( + name = "scenario_action", + indexes = { + @Index(name = "idx_scenario_action_scenario_execution_execution_id", columnList = "scenario_execution_execution_id") + } +) @ToString public class ScenarioAction implements Serializable { diff --git a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/ScenarioExecution.java b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/ScenarioExecution.java index aa21d8259..6c17e697f 100644 --- a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/ScenarioExecution.java +++ b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/ScenarioExecution.java @@ -24,8 +24,10 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.Index; import jakarta.persistence.OneToMany; import jakarta.persistence.OrderBy; +import jakarta.persistence.Table; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; @@ -48,6 +50,14 @@ @Getter @Setter @Entity +@Table( + name = "scenario_execution", + indexes = { + @Index(name = "idx_scenario_execution_scenario_name", columnList = "scenario_name"), + @Index(name = "idx_scenario_execution_start_date", columnList = "start_date"), + @Index(name = "idx_scenario_execution_status", columnList = "status"), + } +) @ToString public class ScenarioExecution implements Serializable { @@ -119,19 +129,22 @@ public void setErrorMessage(String errorMessage) { this.errorMessage = EntityUtils.truncateToColumnSize(getClass(), "errorMessage", errorMessage); } - public void addScenarioParameter(ScenarioParameter scenarioParameter) { + public ScenarioExecution addScenarioParameter(ScenarioParameter scenarioParameter) { scenarioParameters.add(scenarioParameter); scenarioParameter.setScenarioExecution(this); + return this; } - public void addScenarioAction(ScenarioAction scenarioAction) { + public ScenarioExecution addScenarioAction(ScenarioAction scenarioAction) { scenarioActions.add(scenarioAction); scenarioAction.setScenarioExecution(this); + return this; } - public void addScenarioMessage(Message scenarioMessage) { + public ScenarioExecution addScenarioMessage(Message scenarioMessage) { scenarioMessages.add(scenarioMessage); scenarioMessage.setScenarioExecution(this); + return this; } @Override diff --git a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/ScenarioParameter.java b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/ScenarioParameter.java index ea564a59e..ee7d0cb12 100644 --- a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/ScenarioParameter.java +++ b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/ScenarioParameter.java @@ -22,8 +22,10 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.Index; import jakarta.persistence.Lob; import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import jakarta.persistence.Transient; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; @@ -45,6 +47,12 @@ @Getter @Setter @Entity +@Table( + name = "scenario_parameter", + indexes = { + @Index(name = "idx_scenario_parameter_scenario_execution_execution_id", columnList = "scenario_execution_execution_id") + } +) @ToString public class ScenarioParameter extends AbstractAuditingEntity implements Serializable { diff --git a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/TestParameter.java b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/TestParameter.java index 0fd33e4cd..124145bd3 100644 --- a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/TestParameter.java +++ b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/TestParameter.java @@ -21,9 +21,11 @@ import jakarta.persistence.Embeddable; import jakarta.persistence.EmbeddedId; import jakarta.persistence.Entity; +import jakarta.persistence.Index; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.MapsId; +import jakarta.persistence.Table; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import lombok.Getter; @@ -57,6 +59,12 @@ @Getter @Setter @Entity +@Table( + name="test_parameter", + indexes = { + @Index(name="idx_test_parameter_test_result_id", columnList = "test_result_id") + } +) @ToString public class TestParameter extends AbstractAuditingEntity implements Serializable { diff --git a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/TestResult.java b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/TestResult.java index 14d035256..2d96900bd 100644 --- a/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/TestResult.java +++ b/simulator-spring-boot/src/main/java/org/citrusframework/simulator/model/TestResult.java @@ -24,7 +24,9 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.Index; import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.Size; import lombok.Getter; @@ -56,6 +58,14 @@ @Getter @Setter @Entity +@Table( + name = "test_result", + indexes = { + @Index(name = "idx_failure_type", columnList = "failure_type"), + @Index(name = "idx_test_result_class_name", columnList = "class_name"), + @Index(name = "idx_test_result_test_name", columnList = "test_name") + } +) @ToString public class TestResult extends AbstractAuditingEntity implements Serializable { @@ -152,8 +162,10 @@ public Status getStatus() { return Status.fromId(status); } - public void addTestParameter(TestParameter testParameter) { + public TestResult addTestParameter(TestParameter testParameter) { testParameters.add(testParameter); + testParameter.setTestResult(this); + return this; } private int convertToStatus(String resultName) {