From f94c40a7cd88c2490dee58c56a495ff3a1d18cd0 Mon Sep 17 00:00:00 2001 From: Timon Borter Date: Wed, 25 Oct 2023 20:23:36 +0200 Subject: [PATCH] feat: citrus 4.0.0 release --- pom.xml | 8 +- .../simulator/sample/Simulator.java | 4 +- .../simulator/SimulatorSwaggerIT.java | 10 +-- .../simulator/sample/Simulator.java | 4 +- .../simulator/SimulatorAutoConfiguration.java | 13 ++-- .../dictionary/InboundXmlDataDictionary.java | 4 +- .../dictionary/OutboundXmlDataDictionary.java | 3 +- .../simulator/http/HttpScenarioGenerator.java | 77 +++++++++---------- .../scenario/AbstractScenarioStarter.java | 2 +- .../simulator/template/TemplateHelper.java | 26 ++++--- .../simulator/ws/WsdlScenarioGenerator.java | 28 +++---- .../http/HttpScenarioGeneratorTest.java | 4 +- .../template/TemplateHelperTest.java | 2 +- .../ws/WsdlScenarioGeneratorTest.java | 4 +- 14 files changed, 101 insertions(+), 88 deletions(-) diff --git a/pom.xml b/pom.xml index 0dd55d2e1..bb41734ee 100644 --- a/pom.xml +++ b/pom.xml @@ -23,10 +23,10 @@ 3.11.0 1.18.20 - 4.0.0-M2 - 3.1.2 - 6.0.9 - 3.1.3 + 4.0.0 + 3.1.5 + 6.0.13 + 4.0.7 7.5.1 1.6.3 2.12.1 diff --git a/simulator-samples/sample-swagger/src/main/java/org/citrusframework/simulator/sample/Simulator.java b/simulator-samples/sample-swagger/src/main/java/org/citrusframework/simulator/sample/Simulator.java index dc1b03d56..4c04c57d8 100644 --- a/simulator-samples/sample-swagger/src/main/java/org/citrusframework/simulator/sample/Simulator.java +++ b/simulator-samples/sample-swagger/src/main/java/org/citrusframework/simulator/sample/Simulator.java @@ -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; /** @@ -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; } diff --git a/simulator-samples/sample-swagger/src/test/java/org/citrusframework/simulator/SimulatorSwaggerIT.java b/simulator-samples/sample-swagger/src/test/java/org/citrusframework/simulator/SimulatorSwaggerIT.java index fcbbeb190..9b12c5ce1 100644 --- a/simulator-samples/sample-swagger/src/test/java/org/citrusframework/simulator/SimulatorSwaggerIT.java +++ b/simulator-samples/sample-swagger/src/test/java/org/citrusframework/simulator/SimulatorSwaggerIT.java @@ -23,6 +23,7 @@ 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; @@ -30,7 +31,6 @@ 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; @@ -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() @@ -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 @@ -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() @@ -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() diff --git a/simulator-samples/sample-wsdl/src/main/java/org/citrusframework/simulator/sample/Simulator.java b/simulator-samples/sample-wsdl/src/main/java/org/citrusframework/simulator/sample/Simulator.java index 05fe874da..1bf3f859e 100644 --- a/simulator-samples/sample-wsdl/src/main/java/org/citrusframework/simulator/sample/Simulator.java +++ b/simulator-samples/sample-wsdl/src/main/java/org/citrusframework/simulator/sample/Simulator.java @@ -19,6 +19,7 @@ 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; @@ -26,7 +27,6 @@ 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 @@ -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; } } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/SimulatorAutoConfiguration.java b/simulator-starter/src/main/java/org/citrusframework/simulator/SimulatorAutoConfiguration.java index 91214686e..68daa3b86 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/SimulatorAutoConfiguration.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/SimulatorAutoConfiguration.java @@ -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; @@ -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; @@ -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 = ""; } } @@ -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; @@ -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; diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/dictionary/InboundXmlDataDictionary.java b/simulator-starter/src/main/java/org/citrusframework/simulator/dictionary/InboundXmlDataDictionary.java index 8a8cdf945..baeaa74ff 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/dictionary/InboundXmlDataDictionary.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/dictionary/InboundXmlDataDictionary.java @@ -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; @@ -29,7 +30,7 @@ public InboundXmlDataDictionary(SimulatorConfigurationProperties simulatorConfig Resource inboundMappingFile = new PathMatchingResourcePatternResolver().getResource(simulatorConfiguration.getInboundXmlDictionary()); if (inboundMappingFile.exists()) { - mappingFile = inboundMappingFile; + mappingFile = new CitrusResourceWrapper(inboundMappingFile); } } @@ -53,6 +54,7 @@ public T translate(Node node, T value, TestContext context) { /** * Checks if given node set contains node. + * * @param findings * @param node * @return diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/dictionary/OutboundXmlDataDictionary.java b/simulator-starter/src/main/java/org/citrusframework/simulator/dictionary/OutboundXmlDataDictionary.java index 9e4bf508f..fb8c478a1 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/dictionary/OutboundXmlDataDictionary.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/dictionary/OutboundXmlDataDictionary.java @@ -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; @@ -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); } } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/http/HttpScenarioGenerator.java b/simulator-starter/src/main/java/org/citrusframework/simulator/http/HttpScenarioGenerator.java index d06c6bf01..fa05fc883 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/http/HttpScenarioGenerator.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/http/HttpScenarioGenerator.java @@ -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; @@ -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) { @@ -64,7 +72,7 @@ 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)); @@ -72,12 +80,12 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) for (Map.Entry 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"); @@ -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())); } } @@ -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 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; } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/scenario/AbstractScenarioStarter.java b/simulator-starter/src/main/java/org/citrusframework/simulator/scenario/AbstractScenarioStarter.java index 41ae73eee..8506f4567 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/scenario/AbstractScenarioStarter.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/scenario/AbstractScenarioStarter.java @@ -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; diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/template/TemplateHelper.java b/simulator-starter/src/main/java/org/citrusframework/simulator/template/TemplateHelper.java index 9e5400ec8..50407acef 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/template/TemplateHelper.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/template/TemplateHelper.java @@ -1,10 +1,9 @@ package org.citrusframework.simulator.template; import org.citrusframework.exceptions.CitrusRuntimeException; +import org.citrusframework.spi.Resource; +import org.citrusframework.spi.Resources; import org.citrusframework.util.FileUtils; -import lombok.Getter; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; import org.springframework.util.StringUtils; import java.io.IOException; @@ -14,12 +13,16 @@ /** * Helper class for loading templates from the classpath, in particular XML and JSON templates. */ -@Getter public class TemplateHelper { private final String basePath; private final Charset charset; + private TemplateHelper(String basePath, Charset charset) { + this.basePath = adaptBasePath(basePath); + this.charset = charset; + } + /** * Creates a new {@link TemplateHelper} * @@ -41,9 +44,8 @@ public static TemplateHelper instance(String basePath) { return instance(basePath, StandardCharsets.UTF_8); } - private TemplateHelper(String basePath, Charset charset) { - this.basePath = adaptBasePath(basePath); - this.charset = charset; + private static String adaptBasePath(String basePath) { + return StringUtils.endsWithIgnoreCase(basePath, "/") ? basePath : basePath + "/"; } /** @@ -96,10 +98,14 @@ public Resource getFileResource(String resourcePath, String resourceExtension) { if (StringUtils.hasLength(resourceExtension) && !StringUtils.startsWithIgnoreCase(resourceExtension, ".")) { adaptedFileExtension = "." + resourceExtension; } - return new ClassPathResource(basePath + resourcePath + adaptedFileExtension); + return new Resources.ClasspathResource(basePath + resourcePath + adaptedFileExtension); } - private static String adaptBasePath(String basePath) { - return StringUtils.endsWithIgnoreCase(basePath, "/") ? basePath : basePath + "/"; + public String getBasePath() { + return basePath; + } + + public Charset getCharset() { + return charset; } } diff --git a/simulator-starter/src/main/java/org/citrusframework/simulator/ws/WsdlScenarioGenerator.java b/simulator-starter/src/main/java/org/citrusframework/simulator/ws/WsdlScenarioGenerator.java index c7e7c5088..d8c97b227 100644 --- a/simulator-starter/src/main/java/org/citrusframework/simulator/ws/WsdlScenarioGenerator.java +++ b/simulator-starter/src/main/java/org/citrusframework/simulator/ws/WsdlScenarioGenerator.java @@ -10,6 +10,8 @@ import org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.simulator.exception.SimulatorException; +import org.citrusframework.spi.CitrusResourceWrapper; +import org.citrusframework.spi.Resource; import org.citrusframework.xml.schema.locator.JarWSDLLocator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,7 +21,6 @@ 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.util.StringUtils; @@ -41,19 +42,22 @@ */ public class WsdlScenarioGenerator implements BeanFactoryPostProcessor { + /** + * Logger + */ + private static final Logger logger = LoggerFactory.getLogger(WsdlScenarioGenerator.class); + /** * Optional WSDL file location system property for auto generated scenarios */ private static final String SIMULATOR_WSDL_LOCATION_PROPERTY = "citrus.simulator.ws.wsdl.location"; private static final String SIMULATOR_WSDL_LOCATION_ENV = "CITRUS_SIMULATOR_WS_WSDL_LOCATION"; - /** - * Logger - */ - private static final Logger log = LoggerFactory.getLogger(WsdlScenarioGenerator.class); + /** * Target wsdl to generate scenarios from */ private final Resource wsdlResource; + /** * Naming strategy for generated scenarios */ @@ -63,7 +67,8 @@ public class WsdlScenarioGenerator implements BeanFactoryPostProcessor { * Default constructor. */ public WsdlScenarioGenerator(Environment environment) { - wsdlResource = new PathMatchingResourcePatternResolver().getResource(environment.getProperty(SIMULATOR_WSDL_LOCATION_PROPERTY, environment.getProperty(SIMULATOR_WSDL_LOCATION_ENV, ""))); + org.springframework.core.io.Resource springResource = new PathMatchingResourcePatternResolver().getResource(environment.getProperty(SIMULATOR_WSDL_LOCATION_PROPERTY, environment.getProperty(SIMULATOR_WSDL_LOCATION_ENV, ""))); + wsdlResource = new CitrusResourceWrapper(springResource); } /** @@ -115,7 +120,7 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) }; if (beanFactory instanceof BeanDefinitionRegistry) { - log.info("Register auto generated scenario as bean definition: " + scenarioName); + logger.info("Register auto generated scenario as bean definition: " + scenarioName); BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(WsdlOperationScenario.class) .addConstructorArgValue(operation) .addPropertyValue("soapAction", soapAction) @@ -132,7 +137,7 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(scenarioName, beanDefinitionBuilder.getBeanDefinition()); } else { - log.info("Register auto generated scenario as singleton: " + scenarioName); + logger.info("Register auto generated scenario as singleton: " + scenarioName); WsdlOperationScenario scenario = createScenario(operation, soapAction, generateRequest(operation, SampleXmlUtil.createSampleForType(requestElem)), generateResponse(operation, SampleXmlUtil.createSampleForType(responseElem))); beanFactory.registerSingleton(scenarioName, scenario); } @@ -214,8 +219,6 @@ private Definition getWsdlDefinition(Resource wsdl) { } return definition; - } catch (IOException e) { - throw new CitrusRuntimeException("Failed to read wsdl file resource", e); } catch (WSDLException e) { throw new CitrusRuntimeException("Failed to create wsdl schema instance", e); } @@ -232,7 +235,7 @@ private XmlObject compileWsdl(Resource wsdlResource) { return XmlObject.Factory.parse(wsdlResource.getInputStream(), (new XmlOptions()).setLoadLineNumbers().setLoadMessageDigest().setCompileDownloadUrls()); } catch (XmlException e) { for (Object error : e.getErrors()) { - log.error(((XmlError) error).getLine() + String.valueOf(error)); + logger.error(((XmlError) error).getLine() + String.valueOf(error)); } throw new SimulatorException("WSDL could not be parsed", e); } catch (Exception e) { @@ -267,7 +270,7 @@ private SchemaTypeSystem compileXsd(XmlObject wsdl) { schemaTypeSystem = XmlBeans.compileXsd(xsd, XmlBeans.getContextTypeLoader(), new XmlOptions()); } catch (XmlException e) { for (Object error : e.getErrors()) { - log.error("Line " + ((XmlError) error).getLine() + ": " + error); + logger.error("Line " + ((XmlError) error).getLine() + ": " + error); } throw new SimulatorException("Failed to compile XSD schema", e); } catch (Exception e) { @@ -379,5 +382,4 @@ public enum WsdlScenarioNamingStrategy { OPERATION, SOAP_ACTION } - } diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpScenarioGeneratorTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpScenarioGeneratorTest.java index f93147d31..a0593f443 100644 --- a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpScenarioGeneratorTest.java +++ b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpScenarioGeneratorTest.java @@ -1,6 +1,7 @@ package org.citrusframework.simulator.http; import io.swagger.models.Operation; +import org.citrusframework.spi.Resources; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -9,7 +10,6 @@ import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.core.io.ClassPathResource; import org.springframework.web.bind.annotation.RequestMethod; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -37,7 +37,7 @@ class HttpScenarioGeneratorTest { @BeforeEach void beforeEachSetup() { - fixture = new HttpScenarioGenerator(new ClassPathResource("swagger/swagger-api.json")); + fixture = new HttpScenarioGenerator(new Resources.ClasspathResource("swagger/swagger-api.json")); } @Test 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..547e5685b 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 @@ -1,9 +1,9 @@ package org.citrusframework.simulator.template; +import org.citrusframework.spi.Resource; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.springframework.core.io.Resource; import java.util.stream.Stream; 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..4511a7036 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 @@ -1,5 +1,6 @@ package org.citrusframework.simulator.ws; +import org.citrusframework.spi.Resources; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -11,7 +12,6 @@ import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.core.io.ClassPathResource; import java.util.stream.Stream; @@ -71,7 +71,7 @@ static Stream data() { @BeforeEach void beforeEachSetup() { - fixture = new WsdlScenarioGenerator(new ClassPathResource("schema/TestService.wsdl")); + fixture = new WsdlScenarioGenerator(new Resources.ClasspathResource("schema/TestService.wsdl")); } @MethodSource