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 30, 2023
1 parent 31149dd commit 204b777
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 101 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
<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>

<!-- see https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-log4j2/3.1.2 -->
<log4j2.version>2.20.0</log4j2.version>
<!-- see https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-logging/3.1.2 -->
<logback.classic.version>1.4.8</logback.classic.version>
<logback.classic.version>1.4.11</logback.classic.version>

<node.version>v18.18.0</node.version>
<npm.version>9.8.1</npm.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 @@ -21,7 +21,3 @@ citrus.simulator.defaultScenario=Default

# Should Citrus validate incoming messages on syntax and semantics
citrus.simulator.templateValidation=true


logging.level.root=DEBUG
logging.level.web=TRACE
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
@@ -1,9 +1,14 @@
package org.citrusframework.simulator.dictionary;

import static org.citrusframework.simulator.dictionary.XmlUtils.loadXMLMappingFile;

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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
Expand All @@ -20,6 +25,8 @@
*/
public class InboundXmlDataDictionary extends XpathMappingDataDictionary {

private static final Logger logger = LoggerFactory.getLogger(InboundXmlDataDictionary.class);

/**
* Default constructor setting default mappings and mappings file.
*/
Expand All @@ -29,10 +36,18 @@ public InboundXmlDataDictionary(SimulatorConfigurationProperties simulatorConfig

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

@Override
public void initialize() {
loadXMLMappingFile(logger, mappingFile, mappings);

mappings.put("//*[string-length(normalize-space(text())) > 0]", "@ignore@");
mappings.put("//@*", "@ignore@");
}

@Override
public <T> T translate(Node node, T value, TestContext context) {
for (Map.Entry<String, String> expressionEntry : mappings.entrySet()) {
Expand All @@ -53,6 +68,7 @@ public <T> T translate(Node node, T value, TestContext context) {

/**
* Checks if given node set contains node.
*
* @param findings
* @param node
* @return
Expand All @@ -66,12 +82,4 @@ private boolean containsNode(NodeList findings, Node node) {

return false;
}

@Override
public void initialize() {
super.initialize();

mappings.put("//*[string-length(normalize-space(text())) > 0]", "@ignore@");
mappings.put("//@*", "@ignore@");
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package org.citrusframework.simulator.dictionary;

import static org.citrusframework.simulator.dictionary.XmlUtils.loadXMLMappingFile;

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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
Expand All @@ -13,17 +18,24 @@
*/
public class OutboundXmlDataDictionary extends XpathMappingDataDictionary {

private static final Logger logger = LoggerFactory.getLogger(OutboundXmlDataDictionary.class);

/**
* Default constructor setting default mappings and mappings file.
*/
@Autowired
public OutboundXmlDataDictionary(SimulatorConfigurationProperties simulatorConfiguration) {
Resource outboundMappingFile = new PathMatchingResourcePatternResolver().getResource(simulatorConfiguration.getOutboundXmlDictionary());
if (outboundMappingFile.exists()) {
mappingFile = outboundMappingFile;
mappingFile = new CitrusResourceWrapper(outboundMappingFile);
}
}

@Override
public void initialize() {
loadXMLMappingFile(logger, mappingFile, mappings);
}

@Override
public <T> T translate(Node node, T value, TestContext context) {
if (value instanceof String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.citrusframework.simulator.dictionary;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.spi.Resource;
import org.slf4j.Logger;

class XmlUtils {

private XmlUtils(){
// Temporary utility class
}

// TODO: Remove if PR has been resolved and released: https://github.com/citrusframework/citrus/pull/1044
static void loadXMLMappingFile(Logger logger, Resource mappingFile, Map<String, String> mappings) {
if (mappingFile != null) {
logger.debug("Reading data dictionary mapping: {}", mappingFile.getLocation());

Properties props = new Properties();
try (InputStream inputStream = mappingFile.getInputStream()) {
props.loadFromXML(inputStream);
} catch (IOException e) {
throw new CitrusRuntimeException(e);
}

for (Map.Entry<Object, Object> entry : props.entrySet()) {
String key = entry.getKey().toString();

logger.debug("Loading data dictionary mapping: {}={}", key, props.getProperty(key));

if (logger.isDebugEnabled() && mappings.containsKey(key)) {
logger.warn("Overwriting data dictionary mapping '{}'; old value: {} new value: {}", key, mappings.get(key), props.getProperty(key));
}

mappings.put(key, props.getProperty(key));
}

logger.info("Loaded data dictionary mapping: {}", mappingFile.getLocation());
}
}
}
Loading

0 comments on commit 204b777

Please sign in to comment.