Skip to content

Commit

Permalink
feat: citrus 4.0.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Oct 25, 2023
1 parent b6d417a commit f94c40a
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 88 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>

<lombok.version>1.18.20</lombok.version>
<citrus.version>4.0.0-M2</citrus.version>
<spring-boot.version>3.1.2</spring-boot.version>
<spring.version>6.0.9</spring.version>
<spring.ws.version>3.1.3</spring.ws.version>
<citrus.version>4.0.0</citrus.version>
<spring-boot.version>3.1.5</spring-boot.version>
<spring.version>6.0.13</spring.version>
<spring.ws.version>4.0.7</spring.ws.version>
<testng.version>7.5.1</testng.version>
<wsdl4j.version>1.6.3</wsdl4j.version>
<xerces.version>2.12.1</xerces.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import org.citrusframework.simulator.http.HttpScenarioGenerator;
import org.citrusframework.simulator.http.SimulatorRestAdapter;
import org.citrusframework.simulator.http.SimulatorRestConfigurationProperties;
import org.citrusframework.spi.Resources;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpStatus;

/**
Expand Down Expand Up @@ -66,7 +66,7 @@ protected Message handleMessageInternal(Message message) {

@Bean
public static HttpScenarioGenerator scenarioGenerator() {
HttpScenarioGenerator generator = new HttpScenarioGenerator(new ClassPathResource("swagger/petstore-api.json"));
HttpScenarioGenerator generator = new HttpScenarioGenerator(new Resources.ClasspathResource("swagger/petstore-api.json"));
generator.setContextPath("/petstore");
return generator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import org.citrusframework.http.client.HttpClient;
import org.citrusframework.message.MessageType;
import org.citrusframework.simulator.sample.Simulator;
import org.citrusframework.spi.Resources;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
Expand Down Expand Up @@ -92,7 +92,7 @@ public void testAddPet() {
.message()
.accept(MediaType.APPLICATION_JSON_VALUE)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body(new ClassPathResource("templates/pet.json")));
.body(new Resources.ClasspathResource("templates/pet.json")));

$(http().client(petstoreClient)
.receive()
Expand Down Expand Up @@ -127,7 +127,7 @@ public void testGetPetById() {
.response(HttpStatus.OK)
.message()
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body(new ClassPathResource("templates/pet-control.json")));
.body(new Resources.ClasspathResource("templates/pet-control.json")));
}

@CitrusTest
Expand All @@ -143,7 +143,7 @@ public void testUpdatePet() {
.message()
.accept(MediaType.APPLICATION_JSON_VALUE)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body(new ClassPathResource("templates/pet.json")));
.body(new Resources.ClasspathResource("templates/pet.json")));

$(http().client(petstoreClient)
.receive()
Expand Down Expand Up @@ -205,7 +205,7 @@ public void testPlaceOrder() {
.message()
.accept(MediaType.APPLICATION_JSON_VALUE)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body(new ClassPathResource("templates/order.json")));
.body(new Resources.ClasspathResource("templates/order.json")));

$(http().client(petstoreClient)
.receive()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
import org.citrusframework.endpoint.EndpointAdapter;
import org.citrusframework.endpoint.adapter.StaticEndpointAdapter;
import org.citrusframework.message.Message;
import org.citrusframework.spi.Resources;
import org.citrusframework.ws.message.SoapFault;
import org.citrusframework.simulator.ws.SimulatorWebServiceAdapter;
import org.citrusframework.simulator.ws.SimulatorWebServiceConfigurationProperties;
import org.citrusframework.simulator.ws.WsdlScenarioGenerator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;

/**
* @author Christoph Deppisch
Expand Down Expand Up @@ -58,7 +58,7 @@ protected Message handleMessageInternal(Message message) {

@Bean
public static WsdlScenarioGenerator scenarioGenerator() {
WsdlScenarioGenerator generator = new WsdlScenarioGenerator(new ClassPathResource("xsd/Hello.wsdl"));
WsdlScenarioGenerator generator = new WsdlScenarioGenerator(new Resources.ClasspathResource("xsd/Hello.wsdl"));
return generator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.citrusframework.simulator.dictionary.OutboundXmlDataDictionary;
import org.citrusframework.simulator.repository.RepositoryConfig;
import org.citrusframework.simulator.scenario.ScenarioBeanNameGenerator;
import org.citrusframework.spi.CitrusResourceWrapper;
import org.citrusframework.variable.dictionary.json.JsonPathMappingDataDictionary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -75,8 +76,10 @@
@ConditionalOnProperty(prefix = "citrus.simulator", value = "enabled", havingValue = "true", matchIfMissing = true)
public class SimulatorAutoConfiguration {

/** Logger */
private static Logger log = LoggerFactory.getLogger(SimulatorAutoConfiguration.class);
/**
* Logger
*/
private static final Logger logger = LoggerFactory.getLogger(SimulatorAutoConfiguration.class);

/** Application version */
private static String version;
Expand All @@ -91,7 +94,7 @@ public class SimulatorAutoConfiguration {
versionProperties.load(in);
version = versionProperties.get("app.version").toString();
} catch (IOException e) {
log.warn("Unable to read application version information", e);
logger.warn("Unable to read application version information", e);
version = "";
}
}
Expand Down Expand Up @@ -143,7 +146,7 @@ public JsonPathMappingDataDictionary inboundJsonDataDictionary() {

Resource mappingFile = new PathMatchingResourcePatternResolver().getResource(simulatorConfiguration.getInboundJsonDictionary());
if (mappingFile.exists()) {
inboundJsonDataDictionary.setMappingFile(mappingFile);
inboundJsonDataDictionary.setMappingFile(new CitrusResourceWrapper(mappingFile));
}

return inboundJsonDataDictionary;
Expand All @@ -159,7 +162,7 @@ public JsonPathMappingDataDictionary outboundJsonDataDictionary() {

Resource mappingFile = new PathMatchingResourcePatternResolver().getResource(simulatorConfiguration.getOutboundJsonDictionary());
if (mappingFile.exists()) {
outboundJsonDataDictionary.setMappingFile(mappingFile);
outboundJsonDataDictionary.setMappingFile(new CitrusResourceWrapper(mappingFile));
}

return outboundJsonDataDictionary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.citrusframework.context.TestContext;
import org.citrusframework.simulator.config.SimulatorConfigurationProperties;
import org.citrusframework.spi.CitrusResourceWrapper;
import org.citrusframework.variable.dictionary.xml.XpathMappingDataDictionary;
import org.citrusframework.xml.xpath.XPathUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -29,7 +30,7 @@ public InboundXmlDataDictionary(SimulatorConfigurationProperties simulatorConfig

Resource inboundMappingFile = new PathMatchingResourcePatternResolver().getResource(simulatorConfiguration.getInboundXmlDictionary());
if (inboundMappingFile.exists()) {
mappingFile = inboundMappingFile;
mappingFile = new CitrusResourceWrapper(inboundMappingFile);
}
}

Expand All @@ -53,6 +54,7 @@ public <T> T translate(Node node, T value, TestContext context) {

/**
* Checks if given node set contains node.
*
* @param findings
* @param node
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.citrusframework.context.TestContext;
import org.citrusframework.simulator.config.SimulatorConfigurationProperties;
import org.citrusframework.spi.CitrusResourceWrapper;
import org.citrusframework.variable.dictionary.xml.XpathMappingDataDictionary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
Expand All @@ -20,7 +21,7 @@ public class OutboundXmlDataDictionary extends XpathMappingDataDictionary {
public OutboundXmlDataDictionary(SimulatorConfigurationProperties simulatorConfiguration) {
Resource outboundMappingFile = new PathMatchingResourcePatternResolver().getResource(simulatorConfiguration.getOutboundXmlDictionary());
if (outboundMappingFile.exists()) {
mappingFile = outboundMappingFile;
mappingFile = new CitrusResourceWrapper(outboundMappingFile);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.citrusframework.simulator.http;

import java.io.IOException;
import java.util.Map;

import io.swagger.models.Model;
import io.swagger.models.Operation;
import io.swagger.models.Path;
import io.swagger.models.Swagger;
import io.swagger.parser.SwaggerParser;
import org.citrusframework.simulator.exception.SimulatorException;
import org.citrusframework.spi.CitrusResourceWrapper;
import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -18,42 +17,51 @@
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMethod;

import java.io.IOException;
import java.util.Map;

/**
* @author Christoph Deppisch
*/
public class HttpScenarioGenerator implements BeanFactoryPostProcessor {

/** Logger */
private static Logger log = LoggerFactory.getLogger(HttpScenarioGenerator.class);

/** Target swagger API to generate scenarios from */
private final Resource swaggerResource;

/** Optional context path */
private String contextPath = "";

/** Optional Swagger api file location system property for auto generated scenarios */
/**
* Logger
*/
private static final Logger logger = LoggerFactory.getLogger(HttpScenarioGenerator.class);
/**
* Optional Swagger api file location system property for auto generated scenarios
*/
private static final String SIMULATOR_SWAGGER_API_PROPERTY = "citrus.simulator.rest.swagger.api";
private static final String SIMULATOR_SWAGGER_API_ENV = "CITRUS_SIMULATOR_REST_SWAGGER_API";

private static final String SIMULATOR_SWAGGER_CONTEXT_PATH_PROPERTY = "citrus.simulator.rest.swagger.contextPath";
private static final String SIMULATOR_SWAGGER_CONTEXT_PATH_ENV = "CITRUS_SIMULATOR_REST_SWAGGER_CONTEXT_PATH";
/**
* Target swagger API to generate scenarios from
*/
private final Resource swaggerResource;
/**
* Optional context path
*/
private String contextPath = "";

/**
* Constructor using Spring environment.
*/
public HttpScenarioGenerator(Environment environment) {
swaggerResource = new PathMatchingResourcePatternResolver().getResource(environment.getProperty(SIMULATOR_SWAGGER_API_PROPERTY, environment.getProperty(SIMULATOR_SWAGGER_API_ENV, "")));
org.springframework.core.io.Resource springResource = new PathMatchingResourcePatternResolver().getResource(environment.getProperty(SIMULATOR_SWAGGER_API_PROPERTY, environment.getProperty(SIMULATOR_SWAGGER_API_ENV, "")));
swaggerResource = new CitrusResourceWrapper(springResource);

contextPath = environment.getProperty(SIMULATOR_SWAGGER_CONTEXT_PATH_PROPERTY, environment.getProperty(SIMULATOR_SWAGGER_CONTEXT_PATH_ENV, contextPath));
}

/**
* Constructor using swagger API file resource.
*
* @param swaggerResource
*/
public HttpScenarioGenerator(Resource swaggerResource) {
Expand All @@ -64,20 +72,20 @@ public HttpScenarioGenerator(Resource swaggerResource) {
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
try {
Assert.notNull(swaggerResource,
"Missing either swagger api system property setting or explicit swagger api resource for scenario auto generation");
"Missing either swagger api system property setting or explicit swagger api resource for scenario auto generation");

Swagger swagger = new SwaggerParser().parse(FileUtils.readToString(swaggerResource));

for (Map.Entry<String, Path> path : swagger.getPaths().entrySet()) {
for (Map.Entry<io.swagger.models.HttpMethod, Operation> operation : path.getValue().getOperationMap().entrySet()) {

if (beanFactory instanceof BeanDefinitionRegistry) {
log.info("Register auto generated scenario as bean definition: " + operation.getValue().getOperationId());
logger.info("Register auto generated scenario as bean definition: " + operation.getValue().getOperationId());
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(HttpOperationScenario.class)
.addConstructorArgValue((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey())
.addConstructorArgValue(RequestMethod.valueOf(operation.getKey().name()))
.addConstructorArgValue(operation.getValue())
.addConstructorArgValue(swagger.getDefinitions());
.addConstructorArgValue((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey())
.addConstructorArgValue(RequestMethod.valueOf(operation.getKey().name()))
.addConstructorArgValue(operation.getValue())
.addConstructorArgValue(swagger.getDefinitions());

if (beanFactory.containsBeanDefinition("inboundJsonDataDictionary")) {
beanDefinitionBuilder.addPropertyReference("inboundDataDictionary", "inboundJsonDataDictionary");
Expand All @@ -89,7 +97,7 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)

((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(operation.getValue().getOperationId(), beanDefinitionBuilder.getBeanDefinition());
} else {
log.info("Register auto generated scenario as singleton: " + operation.getValue().getOperationId());
logger.info("Register auto generated scenario as singleton: " + operation.getValue().getOperationId());
beanFactory.registerSingleton(operation.getValue().getOperationId(), createScenario((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey(), RequestMethod.valueOf(operation.getKey().name()), operation.getValue(), swagger.getDefinitions()));
}
}
Expand All @@ -100,31 +108,22 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
}

/**
* Creates the scenario with given swagger path and operation information.
* @param path
* @param method
* @param operation
* @param definitions
* @return
* Creates an HTTP scenario based on the given swagger path and operation information.
*
* @param path Request path
* @param method Request method
* @param operation Swagger operation
* @param definitions Additional definitions
* @return a matching HTTP scenario
*/
protected HttpOperationScenario createScenario(String path, RequestMethod method, Operation operation, Map<String, Model> definitions) {
return new HttpOperationScenario(path, method, operation, definitions);
}

/**
* Gets the contextPath.
*
* @return
*/
public String getContextPath() {
return contextPath;
}

/**
* Sets the contextPath.
*
* @param contextPath
*/
public void setContextPath(String contextPath) {
this.contextPath = contextPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import org.citrusframework.simulator.config.SimulatorConfigurationProperties;
import org.citrusframework.simulator.template.TemplateHelper;
import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.util.StringUtils;

import jakarta.annotation.PostConstruct;
Expand Down
Loading

0 comments on commit f94c40a

Please sign in to comment.