diff --git a/simulator-samples/sample-bank-service/src/main/java/org/citrusframework/simulator/sample/starter/CalculateStarter.java b/simulator-samples/sample-bank-service/src/main/java/org/citrusframework/simulator/sample/starter/CalculateStarter.java index e308b108f..9b5ecc76e 100644 --- a/simulator-samples/sample-bank-service/src/main/java/org/citrusframework/simulator/sample/starter/CalculateStarter.java +++ b/simulator-samples/sample-bank-service/src/main/java/org/citrusframework/simulator/sample/starter/CalculateStarter.java @@ -22,7 +22,6 @@ import org.citrusframework.http.client.HttpClient; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import org.citrusframework.simulator.sample.model.QueryParameter; import org.citrusframework.simulator.sample.model.Variable; import org.citrusframework.simulator.sample.scenario.CalculateIban; @@ -79,7 +78,7 @@ public Collection getScenarioParameters() { List scenarioParameters = new ArrayList<>(); // bank account (text box) - scenarioParameters.add(new ScenarioParameterBuilder() + scenarioParameters.add(ScenarioParameter.builder() .name(Variable.ACCOUNT.name()) .label("Bank Account") .required() @@ -88,7 +87,7 @@ public Collection getScenarioParameters() { .build()); // sort code (text box) - scenarioParameters.add(new ScenarioParameterBuilder() + scenarioParameters.add(ScenarioParameter.builder() .name(Variable.SORT_CODE.name()) .label("Sort Code") .required() diff --git a/simulator-samples/sample-bank-service/src/main/java/org/citrusframework/simulator/sample/starter/ValidateStarter.java b/simulator-samples/sample-bank-service/src/main/java/org/citrusframework/simulator/sample/starter/ValidateStarter.java index f23a36fce..570508847 100644 --- a/simulator-samples/sample-bank-service/src/main/java/org/citrusframework/simulator/sample/starter/ValidateStarter.java +++ b/simulator-samples/sample-bank-service/src/main/java/org/citrusframework/simulator/sample/starter/ValidateStarter.java @@ -16,12 +16,8 @@ package org.citrusframework.simulator.sample.starter; -import java.util.ArrayList; -import java.util.List; - import org.citrusframework.http.client.HttpClient; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import org.citrusframework.simulator.sample.model.QueryParameter; import org.citrusframework.simulator.sample.model.Variable; import org.citrusframework.simulator.sample.scenario.ValidateIban; @@ -32,6 +28,9 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; +import java.util.ArrayList; +import java.util.List; + import static org.citrusframework.actions.EchoAction.Builder.echo; import static org.citrusframework.http.actions.HttpActionBuilder.http; @@ -76,7 +75,7 @@ public List getScenarioParameters() { List scenarioParameters = new ArrayList<>(); // iban (text box) - scenarioParameters.add(new ScenarioParameterBuilder() + scenarioParameters.add(ScenarioParameter.builder() .name(Variable.IBAN.name()) .label("IBAN") .required() diff --git a/simulator-samples/sample-combined/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java b/simulator-samples/sample-combined/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java index 22acd0d6c..730688c87 100644 --- a/simulator-samples/sample-combined/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java +++ b/simulator-samples/sample-combined/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java @@ -21,7 +21,6 @@ import java.util.List; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import org.citrusframework.simulator.scenario.AbstractScenarioStarter; import org.citrusframework.simulator.scenario.ScenarioRunner; import org.citrusframework.simulator.scenario.Starter; @@ -49,7 +48,7 @@ public Collection getScenarioParameters() { List scenarioParameters = new ArrayList<>(); // greeting (text area) - scenarioParameters.add(new ScenarioParameterBuilder() + scenarioParameters.add(ScenarioParameter.builder() .name("payload") .label("Payload") .required() diff --git a/simulator-samples/sample-combined/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java b/simulator-samples/sample-combined/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java index 2a9155a2e..49eb660df 100644 --- a/simulator-samples/sample-combined/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java +++ b/simulator-samples/sample-combined/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java @@ -20,7 +20,6 @@ import java.util.List; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import org.citrusframework.simulator.scenario.AbstractScenarioStarter; import org.citrusframework.simulator.scenario.ScenarioRunner; import org.citrusframework.simulator.scenario.Starter; @@ -49,7 +48,7 @@ public List getScenarioParameters() { List scenarioParameters = new ArrayList<>(); // name (text box) - scenarioParameters.add(new ScenarioParameterBuilder() + scenarioParameters.add(ScenarioParameter.builder() .name("greeting") .label("Greeting Text") .required() @@ -58,7 +57,7 @@ public List getScenarioParameters() { .build()); // greeting (text area) - scenarioParameters.add(new ScenarioParameterBuilder() + scenarioParameters.add(ScenarioParameter.builder() .name("payload") .label("Payload") .required() diff --git a/simulator-samples/sample-jms-fax/src/main/java/org/citrusframework/simulator/sample/jms/async/variables/ReferenceId.java b/simulator-samples/sample-jms-fax/src/main/java/org/citrusframework/simulator/sample/jms/async/variables/ReferenceId.java index ebc062caf..1ec595dc1 100644 --- a/simulator-samples/sample-jms-fax/src/main/java/org/citrusframework/simulator/sample/jms/async/variables/ReferenceId.java +++ b/simulator-samples/sample-jms-fax/src/main/java/org/citrusframework/simulator/sample/jms/async/variables/ReferenceId.java @@ -17,7 +17,6 @@ package org.citrusframework.simulator.sample.jms.async.variables; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import java.util.UUID; @@ -44,7 +43,7 @@ public String getValue() { } public ScenarioParameter asScenarioParameter() { - return new ScenarioParameterBuilder() + return ScenarioParameter.builder() .name(REFERENCE_ID_VAR) .label("Reference Id") .required() diff --git a/simulator-samples/sample-jms-fax/src/main/java/org/citrusframework/simulator/sample/jms/async/variables/Status.java b/simulator-samples/sample-jms-fax/src/main/java/org/citrusframework/simulator/sample/jms/async/variables/Status.java index d57213d42..6616232f1 100644 --- a/simulator-samples/sample-jms-fax/src/main/java/org/citrusframework/simulator/sample/jms/async/variables/Status.java +++ b/simulator-samples/sample-jms-fax/src/main/java/org/citrusframework/simulator/sample/jms/async/variables/Status.java @@ -17,7 +17,6 @@ package org.citrusframework.simulator.sample.jms.async.variables; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import org.citrusframework.simulator.sample.jms.async.model.FaxStatusEnumType; /** @@ -37,7 +36,7 @@ public FaxStatusEnumType getValue() { } public ScenarioParameter asScenarioParameter() { - ScenarioParameterBuilder statusParameterBuilder = new ScenarioParameterBuilder() + ScenarioParameter.ScenarioParameterBuilder statusParameterBuilder = ScenarioParameter.builder() .name(Variables.STATUS_VAR) .label("Fax Status") .required() @@ -47,6 +46,7 @@ public ScenarioParameter asScenarioParameter() { for (FaxStatusEnumType value : FaxStatusEnumType.values()) { statusParameterBuilder.addOption(value.value(), value.value()); } + return statusParameterBuilder.build(); } diff --git a/simulator-samples/sample-jms-fax/src/main/java/org/citrusframework/simulator/sample/jms/async/variables/StatusMessage.java b/simulator-samples/sample-jms-fax/src/main/java/org/citrusframework/simulator/sample/jms/async/variables/StatusMessage.java index 83b3b36c2..9d53779d0 100644 --- a/simulator-samples/sample-jms-fax/src/main/java/org/citrusframework/simulator/sample/jms/async/variables/StatusMessage.java +++ b/simulator-samples/sample-jms-fax/src/main/java/org/citrusframework/simulator/sample/jms/async/variables/StatusMessage.java @@ -17,7 +17,6 @@ package org.citrusframework.simulator.sample.jms.async.variables; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import static org.citrusframework.simulator.sample.jms.async.variables.Variables.STATUS_MESSAGE_VAR; @@ -38,7 +37,7 @@ public String getValue() { } public ScenarioParameter asScenarioParameter() { - ScenarioParameterBuilder statusMessageParameterBuilder = new ScenarioParameterBuilder() + ScenarioParameter.ScenarioParameterBuilder statusMessageParameterBuilder = ScenarioParameter.builder() .name(STATUS_MESSAGE_VAR) .label("Status Message") .optional() diff --git a/simulator-samples/sample-jms/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java b/simulator-samples/sample-jms/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java index 68d04f5b3..c63f476bb 100644 --- a/simulator-samples/sample-jms/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java +++ b/simulator-samples/sample-jms/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java @@ -20,7 +20,6 @@ import java.util.List; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import org.citrusframework.simulator.scenario.AbstractScenarioStarter; import org.citrusframework.simulator.scenario.ScenarioRunner; import org.citrusframework.simulator.scenario.Starter; @@ -49,7 +48,7 @@ public List getScenarioParameters() { List scenarioParameter = new ArrayList<>(); // payload (text area) - scenarioParameter.add(new ScenarioParameterBuilder() + scenarioParameter.add(ScenarioParameter.builder() .name("payload") .label("Payload") .required() diff --git a/simulator-samples/sample-jms/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java b/simulator-samples/sample-jms/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java index a94ed6b64..6b7331ad1 100644 --- a/simulator-samples/sample-jms/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java +++ b/simulator-samples/sample-jms/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java @@ -20,7 +20,6 @@ import java.util.List; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import org.citrusframework.simulator.scenario.AbstractScenarioStarter; import org.citrusframework.simulator.scenario.ScenarioRunner; import org.citrusframework.simulator.scenario.Starter; @@ -49,7 +48,7 @@ public List getScenarioParameters() { List scenarioParameter = new ArrayList<>(); // greeting (text box) - scenarioParameter.add(new ScenarioParameterBuilder() + scenarioParameter.add(ScenarioParameter.builder() .name("greeting") .label("Greeting Text") .required() @@ -58,7 +57,7 @@ public List getScenarioParameters() { .build()); // payload (text area) - scenarioParameter.add(new ScenarioParameterBuilder() + scenarioParameter.add(ScenarioParameter.builder() .name("payload") .label("Payload") .required() diff --git a/simulator-samples/sample-mail/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java b/simulator-samples/sample-mail/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java index 51c52007f..368da1546 100644 --- a/simulator-samples/sample-mail/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java +++ b/simulator-samples/sample-mail/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java @@ -20,7 +20,6 @@ import java.util.List; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import org.citrusframework.simulator.scenario.AbstractScenarioStarter; import org.citrusframework.simulator.scenario.ScenarioRunner; import org.citrusframework.simulator.scenario.Starter; @@ -49,7 +48,7 @@ public List getScenarioParameters() { List scenarioParameter = new ArrayList<>(); // payload (text area) - scenarioParameter.add(new ScenarioParameterBuilder() + scenarioParameter.add(ScenarioParameter.builder() .name("payload") .label("Payload") .required() diff --git a/simulator-samples/sample-mail/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java b/simulator-samples/sample-mail/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java index a94ed6b64..6b7331ad1 100644 --- a/simulator-samples/sample-mail/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java +++ b/simulator-samples/sample-mail/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java @@ -20,7 +20,6 @@ import java.util.List; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import org.citrusframework.simulator.scenario.AbstractScenarioStarter; import org.citrusframework.simulator.scenario.ScenarioRunner; import org.citrusframework.simulator.scenario.Starter; @@ -49,7 +48,7 @@ public List getScenarioParameters() { List scenarioParameter = new ArrayList<>(); // greeting (text box) - scenarioParameter.add(new ScenarioParameterBuilder() + scenarioParameter.add(ScenarioParameter.builder() .name("greeting") .label("Greeting Text") .required() @@ -58,7 +57,7 @@ public List getScenarioParameters() { .build()); // payload (text area) - scenarioParameter.add(new ScenarioParameterBuilder() + scenarioParameter.add(ScenarioParameter.builder() .name("payload") .label("Payload") .required() diff --git a/simulator-samples/sample-rest/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java b/simulator-samples/sample-rest/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java index 6a4365c5a..4e095f41e 100644 --- a/simulator-samples/sample-rest/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java +++ b/simulator-samples/sample-rest/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java @@ -21,7 +21,6 @@ import java.util.List; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import org.citrusframework.simulator.scenario.AbstractScenarioStarter; import org.citrusframework.simulator.scenario.ScenarioRunner; import org.citrusframework.simulator.scenario.Starter; @@ -50,7 +49,7 @@ public Collection getScenarioParameters() { List scenarioParameter = new ArrayList<>(); // greeting (text area) - scenarioParameter.add(new ScenarioParameterBuilder() + scenarioParameter.add(ScenarioParameter.builder() .name("payload") .label("Payload") .required() diff --git a/simulator-samples/sample-rest/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java b/simulator-samples/sample-rest/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java index 15cf1aa8f..8e1fbf7c3 100644 --- a/simulator-samples/sample-rest/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java +++ b/simulator-samples/sample-rest/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java @@ -20,7 +20,6 @@ import java.util.List; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import org.citrusframework.simulator.scenario.AbstractScenarioStarter; import org.citrusframework.simulator.scenario.ScenarioRunner; import org.citrusframework.simulator.scenario.Starter; @@ -49,7 +48,7 @@ public List getScenarioParameters() { List scenarioParameter = new ArrayList<>(); // name (text box) - scenarioParameter.add(new ScenarioParameterBuilder() + scenarioParameter.add(ScenarioParameter.builder() .name("greeting") .label("Greeting Text") .required() @@ -58,7 +57,7 @@ public List getScenarioParameters() { .build()); // greeting (text area) - scenarioParameter.add(new ScenarioParameterBuilder() + scenarioParameter.add(ScenarioParameter.builder() .name("payload") .label("Payload") .required() diff --git a/simulator-samples/sample-ws-client/src/main/java/org/citrusframework/simulator/sample/variables/Name.java b/simulator-samples/sample-ws-client/src/main/java/org/citrusframework/simulator/sample/variables/Name.java index b9cbb6ab0..6007166d8 100644 --- a/simulator-samples/sample-ws-client/src/main/java/org/citrusframework/simulator/sample/variables/Name.java +++ b/simulator-samples/sample-ws-client/src/main/java/org/citrusframework/simulator/sample/variables/Name.java @@ -17,7 +17,6 @@ package org.citrusframework.simulator.sample.variables; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import java.util.UUID; @@ -44,7 +43,7 @@ public String getValue() { } public ScenarioParameter asScenarioParameter() { - return new ScenarioParameterBuilder() + return ScenarioParameter.builder() .name(NAME_VAR) .label("Enter your name") .required() diff --git a/simulator-samples/sample-ws/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java b/simulator-samples/sample-ws/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java index b770ec95e..cd0845665 100644 --- a/simulator-samples/sample-ws/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java +++ b/simulator-samples/sample-ws/src/main/java/org/citrusframework/simulator/sample/starter/GoodByeStarter.java @@ -21,7 +21,6 @@ import java.util.List; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import org.citrusframework.simulator.scenario.AbstractScenarioStarter; import org.citrusframework.simulator.scenario.ScenarioRunner; import org.citrusframework.simulator.scenario.Starter; @@ -50,7 +49,7 @@ public Collection getScenarioParameters() { List scenarioParameter = new ArrayList<>(); // name (text box) - scenarioParameter.add(new ScenarioParameterBuilder() + scenarioParameter.add(ScenarioParameter.builder() .name("name") .label("Name") .required() @@ -59,7 +58,7 @@ public Collection getScenarioParameters() { .build()); // greeting (text area) - scenarioParameter.add(new ScenarioParameterBuilder() + scenarioParameter.add(ScenarioParameter.builder() .name("payload") .label("Payload") .required() diff --git a/simulator-samples/sample-ws/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java b/simulator-samples/sample-ws/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java index b2101346a..7ed5cf383 100644 --- a/simulator-samples/sample-ws/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java +++ b/simulator-samples/sample-ws/src/main/java/org/citrusframework/simulator/sample/starter/HelloStarter.java @@ -21,7 +21,6 @@ import java.util.List; import org.citrusframework.simulator.model.ScenarioParameter; -import org.citrusframework.simulator.model.ScenarioParameterBuilder; import org.citrusframework.simulator.scenario.AbstractScenarioStarter; import org.citrusframework.simulator.scenario.ScenarioRunner; import org.citrusframework.simulator.scenario.Starter; @@ -45,7 +44,7 @@ public Collection getScenarioParameters() { List scenarioParameter = new ArrayList<>(); // title (dropdown) - scenarioParameter.add(new ScenarioParameterBuilder() + scenarioParameter.add(ScenarioParameter.builder() .name("title") .label("Title") .required() @@ -57,7 +56,7 @@ public Collection getScenarioParameters() { .build()); // firstname (text box) - scenarioParameter.add(new ScenarioParameterBuilder() + scenarioParameter.add(ScenarioParameter.builder() .name("firstname") .label("First Name") .required() @@ -66,7 +65,7 @@ public Collection getScenarioParameters() { .build()); // lastname (text box) - scenarioParameter.add(new ScenarioParameterBuilder() + scenarioParameter.add(ScenarioParameter.builder() .name("lastname") .label("Last Name") .required() @@ -76,7 +75,7 @@ public Collection getScenarioParameters() { // greeting (text area) - scenarioParameter.add(new ScenarioParameterBuilder() + scenarioParameter.add(ScenarioParameter.builder() .name("greeting") .label("Greeting") .required() 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 59babc111..5f4156b97 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 @@ -57,6 +57,7 @@ public class Message extends AbstractAuditingEntity implements Se /** * Actual direction as a numerical representation of {@link Direction} */ + @NotNull @Column(nullable = false, updatable = false) private Integer direction = Direction.UNKNOWN.getId(); 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 51797289a..3c7a76376 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 @@ -27,6 +27,7 @@ import jakarta.persistence.OneToMany; import jakarta.persistence.OrderBy; import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import org.springframework.util.StringUtils; @@ -66,6 +67,7 @@ public class ScenarioExecution implements Serializable { /** * Actual status as a numerical representation of {@link Status} */ + @NotNull @Column(nullable = false) private Integer status = Status.UNKNOWN.getId(); 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 311d4cbaf..78be9133e 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 @@ -26,8 +26,11 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.Transient; import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; + import java.io.Serial; import java.io.Serializable; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -52,15 +55,17 @@ public class ScenarioParameter extends AbstractAuditingEntity options; + private List options = new ArrayList<>(); + + public static ScenarioParameterBuilder builder() { + return new ScenarioParameterBuilder(); + } public Long getParameterId() { return parameterId; @@ -133,14 +142,15 @@ public void setRequired(boolean required) { @Override public String toString() { return "ScenarioParameter{" + - ", parameterId='" + getParameterId() + "'" + - ", createdDate='" + getCreatedDate() + "'" + - ", name='" + getName() + "'" + "'" + - ", controlType='" + getControlType() + "'" + - ", value='" + getValue() + "'" + - ", required='" + isRequired() + "'" + - ", label='" + getLabel() + "'" + - "}"; + ", parameterId='" + getParameterId() + "'" + + ", name='" + getName() + "'" + "'" + + ", controlType='" + getControlType() + "'" + + ", value='" + getValue() + "'" + + ", required='" + isRequired() + "'" + + ", label='" + getLabel() + "'" + + ", createdDate='" + getCreatedDate() + "'" + + ", lastModifiedDate='" + getLastModifiedDate() + "'" + + "}"; } public enum ControlType { @@ -164,4 +174,64 @@ public static ControlType fromId(int id) { .orElse(ControlType.UNKNOWN); } } + + public static class ScenarioParameterBuilder extends AuditingEntityBuilder { + + private final ScenarioParameter scenarioParameter = new ScenarioParameter(); + + @Override + protected ScenarioParameter getEntity() { + return scenarioParameter; + } + + public ScenarioParameterBuilder name(String name) { + scenarioParameter.name = name; + return this; + } + + public ScenarioParameterBuilder controlType(ControlType controlType) { + scenarioParameter.controlType = controlType.getId(); + return this; + } + + public ScenarioParameterBuilder textbox() { + scenarioParameter.controlType = ScenarioParameter.ControlType.TEXTBOX.getId(); + return this; + } + + public ScenarioParameterBuilder textarea() { + scenarioParameter.controlType = ScenarioParameter.ControlType.TEXTAREA.getId(); + return this; + } + + public ScenarioParameterBuilder dropdown() { + scenarioParameter.controlType = ScenarioParameter.ControlType.DROPDOWN.getId(); + return this; + } + + public ScenarioParameterBuilder value(String value) { + scenarioParameter.value = value; + return this; + } + + public ScenarioParameterBuilder required() { + scenarioParameter.required = true; + return this; + } + + public ScenarioParameterBuilder optional() { + scenarioParameter.required = false; + return this; + } + + public ScenarioParameterBuilder label(String label) { + scenarioParameter.label = label; + return this; + } + + public ScenarioParameterBuilder addOption(String key, String value) { + scenarioParameter.options.add(new ScenarioParameterOption(key, value)); + return this; + } + } } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/model/ScenarioParameterBuilder.java b/simulator-starter/src/main/java/org/citrusframework/simulator/model/ScenarioParameterBuilder.java deleted file mode 100644 index c1dd2164d..000000000 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/model/ScenarioParameterBuilder.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2006-2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.citrusframework.simulator.model; - -import java.util.ArrayList; -import java.util.List; - -public class ScenarioParameterBuilder { - private ScenarioParameter.ControlType controlType = ScenarioParameter.ControlType.TEXTBOX; - private String label; - private String name; - private List options = new ArrayList<>(); - private boolean required = true; - private String value = ""; - - public ScenarioParameterBuilder textbox() { - this.controlType = ScenarioParameter.ControlType.TEXTBOX; - return this; - } - - public ScenarioParameterBuilder dropdown() { - this.controlType = ScenarioParameter.ControlType.DROPDOWN; - return this; - } - - public ScenarioParameterBuilder textarea() { - this.controlType = ScenarioParameter.ControlType.TEXTAREA; - return this; - } - - public ScenarioParameterBuilder label(String label) { - this.label = label; - return this; - } - - public ScenarioParameterBuilder name(String name) { - this.name = name; - return this; - } - - public ScenarioParameterBuilder addOption(String key, String value) { - this.options.add(new ScenarioParameterOption(key, value)); - return this; - } - - public ScenarioParameterBuilder required() { - this.required = true; - return this; - } - - public ScenarioParameterBuilder optional() { - this.required = false; - return this; - } - - public ScenarioParameterBuilder value(String value) { - this.value = value; - return this; - } - - public ScenarioParameter build() { - ScenarioParameter tp = new ScenarioParameter(); - tp.setControlType(controlType); - tp.setLabel(label); - tp.setName(name); - tp.setOptions(options); - tp.setRequired(required); - tp.setValue(value); - return tp; - } -} diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/repository/MessageHeaderRepository.java b/simulator-starter/src/main/java/org/citrusframework/simulator/repository/MessageHeaderRepository.java index ba61ebe2e..f5b59f9aa 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/repository/MessageHeaderRepository.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/repository/MessageHeaderRepository.java @@ -14,7 +14,7 @@ import java.util.Optional; /** - * Spring Data JPA repository for the MessageHeader entity. + * Spring Data JPA repository for the {@link MessageHeader} entity. */ @Repository public interface MessageHeaderRepository extends JpaRepository, JpaSpecificationExecutor { diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/repository/ScenarioActionRepository.java b/simulator-starter/src/main/java/org/citrusframework/simulator/repository/ScenarioActionRepository.java index 990374b18..e33a81d53 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/repository/ScenarioActionRepository.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/repository/ScenarioActionRepository.java @@ -13,7 +13,7 @@ import java.util.Optional; /** - * Spring Data JPA repository for the ScenarioAction entity. + * Spring Data JPA repository for the {@link ScenarioAction} entity. */ @Repository public interface ScenarioActionRepository extends JpaRepository, JpaSpecificationExecutor { @@ -21,23 +21,12 @@ default Optional findOneWithEagerRelationships(Long id) { return this.findOneWithToOneRelationships(id); } - default List findAllWithEagerRelationships() { - return this.findAllWithToOneRelationships(); - } - - default Page findAllWithEagerRelationships(Pageable pageable) { - return this.findAllWithToOneRelationships(pageable); - } - @Query( value = "select scenarioAction from ScenarioAction scenarioAction left join fetch scenarioAction.scenarioExecution", countQuery = "select count(scenarioAction) from ScenarioAction scenarioAction" ) Page findAllWithToOneRelationships(Pageable pageable); - @Query("select scenarioAction from ScenarioAction scenarioAction left join fetch scenarioAction.scenarioExecution") - List findAllWithToOneRelationships(); - @Query( "select scenarioAction from ScenarioAction scenarioAction left join fetch scenarioAction.scenarioExecution where scenarioAction.actionId =:actionId" ) 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 701e9ac66..e072da415 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 @@ -6,7 +6,7 @@ import org.springframework.stereotype.Repository; /** - * Spring Data JPA repository for the ScenarioExecution entity. + * Spring Data JPA repository for the {@link ScenarioExecution} entity. */ @Repository public interface ScenarioExecutionRepository extends JpaRepository, JpaSpecificationExecutor {} diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/repository/ScenarioParameterRepository.java b/simulator-starter/src/main/java/org/citrusframework/simulator/repository/ScenarioParameterRepository.java new file mode 100644 index 000000000..b35697e83 --- /dev/null +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/repository/ScenarioParameterRepository.java @@ -0,0 +1,38 @@ +package org.citrusframework.simulator.repository; + +import org.citrusframework.simulator.model.ScenarioParameter; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; + +/** + * Spring Data JPA repository for the {@link ScenarioParameter} entity. + */ +@Repository +public interface ScenarioParameterRepository extends JpaRepository, JpaSpecificationExecutor { + default Optional findOneWithEagerRelationships(Long id) { + return this.findOneWithToOneRelationships(id); + } + + default Page findAllWithEagerRelationships(Pageable pageable) { + return this.findAllWithToOneRelationships(pageable); + } + + @Query( + value = "select scenarioParameter from ScenarioParameter scenarioParameter left join fetch scenarioParameter.scenarioExecution", + countQuery = "select count(scenarioParameter) from ScenarioParameter scenarioParameter" + ) + Page findAllWithToOneRelationships(Pageable pageable); + + @Query( + "select scenarioParameter from ScenarioParameter scenarioParameter left join fetch scenarioParameter.scenarioExecution where scenarioParameter.id =:id" + ) + Optional findOneWithToOneRelationships(@Param("id") Long id); +} diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/service/ScenarioExecutionQueryService.java b/simulator-starter/src/main/java/org/citrusframework/simulator/service/ScenarioExecutionQueryService.java index e56fef582..a6dab26d7 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/service/ScenarioExecutionQueryService.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/service/ScenarioExecutionQueryService.java @@ -2,10 +2,10 @@ import jakarta.persistence.criteria.JoinType; import org.citrusframework.simulator.model.Message_; -import org.citrusframework.simulator.model.ScenarioAction; import org.citrusframework.simulator.model.ScenarioAction_; import org.citrusframework.simulator.model.ScenarioExecution; import org.citrusframework.simulator.model.ScenarioExecution_; +import org.citrusframework.simulator.model.ScenarioParameter_; import org.citrusframework.simulator.repository.ScenarioExecutionRepository; import org.citrusframework.simulator.service.criteria.ScenarioExecutionCriteria; import org.slf4j.Logger; @@ -125,6 +125,15 @@ protected Specification createSpecification(ScenarioExecution ) ); } + if (criteria.getScenarioParametersId() != null) { + specification = + specification.and( + buildSpecification( + criteria.getScenarioParametersId(), + root -> root.join(ScenarioExecution_.scenarioParameters, JoinType.LEFT).get(ScenarioParameter_.parameterId) + ) + ); + } } return specification; } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/service/ScenarioParameterQueryService.java b/simulator-starter/src/main/java/org/citrusframework/simulator/service/ScenarioParameterQueryService.java new file mode 100644 index 000000000..ef871babb --- /dev/null +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/service/ScenarioParameterQueryService.java @@ -0,0 +1,116 @@ +package org.citrusframework.simulator.service; + +import jakarta.persistence.criteria.JoinType; +import org.citrusframework.simulator.model.ScenarioExecution_; +import org.citrusframework.simulator.model.ScenarioParameter; +import org.citrusframework.simulator.model.ScenarioParameter_; +import org.citrusframework.simulator.repository.ScenarioParameterRepository; +import org.citrusframework.simulator.service.criteria.ScenarioParameterCriteria; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * Service for executing complex queries for {@link ScenarioParameter} entities in the database. + * The main input is a {@link ScenarioParameterCriteria} which gets converted to {@link Specification}, + * in a way that all the filters must apply. + * It returns a {@link List} of {@link ScenarioParameter} or a {@link Page} of {@link ScenarioParameter} which fulfills the criteria. + */ +@Service +@Transactional(readOnly = true) +public class ScenarioParameterQueryService extends QueryService { + + private final Logger log = LoggerFactory.getLogger(ScenarioParameterQueryService.class); + + private final ScenarioParameterRepository scenarioParameterRepository; + + public ScenarioParameterQueryService(ScenarioParameterRepository scenarioParameterRepository) { + this.scenarioParameterRepository = scenarioParameterRepository; + } + + /** + * Return a {@link List} of {@link ScenarioParameter} which matches the criteria from the database. + * @param criteria The object which holds all the filters, which the entities should match. + * @return the matching entities. + */ + @Transactional(readOnly = true) + public List findByCriteria(ScenarioParameterCriteria criteria) { + log.debug("find by criteria : {}", criteria); + final Specification specification = createSpecification(criteria); + return scenarioParameterRepository.findAll(specification); + } + + /** + * Return a {@link Page} of {@link ScenarioParameter} which matches the criteria from the database. + * @param criteria The object which holds all the filters, which the entities should match. + * @param page The page, which should be returned. + * @return the matching entities. + */ + @Transactional(readOnly = true) + public Page findByCriteria(ScenarioParameterCriteria criteria, Pageable page) { + log.debug("find by criteria : {}, page: {}", criteria, page); + final Specification specification = createSpecification(criteria); + return scenarioParameterRepository.findAll(specification, page); + } + + /** + * Return the number of matching entities in the database. + * @param criteria The object which holds all the filters, which the entities should match. + * @return the number of matching entities. + */ + @Transactional(readOnly = true) + public long countByCriteria(ScenarioParameterCriteria criteria) { + log.debug("count by criteria : {}", criteria); + final Specification specification = createSpecification(criteria); + return scenarioParameterRepository.count(specification); + } + + /** + * Function to convert {@link ScenarioParameterCriteria} to a {@link Specification} + * @param criteria The object which holds all the filters, which the entities should match. + * @return the matching {@link Specification} of the entity. + */ + protected Specification createSpecification(ScenarioParameterCriteria criteria) { + Specification specification = Specification.where(null); + if (criteria != null) { + // This has to be called first, because the distinct method returns null + if (criteria.getDistinct() != null) { + specification = specification.and(distinct(criteria.getDistinct())); + } + if (criteria.getParameterId() != null) { + specification = specification.and(buildRangeSpecification(criteria.getParameterId(), ScenarioParameter_.parameterId)); + } + if (criteria.getName() != null) { + specification = specification.and(buildStringSpecification(criteria.getName(), ScenarioParameter_.name)); + } + if (criteria.getControlType() != null) { + specification = specification.and(buildRangeSpecification(criteria.getControlType(), ScenarioParameter_.controlType)); + } + if (criteria.getValue() != null) { + specification = specification.and(buildStringSpecification(criteria.getValue(), ScenarioParameter_.value)); + } + if (criteria.getCreatedDate() != null) { + specification = specification.and(buildRangeSpecification(criteria.getCreatedDate(), ScenarioParameter_.createdDate)); + } + if (criteria.getLastModifiedDate() != null) { + specification = specification.and(buildRangeSpecification(criteria.getLastModifiedDate(), ScenarioParameter_.lastModifiedDate)); + } + if (criteria.getScenarioExecutionId() != null) { + specification = + specification.and( + buildSpecification( + criteria.getScenarioExecutionId(), + root -> root.join(ScenarioParameter_.scenarioExecution, JoinType.LEFT).get(ScenarioExecution_.executionId) + ) + ); + } + } + return specification; + } +} diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/service/ScenarioParameterService.java b/simulator-starter/src/main/java/org/citrusframework/simulator/service/ScenarioParameterService.java new file mode 100644 index 000000000..1af033a86 --- /dev/null +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/service/ScenarioParameterService.java @@ -0,0 +1,43 @@ +package org.citrusframework.simulator.service; + +import org.citrusframework.simulator.model.ScenarioParameter; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.Optional; + +/** + * Service Interface for managing {@link ScenarioParameter}. + */ +public interface ScenarioParameterService { + /** + * Save a scenarioParameter. + * + * @param scenarioParameter the entity to save. + * @return the persisted entity. + */ + ScenarioParameter save(ScenarioParameter scenarioParameter); + + /** + * Get all the scenarioParameters. + * + * @param pageable the pagination information. + * @return the list of entities. + */ + Page findAll(Pageable pageable); + + /** + * Get the "id" scenarioParameter. + * + * @param id the id of the entity. + * @return the entity. + */ + Optional findOne(Long id); + + /** + * Delete the "id" scenarioParameter. + * + * @param id the id of the entity. + */ + void delete(Long id); +} diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/MessageCriteria.java b/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/MessageCriteria.java index 4713fa1e9..816a204c9 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/MessageCriteria.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/MessageCriteria.java @@ -224,7 +224,7 @@ public int hashCode() { @Override public String toString() { return "MessageCriteria{" + - (messageId != null ? "id=" + messageId + ", " : "") + + (messageId != null ? "messageId=" + messageId + ", " : "") + (direction != null ? "direction=" + direction + ", " : "") + (payload != null ? "payload=" + payload + ", " : "") + (citrusMessageId != null ? "citrusMessageId=" + citrusMessageId + ", " : "") + diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/MessageHeaderCriteria.java b/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/MessageHeaderCriteria.java index 034bb251d..7395f4344 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/MessageHeaderCriteria.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/MessageHeaderCriteria.java @@ -184,7 +184,7 @@ public int hashCode() { @Override public String toString() { return "MessageHeaderCriteria{" + - (headerId != null ? "id=" + headerId + ", " : "") + + (headerId != null ? "headerId=" + headerId + ", " : "") + (name != null ? "name=" + name + ", " : "") + (value != null ? "value=" + value + ", " : "") + (createdDate != null ? "createdDate=" + createdDate + ", " : "") + diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/ScenarioActionCriteria.java b/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/ScenarioActionCriteria.java index 92f58d19d..36809a82d 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/ScenarioActionCriteria.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/ScenarioActionCriteria.java @@ -165,7 +165,7 @@ public int hashCode() { @Override public String toString() { return "ScenarioActionCriteria{" + - (actionId != null ? "id=" + actionId + ", " : "") + + (actionId != null ? "actionId=" + actionId + ", " : "") + (name != null ? "name=" + name + ", " : "") + (startDate != null ? "startDate=" + startDate + ", " : "") + (endDate != null ? "endDate=" + endDate + ", " : "") + diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/ScenarioExecutionCriteria.java b/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/ScenarioExecutionCriteria.java index b0a28d09c..09729c347 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/ScenarioExecutionCriteria.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/ScenarioExecutionCriteria.java @@ -43,6 +43,8 @@ public class ScenarioExecutionCriteria implements Serializable, Criteria { private LongFilter scenarioMessagesId; + private LongFilter scenarioParametersId; + private Boolean distinct; public ScenarioExecutionCriteria() { @@ -57,6 +59,7 @@ public ScenarioExecutionCriteria(ScenarioExecutionCriteria other) { this.errorMessage = other.errorMessage == null ? null : other.errorMessage.copy(); this.scenarioActionsId = other.scenarioActionsId == null ? null : other.scenarioActionsId.copy(); this.scenarioMessagesId = other.scenarioMessagesId == null ? null : other.scenarioMessagesId.copy(); + this.scenarioParametersId = other.scenarioParametersId == null ? null : other.scenarioParametersId.copy(); this.distinct = other.distinct; } @@ -185,6 +188,21 @@ public void setScenarioMessagesId(LongFilter scenarioMessagesId) { this.scenarioMessagesId = scenarioMessagesId; } + public LongFilter getScenarioParametersId() { + return scenarioParametersId; + } + + public LongFilter scenarioParametersId() { + if (scenarioParametersId == null) { + scenarioParametersId = new LongFilter(); + } + return scenarioParametersId; + } + + public void setScenarioParametersId(LongFilter scenarioParametersId) { + this.scenarioParametersId = scenarioParametersId; + } + public Boolean getDistinct() { return distinct; } @@ -211,27 +229,29 @@ public boolean equals(Object o) { Objects.equals(errorMessage, that.errorMessage) && Objects.equals(scenarioActionsId, that.scenarioActionsId) && Objects.equals(scenarioMessagesId, that.scenarioMessagesId) && + Objects.equals(scenarioParametersId, that.scenarioParametersId) && Objects.equals(distinct, that.distinct) ); } @Override public int hashCode() { - return Objects.hash(executionId, startDate, endDate, scenarioName, status, errorMessage, scenarioActionsId, scenarioMessagesId, distinct); + return Objects.hash(executionId, startDate, endDate, scenarioName, status, errorMessage, scenarioActionsId, scenarioMessagesId, scenarioParametersId, distinct); } // prettier-ignore @Override public String toString() { return "ScenarioExecutionCriteria{" + - (executionId != null ? "id=" + executionId + ", " : "") + + (executionId != null ? "executionId=" + executionId + ", " : "") + (startDate != null ? "startDate=" + startDate + ", " : "") + (endDate != null ? "endDate=" + endDate + ", " : "") + (scenarioName != null ? "scenarioName=" + scenarioName + ", " : "") + (status != null ? "status=" + status + ", " : "") + (errorMessage != null ? "errorMessage=" + errorMessage + ", " : "") + - (scenarioActionsId != null ? "scenarioMessagesId=" + scenarioActionsId + ", " : "") + + (scenarioActionsId != null ? "scenarioActionsId=" + scenarioActionsId + ", " : "") + (scenarioMessagesId != null ? "scenarioMessagesId=" + scenarioMessagesId + ", " : "") + + (scenarioMessagesId != null ? "scenarioParametersId=" + scenarioParametersId + ", " : "") + (distinct != null ? "distinct=" + distinct + ", " : "") + "}"; } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/ScenarioParameterCriteria.java b/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/ScenarioParameterCriteria.java new file mode 100644 index 000000000..96a907e44 --- /dev/null +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/service/criteria/ScenarioParameterCriteria.java @@ -0,0 +1,218 @@ +package org.citrusframework.simulator.service.criteria; + +import org.citrusframework.simulator.service.filter.InstantFilter; +import org.citrusframework.simulator.service.filter.IntegerFilter; +import org.citrusframework.simulator.service.filter.LongFilter; +import org.citrusframework.simulator.service.filter.StringFilter; +import org.springdoc.core.annotations.ParameterObject; + +import java.io.Serializable; +import java.util.Objects; + +/** + * Criteria class for the {@link org.citrusframework.simulator.model.ScenarioParameter} entity. This class is used + * in {@link org.citrusframework.simulator.web.rest.ScenarioParameterResource} to receive all the possible filtering + * options from the Http GET request parameters. + *

+ * For example the following could be a valid request: + * {@code /scenario-parameters?id.greaterThan=5&attr1.contains=something&attr2.specified=false} + *

+ * As Spring is unable to properly convert the types, unless + * specific {@link org.citrusframework.simulator.service.filter.Filter} class are used, we need to use fix type + * specific filters. + */ +@ParameterObject +@SuppressWarnings("common-java:DuplicatedBlocks") +public class ScenarioParameterCriteria implements Serializable, Criteria { + + private static final long serialVersionUID = 1L; + + private LongFilter parameterId; + + private StringFilter name; + + private IntegerFilter controlType; + + private StringFilter value; + + private InstantFilter createdDate; + + private InstantFilter lastModifiedDate; + + private LongFilter scenarioExecutionId; + + private Boolean distinct; + + public ScenarioParameterCriteria() { + } + + public ScenarioParameterCriteria(ScenarioParameterCriteria other) { + this.parameterId = other.parameterId == null ? null : other.parameterId.copy(); + this.name = other.name == null ? null : other.name.copy(); + this.controlType = other.controlType == null ? null : other.controlType.copy(); + this.value = other.value == null ? null : other.value.copy(); + this.createdDate = other.createdDate == null ? null : other.createdDate.copy(); + this.lastModifiedDate = other.lastModifiedDate == null ? null : other.lastModifiedDate.copy(); + this.scenarioExecutionId = other.scenarioExecutionId == null ? null : other.scenarioExecutionId.copy(); + this.distinct = other.distinct; + } + + @Override + public ScenarioParameterCriteria copy() { + return new ScenarioParameterCriteria(this); + } + + public LongFilter getParameterId() { + return parameterId; + } + + public LongFilter id() { + if (parameterId == null) { + parameterId = new LongFilter(); + } + return parameterId; + } + + public void setParameterId(LongFilter parameterId) { + this.parameterId = parameterId; + } + + public StringFilter getName() { + return name; + } + + public StringFilter name() { + if (name == null) { + name = new StringFilter(); + } + return name; + } + + public void setName(StringFilter name) { + this.name = name; + } + + public IntegerFilter getControlType() { + return controlType; + } + + public IntegerFilter controlType() { + if (controlType == null) { + controlType = new IntegerFilter(); + } + return controlType; + } + + public void setControlType(IntegerFilter controlType) { + this.controlType = controlType; + } + + public StringFilter getValue() { + return value; + } + + public StringFilter value() { + if (value == null) { + value = new StringFilter(); + } + return value; + } + + public void setValue(StringFilter value) { + this.value = value; + } + + public InstantFilter getCreatedDate() { + return createdDate; + } + + public InstantFilter createdDate() { + if (createdDate == null) { + createdDate = new InstantFilter(); + } + return createdDate; + } + + public void setCreatedDate(InstantFilter createdDate) { + this.createdDate = createdDate; + } + + public InstantFilter getLastModifiedDate() { + return lastModifiedDate; + } + + public InstantFilter lastModifiedDate() { + if (lastModifiedDate == null) { + lastModifiedDate = new InstantFilter(); + } + return lastModifiedDate; + } + + public void setLastModifiedDate(InstantFilter lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; + } + + public LongFilter getScenarioExecutionId() { + return scenarioExecutionId; + } + + public LongFilter scenarioExecutionId() { + if (scenarioExecutionId == null) { + scenarioExecutionId = new LongFilter(); + } + return scenarioExecutionId; + } + + public void setScenarioExecutionId(LongFilter scenarioExecutionId) { + this.scenarioExecutionId = scenarioExecutionId; + } + + public Boolean getDistinct() { + return distinct; + } + + public void setDistinct(Boolean distinct) { + this.distinct = distinct; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ScenarioParameterCriteria that = (ScenarioParameterCriteria) o; + return ( + Objects.equals(parameterId, that.parameterId) && + Objects.equals(name, that.name) && + Objects.equals(controlType, that.controlType) && + Objects.equals(value, that.value) && + Objects.equals(createdDate, that.createdDate) && + Objects.equals(lastModifiedDate, that.lastModifiedDate) && + Objects.equals(scenarioExecutionId, that.scenarioExecutionId) && + Objects.equals(distinct, that.distinct) + ); + } + + @Override + public int hashCode() { + return Objects.hash(parameterId, name, controlType, value, createdDate, lastModifiedDate, scenarioExecutionId, distinct); + } + + // prettier-ignore + @Override + public String toString() { + return "ScenarioParameterCriteria{" + + (parameterId != null ? "parameterId=" + parameterId + ", " : "") + + (name != null ? "name=" + name + ", " : "") + + (controlType != null ? "controlType=" + controlType + ", " : "") + + (value != null ? "value=" + value + ", " : "") + + (createdDate != null ? "createdDate=" + createdDate + ", " : "") + + (lastModifiedDate != null ? "lastModifiedDate=" + lastModifiedDate + ", " : "") + + (scenarioExecutionId != null ? "scenarioExecutionId=" + scenarioExecutionId + ", " : "") + + (distinct != null ? "distinct=" + distinct + ", " : "") + + "}"; + } +} diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/service/impl/ScenarioParameterServiceImpl.java b/simulator-starter/src/main/java/org/citrusframework/simulator/service/impl/ScenarioParameterServiceImpl.java new file mode 100644 index 000000000..0af825355 --- /dev/null +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/service/impl/ScenarioParameterServiceImpl.java @@ -0,0 +1,55 @@ +package org.citrusframework.simulator.service.impl; + +import org.citrusframework.simulator.model.ScenarioParameter; +import org.citrusframework.simulator.repository.ScenarioParameterRepository; +import org.citrusframework.simulator.service.ScenarioParameterService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; + +/** + * Service Implementation for managing {@link ScenarioParameter}. + */ +@Service +@Transactional +public class ScenarioParameterServiceImpl implements ScenarioParameterService { + + private final Logger log = LoggerFactory.getLogger(ScenarioParameterServiceImpl.class); + + private final ScenarioParameterRepository scenarioParameterRepository; + + public ScenarioParameterServiceImpl(ScenarioParameterRepository scenarioParameterRepository) { + this.scenarioParameterRepository = scenarioParameterRepository; + } + + @Override + public ScenarioParameter save(ScenarioParameter scenarioParameter) { + log.debug("Request to save ScenarioParameter : {}", scenarioParameter); + return scenarioParameterRepository.save(scenarioParameter); + } + + @Override + @Transactional(readOnly = true) + public Page findAll(Pageable pageable) { + log.debug("Request to get all ScenarioParameters with eager relationships"); + return scenarioParameterRepository.findAllWithEagerRelationships(pageable); + } + + @Override + @Transactional(readOnly = true) + public Optional findOne(Long id) { + log.debug("Request to get ScenarioParameter : {}", id); + return scenarioParameterRepository.findOneWithEagerRelationships(id); + } + + @Override + public void delete(Long id) { + log.debug("Request to delete ScenarioParameter : {}", id); + scenarioParameterRepository.deleteById(id); + } +} diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/web/rest/ScenarioParameterResource.java b/simulator-starter/src/main/java/org/citrusframework/simulator/web/rest/ScenarioParameterResource.java new file mode 100644 index 000000000..9c9b0f655 --- /dev/null +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/web/rest/ScenarioParameterResource.java @@ -0,0 +1,88 @@ +package org.citrusframework.simulator.web.rest; + +import org.citrusframework.simulator.model.ScenarioParameter; +import org.citrusframework.simulator.service.ScenarioParameterQueryService; +import org.citrusframework.simulator.service.ScenarioParameterService; +import org.citrusframework.simulator.service.criteria.ScenarioParameterCriteria; +import org.citrusframework.simulator.web.util.PaginationUtil; +import org.citrusframework.simulator.web.util.ResponseUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; + +import java.util.List; +import java.util.Optional; + +/** + * REST controller for managing {@link ScenarioParameter}. + */ +@RestController +@RequestMapping("/api") +public class ScenarioParameterResource { + + private final Logger log = LoggerFactory.getLogger(ScenarioParameterResource.class); + + private final ScenarioParameterService scenarioParameterService; + + private final ScenarioParameterQueryService scenarioParameterQueryService; + + public ScenarioParameterResource( + ScenarioParameterService scenarioParameterService, + ScenarioParameterQueryService scenarioParameterQueryService + ) { + this.scenarioParameterService = scenarioParameterService; + this.scenarioParameterQueryService = scenarioParameterQueryService; + } + + /** + * {@code GET /scenario-parameters} : get all the scenarioParameters. + * + * @param pageable the pagination information. + * @param criteria the criteria which the requested entities should match. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of scenarioParameters in body. + */ + @GetMapping("/scenario-parameters") + public ResponseEntity> getAllScenarioParameters( + ScenarioParameterCriteria criteria, + @org.springdoc.core.annotations.ParameterObject Pageable pageable + ) { + log.debug("REST request to get ScenarioParameters by criteria: {}", criteria); + + Page page = scenarioParameterQueryService.findByCriteria(criteria, pageable); + HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(), page); + return ResponseEntity.ok().headers(headers).body(page.getContent()); + } + + /** + * {@code GET /scenario-parameters/count} : count all the scenarioParameters. + * + * @param criteria the criteria which the requested entities should match. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the count in body. + */ + @GetMapping("/scenario-parameters/count") + public ResponseEntity countScenarioParameters(ScenarioParameterCriteria criteria) { + log.debug("REST request to count ScenarioParameters by criteria: {}", criteria); + return ResponseEntity.ok().body(scenarioParameterQueryService.countByCriteria(criteria)); + } + + /** + * {@code GET /scenario-parameters/:id} : get the "id" scenarioParameter. + * + * @param id the id of the scenarioParameter to retrieve. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the scenarioParameter, or with status {@code 404 (Not Found)}. + */ + @GetMapping("/scenario-parameters/{id}") + public ResponseEntity getScenarioParameter(@PathVariable Long id) { + log.debug("REST request to get ScenarioParameter : {}", id); + Optional scenarioParameter = scenarioParameterService.findOne(id); + return ResponseUtil.wrapOrNotFound(scenarioParameter); + } +} diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/IntegrationTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/IntegrationTest.java index 5fc15912e..899bdde71 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/IntegrationTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/IntegrationTest.java @@ -14,7 +14,7 @@ */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -@SpringBootTest(classes = { TestApplication.class}) +@SpringBootTest(classes = {TestApplication.class}) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) public @interface IntegrationTest { } diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/InboundXmlDataDictionaryTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/InboundXmlDataDictionaryTest.java index 8dc2991d9..946bf4f2c 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/InboundXmlDataDictionaryTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/InboundXmlDataDictionaryTest.java @@ -23,11 +23,11 @@ class InboundXmlDataDictionaryTest { private static final String MESSAGE_INPUT = String.format("%n" + - " string%n" + - " 100%n" + - " true%n" + - " stringstri%n" + - ""); + " string%n" + + " 100%n" + + " true%n" + + " stringstri%n" + + ""); @Mock private TestContext testContextMock; @@ -50,11 +50,11 @@ void testInboundDictionary() { Message translated = fixture.transform(request, testContextMock); assertEquals(translated.getPayload(String.class), String.format("" + - "%n" + - " @ignore@%n" + - " @ignore@%n" + - " @ignore@%n" + - " @ignore@%n" + - "%n").replace("\r","")); + "%n" + + " @ignore@%n" + + " @ignore@%n" + + " @ignore@%n" + + " @ignore@%n" + + "%n").replace("\r", "")); } } diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/OutboundXmlDataDictionaryTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/OutboundXmlDataDictionaryTest.java index b56e73636..9cc5cd6c6 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/OutboundXmlDataDictionaryTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/OutboundXmlDataDictionaryTest.java @@ -47,12 +47,12 @@ void testInboundDictionary() { String payload = XMLUtils.prettyPrint(translated.getPayload(String.class)); String controlPayload = XMLUtils.prettyPrint(String.format("" + - "%n" + - " citrus:randomString(6)%n" + - " citrus:randomNumber(3)%n" + - " true%n" + - " citrus:randomString(10)%n" + - "%n")); + "%n" + + " citrus:randomString(6)%n" + + " citrus:randomNumber(3)%n" + + " true%n" + + " citrus:randomString(10)%n" + + "%n")); assertEquals(payload, controlPayload); } diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationMatcherTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationMatcherTest.java index 88bf3177b..34f4ffd0d 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationMatcherTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationMatcherTest.java @@ -34,185 +34,197 @@ class HttpRequestAnnotationMatcherTest { HttpRequestAnnotationMatcher fixture; - @BeforeEach - void beforeEachSetup() { - fixture = HttpRequestAnnotationMatcher.instance(); - } - static Stream checkRequestPathSupported() { return Stream.of( Arguments.of( - REQ_MAP_WITH_PATH_NAME, - setupHttpMessage("/path/name", RequestMethod.GET, Collections.emptyMap()), - true, - true + REQ_MAP_WITH_PATH_NAME, + setupHttpMessage("/path/name", RequestMethod.GET, Collections.emptyMap()), + true, + true ), Arguments.of( - REQ_MAP_WITH_PATH_NAME, - setupHttpMessage("/path/name", RequestMethod.GET, Collections.emptyMap()), - false, - true + REQ_MAP_WITH_PATH_NAME, + setupHttpMessage("/path/name", RequestMethod.GET, Collections.emptyMap()), + false, + true ), Arguments.of( - REQ_MAP_WITH_PATH_NAME, - setupHttpMessage("/path/wrong-path", RequestMethod.GET, Collections.emptyMap()), - true, - false + REQ_MAP_WITH_PATH_NAME, + setupHttpMessage("/path/wrong-path", RequestMethod.GET, Collections.emptyMap()), + true, + false ), Arguments.of( - REQ_MAP_WITH_PATH_NAME, - setupHttpMessage("", RequestMethod.GET, Collections.emptyMap()), - true, - false + REQ_MAP_WITH_PATH_NAME, + setupHttpMessage("", RequestMethod.GET, Collections.emptyMap()), + true, + false ), Arguments.of( - REQ_MAP_WITH_PATH_VALUE, - setupHttpMessage("/path/value", RequestMethod.GET, Collections.emptyMap()), - true, - true + REQ_MAP_WITH_PATH_VALUE, + setupHttpMessage("/path/value", RequestMethod.GET, Collections.emptyMap()), + true, + true ), Arguments.of( - REQ_MAP_WITH_PATH_VALUE, - setupHttpMessage("/path/wrong-path", RequestMethod.GET, Collections.emptyMap()), - true, - false + REQ_MAP_WITH_PATH_VALUE, + setupHttpMessage("/path/wrong-path", RequestMethod.GET, Collections.emptyMap()), + true, + false ), Arguments.of( - REQ_MAP_WITH_PATH_VALUE, - setupHttpMessage("", RequestMethod.GET, Collections.emptyMap()), - true, - false + REQ_MAP_WITH_PATH_VALUE, + setupHttpMessage("", RequestMethod.GET, Collections.emptyMap()), + true, + false ), Arguments.of( - REQ_MAP_WITH_PATH_PLACEHOLDER, - setupHttpMessage("/path/place-holder/123", RequestMethod.GET, Collections.emptyMap()), - false, - true + REQ_MAP_WITH_PATH_PLACEHOLDER, + setupHttpMessage("/path/place-holder/123", RequestMethod.GET, Collections.emptyMap()), + false, + true ), Arguments.of( - REQ_MAP_WITH_PATH_PLACEHOLDER, - setupHttpMessage("/path/place-holder/123", RequestMethod.GET, Collections.emptyMap()), - true, - false + REQ_MAP_WITH_PATH_PLACEHOLDER, + setupHttpMessage("/path/place-holder/123", RequestMethod.GET, Collections.emptyMap()), + true, + false ), Arguments.of( - REQ_MAP_WITH_PATH_PLACEHOLDER, - setupHttpMessage("/path/wrong-path", RequestMethod.GET, Collections.emptyMap()), - true, - false + REQ_MAP_WITH_PATH_PLACEHOLDER, + setupHttpMessage("/path/wrong-path", RequestMethod.GET, Collections.emptyMap()), + true, + false ), Arguments.of( - REQ_MAP_WITH_PATH_PLACEHOLDER, - setupHttpMessage("/path/wrong-path", RequestMethod.GET, Collections.emptyMap()), - false, - false + REQ_MAP_WITH_PATH_PLACEHOLDER, + setupHttpMessage("/path/wrong-path", RequestMethod.GET, Collections.emptyMap()), + false, + false ), Arguments.of( - REQ_MAP_WITH_PATH_PATTERN, - setupHttpMessage("/path/pattern/match-me", RequestMethod.GET, Collections.emptyMap()), - true, - false + REQ_MAP_WITH_PATH_PATTERN, + setupHttpMessage("/path/pattern/match-me", RequestMethod.GET, Collections.emptyMap()), + true, + false ), Arguments.of( - REQ_MAP_WITH_PATH_PATTERN, - setupHttpMessage("/path/pattern/match-me", RequestMethod.GET, Collections.emptyMap()), - false, - true + REQ_MAP_WITH_PATH_PATTERN, + setupHttpMessage("/path/pattern/match-me", RequestMethod.GET, Collections.emptyMap()), + false, + true ), Arguments.of( - REQ_MAP_WITH_PATH_PATTERN, - setupHttpMessage("/path/wrong-pattern", RequestMethod.GET, Collections.emptyMap()), - true, - false + REQ_MAP_WITH_PATH_PATTERN, + setupHttpMessage("/path/wrong-pattern", RequestMethod.GET, Collections.emptyMap()), + true, + false ), Arguments.of( - REQ_MAP_WITH_PATH_PATTERN, - setupHttpMessage("/path/wrong-pattern", RequestMethod.GET, Collections.emptyMap()), - false, - false + REQ_MAP_WITH_PATH_PATTERN, + setupHttpMessage("/path/wrong-pattern", RequestMethod.GET, Collections.emptyMap()), + false, + false ), Arguments.of( - REQ_MAP_WITH_PATH_PATTERN, - setupHttpMessage("", RequestMethod.GET, Collections.emptyMap()), - true, - false + REQ_MAP_WITH_PATH_PATTERN, + setupHttpMessage("", RequestMethod.GET, Collections.emptyMap()), + true, + false ), Arguments.of( - REQ_MAP_WITH_PATH_PATTERN, - setupHttpMessage("", RequestMethod.GET, Collections.emptyMap()), - false, - false + REQ_MAP_WITH_PATH_PATTERN, + setupHttpMessage("", RequestMethod.GET, Collections.emptyMap()), + false, + false ), Arguments.of( - REQ_MAP_WITH_PUT_METHOD, - setupHttpMessage("/any-path", RequestMethod.PUT, Collections.emptyMap()), - true, - true + REQ_MAP_WITH_PUT_METHOD, + setupHttpMessage("/any-path", RequestMethod.PUT, Collections.emptyMap()), + true, + true ), Arguments.of( - REQ_MAP_WITH_PUT_METHOD, - setupHttpMessage("", RequestMethod.GET, Collections.emptyMap()), - true, - false + REQ_MAP_WITH_PUT_METHOD, + setupHttpMessage("", RequestMethod.GET, Collections.emptyMap()), + true, + false ), Arguments.of( - REQ_MAP_WITH_QUERY_PARAMS, - setupHttpMessage("/any-path", RequestMethod.GET, Collections.singletonMap("a", Collections.singleton("1"))), - true, - true + REQ_MAP_WITH_QUERY_PARAMS, + setupHttpMessage("/any-path", RequestMethod.GET, Collections.singletonMap("a", Collections.singleton("1"))), + true, + true ), Arguments.of( - REQ_MAP_WITH_QUERY_PARAMS, - setupHttpMessage("/any-path", RequestMethod.GET, Collections.singletonMap("a", Collections.emptySet())), - true, - true + REQ_MAP_WITH_QUERY_PARAMS, + setupHttpMessage("/any-path", RequestMethod.GET, Collections.singletonMap("a", Collections.emptySet())), + true, + true ), Arguments.of( - REQ_MAP_WITH_QUERY_PARAMS, - setupHttpMessage("/any-path", RequestMethod.GET, Stream.of("a=1","b=2").map(item -> item.split("=")).collect(Collectors.toMap(keyValuePair -> keyValuePair[0], keyValuePair -> Collections.singleton(keyValuePair[1])))), - true, - false + REQ_MAP_WITH_QUERY_PARAMS, + setupHttpMessage("/any-path", RequestMethod.GET, Stream.of("a=1", "b=2").map(item -> item.split("=")).collect(Collectors.toMap(keyValuePair -> keyValuePair[0], keyValuePair -> Collections.singleton(keyValuePair[1])))), + true, + false ), Arguments.of( - REQ_MAP_WITH_QUERY_PARAMS, - setupHttpMessage("/any-path", RequestMethod.GET, Collections.singletonMap("c", Collections.singleton("3"))), - true, - false + REQ_MAP_WITH_QUERY_PARAMS, + setupHttpMessage("/any-path", RequestMethod.GET, Collections.singletonMap("c", Collections.singleton("3"))), + true, + false ), Arguments.of( - REQ_MAP_WITH_QUERY_PARAMS, - setupHttpMessage("/any-path", RequestMethod.GET, Collections.emptyMap()), - true, - false + REQ_MAP_WITH_QUERY_PARAMS, + setupHttpMessage("/any-path", RequestMethod.GET, Collections.emptyMap()), + true, + false ), Arguments.of( - REQ_MAP_WITH_ALL_SUPPORTED_RESTRICTIONS, - setupHttpMessage("/path/value", RequestMethod.GET, Collections.singletonMap("a", Collections.singleton("1"))), - true, - true + REQ_MAP_WITH_ALL_SUPPORTED_RESTRICTIONS, + setupHttpMessage("/path/value", RequestMethod.GET, Collections.singletonMap("a", Collections.singleton("1"))), + true, + true ), Arguments.of( - REQ_MAP_WITH_ALL_SUPPORTED_RESTRICTIONS, - setupHttpMessage("/wrong-path", RequestMethod.GET, Collections.singletonMap("a", Collections.singleton("1"))), - true, - false + REQ_MAP_WITH_ALL_SUPPORTED_RESTRICTIONS, + setupHttpMessage("/wrong-path", RequestMethod.GET, Collections.singletonMap("a", Collections.singleton("1"))), + true, + false ), Arguments.of( - REQ_MAP_WITH_ALL_SUPPORTED_RESTRICTIONS, - setupHttpMessage("/path/value", RequestMethod.PUT, Collections.singletonMap("a", Collections.singleton("1"))), - true, - false + REQ_MAP_WITH_ALL_SUPPORTED_RESTRICTIONS, + setupHttpMessage("/path/value", RequestMethod.PUT, Collections.singletonMap("a", Collections.singleton("1"))), + true, + false ), Arguments.of( - REQ_MAP_WITH_ALL_SUPPORTED_RESTRICTIONS, - setupHttpMessage("/path/value", RequestMethod.GET, Collections.emptyMap()), - true, - false + REQ_MAP_WITH_ALL_SUPPORTED_RESTRICTIONS, + setupHttpMessage("/path/value", RequestMethod.GET, Collections.emptyMap()), + true, + false ) ); } + private static RequestMapping getRequestMapping(SimulatorScenario scenario) { + return AnnotationUtils.findAnnotation(scenario.getClass(), RequestMapping.class); + } + + private static HttpMessage setupHttpMessage(String path, RequestMethod method, Map> queryParams) { + final HttpMessage httpMessage = Mockito.mock(HttpMessage.class); + when(httpMessage.getPath()).thenReturn(path); + when(httpMessage.getRequestMethod()).thenReturn(method); + when(httpMessage.getQueryParams()).thenReturn(queryParams); + return httpMessage; + } + + @BeforeEach + void beforeEachSetup() { + fixture = HttpRequestAnnotationMatcher.instance(); + } + @MethodSource @ParameterizedTest void checkRequestPathSupported(RequestMapping requestMapping, HttpMessage httpMessage, boolean exactMatch, boolean expectedResult) { @@ -256,16 +268,4 @@ private static class ScenarioWithQueryParams extends AbstractSimulatorScenario { @RequestMapping(method = RequestMethod.GET, value = "/path/value", params = {"a", "!b"}) private static class ScenarioWithAllSupportedRestrictions extends AbstractSimulatorScenario { } - - private static RequestMapping getRequestMapping(SimulatorScenario scenario) { - return AnnotationUtils.findAnnotation(scenario.getClass(), RequestMapping.class); - } - - private static HttpMessage setupHttpMessage(String path, RequestMethod method, Map> queryParams) { - final HttpMessage httpMessage = Mockito.mock(HttpMessage.class); - when(httpMessage.getPath()).thenReturn(path); - when(httpMessage.getRequestMethod()).thenReturn(method); - when(httpMessage.getQueryParams()).thenReturn(queryParams); - return httpMessage; - } } diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationScenarioMapperTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationScenarioMapperTest.java index b426f7aaf..2e0ebae80 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationScenarioMapperTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationScenarioMapperTest.java @@ -80,7 +80,7 @@ private static class PutFooScenario extends AbstractSimulatorScenario { } @Scenario("IssueScenario") - @RequestMapping(value = "/issues/{name}", method = { RequestMethod.GET, RequestMethod.DELETE }) + @RequestMapping(value = "/issues/{name}", method = {RequestMethod.GET, RequestMethod.DELETE}) private static class IssueScenario extends AbstractSimulatorScenario { } diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestPathScenarioMapperTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestPathScenarioMapperTest.java index 524a1dc69..b92d4f21f 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestPathScenarioMapperTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestPathScenarioMapperTest.java @@ -44,21 +44,21 @@ void testGetMappingKey() { Operation operation = Mockito.mock(Operation.class); fixture.setScenarioList(Arrays.asList(new HttpOperationScenario("/issues/foos", RequestMethod.GET, operation, Collections.emptyMap()), - new HttpOperationScenario("/issues/foos", RequestMethod.POST, operation, Collections.emptyMap()), - new HttpOperationScenario("/issues/foo/{id}", RequestMethod.GET, operation, Collections.emptyMap()), - new HttpOperationScenario("/issues/foo/detail", RequestMethod.GET, operation, Collections.emptyMap()), - new HttpOperationScenario("/issues/bars", RequestMethod.GET, operation, Collections.emptyMap()), - new HttpOperationScenario("/issues/bar/{id}", RequestMethod.GET, operation, Collections.emptyMap()), - new HttpOperationScenario("/issues/bar/detail", RequestMethod.GET, operation, Collections.emptyMap()))); + new HttpOperationScenario("/issues/foos", RequestMethod.POST, operation, Collections.emptyMap()), + new HttpOperationScenario("/issues/foo/{id}", RequestMethod.GET, operation, Collections.emptyMap()), + new HttpOperationScenario("/issues/foo/detail", RequestMethod.GET, operation, Collections.emptyMap()), + new HttpOperationScenario("/issues/bars", RequestMethod.GET, operation, Collections.emptyMap()), + new HttpOperationScenario("/issues/bar/{id}", RequestMethod.GET, operation, Collections.emptyMap()), + new HttpOperationScenario("/issues/bar/detail", RequestMethod.GET, operation, Collections.emptyMap()))); when(operation.getOperationId()) - .thenReturn("fooListScenario") - .thenReturn("fooListPostScenario") - .thenReturn("barListScenario") - .thenReturn("fooScenario") - .thenReturn("barScenario") - .thenReturn("fooDetailScenario") - .thenReturn("barDetailScenario"); + .thenReturn("fooListScenario") + .thenReturn("fooListPostScenario") + .thenReturn("barListScenario") + .thenReturn("fooScenario") + .thenReturn("barScenario") + .thenReturn("fooDetailScenario") + .thenReturn("barDetailScenario"); assertEquals(fixture.getMappingKey(new HttpMessage().method(HttpMethod.GET)), "default"); assertEquals(fixture.getMappingKey(new HttpMessage().method(HttpMethod.POST)), "default"); diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/model/MessageTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/model/MessageTest.java index 081bc1d05..0103f9308 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/model/MessageTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/model/MessageTest.java @@ -1,9 +1,9 @@ package org.citrusframework.simulator.model; -import static org.assertj.core.api.Assertions.assertThat; - import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + class MessageTest { @Test diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/model/TestResultTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/model/TestResultTest.java index 308ea8c47..0008ed3fc 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/model/TestResultTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/model/TestResultTest.java @@ -1,9 +1,9 @@ package org.citrusframework.simulator.model; -import static org.assertj.core.api.Assertions.assertThat; - import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + class TestResultTest { @Test diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/repository/MessageHeaderRepositoryIT.java b/simulator-starter/src/test/java/org/citrusframework/simulator/repository/MessageHeaderRepositoryIT.java index 191b3e076..87b939ec5 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/repository/MessageHeaderRepositoryIT.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/repository/MessageHeaderRepositoryIT.java @@ -28,6 +28,10 @@ class MessageHeaderRepositoryIT { private MessageHeader messageHeader; + private static void verifyRelationships(MessageHeader messageHeaders) { + assertNotNull(messageHeaders.getMessage()); + } + @BeforeEach void beforeEachSetup() { messageHeader = createEntity(entityManager); @@ -53,8 +57,4 @@ void testFindOneWithToOneRelationships() { assertFalse(messageHeaderRepository.findOneWithToOneRelationships(Long.MAX_VALUE).isPresent()); } - - private static void verifyRelationships(MessageHeader messageHeaders) { - assertNotNull(messageHeaders.getMessage()); - } } diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/repository/MessageRepositoryIT.java b/simulator-starter/src/test/java/org/citrusframework/simulator/repository/MessageRepositoryIT.java index 547fb745a..b70d74003 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/repository/MessageRepositoryIT.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/repository/MessageRepositoryIT.java @@ -30,6 +30,11 @@ class MessageRepositoryIT { private Message message; + private static void verifyRelationships(Message messages) { + assertNotNull(messages.getScenarioExecutionId()); + assertNotNull(messages.getScenarioName()); + } + @BeforeEach void beforeEachSetup() throws ScenarioExecution.ErrorMessageTruncationException { message = MessageResourceIT.createEntity(entityManager); @@ -60,9 +65,4 @@ void testFindOneWithToOneRelationships() { assertFalse(messageRepository.findOneWithToOneRelationships(Long.MAX_VALUE).isPresent()); } - - private static void verifyRelationships(Message messages) { - assertNotNull(messages.getScenarioExecutionId()); - assertNotNull(messages.getScenarioName()); - } } diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/repository/ScenarioActionRepositoryIT.java b/simulator-starter/src/test/java/org/citrusframework/simulator/repository/ScenarioActionRepositoryIT.java index 0c5926777..a8bc8d477 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/repository/ScenarioActionRepositoryIT.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/repository/ScenarioActionRepositoryIT.java @@ -30,9 +30,14 @@ class ScenarioActionRepositoryIT { private ScenarioAction scenarioAction; + private static void verifyRelationships(ScenarioAction scenarioAction) { + assertNotNull(scenarioAction.getScenarioExecution()); + } + @BeforeEach void beforeEachSetup() throws ScenarioExecution.ErrorMessageTruncationException { scenarioAction = createEntity(entityManager); + ScenarioExecution scenarioExecution = ScenarioExecutionResourceIT.createEntity(entityManager); entityManager.persist(scenarioExecution); scenarioAction.setScenarioExecution(scenarioExecution); @@ -59,8 +64,4 @@ void testFindOneWithToOneRelationships() { assertFalse(scenarioActionRepository.findOneWithToOneRelationships(Long.MAX_VALUE).isPresent()); } - - private static void verifyRelationships(ScenarioAction scenarioAction) { - assertNotNull(scenarioAction.getScenarioExecution()); - } } diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/repository/ScenarioParameterRepositoryIT.java b/simulator-starter/src/test/java/org/citrusframework/simulator/repository/ScenarioParameterRepositoryIT.java new file mode 100644 index 000000000..a630def7f --- /dev/null +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/repository/ScenarioParameterRepositoryIT.java @@ -0,0 +1,67 @@ +package org.citrusframework.simulator.repository; + +import jakarta.persistence.EntityManager; +import org.citrusframework.simulator.IntegrationTest; +import org.citrusframework.simulator.model.ScenarioExecution; +import org.citrusframework.simulator.model.ScenarioParameter; +import org.citrusframework.simulator.web.rest.ScenarioExecutionResourceIT; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; + +import static org.citrusframework.simulator.web.rest.ScenarioParameterResourceIT.createEntity; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@IntegrationTest +class ScenarioParameterRepositoryIT { + + @Autowired + private EntityManager entityManager; + + @Autowired + ScenarioParameterRepository scenarioParameterRepository; + + private ScenarioParameter scenarioParameter; + + private static void verifyRelationships(ScenarioParameter scenarioParameter) { + assertNotNull(scenarioParameter.getScenarioExecution()); + } + + @BeforeEach + void beforeEachSetup() throws ScenarioExecution.ErrorMessageTruncationException { + scenarioParameter = createEntity(entityManager); + + ScenarioExecution scenarioExecution = ScenarioExecutionResourceIT.createEntity(entityManager); + entityManager.persist(scenarioExecution); + scenarioParameter.setScenarioExecution(scenarioExecution); + + entityManager.persist(scenarioParameter); + } + + @Test + @Transactional + void testFindAllWithToOneRelationships() { + Page scenarioParameters = scenarioParameterRepository.findAllWithToOneRelationships(Pageable.unpaged()); + + assertTrue(scenarioParameters.hasContent()); + verifyRelationships(scenarioParameters.getContent().get(0)); + } + + @Test + @Transactional + void testFindOneWithToOneRelationships() { + Optional scenarioParameters = scenarioParameterRepository.findOneWithToOneRelationships(scenarioParameter.getParameterId()); + + assertTrue(scenarioParameters.isPresent()); + verifyRelationships(scenarioParameters.get()); + + assertFalse(scenarioParameterRepository.findOneWithToOneRelationships(Long.MAX_VALUE).isPresent()); + } +} diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/repository/TestResultRepositoryIT.java b/simulator-starter/src/test/java/org/citrusframework/simulator/repository/TestResultRepositoryIT.java index 7f0627aba..266bda267 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/repository/TestResultRepositoryIT.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/repository/TestResultRepositoryIT.java @@ -25,7 +25,7 @@ class TestResultRepositoryIT { private List testResults; @BeforeEach - void beforeEachSetup(){ + void beforeEachSetup() { testResults = testResultRepository.saveAll( List.of( TestResult.builder() @@ -39,9 +39,10 @@ void beforeEachSetup(){ ) ); } + @Test @Transactional - void countByStatus(){ + void countByStatus() { TestResultByStatus testResultByStatus = testResultRepository.countByStatus(); assertEquals(2, testResultByStatus.total()); @@ -50,7 +51,7 @@ void countByStatus(){ } @AfterEach - void afterEachTeardown(){ + void afterEachTeardown() { testResultRepository.deleteAll(testResults); } } diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/service/criteria/ScenarioParameterCriteriaTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/service/criteria/ScenarioParameterCriteriaTest.java new file mode 100644 index 000000000..5bf19efd9 --- /dev/null +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/service/criteria/ScenarioParameterCriteriaTest.java @@ -0,0 +1,132 @@ +package org.citrusframework.simulator.service.criteria; + +import org.citrusframework.simulator.service.filter.InstantFilter; +import org.citrusframework.simulator.service.filter.IntegerFilter; +import org.citrusframework.simulator.service.filter.LongFilter; +import org.citrusframework.simulator.service.filter.StringFilter; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; + +class ScenarioParameterCriteriaTest { + + private ScenarioParameterCriteria fixture; + + @BeforeEach + void beforeEachSetup() { + fixture = new ScenarioParameterCriteria(); + } + + @Test + void testParameterId() { + assertNull(fixture.getParameterId()); + + LongFilter parameterIdFilter = fixture.id(); + assertNotNull(parameterIdFilter); + assertSame(parameterIdFilter, fixture.getParameterId()); + + LongFilter mockParameterIdFilter = mock(LongFilter.class); + fixture.setParameterId(mockParameterIdFilter); + assertSame(mockParameterIdFilter, fixture.id()); + } + + @Test + void testName() { + assertNull(fixture.getName()); + + StringFilter nameFilter = fixture.name(); + assertNotNull(nameFilter); + assertSame(nameFilter, fixture.getName()); + + StringFilter mockNameFilter = mock(StringFilter.class); + fixture.setName(mockNameFilter); + assertSame(mockNameFilter, fixture.name()); + } + + @Test + void testControlType() { + assertNull(fixture.getControlType()); + + IntegerFilter controlTypeFilter = fixture.controlType(); + assertNotNull(controlTypeFilter); + assertSame(controlTypeFilter, fixture.getControlType()); + + IntegerFilter mockControlTypeFilter = mock(IntegerFilter.class); + fixture.setControlType(mockControlTypeFilter); + assertSame(mockControlTypeFilter, fixture.controlType()); + } + + @Test + void testValue() { + assertNull(fixture.getValue()); + + StringFilter valueFilter = fixture.value(); + assertNotNull(valueFilter); + assertSame(valueFilter, fixture.getValue()); + + StringFilter mockValueFilter = mock(StringFilter.class); + fixture.setValue(mockValueFilter); + assertSame(mockValueFilter, fixture.value()); + } + + @Test + void testCreatedDate() { + assertNull(fixture.getCreatedDate()); + + InstantFilter createdDateFilter = fixture.createdDate(); + assertNotNull(createdDateFilter); + assertSame(createdDateFilter, fixture.getCreatedDate()); + + InstantFilter mockCreatedDateFilter = mock(InstantFilter.class); + fixture.setCreatedDate(mockCreatedDateFilter); + assertSame(mockCreatedDateFilter, fixture.createdDate()); + } + + @Test + void testLastModifiedDate() { + assertNull(fixture.getLastModifiedDate()); + + InstantFilter lastModifiedDateFilter = fixture.lastModifiedDate(); + assertNotNull(lastModifiedDateFilter); + assertSame(lastModifiedDateFilter, fixture.getLastModifiedDate()); + + InstantFilter mockLastModifiedDateFilter = mock(InstantFilter.class); + fixture.setLastModifiedDate(mockLastModifiedDateFilter); + assertSame(mockLastModifiedDateFilter, fixture.lastModifiedDate()); + } + + @Test + void testScenarioExecutionId() { + assertNull(fixture.getScenarioExecutionId()); + + LongFilter scenarioExecutionIdFilter = fixture.scenarioExecutionId(); + assertNotNull(scenarioExecutionIdFilter); + assertSame(scenarioExecutionIdFilter, fixture.getScenarioExecutionId()); + + LongFilter mockScenarioExecutionIdFilter = mock(LongFilter.class); + fixture.setScenarioExecutionId(mockScenarioExecutionIdFilter); + assertSame(mockScenarioExecutionIdFilter, fixture.scenarioExecutionId()); + } + + @Test + void testDistinct() { + assertNull(fixture.getDistinct()); + + fixture.setDistinct(true); + assertTrue(fixture.getDistinct()); + } + + @Test + void testCopy() { + ScenarioParameterCriteria copiedCriteria = fixture.copy(); + assertNotSame(copiedCriteria, fixture); + assertEquals(copiedCriteria, fixture); + } +} diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/service/criteria/TestParameterCriteriaTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/service/criteria/TestParameterCriteriaTest.java index 658f63033..0d3c6a534 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/service/criteria/TestParameterCriteriaTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/service/criteria/TestParameterCriteriaTest.java @@ -6,8 +6,12 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.mockito.Mockito.mock; class TestParameterCriteriaTest { diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/service/impl/MessageHeaderServiceImplTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/service/impl/MessageHeaderServiceImplTest.java index d1632e9b7..4e832b341 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/service/impl/MessageHeaderServiceImplTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/service/impl/MessageHeaderServiceImplTest.java @@ -18,7 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/service/impl/ScenarioActionServiceImplTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/service/impl/ScenarioActionServiceImplTest.java index 563a38a94..21c2ef374 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/service/impl/ScenarioActionServiceImplTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/service/impl/ScenarioActionServiceImplTest.java @@ -1,6 +1,5 @@ package org.citrusframework.simulator.service.impl; -import org.citrusframework.simulator.model.Message; import org.citrusframework.simulator.model.ScenarioAction; import org.citrusframework.simulator.model.ScenarioExecution; import org.citrusframework.simulator.repository.ScenarioActionRepository; @@ -20,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -71,6 +69,7 @@ void testFindAll() { verifyDtoPreparations(); } + @Test void testFindOne() { Long scenarioActionId = 1L; diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/service/impl/ScenarioParameterServiceImplTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/service/impl/ScenarioParameterServiceImplTest.java new file mode 100644 index 000000000..3bc62a905 --- /dev/null +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/service/impl/ScenarioParameterServiceImplTest.java @@ -0,0 +1,84 @@ +package org.citrusframework.simulator.service.impl; + +import org.citrusframework.simulator.model.ScenarioParameter; +import org.citrusframework.simulator.repository.ScenarioParameterRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; + +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class ScenarioParameterServiceImplTest { + + @Mock + private ScenarioParameterRepository scenarioParameterRepositoryMock; + + private ScenarioParameter sampleScenarioParameter; + + private ScenarioParameterServiceImpl fixture; + + @BeforeEach + void beforeEachSetup() { + sampleScenarioParameter = new ScenarioParameter(); + // You can add any necessary initialization for the ScenarioParameter here. + // sampleScenarioParameter.set... + + fixture = new ScenarioParameterServiceImpl(scenarioParameterRepositoryMock); + } + + @Test + void testSave() { + when(scenarioParameterRepositoryMock.save(sampleScenarioParameter)).thenReturn(sampleScenarioParameter); + + ScenarioParameter savedScenarioParameter = fixture.save(sampleScenarioParameter); + assertEquals(sampleScenarioParameter, savedScenarioParameter); + } + + @Test + void testFindAll() { + Pageable pageable = Pageable.unpaged(); + Page page = new PageImpl<>(List.of(sampleScenarioParameter)); + + when(scenarioParameterRepositoryMock.findAllWithEagerRelationships(pageable)).thenReturn(page); + + Page result = fixture.findAll(pageable); + + assertEquals(page, result); + } + + @Test + void testFindOne() { + Long scenarioParameterId = 1L; + + when(scenarioParameterRepositoryMock.findOneWithEagerRelationships(scenarioParameterId)).thenReturn(Optional.of(sampleScenarioParameter)); + + Optional maybeScenarioParameter = fixture.findOne(scenarioParameterId); + + assertTrue(maybeScenarioParameter.isPresent()); + assertEquals(sampleScenarioParameter, maybeScenarioParameter.get()); + } + + @Test + void testDelete() { + Long scenarioParameterId = 1L; + + doNothing().when(scenarioParameterRepositoryMock).deleteById(scenarioParameterId); + + fixture.delete(scenarioParameterId); + + verify(scenarioParameterRepositoryMock).deleteById(scenarioParameterId); + } +} diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/template/TemplateHelperTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/template/TemplateHelperTest.java index 152e53924..7ca005de8 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/template/TemplateHelperTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/template/TemplateHelperTest.java @@ -28,15 +28,6 @@ static Stream getFileResource() { ); } - @MethodSource - @ParameterizedTest - void getFileResource(String basePath, String fileName, String fileExtension, boolean shouldExist) { - final TemplateHelper testling = TemplateHelper.instance(basePath, UTF_8); - final Resource fileResource = testling.getFileResource(fileName, fileExtension); - - assertEquals(shouldExist, fileResource.exists()); - } - static Stream getXmlMessageTemplate() { return Stream.of( Arguments.of("", "test.xml", null), @@ -49,18 +40,6 @@ static Stream getXmlMessageTemplate() { ); } - @MethodSource - @ParameterizedTest - void getXmlMessageTemplate(String basePath, String fileName, String expectedContent) { - final TemplateHelper testling = TemplateHelper.instance(basePath, UTF_8); - try { - final String content = testling.getXmlMessageTemplate(fileName); - assertTrue(content.contains(expectedContent)); - } catch (Exception e) { - assertNull(expectedContent); - } - } - static Stream getJsonMessageTemplate() { return Stream.of( Arguments.of("", "test.json", null), @@ -73,6 +52,27 @@ static Stream getJsonMessageTemplate() { ); } + @MethodSource + @ParameterizedTest + void getFileResource(String basePath, String fileName, String fileExtension, boolean shouldExist) { + final TemplateHelper testling = TemplateHelper.instance(basePath, UTF_8); + final Resource fileResource = testling.getFileResource(fileName, fileExtension); + + assertEquals(shouldExist, fileResource.exists()); + } + + @MethodSource + @ParameterizedTest + void getXmlMessageTemplate(String basePath, String fileName, String expectedContent) { + final TemplateHelper testling = TemplateHelper.instance(basePath, UTF_8); + try { + final String content = testling.getXmlMessageTemplate(fileName); + assertTrue(content.contains(expectedContent)); + } catch (Exception e) { + assertNull(expectedContent); + } + } + @MethodSource @ParameterizedTest void getJsonMessageTemplate(String basePath, String fileName, String expectedContent) { diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/MessageResourceIT.java b/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/MessageResourceIT.java index 38473829d..721e676ce 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/MessageResourceIT.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/MessageResourceIT.java @@ -66,7 +66,7 @@ public class MessageResourceIT { /** * Create an entity for this test. - * + *

* This is a static method, as tests for other entities might also need it, * if they test an entity which requires the current entity. */ @@ -82,7 +82,7 @@ public static Message createEntity(EntityManager entityManager) { /** * Create an updated entity for this test. - * + *

* This is a static method, as tests for other entities might also need it, * if they test an entity which requires the current entity. */ diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/ScenarioActionResourceIT.java b/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/ScenarioActionResourceIT.java index e9699efb4..6f8b1c67c 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/ScenarioActionResourceIT.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/ScenarioActionResourceIT.java @@ -16,6 +16,8 @@ import org.springframework.transaction.annotation.Transactional; import java.time.Instant; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import static org.hamcrest.Matchers.hasItem; @@ -37,9 +39,11 @@ public class ScenarioActionResourceIT { private static final Instant DEFAULT_START_DATE = Instant.ofEpochMilli(0L); private static final Instant UPDATED_START_DATE = Instant.now().truncatedTo(ChronoUnit.MILLIS); + private static final ZonedDateTime SMALLER_START_DATE = ZonedDateTime.ofInstant(Instant.ofEpochMilli(-1L), ZoneOffset.UTC); private static final Instant DEFAULT_END_DATE = Instant.ofEpochMilli(0L); private static final Instant UPDATED_END_DATE = Instant.now().truncatedTo(ChronoUnit.MILLIS); + private static final ZonedDateTime SMALLER_END_DATE = ZonedDateTime.ofInstant(Instant.ofEpochMilli(-1L), ZoneOffset.UTC); private static final String ENTITY_API_URL = "/api/scenario-actions"; private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; @@ -57,7 +61,7 @@ public class ScenarioActionResourceIT { /** * Create an entity for this test. - * + *

* This is a static method, as tests for other entities might also need it, * if they test an entity which requires the current entity. */ @@ -71,7 +75,7 @@ public static ScenarioAction createEntity(EntityManager entityManager) { /** * Create an updated entity for this test. - * + *

* This is a static method, as tests for other entities might also need it, * if they test an entity which requires the current entity. */ @@ -244,6 +248,32 @@ void getAllScenarioActionsByStartDateIsNullOrNotNull() throws Exception { defaultScenarioActionShouldNotBeFound("startDate.specified=false"); } + @Test + @Transactional + void getAllTestParametersByCreatedDateIsGreaterThanOrEqualToSomething() throws Exception { + // Initialize the database + scenarioActionRepository.saveAndFlush(scenarioAction); + + // Get all the testParameterList where startDate is greater than or equal to DEFAULT_CREATED_DATE + defaultScenarioActionShouldBeFound("startDate.greaterThanOrEqual=" + DEFAULT_START_DATE); + + // Get all the testParameterList where startDate is greater than or equal to UPDATED_CREATED_DATE + defaultScenarioActionShouldNotBeFound("startDate.greaterThanOrEqual=" + UPDATED_START_DATE); + } + + @Test + @Transactional + void getAllTestParametersByCreatedDateIsLessThanOrEqualToSomething() throws Exception { + // Initialize the database + scenarioActionRepository.saveAndFlush(scenarioAction); + + // Get all the testParameterList where startDate is less than or equal to DEFAULT_CREATED_DATE + defaultScenarioActionShouldBeFound("startDate.lessThanOrEqual=" + DEFAULT_START_DATE); + + // Get all the testParameterList where startDate is less than or equal to SMALLER_CREATED_DATE + defaultScenarioActionShouldNotBeFound("startDate.lessThanOrEqual=" + SMALLER_START_DATE); + } + @Test @Transactional void getAllScenarioActionsByEndDateIsEqualToSomething() throws Exception { @@ -283,6 +313,32 @@ void getAllScenarioActionsByEndDateIsNullOrNotNull() throws Exception { defaultScenarioActionShouldNotBeFound("endDate.specified=false"); } + @Test + @Transactional + void getAllTestParametersByLastModifiedDateIsGreaterThanOrEqualToSomething() throws Exception { + // Initialize the database + scenarioActionRepository.saveAndFlush(scenarioAction); + + // Get all the testParameterList where endDate is greater than or equal to DEFAULT_LAST_MODIFIED_DATE + defaultScenarioActionShouldBeFound("endDate.greaterThanOrEqual=" + DEFAULT_END_DATE); + + // Get all the testParameterList where endDate is greater than or equal to UPDATED_LAST_MODIFIED_DATE + defaultScenarioActionShouldNotBeFound("endDate.greaterThanOrEqual=" + UPDATED_END_DATE); + } + + @Test + @Transactional + void getAllTestParametersByLastModifiedDateIsLessThanOrEqualToSomething() throws Exception { + // Initialize the database + scenarioActionRepository.saveAndFlush(scenarioAction); + + // Get all the testParameterList where endDate is less than or equal to DEFAULT_LAST_MODIFIED_DATE + defaultScenarioActionShouldBeFound("endDate.lessThanOrEqual=" + DEFAULT_END_DATE); + + // Get all the testParameterList where endDate is less than or equal to SMALLER_LAST_MODIFIED_DATE + defaultScenarioActionShouldNotBeFound("endDate.lessThanOrEqual=" + SMALLER_END_DATE); + } + @Test @Transactional void getAllScenarioActionsByScenarioExecutionIsEqualToSomething() throws Exception { diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/ScenarioExecutionResourceIT.java b/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/ScenarioExecutionResourceIT.java index 1fa46befe..182e57201 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/ScenarioExecutionResourceIT.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/ScenarioExecutionResourceIT.java @@ -32,9 +32,11 @@ public class ScenarioExecutionResourceIT { private static final Instant DEFAULT_START_DATE = Instant.ofEpochMilli(0L); private static final Instant UPDATED_START_DATE = Instant.now().truncatedTo(ChronoUnit.MILLIS); + private static final Instant SMALLER_START_DATE = Instant.ofEpochMilli(-1L); private static final Instant DEFAULT_END_DATE = Instant.ofEpochMilli(0L); private static final Instant UPDATED_END_DATE = Instant.now().truncatedTo(ChronoUnit.MILLIS); + private static final Instant SMALLER_END_DATE = Instant.ofEpochMilli(-1L); private static final String DEFAULT_SCENARIO_NAME = "AAAAAAAAAA"; private static final String UPDATED_SCENARIO_NAME = "BBBBBBBBBB"; @@ -193,6 +195,32 @@ void getAllScenarioExecutionsByStartDateIsNullOrNotNull() throws Exception { defaultScenarioExecutionShouldNotBeFound("startDate.specified=false"); } + @Test + @Transactional + void getAllTestParametersByCreatedDateIsGreaterThanOrEqualToSomething() throws Exception { + // Initialize the database + scenarioExecutionRepository.saveAndFlush(scenarioExecution); + + // Get all the testParameterList where startDate is greater than or equal to DEFAULT_CREATED_DATE + defaultScenarioExecutionShouldBeFound("startDate.greaterThanOrEqual=" + DEFAULT_START_DATE); + + // Get all the testParameterList where startDate is greater than or equal to UPDATED_CREATED_DATE + defaultScenarioExecutionShouldNotBeFound("startDate.greaterThanOrEqual=" + UPDATED_START_DATE); + } + + @Test + @Transactional + void getAllTestParametersByCreatedDateIsLessThanOrEqualToSomething() throws Exception { + // Initialize the database + scenarioExecutionRepository.saveAndFlush(scenarioExecution); + + // Get all the testParameterList where startDate is less than or equal to DEFAULT_CREATED_DATE + defaultScenarioExecutionShouldBeFound("startDate.lessThanOrEqual=" + DEFAULT_START_DATE); + + // Get all the testParameterList where startDate is less than or equal to SMALLER_CREATED_DATE + defaultScenarioExecutionShouldNotBeFound("startDate.lessThanOrEqual=" + SMALLER_START_DATE); + } + @Test @Transactional void getAllScenarioExecutionsByEndDateIsEqualToSomething() throws Exception { @@ -232,6 +260,32 @@ void getAllScenarioExecutionsByEndDateIsNullOrNotNull() throws Exception { defaultScenarioExecutionShouldNotBeFound("endDate.specified=false"); } + @Test + @Transactional + void getAllTestParametersByLastModifiedDateIsGreaterThanOrEqualToSomething() throws Exception { + // Initialize the database + scenarioExecutionRepository.saveAndFlush(scenarioExecution); + + // Get all the testParameterList where endDate is greater than or equal to DEFAULT_LAST_MODIFIED_DATE + defaultScenarioExecutionShouldBeFound("endDate.greaterThanOrEqual=" + DEFAULT_END_DATE); + + // Get all the testParameterList where endDate is greater than or equal to UPDATED_LAST_MODIFIED_DATE + defaultScenarioExecutionShouldNotBeFound("endDate.greaterThanOrEqual=" + UPDATED_END_DATE); + } + + @Test + @Transactional + void getAllTestParametersByLastModifiedDateIsLessThanOrEqualToSomething() throws Exception { + // Initialize the database + scenarioExecutionRepository.saveAndFlush(scenarioExecution); + + // Get all the testParameterList where endDate is less than or equal to DEFAULT_LAST_MODIFIED_DATE + defaultScenarioExecutionShouldBeFound("endDate.lessThanOrEqual=" + DEFAULT_END_DATE); + + // Get all the testParameterList where endDate is less than or equal to SMALLER_LAST_MODIFIED_DATE + defaultScenarioExecutionShouldNotBeFound("endDate.lessThanOrEqual=" + SMALLER_END_DATE); + } + @Test @Transactional void getAllScenarioExecutionsByScenarioNameIsEqualToSomething() throws Exception { diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/ScenarioParameterResourceIT.java b/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/ScenarioParameterResourceIT.java new file mode 100644 index 000000000..6e57f85c6 --- /dev/null +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/ScenarioParameterResourceIT.java @@ -0,0 +1,567 @@ +package org.citrusframework.simulator.web.rest; + +import jakarta.persistence.EntityManager; +import org.citrusframework.simulator.IntegrationTest; +import org.citrusframework.simulator.model.ScenarioExecution; +import org.citrusframework.simulator.model.ScenarioParameter; +import org.citrusframework.simulator.repository.ScenarioParameterRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.transaction.annotation.Transactional; + +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; + +import static org.citrusframework.simulator.web.rest.TestUtil.sameInstant; +import static org.hamcrest.Matchers.hasItem; +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; + +/** + * Integration tests for the {@link ScenarioParameterResource} REST controller. + */ +@IntegrationTest +@AutoConfigureMockMvc +public class ScenarioParameterResourceIT { + + private static final String DEFAULT_NAME = "AAAAAAAAAA"; + private static final String UPDATED_NAME = "BBBBBBBBBB"; + + private static final ScenarioParameter.ControlType DEFAULT_CONTROL_TYPE = ScenarioParameter.ControlType.TEXTBOX; // Integer value: 1 + private static final ScenarioParameter.ControlType UPDATED_CONTROL_TYPE = ScenarioParameter.ControlType.TEXTAREA; // Integer value: 2 + + private static final String DEFAULT_VALUE = "AAAAAAAAAA"; + private static final String UPDATED_VALUE = "BBBBBBBBBB"; + + private static final ZonedDateTime DEFAULT_CREATED_DATE = ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneOffset.UTC); + private static final ZonedDateTime UPDATED_CREATED_DATE = ZonedDateTime.now(ZoneId.systemDefault()).withNano(0); + private static final ZonedDateTime SMALLER_CREATED_DATE = ZonedDateTime.ofInstant(Instant.ofEpochMilli(-1L), ZoneOffset.UTC); + + private static final ZonedDateTime DEFAULT_LAST_MODIFIED_DATE = ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneOffset.UTC); + private static final ZonedDateTime UPDATED_LAST_MODIFIED_DATE = ZonedDateTime.now(ZoneId.systemDefault()).withNano(0); + private static final ZonedDateTime SMALLER_LAST_MODIFIED_DATE = ZonedDateTime.ofInstant(Instant.ofEpochMilli(-1L), ZoneOffset.UTC); + + private static final String ENTITY_API_URL = "/api/scenario-parameters"; + private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; + + @Autowired + private ScenarioParameterRepository scenarioParameterRepository; + + @Autowired + private EntityManager entityManager; + + @Autowired + private MockMvc restScenarioParameterMockMvc; + + private ScenarioParameter scenarioParameter; + + /** + * Create an entity for this test. + *

+ * This is a static method, as tests for other entities might also need it, + * if they test an entity which requires the current entity. + */ + public static ScenarioParameter createEntity(EntityManager entityManager) { + return ScenarioParameter.builder() + .name(DEFAULT_NAME) + .controlType(DEFAULT_CONTROL_TYPE) + .value(DEFAULT_VALUE) + .createdDate(DEFAULT_CREATED_DATE) + .lastModifiedDate(DEFAULT_LAST_MODIFIED_DATE) + .build(); + } + + /** + * Create an updated entity for this test. + *

+ * This is a static method, as tests for other entities might also need it, + * if they test an entity which requires the current entity. + */ + public static ScenarioParameter createUpdatedEntity(EntityManager entityManager) { + return ScenarioParameter.builder() + .name(UPDATED_NAME) + .controlType(UPDATED_CONTROL_TYPE) + .value(UPDATED_VALUE) + .createdDate(UPDATED_CREATED_DATE) + .lastModifiedDate(UPDATED_LAST_MODIFIED_DATE) + .build(); + } + + @BeforeEach + public void initTest() { + scenarioParameter = createEntity(entityManager); + } + + @Test + @Transactional + void getAllScenarioParameters() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList + restScenarioParameterMockMvc + .perform(get(ENTITY_API_URL + "?sort=parameterId,desc")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(jsonPath("$.[*].parameterId").value(hasItem(scenarioParameter.getParameterId().intValue()))) + .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME))) + .andExpect(jsonPath("$.[*].controlType").value(hasItem(DEFAULT_CONTROL_TYPE.toString()))) + .andExpect(jsonPath("$.[*].value").value(hasItem(DEFAULT_VALUE))) + .andExpect(jsonPath("$.[*].createdDate").value(hasItem(sameInstant(DEFAULT_CREATED_DATE)))) + .andExpect(jsonPath("$.[*].lastModifiedDate").value(hasItem(sameInstant(DEFAULT_LAST_MODIFIED_DATE)))); + } + + @Test + @Transactional + void getScenarioParameter() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get the scenarioParameter + restScenarioParameterMockMvc + .perform(get(ENTITY_API_URL_ID, scenarioParameter.getParameterId())) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(jsonPath("$.parameterId").value(scenarioParameter.getParameterId().intValue())) + .andExpect(jsonPath("$.name").value(DEFAULT_NAME)) + .andExpect(jsonPath("$.controlType").value(DEFAULT_CONTROL_TYPE.toString())) + .andExpect(jsonPath("$.value").value(DEFAULT_VALUE)) + .andExpect(jsonPath("$.createdDate").value(sameInstant(DEFAULT_CREATED_DATE))) + .andExpect(jsonPath("$.lastModifiedDate").value(sameInstant(DEFAULT_LAST_MODIFIED_DATE))); + } + + @Test + @Transactional + void getScenarioParametersByIdFiltering() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + Long parameterId = scenarioParameter.getParameterId(); + + defaultScenarioParameterShouldBeFound("parameterId.equals=" + parameterId); + defaultScenarioParameterShouldNotBeFound("parameterId.notEquals=" + parameterId); + + defaultScenarioParameterShouldBeFound("parameterId.greaterThanOrEqual=" + parameterId); + defaultScenarioParameterShouldNotBeFound("parameterId.greaterThan=" + parameterId); + + defaultScenarioParameterShouldBeFound("parameterId.lessThanOrEqual=" + parameterId); + defaultScenarioParameterShouldNotBeFound("parameterId.lessThan=" + parameterId); + } + + @Test + @Transactional + void getAllScenarioParametersByNameIsEqualToSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where name equals to DEFAULT_NAME + defaultScenarioParameterShouldBeFound("name.equals=" + DEFAULT_NAME); + + // Get all the scenarioParameterList where name equals to UPDATED_NAME + defaultScenarioParameterShouldNotBeFound("name.equals=" + UPDATED_NAME); + } + + @Test + @Transactional + void getAllScenarioParametersByNameIsInShouldWork() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where name in DEFAULT_NAME or UPDATED_NAME + defaultScenarioParameterShouldBeFound("name.in=" + DEFAULT_NAME + "," + UPDATED_NAME); + + // Get all the scenarioParameterList where name equals to UPDATED_NAME + defaultScenarioParameterShouldNotBeFound("name.in=" + UPDATED_NAME); + } + + @Test + @Transactional + void getAllScenarioParametersByNameIsNullOrNotNull() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where name is not null + defaultScenarioParameterShouldBeFound("name.specified=true"); + + // Get all the scenarioParameterList where name is null + defaultScenarioParameterShouldNotBeFound("name.specified=false"); + } + + @Test + @Transactional + void getAllScenarioParametersByNameContainsSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where name contains DEFAULT_NAME + defaultScenarioParameterShouldBeFound("name.contains=" + DEFAULT_NAME); + + // Get all the scenarioParameterList where name contains UPDATED_NAME + defaultScenarioParameterShouldNotBeFound("name.contains=" + UPDATED_NAME); + } + + @Test + @Transactional + void getAllScenarioParametersByNameNotContainsSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where name does not contain DEFAULT_NAME + defaultScenarioParameterShouldNotBeFound("name.doesNotContain=" + DEFAULT_NAME); + + // Get all the scenarioParameterList where name does not contain UPDATED_NAME + defaultScenarioParameterShouldBeFound("name.doesNotContain=" + UPDATED_NAME); + } + + @Test + @Transactional + void getAllScenarioParametersByControlTypeIsEqualToSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where controlType equals to DEFAULT_CONTROL_TYPE + defaultScenarioParameterShouldBeFound("controlType.equals=" + DEFAULT_CONTROL_TYPE.getId()); + + // Get all the scenarioParameterList where controlType equals to UPDATED_CONTROL_TYPE + defaultScenarioParameterShouldNotBeFound("controlType.equals=" + UPDATED_CONTROL_TYPE.getId()); + } + + @Test + @Transactional + void getAllScenarioParametersByControlTypeIsInShouldWork() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where controlType in DEFAULT_CONTROL_TYPE or UPDATED_CONTROL_TYPE + defaultScenarioParameterShouldBeFound("controlType.in=" + DEFAULT_CONTROL_TYPE.getId() + "," + UPDATED_CONTROL_TYPE.getId()); + + // Get all the scenarioParameterList where controlType equals to UPDATED_CONTROL_TYPE + defaultScenarioParameterShouldNotBeFound("controlType.in=" + UPDATED_CONTROL_TYPE.getId()); + } + + @Test + @Transactional + void getAllScenarioParametersByControlTypeIsNullOrNotNull() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where controlType is not null + defaultScenarioParameterShouldBeFound("controlType.specified=true"); + + // Get all the scenarioParameterList where controlType is null + defaultScenarioParameterShouldNotBeFound("controlType.specified=false"); + } + + @Test + @Transactional + void getAllScenarioParametersByControlTypeIsGreaterThanOrEqualToSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where controlType is greater than or equal to DEFAULT_CONTROL_TYPE + defaultScenarioParameterShouldBeFound("controlType.greaterThanOrEqual=" + DEFAULT_CONTROL_TYPE.getId()); + + // Get all the scenarioParameterList where controlType is greater than or equal to UPDATED_CONTROL_TYPE + defaultScenarioParameterShouldNotBeFound("controlType.greaterThanOrEqual=" + UPDATED_CONTROL_TYPE.getId()); + } + + @Test + @Transactional + void getAllScenarioParametersByValueIsEqualToSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where value equals to DEFAULT_VALUE + defaultScenarioParameterShouldBeFound("value.equals=" + DEFAULT_VALUE); + + // Get all the scenarioParameterList where value equals to UPDATED_VALUE + defaultScenarioParameterShouldNotBeFound("value.equals=" + UPDATED_VALUE); + } + + @Test + @Transactional + void getAllScenarioParametersByValueIsInShouldWork() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where value in DEFAULT_VALUE or UPDATED_VALUE + defaultScenarioParameterShouldBeFound("value.in=" + DEFAULT_VALUE + "," + UPDATED_VALUE); + + // Get all the scenarioParameterList where value equals to UPDATED_VALUE + defaultScenarioParameterShouldNotBeFound("value.in=" + UPDATED_VALUE); + } + + @Test + @Transactional + void getAllScenarioParametersByValueIsNullOrNotNull() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where value is not null + defaultScenarioParameterShouldBeFound("value.specified=true"); + + // Get all the scenarioParameterList where value is null + defaultScenarioParameterShouldNotBeFound("value.specified=false"); + } + + @Test + @Transactional + void getAllScenarioParametersByValueContainsSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where value contains DEFAULT_VALUE + defaultScenarioParameterShouldBeFound("value.contains=" + DEFAULT_VALUE); + + // Get all the scenarioParameterList where value contains UPDATED_VALUE + defaultScenarioParameterShouldNotBeFound("value.contains=" + UPDATED_VALUE); + } + + @Test + @Transactional + void getAllScenarioParametersByValueNotContainsSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where value does not contain DEFAULT_VALUE + defaultScenarioParameterShouldNotBeFound("value.doesNotContain=" + DEFAULT_VALUE); + + // Get all the scenarioParameterList where value does not contain UPDATED_VALUE + defaultScenarioParameterShouldBeFound("value.doesNotContain=" + UPDATED_VALUE); + } + + @Test + @Transactional + void getAllScenarioParametersByCreatedDateIsEqualToSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where createdDate equals to DEFAULT_CREATED_DATE + defaultScenarioParameterShouldBeFound("createdDate.equals=" + DEFAULT_CREATED_DATE); + + // Get all the scenarioParameterList where createdDate equals to UPDATED_CREATED_DATE + defaultScenarioParameterShouldNotBeFound("createdDate.equals=" + UPDATED_CREATED_DATE); + } + + @Test + @Transactional + void getAllScenarioParametersByCreatedDateIsInShouldWork() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where createdDate in DEFAULT_CREATED_DATE or UPDATED_CREATED_DATE + defaultScenarioParameterShouldBeFound("createdDate.in=" + DEFAULT_CREATED_DATE + "," + UPDATED_CREATED_DATE); + + // Get all the scenarioParameterList where createdDate equals to UPDATED_CREATED_DATE + defaultScenarioParameterShouldNotBeFound("createdDate.in=" + UPDATED_CREATED_DATE); + } + + @Test + @Transactional + void getAllScenarioParametersByCreatedDateIsNullOrNotNull() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where createdDate is not null + defaultScenarioParameterShouldBeFound("createdDate.specified=true"); + + // Get all the scenarioParameterList where createdDate is null + defaultScenarioParameterShouldNotBeFound("createdDate.specified=false"); + } + + @Test + @Transactional + void getAllScenarioParametersByCreatedDateIsGreaterThanOrEqualToSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where createdDate is greater than or equal to DEFAULT_CREATED_DATE + defaultScenarioParameterShouldBeFound("createdDate.greaterThanOrEqual=" + DEFAULT_CREATED_DATE); + + // Get all the scenarioParameterList where createdDate is greater than or equal to UPDATED_CREATED_DATE + defaultScenarioParameterShouldNotBeFound("createdDate.greaterThanOrEqual=" + UPDATED_CREATED_DATE); + } + + @Test + @Transactional + void getAllScenarioParametersByCreatedDateIsLessThanOrEqualToSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where createdDate is less than or equal to DEFAULT_CREATED_DATE + defaultScenarioParameterShouldBeFound("createdDate.lessThanOrEqual=" + DEFAULT_CREATED_DATE); + + // Get all the scenarioParameterList where createdDate is less than or equal to SMALLER_CREATED_DATE + defaultScenarioParameterShouldNotBeFound("createdDate.lessThanOrEqual=" + SMALLER_CREATED_DATE); + } + + @Test + @Transactional + void getAllScenarioParametersByCreatedDateIsLessThanSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where createdDate is less than DEFAULT_CREATED_DATE + defaultScenarioParameterShouldNotBeFound("createdDate.lessThan=" + DEFAULT_CREATED_DATE); + + // Get all the scenarioParameterList where createdDate is less than UPDATED_CREATED_DATE + defaultScenarioParameterShouldBeFound("createdDate.lessThan=" + UPDATED_CREATED_DATE); + } + + @Test + @Transactional + void getAllScenarioParametersByCreatedDateIsGreaterThanSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where createdDate is greater than DEFAULT_CREATED_DATE + defaultScenarioParameterShouldNotBeFound("createdDate.greaterThan=" + DEFAULT_CREATED_DATE); + + // Get all the scenarioParameterList where createdDate is greater than SMALLER_CREATED_DATE + defaultScenarioParameterShouldBeFound("createdDate.greaterThan=" + SMALLER_CREATED_DATE); + } + + @Test + @Transactional + void getAllScenarioParametersByLastModifiedDateIsEqualToSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where lastModifiedDate equals to DEFAULT_LAST_MODIFIED_DATE + defaultScenarioParameterShouldBeFound("lastModifiedDate.equals=" + DEFAULT_LAST_MODIFIED_DATE); + + // Get all the scenarioParameterList where lastModifiedDate equals to UPDATED_LAST_MODIFIED_DATE + defaultScenarioParameterShouldNotBeFound("lastModifiedDate.equals=" + UPDATED_LAST_MODIFIED_DATE); + } + + @Test + @Transactional + void getAllScenarioParametersByLastModifiedDateIsInShouldWork() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where lastModifiedDate in DEFAULT_LAST_MODIFIED_DATE or UPDATED_LAST_MODIFIED_DATE + defaultScenarioParameterShouldBeFound("lastModifiedDate.in=" + DEFAULT_LAST_MODIFIED_DATE + "," + UPDATED_LAST_MODIFIED_DATE); + + // Get all the scenarioParameterList where lastModifiedDate equals to UPDATED_LAST_MODIFIED_DATE + defaultScenarioParameterShouldNotBeFound("lastModifiedDate.in=" + UPDATED_LAST_MODIFIED_DATE); + } + + @Test + @Transactional + void getAllScenarioParametersByLastModifiedDateIsNullOrNotNull() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the scenarioParameterList where lastModifiedDate is not null + defaultScenarioParameterShouldBeFound("lastModifiedDate.specified=true"); + + // Get all the scenarioParameterList where lastModifiedDate is null + defaultScenarioParameterShouldNotBeFound("lastModifiedDate.specified=false"); + } + + @Test + @Transactional + void getAllMessageHeadersByLastModifiedDateIsGreaterThanOrEqualToSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the messageHeaderList where lastModifiedDate is greater than or equal to DEFAULT_LAST_MODIFIED_DATE + defaultScenarioParameterShouldBeFound("lastModifiedDate.greaterThanOrEqual=" + DEFAULT_LAST_MODIFIED_DATE); + + // Get all the messageHeaderList where lastModifiedDate is greater than or equal to UPDATED_LAST_MODIFIED_DATE + defaultScenarioParameterShouldNotBeFound("lastModifiedDate.greaterThanOrEqual=" + UPDATED_LAST_MODIFIED_DATE); + } + + @Test + @Transactional + void getAllMessageHeadersByLastModifiedDateIsLessThanOrEqualToSomething() throws Exception { + // Initialize the database + scenarioParameterRepository.saveAndFlush(scenarioParameter); + + // Get all the messageHeaderList where lastModifiedDate is less than or equal to DEFAULT_LAST_MODIFIED_DATE + defaultScenarioParameterShouldBeFound("lastModifiedDate.lessThanOrEqual=" + DEFAULT_LAST_MODIFIED_DATE); + + // Get all the messageHeaderList where lastModifiedDate is less than or equal to SMALLER_LAST_MODIFIED_DATE + defaultScenarioParameterShouldNotBeFound("lastModifiedDate.lessThanOrEqual=" + SMALLER_LAST_MODIFIED_DATE); + } + + @Test + @Transactional + void getAllScenarioParametersByScenarioExecutionIsEqualToSomething() throws Exception { + ScenarioExecution scenarioExecution; + if (TestUtil.findAll(entityManager, ScenarioExecution.class).isEmpty()) { + scenarioParameterRepository.saveAndFlush(scenarioParameter); + scenarioExecution = ScenarioExecutionResourceIT.createEntity(entityManager); + } else { + scenarioExecution = TestUtil.findAll(entityManager, ScenarioExecution.class).get(0); + } + entityManager.persist(scenarioExecution); + entityManager.flush(); + scenarioParameter.setScenarioExecution(scenarioExecution); + scenarioParameterRepository.saveAndFlush(scenarioParameter); + Long scenarioExecutionId = scenarioExecution.getExecutionId(); + // Get all the scenarioParameterList where scenarioExecution equals to scenarioExecutionId + defaultScenarioParameterShouldBeFound("scenarioExecutionId.equals=" + scenarioExecutionId); + + // Get all the scenarioParameterList where scenarioExecution equals to (scenarioExecutionId + 1) + defaultScenarioParameterShouldNotBeFound("scenarioExecutionId.equals=" + (scenarioExecutionId + 1)); + } + + /** + * Executes the search, and checks that the default entity is returned. + */ + private void defaultScenarioParameterShouldBeFound(String filter) throws Exception { + restScenarioParameterMockMvc + .perform(get(ENTITY_API_URL + "?sort=parameterId,desc&" + filter)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(jsonPath("$.[*].parameterId").value(hasItem(scenarioParameter.getParameterId().intValue()))) + .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME))) + .andExpect(jsonPath("$.[*].controlType").value(hasItem(DEFAULT_CONTROL_TYPE.toString()))) + .andExpect(jsonPath("$.[*].value").value(hasItem(DEFAULT_VALUE))) + .andExpect(jsonPath("$.[*].createdDate").value(hasItem(sameInstant(DEFAULT_CREATED_DATE)))) + .andExpect(jsonPath("$.[*].lastModifiedDate").value(hasItem(sameInstant(DEFAULT_LAST_MODIFIED_DATE)))); + + // Check, that the count call also returns 1 + restScenarioParameterMockMvc + .perform(get(ENTITY_API_URL + "/count?sort=parameterId,desc&" + filter)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string("1")); + } + + /** + * Executes the search, and checks that the default entity is not returned. + */ + private void defaultScenarioParameterShouldNotBeFound(String filter) throws Exception { + restScenarioParameterMockMvc + .perform(get(ENTITY_API_URL + "?sort=parameterId,desc&" + filter)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(jsonPath("$").isArray()) + .andExpect(jsonPath("$").isEmpty()); + + // Check, that the count call also returns 0 + restScenarioParameterMockMvc + .perform(get(ENTITY_API_URL + "/count?sort=parameterId,desc&" + filter)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string("0")); + } + + @Test + @Transactional + void getNonExistingScenarioParameter() throws Exception { + // Get the scenarioParameter + restScenarioParameterMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound()); + } +} diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/TestParameterResourceIT.java b/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/TestParameterResourceIT.java index 08730473b..297cb8cf7 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/TestParameterResourceIT.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/TestParameterResourceIT.java @@ -62,7 +62,7 @@ class TestParameterResourceIT { /** * Create an entity for this test. - * + *

* This is a static method, as tests for other entities might also need it, * if they test an entity which requires the current entity. */ @@ -88,7 +88,7 @@ public static TestParameter createEntity(EntityManager entityManager) { /** * Create an updated entity for this test. - * + *

* This is a static method, as tests for other entities might also need it, * if they test an entity which requires the current entity. */ diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/TestResultResourceIT.java b/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/TestResultResourceIT.java index 0ea32c532..7a17e9f17 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/TestResultResourceIT.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/web/rest/TestResultResourceIT.java @@ -74,7 +74,7 @@ class TestResultResourceIT { /** * Create an entity for this test. - * + *

* This is a static method, as tests for other entities might also need it, * if they test an entity which requires the current entity. */ @@ -93,7 +93,7 @@ public static TestResult createEntity(EntityManager entityManager) { /** * Create an updated entity for this test. - * + *

* This is a static method, as tests for other entities might also need it, * if they test an entity which requires the current entity. */ diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/web/util/ResponseUtilTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/web/util/ResponseUtilTest.java index 95501d712..fa58faac0 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/web/util/ResponseUtilTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/web/util/ResponseUtilTest.java @@ -1,18 +1,19 @@ package org.citrusframework.simulator.web.util; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.List; -import java.util.Optional; import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.server.ResponseStatusException; +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + class ResponseUtilTest { @Test diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/ws/WsdlScenarioGeneratorTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/ws/WsdlScenarioGeneratorTest.java index 527d3c05e..54b4eca3f 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/ws/WsdlScenarioGeneratorTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/ws/WsdlScenarioGeneratorTest.java @@ -43,7 +43,11 @@ class WsdlScenarioGeneratorTest { " true%n" + " stringstri%n" + ""); - + @Mock + private ConfigurableListableBeanFactory beanFactoryMock; + @Mock + private DefaultListableBeanFactory beanRegistryMock; + private WsdlScenarioGenerator fixture; static Stream testGenerateScenarios() { return data(); @@ -61,14 +65,6 @@ static Stream data() { ); } - @Mock - private ConfigurableListableBeanFactory beanFactoryMock; - - @Mock - private DefaultListableBeanFactory beanRegistryMock; - - private WsdlScenarioGenerator fixture; - @BeforeEach void beforeEachSetup() { fixture = new WsdlScenarioGenerator(new ClassPathResource("schema/TestService.wsdl")); diff --git a/simulator-ui/.jhipster/ScenarioExecution.json b/simulator-ui/.jhipster/ScenarioExecution.json index ec19a82f9..3394ae359 100644 --- a/simulator-ui/.jhipster/ScenarioExecution.json +++ b/simulator-ui/.jhipster/ScenarioExecution.json @@ -33,6 +33,13 @@ "pagination": "pagination", "readOnly": true, "relationships": [ + { + "otherEntityName": "scenarioAction", + "otherEntityRelationshipName": "scenarioExecution", + "relationshipName": "scenarioActions", + "relationshipSide": "left", + "relationshipType": "one-to-many" + }, { "otherEntityName": "message", "otherEntityRelationshipName": "scenarioExecution", @@ -41,9 +48,9 @@ "relationshipType": "one-to-many" }, { - "otherEntityName": "scenarioAction", + "otherEntityName": "scenarioParameter", "otherEntityRelationshipName": "scenarioExecution", - "relationshipName": "scenarioAction", + "relationshipName": "scenarioParameters", "relationshipSide": "left", "relationshipType": "one-to-many" } diff --git a/simulator-ui/.jhipster/ScenarioParameter.json b/simulator-ui/.jhipster/ScenarioParameter.json new file mode 100644 index 000000000..f03366162 --- /dev/null +++ b/simulator-ui/.jhipster/ScenarioParameter.json @@ -0,0 +1,47 @@ +{ + "changelogDate": "20231029155942", + "dto": "no", + "entityTableName": "scenario_parameter", + "fields": [ + { + "fieldName": "name", + "fieldType": "String", + "fieldValidateRules": ["required"] + }, + { + "fieldName": "controlType", + "fieldType": "Integer", + "fieldValidateRules": ["required"] + }, + { + "fieldName": "value", + "fieldType": "String", + "fieldValidateRules": ["required"] + }, + { + "fieldName": "createdDate", + "fieldType": "Integer", + "fieldValidateRules": ["required"] + }, + { + "fieldName": "lastModifiedDate", + "fieldType": "Instant", + "fieldValidateRules": ["required"] + } + ], + "jpaMetamodelFiltering": true, + "name": "ScenarioParameter", + "pagination": "pagination", + "readOnly": true, + "relationships": [ + { + "otherEntityField": "scenarioName", + "otherEntityName": "scenarioExecution", + "relationshipName": "scenarioExecution", + "relationshipSide": "left", + "relationshipType": "many-to-one" + } + ], + "searchEngine": "no", + "service": "serviceImpl" +} diff --git a/simulator-ui/.yo-rc.json b/simulator-ui/.yo-rc.json index 101abee13..eb46c33f6 100644 --- a/simulator-ui/.yo-rc.json +++ b/simulator-ui/.yo-rc.json @@ -8,7 +8,7 @@ "creationTimestamp": 1694794967405, "devServerPort": 4200, "enableTranslation": true, - "entities": ["Message", "MessageHeader", "ScenarioExecution", "TestParameter", "TestResult"], + "entities": ["Message", "MessageHeader", "ScenarioExecution", "ScenarioAction", "ScenarioParameter", "TestParameter", "TestResult"], "jhipsterVersion": "8.0.0-beta.3", "languages": ["en"], "microfrontend": false, diff --git a/simulator-ui/src/main/webapp/app/entities/entity-navbar-items.ts b/simulator-ui/src/main/webapp/app/entities/entity-navbar-items.ts index c75045396..4fb7ef77e 100644 --- a/simulator-ui/src/main/webapp/app/entities/entity-navbar-items.ts +++ b/simulator-ui/src/main/webapp/app/entities/entity-navbar-items.ts @@ -7,13 +7,33 @@ export const EntityNavbarItems: NavbarItem[] = [ translationKey: 'global.menu.entities.message', }, { - name: 'TestParameter', - route: '/test-parameter', - translationKey: 'global.menu.entities.testParameter', + name: 'MessageHeader', + route: '/message-header', + translationKey: 'global.menu.entities.messageHeader', + }, + { + name: 'ScenarioExecution', + route: 'scenario-execution', + translationKey: 'global.menu.entities.scenarioExecution', + }, + { + name: 'ScenarioAction', + route: 'scenario-action', + translationKey: 'global.menu.entities.scenarioAction', + }, + { + name: 'ScenarioParameter', + route: 'scenario-parameter', + translationKey: 'global.menu.entities.scenarioParameter', }, { name: 'TestResult', route: '/test-result', translationKey: 'global.menu.entities.testResult', }, + { + name: 'TestParameter', + route: '/test-parameter', + translationKey: 'global.menu.entities.testParameter', + }, ]; diff --git a/simulator-ui/src/main/webapp/app/entities/entity-routing.module.ts b/simulator-ui/src/main/webapp/app/entities/entity-routing.module.ts index 3370e9b88..856c57416 100644 --- a/simulator-ui/src/main/webapp/app/entities/entity-routing.module.ts +++ b/simulator-ui/src/main/webapp/app/entities/entity-routing.module.ts @@ -25,15 +25,20 @@ import { RouterModule } from '@angular/router'; loadChildren: () => import('./scenario-action/scenario-action.routes'), }, { - path: 'test-parameter', - data: { pageTitle: 'citrusSimulatorApp.testParameter.home.title' }, - loadChildren: () => import('./test-parameter/test-parameter.routes'), + path: 'scenario-parameter', + data: { pageTitle: 'citrusSimulatorApp.scenarioParameter.home.title' }, + loadChildren: () => import('./scenario-parameter/scenario-parameter.routes'), }, { path: 'test-result', data: { pageTitle: 'citrusSimulatorApp.testResult.home.title' }, loadChildren: () => import('./test-result/test-result.routes'), }, + { + path: 'test-parameter', + data: { pageTitle: 'citrusSimulatorApp.testParameter.home.title' }, + loadChildren: () => import('./test-parameter/test-parameter.routes'), + }, /* jhipster-needle-add-entity-route - JHipster will add entity modules routes here */ ]), ], diff --git a/simulator-ui/src/main/webapp/app/entities/scenario-execution/list/scenario-execution.component.html b/simulator-ui/src/main/webapp/app/entities/scenario-execution/list/scenario-execution.component.html index b57466bc7..a3ac3c88a 100644 --- a/simulator-ui/src/main/webapp/app/entities/scenario-execution/list/scenario-execution.component.html +++ b/simulator-ui/src/main/webapp/app/entities/scenario-execution/list/scenario-execution.component.html @@ -105,6 +105,21 @@

>Show Messages + + + + diff --git a/simulator-ui/src/main/webapp/app/entities/scenario-parameter/detail/scenario-parameter-detail.component.spec.ts b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/detail/scenario-parameter-detail.component.spec.ts new file mode 100644 index 000000000..06f29051a --- /dev/null +++ b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/detail/scenario-parameter-detail.component.spec.ts @@ -0,0 +1,38 @@ +import { TestBed } from '@angular/core/testing'; +import { provideRouter, withComponentInputBinding } from '@angular/router'; +import { RouterTestingHarness, RouterTestingModule } from '@angular/router/testing'; +import { of } from 'rxjs'; + +import { ScenarioParameterDetailComponent } from './scenario-parameter-detail.component'; + +describe('ScenarioParameter Management Detail Component', () => { + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ScenarioParameterDetailComponent, RouterTestingModule.withRoutes([], { bindToComponentInputs: true })], + providers: [ + provideRouter( + [ + { + path: '**', + component: ScenarioParameterDetailComponent, + resolve: { scenarioParameter: () => of({ parameterId: 123 }) }, + }, + ], + withComponentInputBinding(), + ), + ], + }) + .overrideTemplate(ScenarioParameterDetailComponent, '') + .compileComponents(); + }); + + describe('OnInit', () => { + it('Should load scenarioParameter on init', async () => { + const harness = await RouterTestingHarness.create(); + const instance = await harness.navigateByUrl('/', ScenarioParameterDetailComponent); + + // THEN + expect(instance.scenarioParameter).toEqual(expect.objectContaining({ parameterId: 123 })); + }); + }); +}); diff --git a/simulator-ui/src/main/webapp/app/entities/scenario-parameter/detail/scenario-parameter-detail.component.ts b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/detail/scenario-parameter-detail.component.ts new file mode 100644 index 000000000..4dd03cf2b --- /dev/null +++ b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/detail/scenario-parameter-detail.component.ts @@ -0,0 +1,22 @@ +import { Component, Input } from '@angular/core'; +import { ActivatedRoute, RouterModule } from '@angular/router'; + +import SharedModule from 'app/shared/shared.module'; +import { DurationPipe, FormatMediumDatetimePipe, FormatMediumDatePipe } from 'app/shared/date'; +import { IScenarioParameter } from '../scenario-parameter.model'; + +@Component({ + standalone: true, + selector: 'jhi-scenario-parameter-detail', + templateUrl: './scenario-parameter-detail.component.html', + imports: [SharedModule, RouterModule, DurationPipe, FormatMediumDatetimePipe, FormatMediumDatePipe], +}) +export class ScenarioParameterDetailComponent { + @Input() scenarioParameter: IScenarioParameter | null = null; + + constructor(protected activatedRoute: ActivatedRoute) {} + + previousState(): void { + window.history.back(); + } +} diff --git a/simulator-ui/src/main/webapp/app/entities/scenario-parameter/list/scenario-parameter.component.html b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/list/scenario-parameter.component.html new file mode 100644 index 000000000..e34a3bd40 --- /dev/null +++ b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/list/scenario-parameter.component.html @@ -0,0 +1,124 @@ +
+

+ Scenario Parameters + +
+ +
+

+ + + + + + + +
+ No Scenario Parameters found +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ ID + +
+
+
+ Name + +
+
+
+ Control Type + +
+
+
+ Value + +
+
+
+ Created Date + +
+
+
+ Last Modified Date + +
+
+
+ Scenario Execution + +
+
+ {{ scenarioParameter.parameterId }} + {{ scenarioParameter.name }}{{ scenarioParameter.controlType }}{{ scenarioParameter.value }}{{ scenarioParameter.createdDate }}{{ scenarioParameter.lastModifiedDate | formatMediumDatetime }} + + +
+ +
+
+
+ +
+
+ +
+ +
+ +
+
+
diff --git a/simulator-ui/src/main/webapp/app/entities/scenario-parameter/list/scenario-parameter.component.spec.ts b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/list/scenario-parameter.component.spec.ts new file mode 100644 index 000000000..3aa6ea32f --- /dev/null +++ b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/list/scenario-parameter.component.spec.ts @@ -0,0 +1,125 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { HttpHeaders, HttpResponse } from '@angular/common/http'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { ActivatedRoute } from '@angular/router'; +import { RouterTestingModule } from '@angular/router/testing'; +import { of } from 'rxjs'; + +import { ScenarioParameterService } from '../service/scenario-parameter.service'; + +import { ScenarioParameterComponent } from './scenario-parameter.component'; +import SpyInstance = jest.SpyInstance; + +describe('ScenarioParameter Management Component', () => { + let comp: ScenarioParameterComponent; + let fixture: ComponentFixture; + let service: ScenarioParameterService; + let routerNavigateSpy: SpyInstance>; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [ + RouterTestingModule.withRoutes([{ path: 'scenario-parameter', component: ScenarioParameterComponent }]), + HttpClientTestingModule, + ScenarioParameterComponent, + ], + providers: [ + { + provide: ActivatedRoute, + useValue: { + data: of({ + defaultSort: 'parameterId,asc', + }), + queryParamMap: of( + jest.requireActual('@angular/router').convertToParamMap({ + page: '1', + size: '1', + sort: 'parameterId,desc', + 'filter[someId.in]': 'dc4279ea-cfb9-11ec-9d64-0242ac120002', + }), + ), + snapshot: { queryParams: {} }, + }, + }, + ], + }) + .overrideTemplate(ScenarioParameterComponent, '') + .compileComponents(); + + fixture = TestBed.createComponent(ScenarioParameterComponent); + comp = fixture.componentInstance; + service = TestBed.inject(ScenarioParameterService); + routerNavigateSpy = jest.spyOn(comp.router, 'navigate'); + + const headers = new HttpHeaders(); + jest.spyOn(service, 'query').mockReturnValue( + of( + new HttpResponse({ + body: [{ parameterId: 123 }], + headers, + }), + ), + ); + }); + + it('Should call load all on init', () => { + // WHEN + comp.ngOnInit(); + + // THEN + expect(service.query).toHaveBeenCalled(); + expect(comp.scenarioParameters?.[0]).toEqual(expect.objectContaining({ parameterId: 123 })); + }); + + describe('trackId', () => { + it('Should forward to scenarioParameterService', () => { + const entity = { parameterId: 123 }; + jest.spyOn(service, 'getScenarioParameterIdentifier'); + const parameterId = comp.trackId(0, entity); + expect(service.getScenarioParameterIdentifier).toHaveBeenCalledWith(entity); + expect(parameterId).toBe(entity.parameterId); + }); + }); + + it('should load a page', () => { + // WHEN + comp.navigateToPage(1); + + // THEN + expect(routerNavigateSpy).toHaveBeenCalled(); + }); + + it('should calculate the sort attribute for a parameterId', () => { + // WHEN + comp.ngOnInit(); + + // THEN + expect(service.query).toHaveBeenLastCalledWith(expect.objectContaining({ sort: ['parameterId,desc'] })); + }); + + it('should calculate the sort attribute for a non-id attribute', () => { + // GIVEN + comp.predicate = 'name'; + + // WHEN + comp.navigateToWithComponentValues(); + + // THEN + expect(routerNavigateSpy).toHaveBeenLastCalledWith( + expect.anything(), + expect.objectContaining({ + queryParams: expect.objectContaining({ + sort: ['name,asc'], + }), + }), + ); + }); + + it('should calculate the filter attribute', () => { + // WHEN + comp.ngOnInit(); + + // THEN + expect(service.query).toHaveBeenLastCalledWith(expect.objectContaining({ 'someId.in': ['dc4279ea-cfb9-11ec-9d64-0242ac120002'] })); + }); +}); diff --git a/simulator-ui/src/main/webapp/app/entities/scenario-parameter/list/scenario-parameter.component.ts b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/list/scenario-parameter.component.ts new file mode 100644 index 000000000..f3a035026 --- /dev/null +++ b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/list/scenario-parameter.component.ts @@ -0,0 +1,152 @@ +import { Component, OnInit } from '@angular/core'; +import { HttpHeaders } from '@angular/common/http'; +import { ActivatedRoute, Data, ParamMap, Router, RouterModule } from '@angular/router'; +import { combineLatest, Observable, switchMap, tap } from 'rxjs'; + +import SharedModule from 'app/shared/shared.module'; +import { SortDirective, SortByDirective } from 'app/shared/sort'; +import { DurationPipe, FormatMediumDatetimePipe, FormatMediumDatePipe } from 'app/shared/date'; +import { ItemCountComponent } from 'app/shared/pagination'; +import { FormsModule } from '@angular/forms'; + +import { ITEMS_PER_PAGE, PAGE_HEADER, TOTAL_COUNT_RESPONSE_HEADER } from 'app/config/pagination.constants'; +import { ASC, DESC, SORT, DEFAULT_SORT_DATA } from 'app/config/navigation.constants'; +import { FilterComponent, FilterOptions, IFilterOptions, IFilterOption } from 'app/shared/filter'; +import { EntityArrayResponseType, ScenarioParameterService } from '../service/scenario-parameter.service'; +import { IScenarioParameter } from '../scenario-parameter.model'; + +@Component({ + standalone: true, + selector: 'jhi-scenario-parameter', + templateUrl: './scenario-parameter.component.html', + imports: [ + RouterModule, + FormsModule, + SharedModule, + SortDirective, + SortByDirective, + DurationPipe, + FormatMediumDatetimePipe, + FormatMediumDatePipe, + FilterComponent, + ItemCountComponent, + ], +}) +export class ScenarioParameterComponent implements OnInit { + scenarioParameters?: IScenarioParameter[]; + isLoading = false; + + predicate = 'parameterId'; + ascending = true; + filters: IFilterOptions = new FilterOptions(); + + itemsPerPage = ITEMS_PER_PAGE; + totalItems = 0; + page = 1; + + constructor( + protected scenarioParameterService: ScenarioParameterService, + protected activatedRoute: ActivatedRoute, + public router: Router, + ) {} + + trackId = (_index: number, item: IScenarioParameter): number => this.scenarioParameterService.getScenarioParameterIdentifier(item); + + ngOnInit(): void { + this.load(); + + this.filters.filterChanges.subscribe(filterOptions => this.handleNavigation(1, this.predicate, this.ascending, filterOptions)); + } + + load(): void { + this.loadFromBackendWithRouteInformations().subscribe({ + next: (res: EntityArrayResponseType) => { + this.onResponseSuccess(res); + }, + }); + } + + navigateToWithComponentValues(): void { + this.handleNavigation(this.page, this.predicate, this.ascending, this.filters.filterOptions); + } + + navigateToPage(page = this.page): void { + this.handleNavigation(page, this.predicate, this.ascending, this.filters.filterOptions); + } + + protected loadFromBackendWithRouteInformations(): Observable { + return combineLatest([this.activatedRoute.queryParamMap, this.activatedRoute.data]).pipe( + tap(([params, data]) => this.fillComponentAttributeFromRoute(params, data)), + switchMap(() => this.queryBackend(this.page, this.predicate, this.ascending, this.filters.filterOptions)), + ); + } + + protected fillComponentAttributeFromRoute(params: ParamMap, data: Data): void { + const page = params.get(PAGE_HEADER); + this.page = +(page ?? 1); + const sort = (params.get(SORT) ?? data[DEFAULT_SORT_DATA]).split(','); + this.predicate = sort[0]; + this.ascending = sort[1] === ASC; + this.filters.initializeFromParams(params); + } + + protected onResponseSuccess(response: EntityArrayResponseType): void { + this.fillComponentAttributesFromResponseHeader(response.headers); + const dataFromBody = this.fillComponentAttributesFromResponseBody(response.body); + this.scenarioParameters = dataFromBody; + } + + protected fillComponentAttributesFromResponseBody(data: IScenarioParameter[] | null): IScenarioParameter[] { + return data ?? []; + } + + protected fillComponentAttributesFromResponseHeader(headers: HttpHeaders): void { + this.totalItems = Number(headers.get(TOTAL_COUNT_RESPONSE_HEADER)); + } + + protected queryBackend( + page?: number, + predicate?: string, + ascending?: boolean, + filterOptions?: IFilterOption[], + ): Observable { + this.isLoading = true; + const pageToLoad: number = page ?? 1; + const queryObject: any = { + page: pageToLoad - 1, + size: this.itemsPerPage, + eagerload: true, + sort: this.getSortQueryParam(predicate, ascending), + }; + filterOptions?.forEach(filterOption => { + queryObject[filterOption.name] = filterOption.values; + }); + return this.scenarioParameterService.query(queryObject).pipe(tap(() => (this.isLoading = false))); + } + + protected handleNavigation(page = this.page, predicate?: string, ascending?: boolean, filterOptions?: IFilterOption[]): void { + const queryParamsObj: any = { + page, + size: this.itemsPerPage, + sort: this.getSortQueryParam(predicate, ascending), + }; + + filterOptions?.forEach(filterOption => { + queryParamsObj[filterOption.nameAsQueryParam()] = filterOption.values; + }); + + this.router.navigate(['./'], { + relativeTo: this.activatedRoute, + queryParams: queryParamsObj, + }); + } + + protected getSortQueryParam(predicate = this.predicate, ascending = this.ascending): string[] { + const ascendingQueryParam = ascending ? ASC : DESC; + if (predicate === '') { + return []; + } else { + return [predicate + ',' + ascendingQueryParam]; + } + } +} diff --git a/simulator-ui/src/main/webapp/app/entities/scenario-parameter/route/scenario-parameter-routing-resolve.service.spec.ts b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/route/scenario-parameter-routing-resolve.service.spec.ts new file mode 100644 index 000000000..2422e0a76 --- /dev/null +++ b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/route/scenario-parameter-routing-resolve.service.spec.ts @@ -0,0 +1,99 @@ +import { TestBed } from '@angular/core/testing'; +import { HttpResponse } from '@angular/common/http'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { ActivatedRouteSnapshot, ActivatedRoute, Router, convertToParamMap } from '@angular/router'; +import { RouterTestingModule } from '@angular/router/testing'; +import { of } from 'rxjs'; + +import { IScenarioParameter } from '../scenario-parameter.model'; +import { ScenarioParameterService } from '../service/scenario-parameter.service'; + +import scenarioParameterResolve from './scenario-parameter-routing-resolve.service'; + +describe('ScenarioParameter routing resolve service', () => { + let mockRouter: Router; + let mockActivatedRouteSnapshot: ActivatedRouteSnapshot; + let service: ScenarioParameterService; + let resultScenarioParameter: IScenarioParameter | null | undefined; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule, RouterTestingModule.withRoutes([])], + providers: [ + { + provide: ActivatedRoute, + useValue: { + snapshot: { + paramMap: convertToParamMap({}), + }, + }, + }, + ], + }); + mockRouter = TestBed.inject(Router); + jest.spyOn(mockRouter, 'navigate').mockImplementation(() => Promise.resolve(true)); + mockActivatedRouteSnapshot = TestBed.inject(ActivatedRoute).snapshot; + service = TestBed.inject(ScenarioParameterService); + resultScenarioParameter = undefined; + }); + + describe('resolve', () => { + it('should return IScenarioParameter returned by find', () => { + // GIVEN + service.find = jest.fn(parameterId => of(new HttpResponse({ body: { parameterId } }))); + mockActivatedRouteSnapshot.params = { parameterId: 123 }; + + // WHEN + TestBed.runInInjectionContext(() => { + scenarioParameterResolve(mockActivatedRouteSnapshot).subscribe({ + next(result) { + resultScenarioParameter = result; + }, + }); + }); + + // THEN + expect(service.find).toBeCalledWith(123); + expect(resultScenarioParameter).toEqual({ parameterId: 123 }); + }); + + it('should return null if parameterId is not provided', () => { + // GIVEN + service.find = jest.fn(); + mockActivatedRouteSnapshot.params = {}; + + // WHEN + TestBed.runInInjectionContext(() => { + scenarioParameterResolve(mockActivatedRouteSnapshot).subscribe({ + next(result) { + resultScenarioParameter = result; + }, + }); + }); + + // THEN + expect(service.find).not.toBeCalled(); + expect(resultScenarioParameter).toEqual(null); + }); + + it('should route to 404 page if data not found in server', () => { + // GIVEN + jest.spyOn(service, 'find').mockReturnValue(of(new HttpResponse({ body: null }))); + mockActivatedRouteSnapshot.params = { parameterId: 123 }; + + // WHEN + TestBed.runInInjectionContext(() => { + scenarioParameterResolve(mockActivatedRouteSnapshot).subscribe({ + next(result) { + resultScenarioParameter = result; + }, + }); + }); + + // THEN + expect(service.find).toBeCalledWith(123); + expect(resultScenarioParameter).toEqual(undefined); + expect(mockRouter.navigate).toHaveBeenCalledWith(['404']); + }); + }); +}); diff --git a/simulator-ui/src/main/webapp/app/entities/scenario-parameter/route/scenario-parameter-routing-resolve.service.ts b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/route/scenario-parameter-routing-resolve.service.ts new file mode 100644 index 000000000..43f650f7e --- /dev/null +++ b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/route/scenario-parameter-routing-resolve.service.ts @@ -0,0 +1,29 @@ +import { inject } from '@angular/core'; +import { HttpResponse } from '@angular/common/http'; +import { ActivatedRouteSnapshot, Router } from '@angular/router'; +import { of, EMPTY, Observable } from 'rxjs'; +import { mergeMap } from 'rxjs/operators'; + +import { IScenarioParameter } from '../scenario-parameter.model'; +import { ScenarioParameterService } from '../service/scenario-parameter.service'; + +export const scenarioParameterResolve = (route: ActivatedRouteSnapshot): Observable => { + const parameterId = route.params['parameterId']; + if (parameterId) { + return inject(ScenarioParameterService) + .find(parameterId) + .pipe( + mergeMap((scenarioParameter: HttpResponse) => { + if (scenarioParameter.body) { + return of(scenarioParameter.body); + } else { + inject(Router).navigate(['404']); + return EMPTY; + } + }), + ); + } + return of(null); +}; + +export default scenarioParameterResolve; diff --git a/simulator-ui/src/main/webapp/app/entities/scenario-parameter/scenario-parameter.model.ts b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/scenario-parameter.model.ts new file mode 100644 index 000000000..4ce49f39e --- /dev/null +++ b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/scenario-parameter.model.ts @@ -0,0 +1,14 @@ +import dayjs from 'dayjs/esm'; +import { IScenarioExecution } from 'app/entities/scenario-execution/scenario-execution.model'; + +export interface IScenarioParameter { + parameterId: number; + name?: string | null; + controlType?: number | null; + value?: string | null; + createdDate?: number | null; + lastModifiedDate?: dayjs.Dayjs | null; + scenarioExecution?: Pick | null; +} + +export type NewScenarioParameter = Omit & { parameterId: null }; diff --git a/simulator-ui/src/main/webapp/app/entities/scenario-parameter/scenario-parameter.routes.ts b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/scenario-parameter.routes.ts new file mode 100644 index 000000000..178774261 --- /dev/null +++ b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/scenario-parameter.routes.ts @@ -0,0 +1,25 @@ +import { Routes } from '@angular/router'; + +import { ASC } from 'app/config/navigation.constants'; +import { ScenarioParameterComponent } from './list/scenario-parameter.component'; +import { ScenarioParameterDetailComponent } from './detail/scenario-parameter-detail.component'; +import ScenarioParameterResolve from './route/scenario-parameter-routing-resolve.service'; + +const scenarioParameterRoute: Routes = [ + { + path: '', + component: ScenarioParameterComponent, + data: { + defaultSort: 'parameterId,' + ASC, + }, + }, + { + path: ':parameterId/view', + component: ScenarioParameterDetailComponent, + resolve: { + scenarioParameter: ScenarioParameterResolve, + }, + }, +]; + +export default scenarioParameterRoute; diff --git a/simulator-ui/src/main/webapp/app/entities/scenario-parameter/scenario-parameter.test-samples.ts b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/scenario-parameter.test-samples.ts new file mode 100644 index 000000000..a4c314ff2 --- /dev/null +++ b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/scenario-parameter.test-samples.ts @@ -0,0 +1,44 @@ +import dayjs from 'dayjs/esm'; + +import { IScenarioParameter, NewScenarioParameter } from './scenario-parameter.model'; + +export const sampleWithRequiredData: IScenarioParameter = { + parameterId: 13246, + name: 'separately', + controlType: 26023, + value: 'underexpose since commerce', + createdDate: 21593, + lastModifiedDate: dayjs('2023-10-28T20:48'), +}; + +export const sampleWithPartialData: IScenarioParameter = { + parameterId: 25616, + name: 'jellyfish adolescent on', + controlType: 3663, + value: 'outside hastily', + createdDate: 26077, + lastModifiedDate: dayjs('2023-10-28T23:22'), +}; + +export const sampleWithFullData: IScenarioParameter = { + parameterId: 16729, + name: 'cytokine', + controlType: 21298, + value: 'coarse', + createdDate: 9490, + lastModifiedDate: dayjs('2023-10-29T08:59'), +}; + +export const sampleWithNewData: NewScenarioParameter = { + name: 'who', + controlType: 24095, + value: 'whoa', + createdDate: 11500, + lastModifiedDate: dayjs('2023-10-28T17:10'), + parameterId: null, +}; + +Object.freeze(sampleWithNewData); +Object.freeze(sampleWithRequiredData); +Object.freeze(sampleWithPartialData); +Object.freeze(sampleWithFullData); diff --git a/simulator-ui/src/main/webapp/app/entities/scenario-parameter/service/scenario-parameter.service.spec.ts b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/service/scenario-parameter.service.spec.ts new file mode 100644 index 000000000..81ca53c18 --- /dev/null +++ b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/service/scenario-parameter.service.spec.ts @@ -0,0 +1,159 @@ +import { TestBed } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; + +import { IScenarioParameter } from '../scenario-parameter.model'; +import { sampleWithRequiredData, sampleWithPartialData, sampleWithFullData } from '../scenario-parameter.test-samples'; + +import { ScenarioParameterService, RestScenarioParameter } from './scenario-parameter.service'; + +const requireRestSample: RestScenarioParameter = { + ...sampleWithRequiredData, + lastModifiedDate: sampleWithRequiredData.lastModifiedDate?.toJSON(), +}; + +describe('ScenarioParameter Service', () => { + let service: ScenarioParameterService; + let httpMock: HttpTestingController; + let expectedResult: IScenarioParameter | IScenarioParameter[] | boolean | null; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + }); + expectedResult = null; + service = TestBed.inject(ScenarioParameterService); + httpMock = TestBed.inject(HttpTestingController); + }); + + describe('Service methods', () => { + it('should find an element', () => { + const returnedFromService = { ...requireRestSample }; + const expected = { ...sampleWithRequiredData }; + + service.find(123).subscribe(resp => (expectedResult = resp.body)); + + const req = httpMock.expectOne({ method: 'GET' }); + req.flush(returnedFromService); + expect(expectedResult).toMatchObject(expected); + }); + + it('should return a list of ScenarioParameter', () => { + const returnedFromService = { ...requireRestSample }; + + const expected = { ...sampleWithRequiredData }; + + service.query().subscribe(resp => (expectedResult = resp.body)); + + const req = httpMock.expectOne({ method: 'GET' }); + req.flush([returnedFromService]); + httpMock.verify(); + expect(expectedResult).toMatchObject([expected]); + }); + + describe('addScenarioParameterToCollectionIfMissing', () => { + it('should add a ScenarioParameter to an empty array', () => { + const scenarioParameter: IScenarioParameter = sampleWithRequiredData; + expectedResult = service.addScenarioParameterToCollectionIfMissing([], scenarioParameter); + expect(expectedResult).toHaveLength(1); + expect(expectedResult).toContain(scenarioParameter); + }); + + it('should not add a ScenarioParameter to an array that contains it', () => { + const scenarioParameter: IScenarioParameter = sampleWithRequiredData; + const scenarioParameterCollection: IScenarioParameter[] = [ + { + ...scenarioParameter, + }, + sampleWithPartialData, + ]; + expectedResult = service.addScenarioParameterToCollectionIfMissing(scenarioParameterCollection, scenarioParameter); + expect(expectedResult).toHaveLength(2); + }); + + it("should add a ScenarioParameter to an array that doesn't contain it", () => { + const scenarioParameter: IScenarioParameter = sampleWithRequiredData; + const scenarioParameterCollection: IScenarioParameter[] = [sampleWithPartialData]; + expectedResult = service.addScenarioParameterToCollectionIfMissing(scenarioParameterCollection, scenarioParameter); + expect(expectedResult).toHaveLength(2); + expect(expectedResult).toContain(scenarioParameter); + }); + + it('should add only unique ScenarioParameter to an array', () => { + const scenarioParameterArray: IScenarioParameter[] = [sampleWithRequiredData, sampleWithPartialData, sampleWithFullData]; + const scenarioParameterCollection: IScenarioParameter[] = [sampleWithRequiredData]; + expectedResult = service.addScenarioParameterToCollectionIfMissing(scenarioParameterCollection, ...scenarioParameterArray); + expect(expectedResult).toHaveLength(3); + }); + + it('should accept varargs', () => { + const scenarioParameter: IScenarioParameter = sampleWithRequiredData; + const scenarioParameter2: IScenarioParameter = sampleWithPartialData; + expectedResult = service.addScenarioParameterToCollectionIfMissing([], scenarioParameter, scenarioParameter2); + expect(expectedResult).toHaveLength(2); + expect(expectedResult).toContain(scenarioParameter); + expect(expectedResult).toContain(scenarioParameter2); + }); + + it('should accept null and undefined values', () => { + const scenarioParameter: IScenarioParameter = sampleWithRequiredData; + expectedResult = service.addScenarioParameterToCollectionIfMissing([], null, scenarioParameter, undefined); + expect(expectedResult).toHaveLength(1); + expect(expectedResult).toContain(scenarioParameter); + }); + + it('should return initial array if no ScenarioParameter is added', () => { + const scenarioParameterCollection: IScenarioParameter[] = [sampleWithRequiredData]; + expectedResult = service.addScenarioParameterToCollectionIfMissing(scenarioParameterCollection, undefined, null); + expect(expectedResult).toEqual(scenarioParameterCollection); + }); + }); + + describe('compareScenarioParameter', () => { + it('Should return true if both entities are null', () => { + const entity1 = null; + const entity2 = null; + + const compareResult = service.compareScenarioParameter(entity1, entity2); + + expect(compareResult).toEqual(true); + }); + + it('Should return false if one entity is null', () => { + const entity1 = { parameterId: 123 }; + const entity2 = null; + + const compareResult1 = service.compareScenarioParameter(entity1, entity2); + const compareResult2 = service.compareScenarioParameter(entity2, entity1); + + expect(compareResult1).toEqual(false); + expect(compareResult2).toEqual(false); + }); + + it('Should return false if primaryKey differs', () => { + const entity1 = { parameterId: 123 }; + const entity2 = { parameterId: 456 }; + + const compareResult1 = service.compareScenarioParameter(entity1, entity2); + const compareResult2 = service.compareScenarioParameter(entity2, entity1); + + expect(compareResult1).toEqual(false); + expect(compareResult2).toEqual(false); + }); + + it('Should return false if primaryKey matches', () => { + const entity1 = { parameterId: 123 }; + const entity2 = { parameterId: 123 }; + + const compareResult1 = service.compareScenarioParameter(entity1, entity2); + const compareResult2 = service.compareScenarioParameter(entity2, entity1); + + expect(compareResult1).toEqual(true); + expect(compareResult2).toEqual(true); + }); + }); + }); + + afterEach(() => { + httpMock.verify(); + }); +}); diff --git a/simulator-ui/src/main/webapp/app/entities/scenario-parameter/service/scenario-parameter.service.ts b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/service/scenario-parameter.service.ts new file mode 100644 index 000000000..05e3ab192 --- /dev/null +++ b/simulator-ui/src/main/webapp/app/entities/scenario-parameter/service/scenario-parameter.service.ts @@ -0,0 +1,108 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpResponse } from '@angular/common/http'; +import { Observable } from 'rxjs'; + +import { map } from 'rxjs/operators'; + +import dayjs from 'dayjs/esm'; + +import { isPresent } from 'app/core/util/operators'; +import { ApplicationConfigService } from 'app/core/config/application-config.service'; +import { createRequestOption } from 'app/core/request/request-util'; +import { IScenarioParameter, NewScenarioParameter } from '../scenario-parameter.model'; + +export type PartialUpdateScenarioParameter = Partial & Pick; + +type RestOf = Omit & { + lastModifiedDate?: string | null; +}; + +export type RestScenarioParameter = RestOf; + +export type NewRestScenarioParameter = RestOf; + +export type PartialUpdateRestScenarioParameter = RestOf; + +export type EntityResponseType = HttpResponse; +export type EntityArrayResponseType = HttpResponse; + +@Injectable({ providedIn: 'root' }) +export class ScenarioParameterService { + protected resourceUrl = this.applicationConfigService.getEndpointFor('api/scenario-parameters'); + + constructor( + protected http: HttpClient, + protected applicationConfigService: ApplicationConfigService, + ) {} + + find(parameterId: number): Observable { + return this.http + .get(`${this.resourceUrl}/${parameterId}`, { observe: 'response' }) + .pipe(map(res => this.convertResponseFromServer(res))); + } + + query(req?: any): Observable { + const options = createRequestOption(req); + return this.http + .get(this.resourceUrl, { params: options, observe: 'response' }) + .pipe(map(res => this.convertResponseArrayFromServer(res))); + } + + getScenarioParameterIdentifier(scenarioParameter: Pick): number { + return scenarioParameter.parameterId; + } + + compareScenarioParameter(o1: Pick | null, o2: Pick | null): boolean { + return o1 && o2 ? this.getScenarioParameterIdentifier(o1) === this.getScenarioParameterIdentifier(o2) : o1 === o2; + } + + addScenarioParameterToCollectionIfMissing>( + scenarioParameterCollection: Type[], + ...scenarioParametersToCheck: (Type | null | undefined)[] + ): Type[] { + const scenarioParameters: Type[] = scenarioParametersToCheck.filter(isPresent); + if (scenarioParameters.length > 0) { + const scenarioParameterCollectionIdentifiers = scenarioParameterCollection.map( + scenarioParameterItem => this.getScenarioParameterIdentifier(scenarioParameterItem)!, + ); + const scenarioParametersToAdd = scenarioParameters.filter(scenarioParameterItem => { + const scenarioParameterIdentifier = this.getScenarioParameterIdentifier(scenarioParameterItem); + if (scenarioParameterCollectionIdentifiers.includes(scenarioParameterIdentifier)) { + return false; + } + scenarioParameterCollectionIdentifiers.push(scenarioParameterIdentifier); + return true; + }); + return [...scenarioParametersToAdd, ...scenarioParameterCollection]; + } + return scenarioParameterCollection; + } + + protected convertDateFromClient( + scenarioParameter: T, + ): RestOf { + return { + ...scenarioParameter, + lastModifiedDate: scenarioParameter.lastModifiedDate?.toJSON() ?? null, + }; + } + + protected convertDateFromServer(restScenarioParameter: RestScenarioParameter): IScenarioParameter { + return { + ...restScenarioParameter, + lastModifiedDate: restScenarioParameter.lastModifiedDate ? dayjs(restScenarioParameter.lastModifiedDate) : undefined, + }; + } + + protected convertResponseFromServer(res: HttpResponse): HttpResponse { + return res.clone({ + body: res.body ? this.convertDateFromServer(res.body) : null, + }); + } + + protected convertResponseArrayFromServer(res: HttpResponse): HttpResponse { + return res.clone({ + body: res.body ? res.body.map(item => this.convertDateFromServer(item)) : null, + }); + } +} diff --git a/simulator-ui/src/main/webapp/app/layouts/navbar/navbar.component.html b/simulator-ui/src/main/webapp/app/layouts/navbar/navbar.component.html index 4fb4effe6..2330d8aa6 100644 --- a/simulator-ui/src/main/webapp/app/layouts/navbar/navbar.component.html +++ b/simulator-ui/src/main/webapp/app/layouts/navbar/navbar.component.html @@ -90,6 +90,18 @@ Scenario Action +
  • + + + Scenario Parameter + +