Skip to content

Commit

Permalink
feat(#254): load scenarios at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Nov 2, 2024
1 parent 3062970 commit b5ade58
Show file tree
Hide file tree
Showing 36 changed files with 1,306 additions and 99 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<citrus.version>4.3.3</citrus.version>

<spring-boot.version>3.3.4</spring-boot.version>
<spring.version>6.3.4</spring.version>
<spring.version>6.1.13</spring.version>
<testng.version>7.10.2</testng.version>
<wsdl4j.version>1.6.3</wsdl4j.version>
<xerces.version>2.12.2</xerces.version>
Expand Down Expand Up @@ -68,6 +68,7 @@
</ciManagement>

<modules>
<module>simulator-spring-boot-api</module>
<module>simulator-spring-boot</module>
<module>simulator-ui</module>
<module>simulator-docs</module>
Expand Down Expand Up @@ -174,6 +175,11 @@
</dependency>

<!-- Citrus Simulator -->
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-spring-boot-simulator-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-spring-boot-simulator</artifactId>
Expand Down
82 changes: 82 additions & 0 deletions simulator-spring-boot-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-simulator</artifactId>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>citrus-spring-boot-simulator-api</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!-- Citrus -->
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-core</artifactId>
<!-- Exclude in order solve org.w3c.dom is accessible from more than one module for jdk 11 -->
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-http</artifactId>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-ws</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
</dependency>

<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>

<!-- Test scoped -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
import org.citrusframework.message.Message;
import org.citrusframework.simulator.scenario.ScenarioEndpoint;

/**
* @author Christoph Deppisch
*/
public interface CorrelationHandler {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package org.citrusframework.simulator.exception;

/**
* @author Christoph Deppisch
*/
public class SimulatorException extends RuntimeException {

private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 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.http;

import org.citrusframework.http.actions.HttpServerActionBuilder;

public interface HttpScenarioActionBuilder {

HttpServerActionBuilder.HttpServerReceiveActionBuilder receive();

HttpServerActionBuilder.HttpServerSendActionBuilder send();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @author Christoph Deppisch
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Component
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 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.scenario;

import org.citrusframework.endpoint.AbstractEndpoint;
import org.citrusframework.endpoint.EndpointConfiguration;
import org.citrusframework.message.Message;
import org.citrusframework.messaging.Consumer;
import org.citrusframework.messaging.Producer;

import java.util.concurrent.CompletableFuture;

public abstract class ScenarioEndpoint extends AbstractEndpoint implements Producer, Consumer {

public ScenarioEndpoint(EndpointConfiguration endpointConfiguration) {
super(endpointConfiguration);
}

public abstract void add(Message request, CompletableFuture<Message> responseFuture);

abstract void fail(Throwable error);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@

import org.citrusframework.endpoint.AbstractEndpointConfiguration;

/**
* @author Christoph Deppisch
*/
public class ScenarioEndpointConfiguration extends AbstractEndpointConfiguration {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 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.scenario;

import org.citrusframework.GherkinTestActionRunner;
import org.citrusframework.simulator.http.HttpScenarioActionBuilder;
import org.citrusframework.simulator.soap.SoapScenarioActionBuilder;

public interface ScenarioRunner extends GherkinTestActionRunner {

HttpScenarioActionBuilder http();

SoapScenarioActionBuilder soap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import static org.springframework.aop.framework.AopProxyUtils.ultimateTargetClass;

@NoArgsConstructor(access = PRIVATE)
public class ScenarioUtils {
public final class ScenarioUtils {

/**
* Retrieves the specified annotation from the class hierarchy of the given scenario object.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 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.scenario;

import jakarta.annotation.Nullable;
import org.citrusframework.TestCaseRunner;
import org.citrusframework.simulator.correlation.CorrelationHandler;

public abstract class SimpleInitializedSimulatorScenario implements CorrelationHandler, SimulatorScenarioWithEndpoint {

private @Nullable ScenarioEndpoint scenarioEndpoint;

private @Nullable TestCaseRunner testCaseRunner;

@Override
public @Nullable ScenarioEndpoint getScenarioEndpoint() {
return scenarioEndpoint;
}

@Override
public void setScenarioEndpoint(@Nullable ScenarioEndpoint scenarioEndpoint) {
this.scenarioEndpoint = scenarioEndpoint;
}

@Override
public @Nullable TestCaseRunner getTestCaseRunner() {
return testCaseRunner;
}

@Override
public void setTestCaseRunner(TestCaseRunner testCaseRunner) {
this.testCaseRunner = testCaseRunner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
* limitations under the License.
*/

package org.citrusframework.simulator.scenario;

import jakarta.annotation.Nullable;
package org.citrusframework.simulator.scenario;import jakarta.annotation.Nullable;
import org.citrusframework.DefaultTestCaseRunner;
import org.citrusframework.TestCaseRunner;
import org.citrusframework.exceptions.CitrusRuntimeException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 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.scenario;

import jakarta.annotation.Nullable;

/**
* Classes implementing this interface will have the {@link ScenarioEndpoint} injected after instantiation at runtime.
* Similar to an initialized Spring bean, but controlled by the simulator.
* <code>
*
* @Override public void afterPropertiesSet() {
* scenarioEndpoint = new ScenarioEndpoint(new ScenarioEndpointConfiguration());
* }
* </code>
* @see org.springframework.beans.factory.InitializingBean
*/
public interface SimulatorScenarioWithEndpoint extends SimulatorScenario {

void setScenarioEndpoint(@Nullable ScenarioEndpoint scenarioEndpoint);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 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.soap;

import org.citrusframework.ws.actions.ReceiveSoapMessageAction;
import org.citrusframework.ws.actions.SendSoapMessageAction;

public interface SoapScenarioActionBuilder {

ReceiveSoapMessageAction.Builder receive();

SendSoapMessageAction.Builder send();
}
Loading

0 comments on commit b5ade58

Please sign in to comment.