T assertNotNull(T object, String errorMessage) {
+ if (object == null) {
+ throw new CitrusRuntimeException(errorMessage);
+ }
+
+ return object;
+ }
+}
diff --git a/core/citrus-api/src/main/java/org/citrusframework/util/ReflectionHelper.java b/core/citrus-api/src/main/java/org/citrusframework/util/ReflectionHelper.java
new file mode 100644
index 0000000000..00b88bb521
--- /dev/null
+++ b/core/citrus-api/src/main/java/org/citrusframework/util/ReflectionHelper.java
@@ -0,0 +1,255 @@
+/*
+ * Copyright 2023 the original author or authors.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.util;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+
+import org.citrusframework.exceptions.CitrusRuntimeException;
+
+/**
+ * Helper for working with reflection on classes.
+ *
+ * This code is based on org.apache.camel.util.ReflectionHelper class.
+ */
+public class ReflectionHelper {
+
+ private ReflectionHelper() {
+ // utility class
+ }
+
+ /**
+ * Callback interface invoked on each field in the hierarchy.
+ */
+ @FunctionalInterface
+ public interface FieldCallback {
+
+ /**
+ * Perform an operation using the given field.
+ *
+ * @param field the field to operate on
+ */
+ void doWith(Field field) throws IllegalArgumentException, IllegalAccessException;
+ }
+
+ /**
+ * Action to take on each method.
+ */
+ @FunctionalInterface
+ public interface MethodCallback {
+
+ /**
+ * Perform an operation using the given method.
+ *
+ * @param method the method to operate on
+ */
+ void doWith(Method method) throws IllegalArgumentException, IllegalAccessException;
+ }
+
+ /**
+ * Action to take on each class.
+ */
+ @FunctionalInterface
+ public interface ClassCallback {
+
+ /**
+ * Perform an operation using the given class.
+ *
+ * @param clazz the class to operate on
+ */
+ void doWith(Class> clazz) throws IllegalArgumentException, IllegalAccessException;
+ }
+
+ /**
+ * Perform the given callback operation on the nested (inner) classes.
+ *
+ * @param clazz class to start looking at
+ * @param cc the callback to invoke for each inner class (excluding the class itself)
+ */
+ public static void doWithClasses(Class> clazz, ClassCallback cc) throws IllegalArgumentException {
+ // and then nested classes
+ Class>[] classes = clazz.getDeclaredClasses();
+ for (Class> aClazz : classes) {
+ try {
+ cc.doWith(aClazz);
+ } catch (IllegalAccessException ex) {
+ throw new IllegalStateException("Shouldn't be illegal to access class '" + aClazz.getName() + "': " + ex);
+ }
+ }
+ }
+
+ /**
+ * Invoke the given callback on all fields in the target class, going up the class hierarchy to get all declared
+ * fields.
+ *
+ * @param clazz the target class to analyze
+ * @param fc the callback to invoke for each field
+ */
+ public static void doWithFields(Class> clazz, FieldCallback fc) throws IllegalArgumentException {
+ // Keep backing up the inheritance hierarchy.
+ Class> targetClass = clazz;
+ do {
+ Field[] fields = targetClass.getDeclaredFields();
+ for (Field field : fields) {
+ try {
+ fc.doWith(field);
+ } catch (IllegalAccessException ex) {
+ throw new IllegalStateException("Shouldn't be illegal to access field '" + field.getName() + "': " + ex);
+ }
+ }
+ targetClass = targetClass.getSuperclass();
+ } while (targetClass != null && targetClass != Object.class);
+ }
+
+ /**
+ * Perform the given callback operation on all matching methods of the given class and superclasses (or given
+ * interface and super-interfaces).
+ *
+ * Important: This method does not take the {@link java.lang.reflect.Method#isBridge() bridge methods} into
+ * account.
+ *
+ * @param clazz class to start looking at
+ * @param mc the callback to invoke for each method
+ */
+ public static void doWithMethods(Class> clazz, MethodCallback mc) throws IllegalArgumentException {
+ // Keep backing up the inheritance hierarchy.
+ Method[] methods = clazz.getDeclaredMethods();
+ for (Method method : methods) {
+ if (method.isBridge()) {
+ // skip the bridge methods which in Java 8 leads to problems with inheritance
+ // see https://bugs.openjdk.java.net/browse/JDK-6695379
+ continue;
+ }
+ try {
+ mc.doWith(method);
+ } catch (IllegalAccessException ex) {
+ throw new IllegalStateException("Shouldn't be illegal to access method '" + method.getName() + "': " + ex);
+ }
+ }
+ if (clazz.getSuperclass() != null) {
+ doWithMethods(clazz.getSuperclass(), mc);
+ } else if (clazz.isInterface()) {
+ for (Class> superIfc : clazz.getInterfaces()) {
+ doWithMethods(superIfc, mc);
+ }
+ }
+ }
+
+ /**
+ * Attempt to find a {@link Field field} on the supplied {@link Class} with the
+ * supplied {@code name} and/or {@link Class type}. Searches all superclasses
+ * up to {@link Object}.
+ * @param clazz the class to introspect
+ * @param name the name of the field (may be {@code null} if type is specified)
+ * @return the corresponding Field object, or {@code null} if not found
+ */
+ public static Field findField(Class> clazz, String name) {
+ ObjectHelper.assertNotNull(clazz, "Class must not be null");
+ Class> searchType = clazz;
+ while (Object.class != searchType && searchType != null) {
+ Field[] fields = searchType.getDeclaredFields();
+ for (Field field : fields) {
+ if (name.equals(field.getName())) {
+ return field;
+ }
+ }
+ searchType = searchType.getSuperclass();
+ }
+ return null;
+ }
+
+ /**
+ * Attempt to find a {@link Method} on the supplied class with the supplied name and parameter types. Searches all
+ * superclasses up to {@code Object}.
+ *
+ * Returns {@code null} if no {@link Method} can be found.
+ *
+ * @param clazz the class to introspect
+ * @param name the name of the method
+ * @param paramTypes the parameter types of the method (may be {@code null} to indicate any signature)
+ * @return the Method object, or {@code null} if none found
+ */
+ public static Method findMethod(Class> clazz, String name, Class>... paramTypes) {
+ ObjectHelper.assertNotNull(clazz, "Class must not be null");
+ ObjectHelper.assertNotNull(name, "Method name must not be null");
+ Class> searchType = clazz;
+ while (searchType != null) {
+ Method[] methods = searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods();
+ for (Method method : methods) {
+ if (name.equals(method.getName())
+ && (paramTypes == null || Arrays.equals(paramTypes, method.getParameterTypes()))) {
+ return method;
+ }
+ }
+ searchType = searchType.getSuperclass();
+ }
+ return null;
+ }
+
+ /**
+ * Invoke the specified {@link Method} against the supplied target object with the
+ * supplied arguments. The target object can be {@code null} when invoking a
+ * static {@link Method}.
+ * @param method the method to invoke
+ * @param target the target object to invoke the method on
+ * @param args the invocation arguments (may be {@code null})
+ * @return the invocation result, if any
+ */
+ public static Object invokeMethod(Method method, Object target, Object... args) {
+ try {
+ return method.invoke(target, args);
+ }
+ catch (Exception e) {
+ throw new CitrusRuntimeException("Failed to invoke method", e);
+ }
+ }
+
+ public static void setField(Field f, Object instance, Object value) {
+ try {
+ if (!Modifier.isPublic(f.getModifiers()) && !f.canAccess(instance)) {
+ f.setAccessible(true);
+ }
+ f.set(instance, value);
+ } catch (Exception e) {
+ throw new UnsupportedOperationException("Cannot inject value of class: " + value.getClass() + " into: " + f);
+ }
+ }
+
+ public static Object getField(Field f, Object instance) {
+ try {
+ if ((!Modifier.isPublic(f.getModifiers()) ||
+ !Modifier.isPublic(f.getDeclaringClass().getModifiers()) ||
+ Modifier.isFinal(f.getModifiers())) &&
+ (Modifier.isStatic(f.getModifiers()) ? !f.canAccess(null) : !f.canAccess(instance))) {
+ f.setAccessible(true);
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+
+ try {
+ return f.get(instance);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+}
diff --git a/core/citrus-api/src/main/java/org/citrusframework/validation/context/SchemaValidationContext.java b/core/citrus-api/src/main/java/org/citrusframework/validation/context/SchemaValidationContext.java
index 08f4944c5d..facb9df3de 100644
--- a/core/citrus-api/src/main/java/org/citrusframework/validation/context/SchemaValidationContext.java
+++ b/core/citrus-api/src/main/java/org/citrusframework/validation/context/SchemaValidationContext.java
@@ -30,13 +30,13 @@ public interface SchemaValidationContext {
/**
* Gets the schemaRepository.
- * @return the schemaRepository the schemaRepository to get.
+ * @return the schemaRepository to get.
*/
String getSchemaRepository();
/**
* Gets the schema.
- * @return the schema the schema to get.
+ * @return the schema to get.
*/
String getSchema();
diff --git a/core/citrus-api/src/main/java/org/citrusframework/variable/SegmentVariableExtractorRegistry.java b/core/citrus-api/src/main/java/org/citrusframework/variable/SegmentVariableExtractorRegistry.java
index f56247ad0f..d0cd555aa2 100644
--- a/core/citrus-api/src/main/java/org/citrusframework/variable/SegmentVariableExtractorRegistry.java
+++ b/core/citrus-api/src/main/java/org/citrusframework/variable/SegmentVariableExtractorRegistry.java
@@ -1,16 +1,20 @@
package org.citrusframework.variable;
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.spi.ResourcePathTypeResolver;
import org.citrusframework.spi.TypeResolver;
+import org.citrusframework.util.ReflectionHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.ReflectionUtils;
-
-import java.lang.reflect.Array;
-import java.lang.reflect.Field;
-import java.util.*;
/**
* Simple registry holding all available segment variable extractor implementations. Test context can ask this registry for
@@ -163,14 +167,13 @@ private ObjectFieldValueExtractor() {
@Override
protected Object doExtractIndexedValue(TestContext testContext, Object parentObject, VariableExpressionSegmentMatcher matcher) {
- Field field = ReflectionUtils.findField(parentObject.getClass(), matcher.getSegmentExpression());
+ Field field = ReflectionHelper.findField(parentObject.getClass(), matcher.getSegmentExpression());
if (field == null) {
throw new CitrusRuntimeException(String.format("Failed to get variable - unknown field '%s' on type %s",
matcher.getSegmentExpression(), parentObject.getClass().getName()));
}
- ReflectionUtils.makeAccessible(field);
- return ReflectionUtils.getField(field, parentObject);
+ return ReflectionHelper.getField(field, parentObject);
}
@Override
diff --git a/core/citrus-base/src/main/java/org/citrusframework/CitrusContext.java b/core/citrus-base/src/main/java/org/citrusframework/CitrusContext.java
index 798e45d61a..d40a3a80dc 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/CitrusContext.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/CitrusContext.java
@@ -29,7 +29,7 @@
import org.citrusframework.validation.matcher.ValidationMatcherRegistry;
import org.citrusframework.variable.GlobalVariables;
import org.citrusframework.xml.namespace.NamespaceContextBuilder;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* Default Citrus context implementation holds basic components used in Citrus.
diff --git a/core/citrus-base/src/main/java/org/citrusframework/actions/AbstractAsyncTestAction.java b/core/citrus-base/src/main/java/org/citrusframework/actions/AbstractAsyncTestAction.java
index 82f200a7d8..03f4ac5482 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/actions/AbstractAsyncTestAction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/actions/AbstractAsyncTestAction.java
@@ -18,6 +18,8 @@
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.citrusframework.Completable;
@@ -25,7 +27,6 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.task.SimpleAsyncTaskExecutor;
/**
* Test action that performs in a separate thread. Action execution is not blocking the test execution chain. After
@@ -45,7 +46,7 @@ public abstract class AbstractAsyncTestAction extends AbstractTestAction impleme
@Override
public final void doExecute(TestContext context) {
CompletableFuture result = new CompletableFuture<>();
- SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
+ ExecutorService executor = Executors.newSingleThreadExecutor();
finished = executor.submit(() -> {
try {
doExecuteAsync(context);
diff --git a/core/citrus-base/src/main/java/org/citrusframework/actions/AntRunAction.java b/core/citrus-base/src/main/java/org/citrusframework/actions/AntRunAction.java
index 570eb00dd2..f6b67bab76 100755
--- a/core/citrus-base/src/main/java/org/citrusframework/actions/AntRunAction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/actions/AntRunAction.java
@@ -18,26 +18,25 @@
import java.io.IOException;
import java.io.PrintStream;
-import java.util.Arrays;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Stack;
-import org.citrusframework.AbstractTestActionBuilder;
-import org.citrusframework.context.TestContext;
-import org.citrusframework.exceptions.CitrusRuntimeException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
+import org.citrusframework.AbstractTestActionBuilder;
+import org.citrusframework.context.TestContext;
+import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.core.io.support.PropertiesLoaderUtils;
-import org.springframework.util.StringUtils;
/**
* Action calls Apache ANT with given build file and runs ANT targets
@@ -93,7 +92,7 @@ public void doExecute(TestContext context) {
String buildFileResource = context.replaceDynamicContentInString(buildFilePath);
try {
- ProjectHelper.configureProject(project, new PathMatchingResourcePatternResolver().getResource(buildFileResource).getFile());
+ ProjectHelper.configureProject(project, Resources.newClasspathResource(buildFileResource).getFile());
for (Entry entry : properties.entrySet()) {
String propertyValue = entry.getValue() != null ? context.replaceDynamicContentInString(entry.getValue().toString()) : "";
@@ -122,8 +121,6 @@ public void doExecute(TestContext context) {
}
} catch (BuildException e) {
throw new CitrusRuntimeException("Failed to run ANT build file", e);
- } catch (IOException e) {
- throw new CitrusRuntimeException("Failed to read ANT build file", e);
}
logger.info("Executed ANT build: " + buildFileResource);
@@ -171,9 +168,10 @@ private void loadBuildPropertyFile(Project project, TestContext context) {
if (StringUtils.hasText(propertyFilePath)) {
String propertyFileResource = context.replaceDynamicContentInString(propertyFilePath);
logger.info("Reading build property file: " + propertyFileResource);
- Properties fileProperties;
+ Properties fileProperties = new Properties();
try {
- fileProperties = PropertiesLoaderUtils.loadProperties(new PathMatchingResourcePatternResolver().getResource(propertyFileResource));
+ Resource propertyResource = Resources.newClasspathResource(propertyFileResource);
+ fileProperties.load(propertyResource.getInputStream());
for (Entry entry : fileProperties.entrySet()) {
String propertyValue = entry.getValue() != null ? context.replaceDynamicContentInString(entry.getValue().toString()) : "";
@@ -286,7 +284,7 @@ public Builder target(String target) {
* @param targets
*/
public Builder targets(String ... targets) {
- this.targets = StringUtils.collectionToCommaDelimitedString(Arrays.asList(targets));
+ this.targets = String.join(",", targets);
return this;
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/actions/InputAction.java b/core/citrus-base/src/main/java/org/citrusframework/actions/InputAction.java
index 4383100671..eeaaac150a 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/actions/InputAction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/actions/InputAction.java
@@ -29,7 +29,7 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* Test action prompts user data from standard input stream. The input data is then stored as new
diff --git a/core/citrus-base/src/main/java/org/citrusframework/actions/JavaAction.java b/core/citrus-base/src/main/java/org/citrusframework/actions/JavaAction.java
index 000df256a3..715c52f850 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/actions/JavaAction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/actions/JavaAction.java
@@ -22,14 +22,15 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.stream.Collectors;
import org.citrusframework.AbstractTestActionBuilder;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.util.ReflectionHelper;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.ReflectionUtils;
-import org.springframework.util.StringUtils;
/**
* Action to enable class invocation through java reflection
@@ -86,7 +87,7 @@ public void doExecute(TestContext context) {
methodTypes[i] = methodArgs.get(i).getClass();
if (methodArgs.get(i).getClass().equals(List.class)) {
- String[] converted = StringUtils.toStringArray((List)methodArgs.get(i));
+ String[] converted = ((List)methodArgs.get(i)).toArray(new String[]{});
for (int j = 0; j < converted.length; j++) {
converted[j] = context.replaceDynamicContentInString(converted[j]);
@@ -118,11 +119,11 @@ public void doExecute(TestContext context) {
}
private void invokeMethod(Object instance, Class>[] methodTypes, Object[] methodObjects) throws IllegalArgumentException, InvocationTargetException, IllegalAccessException, CitrusRuntimeException {
- Method methodToRun = ReflectionUtils.findMethod(instance.getClass(), methodName, methodTypes);
+ Method methodToRun = ReflectionHelper.findMethod(instance.getClass(), methodName, methodTypes);
if (methodToRun == null) {
throw new CitrusRuntimeException("Unable to find method '" + methodName + "(" +
- StringUtils.arrayToCommaDelimitedString(methodTypes) + ")' for class '" + instance.getClass() + "'");
+ Arrays.stream(methodTypes).map(Class::getSimpleName).collect(Collectors.joining(",")) + ")' for class '" + instance.getClass() + "'");
}
logger.info("Invoking method '" + methodToRun.toString() + "' on instance '" + instance.getClass() + "'");
diff --git a/core/citrus-base/src/main/java/org/citrusframework/actions/LoadPropertiesAction.java b/core/citrus-base/src/main/java/org/citrusframework/actions/LoadPropertiesAction.java
index ea19f55b84..9d330d7622 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/actions/LoadPropertiesAction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/actions/LoadPropertiesAction.java
@@ -24,15 +24,14 @@
import org.citrusframework.AbstractTestActionBuilder;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
/**
* Action reads property files and creates test variables for every property entry. File
- * resource path can define a {@link org.springframework.core.io.ClassPathResource} or
- * a {@link org.springframework.core.io.FileSystemResource}.
+ * resource path can define a resource located on classpath or file system.
*
* @author Christoph Deppisch
*/
@@ -58,7 +57,7 @@ public void doExecute(TestContext context) {
Resource resource = FileUtils.getFileResource(filePath, context);
if (logger.isDebugEnabled()) {
- logger.debug("Reading property file " + resource.getFilename());
+ logger.debug("Reading property file " + FileUtils.getFileName(resource.getLocation()));
}
Properties props = FileUtils.loadAsProperties(resource);
@@ -85,7 +84,7 @@ public void doExecute(TestContext context) {
context.resolveDynamicValuesInMap(unresolved).forEach(context::setVariable);
- logger.info("Loaded property file " + resource.getFilename());
+ logger.info("Loaded property file " + FileUtils.getFileName(resource.getLocation()));
}
/**
diff --git a/core/citrus-base/src/main/java/org/citrusframework/actions/PurgeEndpointAction.java b/core/citrus-base/src/main/java/org/citrusframework/actions/PurgeEndpointAction.java
index 0be9dc38dd..524775ce75 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/actions/PurgeEndpointAction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/actions/PurgeEndpointAction.java
@@ -34,7 +34,7 @@
import org.citrusframework.spi.ReferenceResolverAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* Action purges all messages from a message endpoint. Action receives
diff --git a/core/citrus-base/src/main/java/org/citrusframework/actions/ReceiveMessageAction.java b/core/citrus-base/src/main/java/org/citrusframework/actions/ReceiveMessageAction.java
index 4545567569..05cc66c11f 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/actions/ReceiveMessageAction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/actions/ReceiveMessageAction.java
@@ -60,12 +60,11 @@
import org.citrusframework.variable.dictionary.DataDictionary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* This action receives messages from a service destination. Action uses a {@link org.citrusframework.endpoint.Endpoint}
- * to receive the message, this means that action is independent from any message transport.
+ * to receive the message, this means that this action is independent of any message transport.
*
* The received message is validated using a {@link MessageValidator} supporting expected
* control message payload and header templates.
@@ -239,7 +238,7 @@ protected void validateMessage(Message message, TestContext context) {
logger.debug("Control message:\n" + controlMessage.print(context));
}
- if (!CollectionUtils.isEmpty(validators)) {
+ if (!validators.isEmpty()) {
for (MessageValidator extends ValidationContext> messageValidator : validators) {
messageValidator.validateMessage(message, controlMessage, context, validationContexts);
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/actions/ReceiveTimeoutAction.java b/core/citrus-base/src/main/java/org/citrusframework/actions/ReceiveTimeoutAction.java
index 08abbb83e2..de859a7942 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/actions/ReceiveTimeoutAction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/actions/ReceiveTimeoutAction.java
@@ -30,7 +30,7 @@
import org.citrusframework.messaging.SelectiveConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* Action expecting a timeout on a message destination, this means that no message
diff --git a/core/citrus-base/src/main/java/org/citrusframework/actions/SendMessageAction.java b/core/citrus-base/src/main/java/org/citrusframework/actions/SendMessageAction.java
index 4476c8b56a..8c5f789e31 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/actions/SendMessageAction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/actions/SendMessageAction.java
@@ -19,6 +19,8 @@
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import org.citrusframework.CitrusSettings;
import org.citrusframework.Completable;
@@ -42,8 +44,7 @@
import org.citrusframework.variable.dictionary.DataDictionary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.task.SimpleAsyncTaskExecutor;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
@@ -144,7 +145,7 @@ public void doExecute(final TestContext context) {
if (forkMode) {
logger.debug("Forking message sending action ...");
- SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
+ ExecutorService taskExecutor = Executors.newSingleThreadExecutor();
taskExecutor.execute(() -> {
try {
validateMessage(message, context);
diff --git a/core/citrus-base/src/main/java/org/citrusframework/actions/TransformAction.java b/core/citrus-base/src/main/java/org/citrusframework/actions/TransformAction.java
index 39344fca8e..ca3eb12956 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/actions/TransformAction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/actions/TransformAction.java
@@ -27,12 +27,12 @@
import org.citrusframework.CitrusSettings;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
import org.citrusframework.xml.StringResult;
import org.citrusframework.xml.StringSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
/**
diff --git a/core/citrus-base/src/main/java/org/citrusframework/annotations/CitrusAnnotations.java b/core/citrus-base/src/main/java/org/citrusframework/annotations/CitrusAnnotations.java
index 4d326ebeb9..88b5a1393f 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/annotations/CitrusAnnotations.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/annotations/CitrusAnnotations.java
@@ -16,8 +16,8 @@
package org.citrusframework.annotations;
-import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
import java.util.Arrays;
import org.citrusframework.Citrus;
@@ -29,11 +29,11 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.spi.BindToRegistry;
import org.citrusframework.spi.ReferenceRegistry;
+import org.citrusframework.util.ReflectionHelper;
import org.citrusframework.validation.MessageValidator;
import org.citrusframework.validation.context.ValidationContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.ReflectionUtils;
/**
* Dependency injection support for {@link CitrusFramework}, {@link CitrusResource} and {@link CitrusEndpoint} annotations.
@@ -102,26 +102,13 @@ public static void injectEndpoints(final Object target, final TestContext contex
* @param citrusFramework
*/
public static void injectCitrusFramework(final Object testCase, final Citrus citrusFramework) {
- ReflectionUtils.doWithFields(testCase.getClass(), new ReflectionUtils.FieldCallback() {
- @Override
- public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
- logger.trace(String.format("Injecting Citrus framework instance on test class field '%s'", field.getName()));
- ReflectionUtils.setField(field, testCase, citrusFramework);
+ ReflectionHelper.doWithFields(testCase.getClass(), field -> {
+ if (!field.isAnnotationPresent(CitrusFramework.class) || !Citrus.class.isAssignableFrom(field.getType())) {
+ return;
}
- }, new ReflectionUtils.FieldFilter() {
- @Override
- public boolean matches(Field field) {
- if (field.isAnnotationPresent(CitrusFramework.class) &&
- Citrus.class.isAssignableFrom(field.getType())) {
- if (!field.isAccessible()) {
- ReflectionUtils.makeAccessible(field);
- }
-
- return true;
- }
- return false;
- }
+ logger.trace(String.format("Injecting Citrus framework instance on test class field '%s'", field.getName()));
+ ReflectionHelper.setField(field, testCase, citrusFramework);
});
}
@@ -131,19 +118,13 @@ public boolean matches(Field field) {
* @param context
*/
public static void injectCitrusContext(final Object target, final CitrusContext context) {
- ReflectionUtils.doWithFields(target.getClass(), field -> {
- logger.trace(String.format("Injecting Citrus context instance on test class field '%s'", field.getName()));
- ReflectionUtils.setField(field, target, context);
- }, field -> {
- if (field.isAnnotationPresent(CitrusResource.class) && CitrusContext.class.isAssignableFrom(field.getType())) {
- if (!field.isAccessible()) {
- ReflectionUtils.makeAccessible(field);
- }
-
- return true;
+ ReflectionHelper.doWithFields(target.getClass(), field -> {
+ if (!field.isAnnotationPresent(CitrusResource.class) || !CitrusContext.class.isAssignableFrom(field.getType())) {
+ return;
}
- return false;
+ logger.trace(String.format("Injecting Citrus context instance on test class field '%s'", field.getName()));
+ ReflectionHelper.setField(field, target, context);
});
}
@@ -153,24 +134,18 @@ public static void injectCitrusContext(final Object target, final CitrusContext
* @param context
*/
public static void injectTestContext(final Object target, final TestContext context) {
- ReflectionUtils.doWithFields(target.getClass(), field -> {
+ ReflectionHelper.doWithFields(target.getClass(), field -> {
+ if (!field.isAnnotationPresent(CitrusResource.class) || !TestContext.class.isAssignableFrom(field.getType())) {
+ return;
+ }
+
Class> type = field.getType();
if (TestContext.class.isAssignableFrom(type)) {
logger.trace(String.format("Injecting test context instance on test class field '%s'", field.getName()));
- ReflectionUtils.setField(field, target, context);
+ ReflectionHelper.setField(field, target, context);
} else {
throw new CitrusRuntimeException("Not able to provide a Citrus resource injection for type " + type);
}
- }, field -> {
- if (field.isAnnotationPresent(CitrusResource.class) && TestContext.class.isAssignableFrom(field.getType())) {
- if (!field.isAccessible()) {
- ReflectionUtils.makeAccessible(field);
- }
-
- return true;
- }
-
- return false;
});
}
@@ -180,24 +155,18 @@ public static void injectTestContext(final Object target, final TestContext cont
* @param runner
*/
public static void injectTestRunner(final Object target, final TestCaseRunner runner) {
- ReflectionUtils.doWithFields(target.getClass(), field -> {
+ ReflectionHelper.doWithFields(target.getClass(), field -> {
+ if (!field.isAnnotationPresent(CitrusResource.class) || !TestCaseRunner.class.isAssignableFrom(field.getType())) {
+ return;
+ }
+
Class> type = field.getType();
if (TestCaseRunner.class.isAssignableFrom(type)) {
logger.trace(String.format("Injecting test runner instance on test class field '%s'", field.getName()));
- ReflectionUtils.setField(field, target, runner);
+ ReflectionHelper.setField(field, target, runner);
} else {
throw new CitrusRuntimeException("Not able to provide a Citrus resource injection for type " + type);
}
- }, field -> {
- if (field.isAnnotationPresent(CitrusResource.class) && TestCaseRunner.class.isAssignableFrom(field.getType())) {
- if (!field.isAccessible()) {
- ReflectionUtils.makeAccessible(field);
- }
-
- return true;
- }
-
- return false;
});
injectTestActionRunner(target, runner);
@@ -210,24 +179,18 @@ public static void injectTestRunner(final Object target, final TestCaseRunner ru
* @param runner
*/
private static void injectTestActionRunner(final Object target, final TestActionRunner runner) {
- ReflectionUtils.doWithFields(target.getClass(), field -> {
+ ReflectionHelper.doWithFields(target.getClass(), field -> {
+ if (!field.isAnnotationPresent(CitrusResource.class) || !TestActionRunner.class.isAssignableFrom(field.getType())) {
+ return;
+ }
+
Class> type = field.getType();
if (TestActionRunner.class.isAssignableFrom(type)) {
logger.trace(String.format("Injecting test action runner instance on test class field '%s'", field.getName()));
- ReflectionUtils.setField(field, target, runner);
+ ReflectionHelper.setField(field, target, runner);
} else {
throw new CitrusRuntimeException("Not able to provide a Citrus resource injection for type " + type);
}
- }, field -> {
- if (field.isAnnotationPresent(CitrusResource.class) && TestActionRunner.class.isAssignableFrom(field.getType())) {
- if (!field.isAccessible()) {
- ReflectionUtils.makeAccessible(field);
- }
-
- return true;
- }
-
- return false;
});
}
@@ -237,24 +200,18 @@ private static void injectTestActionRunner(final Object target, final TestAction
* @param runner
*/
private static void injectGherkinTestActionRunner(final Object target, final GherkinTestActionRunner runner) {
- ReflectionUtils.doWithFields(target.getClass(), field -> {
+ ReflectionHelper.doWithFields(target.getClass(), field -> {
+ if (!field.isAnnotationPresent(CitrusResource.class) || !GherkinTestActionRunner.class.isAssignableFrom(field.getType())) {
+ return;
+ }
+
Class> type = field.getType();
if (GherkinTestActionRunner.class.isAssignableFrom(type)) {
logger.trace(String.format("Injecting test action runner instance on test class field '%s'", field.getName()));
- ReflectionUtils.setField(field, target, runner);
+ ReflectionHelper.setField(field, target, runner);
} else {
throw new CitrusRuntimeException("Not able to provide a Citrus resource injection for type " + type);
}
- }, field -> {
- if (field.isAnnotationPresent(CitrusResource.class) && GherkinTestActionRunner.class.isAssignableFrom(field.getType())) {
- if (!field.isAccessible()) {
- ReflectionUtils.makeAccessible(field);
- }
-
- return true;
- }
-
- return false;
});
}
@@ -303,7 +260,13 @@ public static void parseConfiguration(Object configuration, CitrusContext citrus
Arrays.stream(configClass.getDeclaredFields())
.filter(f -> f.getAnnotation(BindToRegistry.class) != null)
- .peek(ReflectionUtils::makeAccessible)
+ .peek(f -> {
+ if ((!Modifier.isPublic(f.getModifiers()) ||
+ !Modifier.isPublic(f.getDeclaringClass().getModifiers()) ||
+ Modifier.isFinal(f.getModifiers())) && !f.isAccessible()) {
+ f.setAccessible(true);
+ }
+ })
.forEach(f -> {
try {
String name = ReferenceRegistry.getName(f.getAnnotation(BindToRegistry.class), f.getName());
diff --git a/core/citrus-base/src/main/java/org/citrusframework/condition/FileCondition.java b/core/citrus-base/src/main/java/org/citrusframework/condition/FileCondition.java
index 808fe74fd3..7fe79ddb96 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/condition/FileCondition.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/condition/FileCondition.java
@@ -17,7 +17,6 @@
package org.citrusframework.condition;
import java.io.File;
-import java.io.IOException;
import org.citrusframework.context.TestContext;
import org.citrusframework.util.FileUtils;
@@ -57,7 +56,7 @@ public boolean isSatisfied(TestContext context) {
} else {
try {
return FileUtils.getFileResource(context.replaceDynamicContentInString(filePath), context).getFile().isFile();
- } catch (IOException e) {
+ } catch (Exception e) {
logger.warn(String.format("Failed to access file resource '%s'", e.getMessage()));
return false;
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/container/AbstractIteratingActionContainer.java b/core/citrus-base/src/main/java/org/citrusframework/container/AbstractIteratingActionContainer.java
index 26a2020836..9365b77e4d 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/container/AbstractIteratingActionContainer.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/container/AbstractIteratingActionContainer.java
@@ -16,16 +16,13 @@
package org.citrusframework.container;
-import java.util.Properties;
-
import org.citrusframework.AbstractIteratingContainerBuilder;
-import org.citrusframework.CitrusSettings;
import org.citrusframework.TestActionBuilder;
import org.citrusframework.context.TestContext;
+import org.citrusframework.context.TestContextFactory;
import org.citrusframework.exceptions.ValidationException;
import org.citrusframework.util.BooleanExpressionParser;
import org.citrusframework.validation.matcher.ValidationMatcherUtils;
-import org.springframework.util.PropertyPlaceholderHelper;
/**
* @author Christoph Deppisch
@@ -91,13 +88,9 @@ protected boolean checkCondition(TestContext context) {
// replace dynamic content with each iteration
String conditionString = condition;
- if (conditionString.contains(CitrusSettings.VARIABLE_PREFIX + indexName + CitrusSettings.VARIABLE_SUFFIX)) {
- Properties props = new Properties();
- props.put(indexName, String.valueOf(index));
- conditionString = new PropertyPlaceholderHelper(CitrusSettings.VARIABLE_PREFIX, CitrusSettings.VARIABLE_SUFFIX).replacePlaceholders(conditionString, props);
- }
-
- conditionString = context.replaceDynamicContentInString(conditionString);
+ TestContext temp = TestContextFactory.copyOf(context);
+ temp.setVariable(indexName, String.valueOf(index));
+ conditionString = temp.replaceDynamicContentInString(conditionString);
if (ValidationMatcherUtils.isValidationMatcherExpression(conditionString)) {
try {
@@ -108,7 +101,7 @@ protected boolean checkCondition(TestContext context) {
}
}
- if (conditionString.indexOf(indexName) != -1) {
+ if (conditionString.contains(indexName)) {
conditionString = conditionString.replaceAll(indexName, String.valueOf(index));
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/container/AbstractSuiteActionContainer.java b/core/citrus-base/src/main/java/org/citrusframework/container/AbstractSuiteActionContainer.java
index 0764836bb0..37c3ad7d22 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/container/AbstractSuiteActionContainer.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/container/AbstractSuiteActionContainer.java
@@ -21,10 +21,9 @@
import java.util.List;
import java.util.Map;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
/**
* Abstract suit container actions executed before and after test suite run. Container decides
@@ -60,7 +59,7 @@ public boolean shouldExecute(String suiteName, String[] includedGroups) {
String baseErrorMessage = "Skip before/after suite container because of %s restriction - do not execute container '%s'";
if (StringUtils.hasText(suiteName) &&
- !CollectionUtils.isEmpty(suiteNames) && ! suiteNames.contains(suiteName)) {
+ suiteNames != null && !suiteNames.isEmpty() && !suiteNames.contains(suiteName)) {
logger.warn(String.format(baseErrorMessage, "suite name", getName()));
return false;
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/container/AbstractTestBoundaryActionContainer.java b/core/citrus-base/src/main/java/org/citrusframework/container/AbstractTestBoundaryActionContainer.java
index 027fc3b3d5..43e6556c66 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/container/AbstractTestBoundaryActionContainer.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/container/AbstractTestBoundaryActionContainer.java
@@ -20,11 +20,11 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.regex.Pattern;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.PatternMatchUtils;
-import org.springframework.util.StringUtils;
/**
* Abstract test action container describes methods to enable/disable container execution based on given test name, package
@@ -64,14 +64,14 @@ public boolean shouldExecute(String testName, String packageName, String[] inclu
String baseErrorMessage = "Skip before test container because of %s restrictions - do not execute container '%s'";
if (StringUtils.hasText(packageNamePattern)) {
- if (!PatternMatchUtils.simpleMatch(packageNamePattern, packageName)) {
+ if (!Pattern.compile(packageNamePattern).matcher(packageName).matches()) {
logger.warn(String.format(baseErrorMessage, "test package", getName()));
return false;
}
}
if (StringUtils.hasText(namePattern)) {
- if (!PatternMatchUtils.simpleMatch(namePattern, testName)) {
+ if (!Pattern.compile(sanitizePatten(namePattern)).matcher(testName).matches()) {
logger.warn(String.format(baseErrorMessage, "test name", getName()));
return false;
}
@@ -101,6 +101,22 @@ public boolean shouldExecute(String testName, String packageName, String[] inclu
return true;
}
+ /**
+ * Translate leading and trailing asterisk wildcard to proper regex pattern.
+ * @param pattern
+ * @return
+ */
+ private String sanitizePatten(String pattern) {
+ if (pattern.startsWith("*")) {
+ return "." + pattern;
+ }
+
+ if (pattern.endsWith("*") && pattern.charAt(pattern.length()-2) != '.') {
+ return pattern.substring(0, pattern.length() -1) + ".*";
+ }
+
+ return pattern;
+ }
/**
diff --git a/core/citrus-base/src/main/java/org/citrusframework/container/SequenceAfterTest.java b/core/citrus-base/src/main/java/org/citrusframework/container/SequenceAfterTest.java
index 95da484509..b897d00e04 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/container/SequenceAfterTest.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/container/SequenceAfterTest.java
@@ -22,7 +22,6 @@
import org.citrusframework.context.TestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
/**
* Sequence of test actions executed after a test case. Container execution can be restricted according to test name ,
@@ -37,7 +36,7 @@ public class SequenceAfterTest extends AbstractTestBoundaryActionContainer imple
@Override
public void doExecute(TestContext context) {
- if (CollectionUtils.isEmpty(actions)) {
+ if (actions == null || actions.isEmpty()) {
return;
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/container/SequenceBeforeTest.java b/core/citrus-base/src/main/java/org/citrusframework/container/SequenceBeforeTest.java
index 8373deaa79..8a11e5f9e3 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/container/SequenceBeforeTest.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/container/SequenceBeforeTest.java
@@ -22,7 +22,6 @@
import org.citrusframework.context.TestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
/**
* Sequence of test actions executed before a test case. Container execution can be restricted according to test name ,
@@ -37,7 +36,7 @@ public class SequenceBeforeTest extends AbstractTestBoundaryActionContainer impl
@Override
public void doExecute(TestContext context) {
- if (CollectionUtils.isEmpty(actions)) {
+ if (actions == null || actions.isEmpty()) {
return;
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/container/Template.java b/core/citrus-base/src/main/java/org/citrusframework/container/Template.java
index 7853c365b4..1a953f8b7e 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/container/Template.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/container/Template.java
@@ -31,13 +31,13 @@
import org.citrusframework.actions.AbstractTestAction;
import org.citrusframework.actions.NoopTestAction;
import org.citrusframework.context.TestContext;
+import org.citrusframework.context.TestContextFactory;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.functions.FunctionUtils;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
import org.citrusframework.spi.SimpleReferenceResolver;
import org.citrusframework.util.FileUtils;
-import org.citrusframework.variable.GlobalVariables;
import org.citrusframework.variable.VariableUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -102,25 +102,7 @@ public void doExecute(TestContext context) {
if (globalContext) {
innerContext = context;
} else {
- innerContext = new TestContext();
- innerContext.setFunctionRegistry(context.getFunctionRegistry());
-
- innerContext.setGlobalVariables(new GlobalVariables.Builder()
- .variables(context.getGlobalVariables())
- .build());
- innerContext.getVariables().putAll(context.getVariables());
-
- innerContext.setMessageStore(context.getMessageStore());
- innerContext.setMessageValidatorRegistry(context.getMessageValidatorRegistry());
- innerContext.setValidationMatcherRegistry(context.getValidationMatcherRegistry());
- innerContext.setTestListeners(context.getTestListeners());
- innerContext.setMessageListeners(context.getMessageListeners());
- innerContext.setMessageProcessors(context.getMessageProcessors());
- innerContext.setEndpointFactory(context.getEndpointFactory());
- innerContext.setNamespaceContextBuilder(context.getNamespaceContextBuilder());
- innerContext.setReferenceResolver(context.getReferenceResolver());
- innerContext.setTypeConverter(context.getTypeConverter());
- innerContext.setLogModifier(context.getLogModifier());
+ innerContext = TestContextFactory.copyOf(context);
}
for (Entry entry : parameter.entrySet()) {
diff --git a/core/citrus-base/src/main/java/org/citrusframework/container/Timer.java b/core/citrus-base/src/main/java/org/citrusframework/container/Timer.java
index ed5f4b91e4..fcb3594630 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/container/Timer.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/container/Timer.java
@@ -17,6 +17,8 @@
package org.citrusframework.container;
import java.util.TimerTask;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import org.citrusframework.AbstractTestContainerBuilder;
@@ -25,8 +27,7 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.task.SimpleAsyncTaskExecutor;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Martin Maher
@@ -63,12 +64,8 @@ public Timer(Builder builder) {
@Override
public void doExecute(final TestContext context) {
if (fork) {
- SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
- taskExecutor.execute(new Runnable() {
- public void run() {
- configureAndRunTimer(context);
- }
- });
+ ExecutorService taskExecutor = Executors.newSingleThreadExecutor();
+ taskExecutor.execute(() -> configureAndRunTimer(context));
} else {
configureAndRunTimer(context);
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/container/Wait.java b/core/citrus-base/src/main/java/org/citrusframework/container/Wait.java
index 892f4907f3..22ece26355 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/container/Wait.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/container/Wait.java
@@ -151,7 +151,7 @@ public String getInterval() {
*/
public static class Builder extends AbstractTestActionBuilder> implements TestActionBuilder.DelegatingTestActionBuilder {
- protected Condition condition;
+ protected C condition;
protected String time = "5000";
protected String interval = "1000";
@@ -172,7 +172,7 @@ public static Builder waitFor() {
*/
public Builder condition(C condition) {
this.condition = condition;
- this.delegate = this::build;
+ this.delegate = this;
return this;
}
@@ -193,7 +193,7 @@ public > T condition(T conditionBuilder) {
* @return A WaitMessageConditionBuilder for further configuration
*/
public WaitMessageConditionBuilder message() {
- this.condition = new MessageCondition();
+ this.condition = (C) new MessageCondition();
WaitMessageConditionBuilder builder = new WaitMessageConditionBuilder((Builder) this);
this.delegate = builder;
return builder;
@@ -204,7 +204,7 @@ public WaitMessageConditionBuilder message() {
* @return A WaitActionConditionBuilder for further configuration
*/
public WaitActionConditionBuilder execution() {
- this.condition = new ActionCondition();
+ this.condition = (C) new ActionCondition();
WaitActionConditionBuilder builder = new WaitActionConditionBuilder((Builder) this);
this.delegate = builder;
return builder;
@@ -215,7 +215,7 @@ public WaitActionConditionBuilder execution() {
* @return A WaitHttpConditionBuilder for further configuration
*/
public WaitHttpConditionBuilder http() {
- this.condition = new HttpCondition();
+ this.condition = (C) new HttpCondition();
WaitHttpConditionBuilder builder = new WaitHttpConditionBuilder((Builder) this);
this.delegate = builder;
return builder;
@@ -226,7 +226,7 @@ public WaitHttpConditionBuilder http() {
* @return A WaitFileConditionBuilder for further configuration
*/
public WaitFileConditionBuilder file() {
- this.condition = new FileCondition();
+ this.condition = (C) new FileCondition();
WaitFileConditionBuilder builder = new WaitFileConditionBuilder((Builder) this);
this.delegate = builder;
return builder;
diff --git a/core/citrus-base/src/main/java/org/citrusframework/context/TestContextFactory.java b/core/citrus-base/src/main/java/org/citrusframework/context/TestContextFactory.java
index 8062500020..3f134b5c0e 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/context/TestContextFactory.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/context/TestContextFactory.java
@@ -108,6 +108,29 @@ public static TestContextFactory newInstance() {
return factory;
}
+ public static TestContext copyOf(TestContext context) {
+ TestContext result = new TestContext();
+ result.setFunctionRegistry(context.getFunctionRegistry());
+
+ result.setGlobalVariables(new GlobalVariables.Builder()
+ .variables(context.getGlobalVariables())
+ .build());
+ result.getVariables().putAll(context.getVariables());
+
+ result.setMessageStore(context.getMessageStore());
+ result.setMessageValidatorRegistry(context.getMessageValidatorRegistry());
+ result.setValidationMatcherRegistry(context.getValidationMatcherRegistry());
+ result.setTestListeners(context.getTestListeners());
+ result.setMessageListeners(context.getMessageListeners());
+ result.setMessageProcessors(context.getMessageProcessors());
+ result.setEndpointFactory(context.getEndpointFactory());
+ result.setNamespaceContextBuilder(context.getNamespaceContextBuilder());
+ result.setReferenceResolver(context.getReferenceResolver());
+ result.setTypeConverter(context.getTypeConverter());
+ result.setLogModifier(context.getLogModifier());
+ return result;
+ }
+
/**
* Factory method creates new test context instance and adds all default components in this factory.
* @return
diff --git a/core/citrus-base/src/main/java/org/citrusframework/endpoint/AbstractEndpointComponent.java b/core/citrus-base/src/main/java/org/citrusframework/endpoint/AbstractEndpointComponent.java
index ad57eded17..8fcff5d562 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/endpoint/AbstractEndpointComponent.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/endpoint/AbstractEndpointComponent.java
@@ -29,9 +29,9 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.util.ReflectionHelper;
import org.citrusframework.util.TypeConversionUtils;
-import org.springframework.util.ReflectionUtils;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* Default endpoint component reads component name from endpoint uri and parses parameters from uri using
@@ -124,13 +124,13 @@ public Map getParameters(String endpointUri) {
*/
protected void enrichEndpointConfiguration(EndpointConfiguration endpointConfiguration, Map parameters, TestContext context) {
for (Map.Entry parameterEntry : parameters.entrySet()) {
- Field field = ReflectionUtils.findField(endpointConfiguration.getClass(), parameterEntry.getKey());
+ Field field = ReflectionHelper.findField(endpointConfiguration.getClass(), parameterEntry.getKey());
if (field == null) {
throw new CitrusRuntimeException(String.format("Unable to find parameter field on endpoint configuration '%s'", parameterEntry.getKey()));
}
- Method setter = ReflectionUtils.findMethod(endpointConfiguration.getClass(), "set" + parameterEntry.getKey().substring(0, 1).toUpperCase() + parameterEntry.getKey().substring(1), field.getType());
+ Method setter = ReflectionHelper.findMethod(endpointConfiguration.getClass(), "set" + parameterEntry.getKey().substring(0, 1).toUpperCase() + parameterEntry.getKey().substring(1), field.getType());
if (setter == null) {
throw new CitrusRuntimeException(String.format("Unable to find parameter setter on endpoint configuration '%s'",
@@ -138,9 +138,9 @@ protected void enrichEndpointConfiguration(EndpointConfiguration endpointConfigu
}
if (parameterEntry.getValue() != null) {
- ReflectionUtils.invokeMethod(setter, endpointConfiguration, TypeConversionUtils.convertStringToType(parameterEntry.getValue(), field.getType(), context));
+ ReflectionHelper.invokeMethod(setter, endpointConfiguration, TypeConversionUtils.convertStringToType(parameterEntry.getValue(), field.getType(), context));
} else {
- ReflectionUtils.invokeMethod(setter, endpointConfiguration, field.getType().cast(null));
+ ReflectionHelper.invokeMethod(setter, endpointConfiguration, field.getType().cast(null));
}
}
}
@@ -159,7 +159,7 @@ protected Map getEndpointConfigurationParameters(Map params = new HashMap<>();
for (Map.Entry parameterEntry : parameters.entrySet()) {
- Field field = ReflectionUtils.findField(endpointConfigurationType, parameterEntry.getKey());
+ Field field = ReflectionHelper.findField(endpointConfigurationType, parameterEntry.getKey());
if (field != null) {
params.put(parameterEntry.getKey(), parameterEntry.getValue());
@@ -183,7 +183,7 @@ protected String getParameterString(Map parameters,
StringBuilder paramString = new StringBuilder();
for (Map.Entry parameterEntry : parameters.entrySet()) {
- Field field = ReflectionUtils.findField(endpointConfigurationType, parameterEntry.getKey());
+ Field field = ReflectionHelper.findField(endpointConfigurationType, parameterEntry.getKey());
if (field == null) {
if (paramString.length() == 0) {
diff --git a/core/citrus-base/src/main/java/org/citrusframework/endpoint/adapter/StaticResponseEndpointAdapter.java b/core/citrus-base/src/main/java/org/citrusframework/endpoint/adapter/StaticResponseEndpointAdapter.java
index e99ab947c4..ae57efc5f6 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/endpoint/adapter/StaticResponseEndpointAdapter.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/endpoint/adapter/StaticResponseEndpointAdapter.java
@@ -27,8 +27,7 @@
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* Endpoint adapter always returns a static response message.
@@ -58,7 +57,7 @@ public Message handleMessageInternal(Message request) {
context.getMessageStore().storeMessage("request", request);
if (StringUtils.hasText(messagePayloadResource)) {
try {
- payload = context.replaceDynamicContentInString(FileUtils.readToString(new PathMatchingResourcePatternResolver().getResource(messagePayloadResource),
+ payload = context.replaceDynamicContentInString(FileUtils.readToString(FileUtils.getFileResource(messagePayloadResource),
Charset.forName(context.replaceDynamicContentInString(messagePayloadResourceCharset))));
} catch (IOException e) {
throw new CitrusRuntimeException("Failed to read message payload file resource", e);
diff --git a/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/DirectConsumer.java b/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/DirectConsumer.java
index 733818203c..129ac6798b 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/DirectConsumer.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/DirectConsumer.java
@@ -10,7 +10,7 @@
import org.citrusframework.messaging.AbstractSelectiveMessageConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/DirectProducer.java b/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/DirectProducer.java
index 16327c67d0..5a6a5210e5 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/DirectProducer.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/DirectProducer.java
@@ -7,7 +7,7 @@
import org.citrusframework.messaging.Producer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/DirectSyncConsumer.java b/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/DirectSyncConsumer.java
index 2da2103f69..5d41b733b7 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/DirectSyncConsumer.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/DirectSyncConsumer.java
@@ -6,10 +6,10 @@
import org.citrusframework.message.correlation.CorrelationManager;
import org.citrusframework.message.correlation.PollingCorrelationManager;
import org.citrusframework.messaging.ReplyProducer;
+import org.citrusframework.util.ObjectHelper;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -46,12 +46,12 @@ public Message receive(String selector, TestContext context, long timeout) {
@Override
public void send(Message message, TestContext context) {
- Assert.notNull(message, "Can not send empty message");
+ ObjectHelper.assertNotNull(message, "Can not send empty message");
String correlationKeyName = endpointConfiguration.getCorrelator().getCorrelationKeyName(getName());
String correlationKey = correlationManager.getCorrelationKey(correlationKeyName, context);
MessageQueue replyQueue = correlationManager.find(correlationKey, endpointConfiguration.getTimeout());
- Assert.notNull(replyQueue, "Failed to find reply channel for message correlation key: " + correlationKey);
+ ObjectHelper.assertNotNull(replyQueue, "Failed to find reply channel for message correlation key: " + correlationKey);
if (logger.isDebugEnabled()) {
logger.debug("Sending message to reply channel: '" + replyQueue + "'");
diff --git a/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/annotation/DirectEndpointConfigParser.java b/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/annotation/DirectEndpointConfigParser.java
index c24c24e4dc..1db4d8dfe6 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/annotation/DirectEndpointConfigParser.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/annotation/DirectEndpointConfigParser.java
@@ -6,7 +6,7 @@
import org.citrusframework.endpoint.direct.DirectEndpointBuilder;
import org.citrusframework.message.MessageQueue;
import org.citrusframework.spi.ReferenceResolver;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/annotation/DirectSyncEndpointConfigParser.java b/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/annotation/DirectSyncEndpointConfigParser.java
index cf74da9e4f..5a7b1a7347 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/annotation/DirectSyncEndpointConfigParser.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/endpoint/direct/annotation/DirectSyncEndpointConfigParser.java
@@ -7,7 +7,7 @@
import org.citrusframework.message.MessageCorrelator;
import org.citrusframework.message.MessageQueue;
import org.citrusframework.spi.ReferenceResolver;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/core/citrus-base/src/main/java/org/citrusframework/endpoint/resolver/DynamicEndpointUriResolver.java b/core/citrus-base/src/main/java/org/citrusframework/endpoint/resolver/DynamicEndpointUriResolver.java
index 0775c3fde0..2baefdf300 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/endpoint/resolver/DynamicEndpointUriResolver.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/endpoint/resolver/DynamicEndpointUriResolver.java
@@ -21,7 +21,7 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* Endpoint uri resolver working on message headers. Resolver is searching for a specific header entry which holds the actual
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/AbsoluteFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/AbsoluteFunction.java
index da155eacc2..3b3dc15fd9 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/AbsoluteFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/AbsoluteFunction.java
@@ -16,16 +16,15 @@
package org.citrusframework.functions.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.util.List;
/**
* Function returning the absolute value of a decimal number.
- *
+ *
* @author Christoph Deppisch
*/
public class AbsoluteFunction implements Function {
@@ -35,12 +34,12 @@ public class AbsoluteFunction implements Function {
* @throws InvalidFunctionUsageException
*/
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
String param = parameterList.get(0);
-
+
if (param.contains(".")) {
return String.valueOf(Math.abs(Double.valueOf(param)));
} else {
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/AvgFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/AvgFunction.java
index 7983fd3c81..9b2f193088 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/AvgFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/AvgFunction.java
@@ -16,16 +16,15 @@
package org.citrusframework.functions.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.util.List;
/**
* Function returning the average of a set of numeric values.
- *
+ *
* @author Christoph Deppisch
*/
public class AvgFunction implements Function {
@@ -35,7 +34,7 @@ public class AvgFunction implements Function {
* @throws InvalidFunctionUsageException
*/
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/CeilingFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/CeilingFunction.java
index 86f2b64f8e..6435819ddf 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/CeilingFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/CeilingFunction.java
@@ -16,17 +16,16 @@
package org.citrusframework.functions.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.util.List;
/**
- * Returns the smallest (closest to negative infinity) double value
+ * Returns the smallest (closest to negative infinity) double value
* according to the numeric argument.
- *
+ *
* @author Christoph Deppisch
*/
public class CeilingFunction implements Function {
@@ -36,7 +35,7 @@ public class CeilingFunction implements Function {
* @throws InvalidFunctionUsageException
*/
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/ChangeDateFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/ChangeDateFunction.java
index f6756776ff..4101d74322 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/ChangeDateFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/ChangeDateFunction.java
@@ -16,17 +16,16 @@
package org.citrusframework.functions.core;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.List;
/**
* Function changes given date value by adding/subtracting day/month/year/hour/minute
@@ -45,7 +44,7 @@ public class ChangeDateFunction extends AbstractDateFunction {
* @throws CitrusRuntimeException
*/
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/ConcatFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/ConcatFunction.java
index 85095f1901..fc27a7de3f 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/ConcatFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/ConcatFunction.java
@@ -16,17 +16,16 @@
package org.citrusframework.functions.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.util.List;
/**
* Function concatenating multiple tokens to a single string. Tokens can be either
* static string values or dynamic variables or functions.
- *
+ *
* @author Christoph Deppisch
*/
public class ConcatFunction implements Function {
@@ -36,7 +35,7 @@ public class ConcatFunction implements Function {
* @throws InvalidFunctionUsageException
*/
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/CurrentDateFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/CurrentDateFunction.java
index 399c265a66..284cadfb33 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/CurrentDateFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/CurrentDateFunction.java
@@ -16,20 +16,19 @@
package org.citrusframework.functions.core;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
-
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.List;
/**
* Function returning the actual date as formatted string value. User specifies format string
- * as argument. Function also supports additional date offset in order to manipulate result date value.
- *
+ * as argument. Function also supports additional date offset in order to manipulate result date value.
+ *
* @author Christoph Deppisch
*/
public class CurrentDateFunction extends AbstractDateFunction {
@@ -43,11 +42,10 @@ public class CurrentDateFunction extends AbstractDateFunction {
*/
public String execute(List parameterList, TestContext context) {
Calendar calendar = Calendar.getInstance();
-
+
SimpleDateFormat dateFormat;
- String result = "";
-
- if (!CollectionUtils.isEmpty(parameterList)) {
+ String result;
+ if (parameterList != null && !parameterList.isEmpty()) {
dateFormat = new SimpleDateFormat(parameterList.get(0));
} else {
dateFormat = getDefaultDateFormat();
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/DecodeBase64Function.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/DecodeBase64Function.java
index ac827f4cab..d25d058415 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/DecodeBase64Function.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/DecodeBase64Function.java
@@ -16,34 +16,33 @@
package org.citrusframework.functions.core;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+import org.apache.commons.codec.binary.Base64;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.apache.commons.codec.binary.Base64;
-import org.springframework.util.CollectionUtils;
-
-import java.io.UnsupportedEncodingException;
-import java.util.List;
/**
* Decodes base64 binary data to a character sequence.
- *
+ *
* @author Christoph Deppisch
*/
public class DecodeBase64Function implements Function {
@Override
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList) || parameterList.size() < 1) {
+ if (parameterList == null || parameterList.size() < 1) {
throw new InvalidFunctionUsageException("Invalid function parameter usage! Missing parameters!");
}
-
+
String charset = "UTF-8";
if (parameterList.size() > 1) {
charset = parameterList.get(1);
}
-
+
try {
return new String(Base64.decodeBase64(parameterList.get(0)), charset);
} catch (UnsupportedEncodingException e) {
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/EncodeBase64Function.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/EncodeBase64Function.java
index 13879a0245..f4968ff902 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/EncodeBase64Function.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/EncodeBase64Function.java
@@ -16,34 +16,33 @@
package org.citrusframework.functions.core;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+import org.apache.commons.codec.binary.Base64;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.apache.commons.codec.binary.Base64;
-import org.springframework.util.CollectionUtils;
-
-import java.io.UnsupportedEncodingException;
-import java.util.List;
/**
* Encodes a character sequence to base64 binary using given charset.
- *
+ *
* @author Christoph Deppisch
*/
public class EncodeBase64Function implements Function {
@Override
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList) || parameterList.size() < 1) {
+ if (parameterList == null || parameterList.size() < 1) {
throw new InvalidFunctionUsageException("Invalid function parameter usage! Missing parameters!");
}
-
+
String charset = "UTF-8";
if (parameterList.size() > 1) {
charset = parameterList.get(1);
}
-
+
try {
return Base64.encodeBase64String(parameterList.get(0).getBytes(charset));
} catch (UnsupportedEncodingException e) {
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/FloorFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/FloorFunction.java
index 66738711d2..3f7c6b4e87 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/FloorFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/FloorFunction.java
@@ -16,17 +16,16 @@
package org.citrusframework.functions.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.util.List;
/**
* Returns the largest (closest to positive infinity) double value according to numeric argument
* value.
- *
+ *
* @author Christoph Deppisch
*/
public class FloorFunction implements Function {
@@ -36,7 +35,7 @@ public class FloorFunction implements Function {
* @throws InvalidFunctionUsageException
*/
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/LoadMessageFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/LoadMessageFunction.java
index fc7c155163..ed066c8243 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/LoadMessageFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/LoadMessageFunction.java
@@ -23,8 +23,7 @@
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
import org.citrusframework.message.Message;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* Function loads message from test context message store. Incoming and sent messages get automatically
@@ -37,7 +36,7 @@ public class LoadMessageFunction implements Function {
@Override
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/LowerCaseFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/LowerCaseFunction.java
index 62d5e1b732..877a6c891d 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/LowerCaseFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/LowerCaseFunction.java
@@ -16,16 +16,15 @@
package org.citrusframework.functions.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.util.List;
/**
* Function returns given string argument in lower case.
- *
+ *
* @author Christoph Deppisch
*/
public class LowerCaseFunction implements Function {
@@ -35,7 +34,7 @@ public class LowerCaseFunction implements Function {
* @throws InvalidFunctionUsageException
*/
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/MaxFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/MaxFunction.java
index 402c2b7dbe..2d37eb68a6 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/MaxFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/MaxFunction.java
@@ -16,16 +16,15 @@
package org.citrusframework.functions.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.util.List;
/**
* Function returns the maximum numeric value in a set of numeric arguments.
- *
+ *
* @author Christoph Deppisch
*/
public class MaxFunction implements Function {
@@ -35,7 +34,7 @@ public class MaxFunction implements Function {
* @throws InvalidFunctionUsageException
*/
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/MinFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/MinFunction.java
index 6885c971e7..aa2fc633a7 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/MinFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/MinFunction.java
@@ -16,16 +16,15 @@
package org.citrusframework.functions.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.util.List;
/**
* Returns the minimum value in a set of numeric arguments.
- *
+ *
* @author Christoph Deppisch
*/
public class MinFunction implements Function {
@@ -35,7 +34,7 @@ public class MinFunction implements Function {
* @throws InvalidFunctionUsageException
*/
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/RandomNumberFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/RandomNumberFunction.java
index 3edfc97873..bfc0be5888 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/RandomNumberFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/RandomNumberFunction.java
@@ -22,7 +22,6 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
/**
* Function returning a random numeric value. Argument specifies the number of digits and
@@ -42,7 +41,7 @@ public String execute(List parameterList, TestContext context) {
int numberLength;
boolean paddingOn = true;
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/RandomStringFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/RandomStringFunction.java
index f2bc229c15..7dd715d20c 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/RandomStringFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/RandomStringFunction.java
@@ -16,18 +16,17 @@
package org.citrusframework.functions.core;
+import java.util.List;
+import java.util.Random;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.util.List;
-import java.util.Random;
/**
* Function generating a random string containing alphabetic characters. Arguments specify
* upper and lower case mode.
- *
+ *
* @author Christoph Deppisch
*/
public class RandomStringFunction implements Function {
@@ -46,7 +45,7 @@ public class RandomStringFunction implements Function {
'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z' };
-
+
private static final char[] NUMBERS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', };
/** Mode upper case */
@@ -67,7 +66,7 @@ public String execute(List parameterList, TestContext context) {
String notationMethod = MIXED;
boolean includeNumbers = false;
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
@@ -87,7 +86,7 @@ public String execute(List parameterList, TestContext context) {
if (parameterList.size() > 2) {
includeNumbers = Boolean.valueOf(parameterList.get(2));
}
-
+
if (notationMethod.equals(UPPERCASE)) {
return getRandomString(numberOfLetters, ALPHABET_UPPER, includeNumbers);
} else if (notationMethod.equals(LOWERCASE)) {
@@ -106,26 +105,26 @@ public String execute(List parameterList, TestContext context) {
*/
public static String getRandomString(int numberOfLetters, char[] alphabet, boolean includeNumbers) {
StringBuilder builder = new StringBuilder();
-
+
int upperRange = alphabet.length - 1;
-
+
// make sure first character is not a number
builder.append(alphabet[generator.nextInt(upperRange)]);
-
+
if (includeNumbers) {
upperRange += NUMBERS.length;
}
-
+
for (int i = 1; i < numberOfLetters; i++) {
int letterIndex = generator.nextInt(upperRange);
-
+
if (letterIndex > alphabet.length - 1) {
builder.append(NUMBERS[letterIndex - alphabet.length]);
} else {
builder.append(alphabet[letterIndex]);
}
}
-
+
return builder.toString();
}
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/ReadFileResourceFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/ReadFileResourceFunction.java
index 4862effa00..73cac78609 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/ReadFileResourceFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/ReadFileResourceFunction.java
@@ -16,18 +16,15 @@
package org.citrusframework.functions.core;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.commons.codec.binary.Base64;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
import org.citrusframework.util.FileUtils;
-import org.apache.commons.codec.binary.Base64;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.FileCopyUtils;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.List;
/**
* Function reads file from given file path and returns the complete file content as function result.
@@ -50,7 +47,7 @@ public class ReadFileResourceFunction implements Function {
@Override
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Missing file path function parameter");
}
@@ -61,7 +58,7 @@ public String execute(List parameterList, TestContext context) {
if (parameterList.size() > 2 && Boolean.parseBoolean(parameterList.get(2))) {
return Base64.encodeBase64String(readFileContent(parameterList.get(0), context, true).getBytes(FileUtils.getCharset(parameterList.get(0))));
} else {
- return Base64.encodeBase64String(FileCopyUtils.copyToByteArray(FileUtils.getFileResource(parameterList.get(0), context).getInputStream()));
+ return Base64.encodeBase64String(FileUtils.copyToByteArray(FileUtils.getFileResource(parameterList.get(0), context)));
}
} else {
return readFileContent(parameterList.get(0), context, true);
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/RoundFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/RoundFunction.java
index f0c136025c..3b82450d05 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/RoundFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/RoundFunction.java
@@ -16,16 +16,15 @@
package org.citrusframework.functions.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.util.List;
/**
* Function returns the closest integer value to a decimal argument.
- *
+ *
* @author Christoph Deppisch
*/
public class RoundFunction implements Function {
@@ -35,7 +34,7 @@ public class RoundFunction implements Function {
* @throws InvalidFunctionUsageException
*/
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/StringLengthFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/StringLengthFunction.java
index 8e378f4dfc..5e9e1a518f 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/StringLengthFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/StringLengthFunction.java
@@ -16,16 +16,15 @@
package org.citrusframework.functions.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.util.List;
/**
* Returning the length of a given string argument.
- *
+ *
* @author Christoph Deppisch
*/
public class StringLengthFunction implements Function {
@@ -35,7 +34,7 @@ public class StringLengthFunction implements Function {
* @throws InvalidFunctionUsageException
*/
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/SubstringFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/SubstringFunction.java
index fa1f333de2..52240ae136 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/SubstringFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/SubstringFunction.java
@@ -16,20 +16,20 @@
package org.citrusframework.functions.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.StringUtils;
-
-import java.util.List;
+import org.citrusframework.util.StringUtils;
/**
* Function implements simple substring functionality.
- *
+ *
* Function requires at least a target string and a beginIndex as function parameters. A
- * optional endIndex may be given as function parameter, too. The parameter usage looks
+ * optional endIndex may be given as function parameter, too. The parameter usage looks
* like this: substring(targetString, beginIndex, [endIndex]).
- *
+ *
* @author Christoph Deppisch
*/
public class SubstringFunction implements Function {
@@ -51,7 +51,7 @@ public String execute(List parameterList, TestContext context) {
if (!StringUtils.hasText(beginIndex)) {
throw new InvalidFunctionUsageException("Invalid beginIndex - please check function parameters");
}
-
+
if (parameterList.size() > 2) {
endIndex = parameterList.get(2);
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/SumFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/SumFunction.java
index 590189a5df..6dc1a1adf3 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/SumFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/SumFunction.java
@@ -16,16 +16,15 @@
package org.citrusframework.functions.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.util.List;
/**
* Function to sum up all numeric arguments.
- *
+ *
* @author Christoph Deppisch
*/
public class SumFunction implements Function {
@@ -35,7 +34,7 @@ public class SumFunction implements Function {
* @throws InvalidFunctionUsageException
*/
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/SystemPropertyFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/SystemPropertyFunction.java
index b559fad93b..9c8c35b240 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/SystemPropertyFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/SystemPropertyFunction.java
@@ -16,25 +16,24 @@
package org.citrusframework.functions.core;
+import java.util.List;
+import java.util.Optional;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.util.List;
-import java.util.Optional;
/**
* Function returns given string argument in lower case.
- *
+ *
* @author Christoph Deppisch
*/
public class SystemPropertyFunction implements Function {
@Override
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Invalid function parameters - must set system property name");
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/UpperCaseFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/UpperCaseFunction.java
index 64317f95a3..40f057fff7 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/UpperCaseFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/UpperCaseFunction.java
@@ -16,16 +16,15 @@
package org.citrusframework.functions.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.util.List;
/**
* Returns given string argument in upper case letters.
- *
+ *
* @author Christoph Deppisch
*/
public class UpperCaseFunction implements Function {
@@ -35,7 +34,7 @@ public class UpperCaseFunction implements Function {
* @throws InvalidFunctionUsageException
*/
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/UrlDecodeFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/UrlDecodeFunction.java
index 6a13f69221..4b19324340 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/UrlDecodeFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/UrlDecodeFunction.java
@@ -16,34 +16,33 @@
package org.citrusframework.functions.core;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.util.List;
/**
* Decodes URL encoded string to a character sequence.
- *
+ *
* @author Christoph Deppisch
*/
public class UrlDecodeFunction implements Function {
@Override
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList) || parameterList.size() < 1) {
+ if (parameterList == null || parameterList.size() < 1) {
throw new InvalidFunctionUsageException("Invalid function parameter usage! Missing parameters!");
}
-
+
String charset = "UTF-8";
if (parameterList.size() > 1) {
charset = parameterList.get(1);
}
-
+
try {
return URLDecoder.decode(parameterList.get(0), charset);
} catch (UnsupportedEncodingException e) {
diff --git a/core/citrus-base/src/main/java/org/citrusframework/functions/core/UrlEncodeFunction.java b/core/citrus-base/src/main/java/org/citrusframework/functions/core/UrlEncodeFunction.java
index 2c78a5b1d5..5c97fa6d80 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/functions/core/UrlEncodeFunction.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/functions/core/UrlEncodeFunction.java
@@ -16,34 +16,33 @@
package org.citrusframework.functions.core;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.List;
/**
* Encodes a character sequence to URL encoded string using given charset.
- *
+ *
* @author Christoph Deppisch
*/
public class UrlEncodeFunction implements Function {
@Override
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList) || parameterList.size() < 1) {
+ if (parameterList == null || parameterList.size() < 1) {
throw new InvalidFunctionUsageException("Invalid function parameter usage! Missing parameters!");
}
-
+
String charset = "UTF-8";
if (parameterList.size() > 1) {
charset = parameterList.get(1);
}
-
+
try {
return URLEncoder.encode(parameterList.get(0), charset);
} catch (UnsupportedEncodingException e) {
diff --git a/core/citrus-base/src/main/java/org/citrusframework/main/scan/ClassPathTestScanner.java b/core/citrus-base/src/main/java/org/citrusframework/main/scan/ClassPathTestScanner.java
index fe8694eba2..02b10d0340 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/main/scan/ClassPathTestScanner.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/main/scan/ClassPathTestScanner.java
@@ -18,24 +18,20 @@
import java.io.IOException;
import java.lang.annotation.Annotation;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import org.citrusframework.TestClass;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.ClasspathResourceResolver;
+import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.ReflectionHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.annotation.AnnotationUtils;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.core.io.support.ResourcePatternResolver;
-import org.springframework.core.type.ClassMetadata;
-import org.springframework.core.type.classreading.MetadataReader;
-import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
-import org.springframework.util.ClassUtils;
-import org.springframework.util.ReflectionUtils;
/**
* @author Christoph Deppisch
@@ -61,22 +57,14 @@ public ClassPathTestScanner(Class extends Annotation> annotationType, String..
@Override
public List findTestsInPackage(String packageName) {
try {
- PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
-
- String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
- ClassUtils.convertClassNameToResourcePath(packageName) + "/**/*.class";
-
- Resource[] resources = resolver.getResources(packageSearchPath);
+ ClasspathResourceResolver resolver = new ClasspathResourceResolver();
+ Set resources = resolver.getClasses(packageName);
List classes = new ArrayList<>();
- for (Resource resource : resources) {
- if (!resource.isReadable()) {
- continue;
- }
-
- MetadataReader metadataReader = new SimpleMetadataReaderFactory().getMetadataReader(resource);
- if (isIncluded(metadataReader.getClassMetadata())) {
- classes.add(metadataReader.getClassMetadata().getClassName());
+ for (Path resource : resources) {
+ String className = String.format("%s.%s", packageName, FileUtils.getBaseName(String.valueOf(resource.getFileName())));
+ if (isIncluded(className)) {
+ classes.add(className);
}
}
@@ -89,22 +77,26 @@ public List findTestsInPackage(String packageName) {
}
}
- protected boolean isIncluded(ClassMetadata metadata) {
- if (!isIncluded(metadata.getClassName())) {
+ protected boolean isIncluded(String className) {
+ if (!super.isIncluded(className)) {
return false;
}
try {
- Class> clazz = Class.forName(metadata.getClassName());
+ Class> clazz = Class.forName(className);
if (clazz.isAnnotationPresent(annotationType)) {
return true;
}
AtomicBoolean hasTestMethod = new AtomicBoolean(false);
- ReflectionUtils.doWithMethods(clazz, method -> hasTestMethod.set(true), method -> AnnotationUtils.findAnnotation(method, annotationType) != null);
+ ReflectionHelper.doWithMethods(clazz, method -> {
+ if (method.getDeclaredAnnotation(annotationType) != null) {
+ hasTestMethod.set(true);
+ }
+ });
return hasTestMethod.get();
} catch (NoClassDefFoundError | ClassNotFoundException e) {
- logger.warn("Unable to access class: " + metadata.getClassName());
+ logger.warn("Unable to access class: " + className);
return false;
}
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/main/scan/JarFileTestScanner.java b/core/citrus-base/src/main/java/org/citrusframework/main/scan/JarFileTestScanner.java
index 05dadbdffd..c7b3c2f3be 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/main/scan/JarFileTestScanner.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/main/scan/JarFileTestScanner.java
@@ -26,10 +26,9 @@
import org.citrusframework.TestClass;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.util.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.AntPathMatcher;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -55,8 +54,8 @@ public List findTestsInPackage(String packageToScan) {
try (JarFile jar = new JarFile(artifact)) {
for (Enumeration entries = jar.entries(); entries.hasMoreElements();) {
JarEntry entry = entries.nextElement();
- String className = StringUtils.stripFilenameExtension(entry.getName()).replace( "/", "." );
- if (new AntPathMatcher().matchStart(packageToScan.replace( ".", "/" ), entry.getName()) && isIncluded(className)) {
+ String className = FileUtils.getBaseName(entry.getName()).replace( "/", "." );
+ if (packageToScan.replace( ".", "/" ).startsWith(entry.getName()) && isIncluded(className)) {
logger.info("Found test class candidate in test jar file: " + entry.getName());
testClasses.add(new TestClass(className));
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/message/DelegatingPathExpressionProcessor.java b/core/citrus-base/src/main/java/org/citrusframework/message/DelegatingPathExpressionProcessor.java
index 80c8544abf..4314be2268 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/message/DelegatingPathExpressionProcessor.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/message/DelegatingPathExpressionProcessor.java
@@ -27,7 +27,6 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.validation.json.JsonPathMessageValidationContext;
-import org.springframework.util.CollectionUtils;
/**
* Generic processor implementation delegating to JSONPath or XPath message processor based on given expression
@@ -49,7 +48,7 @@ public DelegatingPathExpressionProcessor(Builder builder) {
@Override
public void process(Message message, TestContext context) {
- if (CollectionUtils.isEmpty(pathExpressions)) {
+ if (pathExpressions.isEmpty()) {
return;
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/message/MessageSelectorBuilder.java b/core/citrus-base/src/main/java/org/citrusframework/message/MessageSelectorBuilder.java
index 3a3da9da62..170147275e 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/message/MessageSelectorBuilder.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/message/MessageSelectorBuilder.java
@@ -22,8 +22,7 @@
import java.util.Map.Entry;
import org.citrusframework.context.TestContext;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* Constructs message selectors either from string value or from key value maps. Currently only AND logical combination
@@ -54,7 +53,7 @@ public MessageSelectorBuilder(String selectorString) {
public static String build(String messageSelector, Map messageSelectorMap, TestContext context) {
if (StringUtils.hasText(messageSelector)) {
return context.replaceDynamicContentInString(messageSelector);
- } else if (!CollectionUtils.isEmpty(messageSelectorMap)) {
+ } else if (messageSelectorMap != null && !messageSelectorMap.isEmpty()) {
return MessageSelectorBuilder.fromKeyValueMap(
context.resolveDynamicValuesInMap(messageSelectorMap)).build();
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/message/ZipMessage.java b/core/citrus-base/src/main/java/org/citrusframework/message/ZipMessage.java
index d422bb768c..4b55ea3537 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/message/ZipMessage.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/message/ZipMessage.java
@@ -16,17 +16,22 @@
package org.citrusframework.message;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.util.StringUtils;
-
-import java.io.*;
-import java.util.*;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
/**
* @author Christoph Deppisch
@@ -69,7 +74,23 @@ public ZipMessage addEntry(Resource resource) {
try {
addEntry(new Entry(resource.getFile()));
} catch (IOException e) {
- throw new CitrusRuntimeException("Failed to read zip entry content from given resource", e);
+ throw new CitrusRuntimeException(String.format("Failed to read zip entry content from given resource: %s", resource.getLocation()), e);
+ }
+ return this;
+ }
+
+ /**
+ * Adds new zip archive entry. Resource can be a file or directory. In case of directory all files will be automatically added
+ * to the zip archive. Directory structures are retained throughout this process.
+ *
+ * @param resource
+ * @return
+ */
+ public ZipMessage addEntry(Path resource) {
+ try {
+ addEntry(new Entry(resource.toFile()));
+ } catch (IOException e) {
+ throw new CitrusRuntimeException(String.format("Failed to read zip entry content from given resource: %s", resource), e);
}
return this;
}
@@ -172,7 +193,7 @@ public Entry(String name, File file) throws IOException {
entries.add(new Entry(child));
}
} else {
- this.content = FileCopyUtils.copyToByteArray(file);
+ this.content = FileUtils.copyToByteArray(file);
}
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/message/builder/FileResourcePayloadBuilder.java b/core/citrus-base/src/main/java/org/citrusframework/message/builder/FileResourcePayloadBuilder.java
index 4ccdcd96d1..c20ab3554d 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/message/builder/FileResourcePayloadBuilder.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/message/builder/FileResourcePayloadBuilder.java
@@ -28,8 +28,8 @@
import org.citrusframework.message.MessagePayloadBuilder;
import org.citrusframework.message.MessageType;
import org.citrusframework.message.MessageTypeAware;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.Resource;
/**
* @author Christoph Deppisch
diff --git a/core/citrus-base/src/main/java/org/citrusframework/message/builder/MessageBuilderSupport.java b/core/citrus-base/src/main/java/org/citrusframework/message/builder/MessageBuilderSupport.java
index 7af7dd8caf..b98c17d3b5 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/message/builder/MessageBuilderSupport.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/message/builder/MessageBuilderSupport.java
@@ -44,13 +44,13 @@
import org.citrusframework.message.WithPayloadBuilder;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
import org.citrusframework.validation.builder.DefaultMessageBuilder;
import org.citrusframework.validation.builder.StaticMessageBuilder;
import org.citrusframework.variable.VariableExtractor;
import org.citrusframework.variable.VariableExtractorAdapter;
import org.citrusframework.variable.dictionary.DataDictionary;
-import org.springframework.core.io.Resource;
/**
* @author Christoph Deppisch
diff --git a/core/citrus-base/src/main/java/org/citrusframework/message/selector/DelegatingMessageSelector.java b/core/citrus-base/src/main/java/org/citrusframework/message/selector/DelegatingMessageSelector.java
index 4c35b3f98e..877b24aa3f 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/message/selector/DelegatingMessageSelector.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/message/selector/DelegatingMessageSelector.java
@@ -21,10 +21,10 @@
import java.util.Map;
import org.citrusframework.context.TestContext;
+import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageSelector;
import org.citrusframework.message.MessageSelectorBuilder;
-import org.springframework.util.Assert;
/**
* Message selector delegates incoming messages to several other selector implementations
@@ -51,7 +51,9 @@ public DelegatingMessageSelector(String selector, TestContext context) {
this.context = context;
this.matchingHeaders = MessageSelectorBuilder.withString(selector).toKeyValueMap();
- Assert.isTrue(matchingHeaders.size() > 0, "Invalid empty message selector");
+ if (matchingHeaders.isEmpty()) {
+ throw new CitrusRuntimeException("Invalid empty message selector");
+ }
factories = new ArrayList<>();
diff --git a/core/citrus-base/src/main/java/org/citrusframework/message/selector/PayloadMatchingMessageSelector.java b/core/citrus-base/src/main/java/org/citrusframework/message/selector/PayloadMatchingMessageSelector.java
index d0ddfd4de5..4d8fa1d225 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/message/selector/PayloadMatchingMessageSelector.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/message/selector/PayloadMatchingMessageSelector.java
@@ -16,8 +16,8 @@
package org.citrusframework.message.selector;
import org.citrusframework.context.TestContext;
+import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
-import org.springframework.util.Assert;
/**
* Message selector matches one or more header elements with the message header. Only in case all
@@ -37,9 +37,10 @@ public class PayloadMatchingMessageSelector extends AbstractMessageSelector {
public PayloadMatchingMessageSelector(String selectKey, String matchingValue, TestContext context) {
super(selectKey, matchingValue, context);
- Assert.isTrue(selectKey.equals(SELECTOR_ID),
- String.format("Invalid usage of payload matching message selector - " +
+ if (!selectKey.equals(SELECTOR_ID)) {
+ throw new CitrusRuntimeException(String.format("Invalid usage of payload matching message selector - " +
"usage restricted to key '%s' but was '%s'", SELECTOR_ID, selectKey));
+ }
}
@Override
diff --git a/core/citrus-base/src/main/java/org/citrusframework/report/FailureStackTestListener.java b/core/citrus-base/src/main/java/org/citrusframework/report/FailureStackTestListener.java
index ae8d9617f4..cad5a9b444 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/report/FailureStackTestListener.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/report/FailureStackTestListener.java
@@ -16,20 +16,20 @@
package org.citrusframework.report;
-import javax.xml.parsers.SAXParserFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
+import javax.xml.parsers.SAXParserFactory;
import org.citrusframework.TestAction;
import org.citrusframework.TestCase;
import org.citrusframework.container.TestActionContainer;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
@@ -63,7 +63,7 @@ public static List getFailureStack(final TestCase test) {
try {
final String testFilePath = test.getPackageName().replace('.', '/') + "/" + test.getName();
- Resource testFileResource = new ClassPathResource(testFilePath + FileUtils.FILE_EXTENSION_XML);
+ Resource testFileResource = Resources.newClasspathResource(testFilePath + FileUtils.FILE_EXTENSION_XML);
if (!testFileResource.exists()) {
return failureStack;
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/report/HtmlReporter.java b/core/citrus-base/src/main/java/org/citrusframework/report/HtmlReporter.java
index 96765fcd9f..71238bee78 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/report/HtmlReporter.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/report/HtmlReporter.java
@@ -19,7 +19,6 @@
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
-import java.io.FileReader;
import java.io.IOException;
import java.text.DateFormat;
import java.util.HashMap;
@@ -27,16 +26,16 @@
import java.util.Optional;
import java.util.Properties;
+import org.apache.commons.codec.binary.Base64;
import org.citrusframework.TestCase;
import org.citrusframework.TestCaseMetaInfo;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
import org.citrusframework.util.PropertyUtils;
-import org.apache.commons.codec.binary.Base64;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.util.StringUtils;
/**
* Basic logging reporter generating a HTML report with detailed test results.
@@ -58,7 +57,7 @@ public class HtmlReporter extends AbstractOutputFileReporter implements TestList
private String testDetailTemplate = HtmlReporterSettings.getReportDetailTemplate();
/** Output directory */
- private String outputDirectory = HtmlReporterSettings.getReportDirectory();
+ private final String outputDirectory = HtmlReporterSettings.getReportDirectory();
/** Resulting HTML test report file name */
private String reportFileName = HtmlReporterSettings.getReportFile();
@@ -172,8 +171,7 @@ private String getCodeSnippetHtml(Throwable cause) {
if (!ex.getFailureStack().isEmpty()) {
FailureStackElement stackElement = ex.getFailureStack().pop();
if (stackElement.getLineNumberStart() > 0) {
- reader = new BufferedReader(new FileReader(
- new ClassPathResource(stackElement.getTestFilePath() + FileUtils.FILE_EXTENSION_XML).getFile()));
+ reader = new BufferedReader(Resources.newClasspathResource(stackElement.getTestFilePath() + FileUtils.FILE_EXTENSION_XML).getReader());
codeSnippet.append("");
codeSnippet.append("
" + stackElement.getTestFilePath() + ".xml ");
diff --git a/core/citrus-base/src/main/java/org/citrusframework/report/JUnitReporter.java b/core/citrus-base/src/main/java/org/citrusframework/report/JUnitReporter.java
index ebe3b80481..ff96778022 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/report/JUnitReporter.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/report/JUnitReporter.java
@@ -37,7 +37,7 @@
import org.apache.commons.lang.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/core/citrus-base/src/main/java/org/citrusframework/report/LoggingReporter.java b/core/citrus-base/src/main/java/org/citrusframework/report/LoggingReporter.java
index 8991585c4f..8d00a24740 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/report/LoggingReporter.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/report/LoggingReporter.java
@@ -25,10 +25,10 @@
import org.citrusframework.container.TestActionContainer;
import org.citrusframework.context.TestContext;
import org.citrusframework.message.Message;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.NOPLoggerFactory;
-import org.springframework.util.StringUtils;
/**
* Simple logging reporter printing test start and ending to the console/logger.
diff --git a/core/citrus-base/src/main/java/org/citrusframework/util/FileUtils.java b/core/citrus-base/src/main/java/org/citrusframework/util/FileUtils.java
index b9048706d1..3382ebb25b 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/util/FileUtils.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/util/FileUtils.java
@@ -22,9 +22,9 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.Charset;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -35,14 +35,10 @@
import org.citrusframework.CitrusSettings;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.util.ResourceUtils;
/**
* Class to provide general file utilities, such as listing all XML files in a directory,
@@ -116,17 +112,11 @@ public static String readToString(File file) throws IOException {
*/
public static String readToString(Resource resource, Charset charset) throws IOException {
if (simulationMode) {
- if (resource instanceof ClassPathResource) {
- return ((ClassPathResource) resource).getPath();
- } else if (resource instanceof FileSystemResource) {
- return ((FileSystemResource) resource).getPath();
- } else {
- return resource.getFilename();
- }
+ resource.getLocation();
}
if (logger.isDebugEnabled()) {
- logger.debug(String.format("Reading file resource: '%s' (encoding is '%s')", resource.getFilename(), charset.displayName()));
+ logger.debug(String.format("Reading file resource: '%s' (encoding is '%s')", resource.getLocation(), charset.displayName()));
}
return readToString(resource.getInputStream(), charset);
}
@@ -139,7 +129,7 @@ public static String readToString(Resource resource, Charset charset) throws IOE
* @throws IOException
*/
public static String readToString(InputStream inputStream, Charset charset) throws IOException {
- return new String(FileCopyUtils.copyToByteArray(inputStream), charset);
+ return new String(inputStream.readAllBytes(), charset);
}
/**
@@ -148,8 +138,18 @@ public static String readToString(InputStream inputStream, Charset charset) thro
* @param file
*/
public static void writeToFile(InputStream inputStream, File file) {
- try (InputStreamReader inputStreamReader = new InputStreamReader(inputStream)) {
- writeToFile(FileCopyUtils.copyToString(inputStreamReader), file, getDefaultCharset());
+ if (logger.isDebugEnabled()) {
+ logger.debug(String.format("Writing file resource: '%s'", file.getName()));
+ }
+
+ if (!file.getParentFile().exists()) {
+ if (!file.getParentFile().mkdirs()) {
+ throw new CitrusRuntimeException("Unable to create folder structure for file: " + file.getPath());
+ }
+ }
+
+ try (inputStream) {
+ Files.copy(inputStream, file.toPath());
} catch (IOException e) {
throw new CitrusRuntimeException("Failed to write file", e);
}
@@ -198,10 +198,10 @@ public static void writeToFile(String content, File file, Charset charset) {
*/
public static List
findFiles(final String startDir, final Set fileNamePatterns) {
/* file names to be returned */
- final List files = new ArrayList();
+ final List files = new ArrayList<>();
- /* Stack to hold potential sub directories */
- final Stack dirs = new Stack();
+ /* Stack to hold potential subdirectories */
+ final Stack dirs = new Stack<>();
/* start directory */
final File startdir = new File(startDir);
@@ -222,14 +222,9 @@ public static List findFiles(final String startDir, final Set file
boolean accepted = tmp.isDirectory();
for (String fileNamePattern : fileNamePatterns) {
- if (fileNamePattern.contains("/")) {
- fileNamePattern = fileNamePattern.substring(fileNamePattern.lastIndexOf('/') + 1);
- }
-
- fileNamePattern = fileNamePattern.replace(".", "\\.").replace("*", ".*");
-
if (name.matches(fileNamePattern)) {
accepted = true;
+ break;
}
}
@@ -257,13 +252,7 @@ public static List findFiles(final String startDir, final Set file
* @return
*/
public static Resource getFileResource(String filePath, TestContext context) {
- if (filePath.contains(FILE_PATH_CHARSET_PARAMETER)) {
- return new PathMatchingResourcePatternResolver().getResource(
- context.replaceDynamicContentInString(filePath.substring(0, filePath.indexOf(FileUtils.FILE_PATH_CHARSET_PARAMETER))));
- } else {
- return new PathMatchingResourcePatternResolver().getResource(
- context.replaceDynamicContentInString(filePath));
- }
+ return getFileResource(context.replaceDynamicContentInString(filePath));
}
/**
@@ -273,25 +262,13 @@ public static Resource getFileResource(String filePath, TestContext context) {
*/
public static Resource getFileResource(String filePath) {
String path;
-
if (filePath.contains(FILE_PATH_CHARSET_PARAMETER)) {
path = filePath.substring(0, filePath.indexOf(FileUtils.FILE_PATH_CHARSET_PARAMETER));
} else {
path = filePath;
}
- if (path.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
- return new FileSystemResource(path.substring(ResourceUtils.FILE_URL_PREFIX.length()));
- } else if (path.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
- return new PathMatchingResourcePatternResolver().getResource(path);
- }
-
- Resource file = new FileSystemResource(path);
- if (!file.exists()) {
- return new PathMatchingResourcePatternResolver().getResource(path);
- }
-
- return file;
+ return Resources.create(path);
}
/**
@@ -338,7 +315,7 @@ public static String getFileExtension(String path) {
public static Properties loadAsProperties(Resource resource) {
Properties properties = new Properties();
try (InputStream is = resource.getInputStream()) {
- String filename = resource.getFilename();
+ String filename = getFileName(resource.getLocation());
if (filename != null && filename.endsWith(FILE_EXTENSION_XML)) {
properties.loadFromXML(is);
} else {
@@ -351,6 +328,20 @@ public static Properties loadAsProperties(Resource resource) {
return properties;
}
+ /**
+ * Gets the file name from given file path.
+ * @param path
+ * @return
+ */
+ public static String getFileName(String path) {
+ if (path == null || path.isBlank()) {
+ return "";
+ }
+
+ int separatorIndex = path.lastIndexOf("/");
+ return (separatorIndex != -1 ? path.substring(separatorIndex + 1) : path);
+ }
+
/**
* Remove file extension from file name.
* @param fileName
@@ -384,4 +375,35 @@ public static String getBasePath(String filePath) {
return filePath;
}
+
+ public static byte[] copyToByteArray(File file) {
+ if (file == null) {
+ return new byte[0];
+ }
+
+ try (InputStream in = Files.newInputStream(file.toPath())) {
+ return in.readAllBytes();
+ } catch (IOException e) {
+ throw new CitrusRuntimeException("Failed to read file content", e);
+ }
+ }
+
+ public static byte[] copyToByteArray(Resource resource) {
+ try (InputStream in = resource.getInputStream()) {
+ if (in == null) {
+ throw new CitrusRuntimeException(String.format("Unable to access input stream of resource %s", resource.getLocation()));
+ }
+ return in.readAllBytes();
+ } catch (IOException e) {
+ throw new CitrusRuntimeException("Failed to read resource", e);
+ }
+ }
+
+ public static byte[] copyToByteArray(InputStream inputStream) {
+ try (inputStream) {
+ return inputStream.readAllBytes();
+ } catch (IOException e) {
+ throw new CitrusRuntimeException("Failed to read input stream", e);
+ }
+ }
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/util/PropertyUtils.java b/core/citrus-base/src/main/java/org/citrusframework/util/PropertyUtils.java
index ab8e8d6b2b..b5f9e2f825 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/util/PropertyUtils.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/util/PropertyUtils.java
@@ -20,7 +20,7 @@
import java.util.Properties;
import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.springframework.core.io.Resource;
+import org.citrusframework.spi.Resource;
/**
* Utility class supporting property replacement in template files.
diff --git a/core/citrus-base/src/main/java/org/citrusframework/util/StringUtils.java b/core/citrus-base/src/main/java/org/citrusframework/util/StringUtils.java
new file mode 100644
index 0000000000..6101863249
--- /dev/null
+++ b/core/citrus-base/src/main/java/org/citrusframework/util/StringUtils.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2023 the original author or authors.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.util;
+
+/**
+ * Utility helper class for Strings.
+ */
+public class StringUtils {
+
+ private StringUtils() {
+ //prevent instantiation of utility class
+ }
+
+ /**
+ * Helper method checks for non-null and non-blank String.
+ * @param str
+ * @return
+ */
+ public static boolean hasText(String str) {
+ return str != null && !str.isBlank();
+ }
+
+ /**
+ * String helper checking for isEmpty String and adds null check on given parameter.
+ * @param str
+ * @return
+ */
+ public static boolean isEmpty(String str) {
+ return str == null || str.isEmpty();
+ }
+}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/validation/DefaultHeaderValidator.java b/core/citrus-base/src/main/java/org/citrusframework/validation/DefaultHeaderValidator.java
index dd712a96ea..42ef715e0f 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/validation/DefaultHeaderValidator.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/validation/DefaultHeaderValidator.java
@@ -22,12 +22,11 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.ValidationException;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.context.HeaderValidationContext;
import org.citrusframework.validation.matcher.ValidationMatcherUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -54,29 +53,25 @@ public void validateHeader(String headerName, Object receivedValue, Object contr
.map(context::replaceDynamicContentInString)
.orElse("");
- try {
- if (receivedValue != null) {
- String receivedValueString = context.getTypeConverter().convertIfNecessary(receivedValue, String.class);
- if (ValidationMatcherUtils.isValidationMatcherExpression(expectedValue)) {
- ValidationMatcherUtils.resolveValidationMatcher(headerName, receivedValueString,
- expectedValue, context);
- return;
- }
+ if (receivedValue != null) {
+ String receivedValueString = context.getTypeConverter().convertIfNecessary(receivedValue, String.class);
+ if (ValidationMatcherUtils.isValidationMatcherExpression(expectedValue)) {
+ ValidationMatcherUtils.resolveValidationMatcher(headerName, receivedValueString,
+ expectedValue, context);
+ return;
+ }
- Assert.isTrue(receivedValueString.equals(expectedValue),
- "Values not equal for header element '"
- + headerName + "', expected '"
- + expectedValue + "' but was '"
- + receivedValue + "'");
- } else {
- Assert.isTrue(!StringUtils.hasText(expectedValue),
- "Values not equal for header element '"
- + headerName + "', expected '"
- + expectedValue + "' but was '"
- + null + "'");
+ if (!receivedValueString.equals(expectedValue)) {
+ throw new ValidationException("Values not equal for header element '"
+ + headerName + "', expected '"
+ + expectedValue + "' but was '"
+ + receivedValue + "'");
}
- } catch (IllegalArgumentException e) {
- throw new ValidationException("Validation failed:", e);
+ } else if (StringUtils.hasText(expectedValue)) {
+ throw new ValidationException("Values not equal for header element '"
+ + headerName + "', expected '"
+ + expectedValue + "' but was '"
+ + null + "'");
}
if (logger.isDebugEnabled()) {
diff --git a/core/citrus-base/src/main/java/org/citrusframework/validation/DefaultMessageHeaderValidator.java b/core/citrus-base/src/main/java/org/citrusframework/validation/DefaultMessageHeaderValidator.java
index 438e6cb758..a71be029ed 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/validation/DefaultMessageHeaderValidator.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/validation/DefaultMessageHeaderValidator.java
@@ -35,7 +35,6 @@
import org.citrusframework.validation.context.HeaderValidationContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
/**
* Basic header message validator provides message header validation. Subclasses only have to add
@@ -59,7 +58,9 @@ public void validateMessage(Message receivedMessage, Message controlMessage, Tes
Map controlHeaders = controlMessage.getHeaders();
Map receivedHeaders = receivedMessage.getHeaders();
- if (CollectionUtils.isEmpty(controlHeaders)) { return; }
+ if (controlHeaders == null || controlHeaders.isEmpty()) {
+ return;
+ }
logger.debug("Start message header validation ...");
diff --git a/core/citrus-base/src/main/java/org/citrusframework/validation/DelegatingPayloadVariableExtractor.java b/core/citrus-base/src/main/java/org/citrusframework/validation/DelegatingPayloadVariableExtractor.java
index 88c67dcb4b..5a34c41272 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/validation/DelegatingPayloadVariableExtractor.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/validation/DelegatingPayloadVariableExtractor.java
@@ -28,7 +28,6 @@
import org.citrusframework.variable.VariableExtractor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
/**
* Generic extractor implementation delegating to JSONPath or XPath variable extractor based on given expression
@@ -59,7 +58,9 @@ public DelegatingPayloadVariableExtractor(Builder builder) {
@Override
public void extractVariables(Message message, TestContext context) {
- if (CollectionUtils.isEmpty(pathExpressions)) {return;}
+ if (pathExpressions.isEmpty()) {
+ return;
+ }
if (logger.isDebugEnabled()) {
logger.debug("Reading path elements.");
diff --git a/core/citrus-base/src/main/java/org/citrusframework/validation/interceptor/BinaryMessageProcessor.java b/core/citrus-base/src/main/java/org/citrusframework/validation/interceptor/BinaryMessageProcessor.java
index 923c46bc31..259a5fb791 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/validation/interceptor/BinaryMessageProcessor.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/validation/interceptor/BinaryMessageProcessor.java
@@ -1,17 +1,15 @@
package org.citrusframework.validation.interceptor;
-import java.io.IOException;
import java.nio.charset.Charset;
import org.citrusframework.CitrusSettings;
import org.citrusframework.context.TestContext;
-import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.AbstractMessageProcessor;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageProcessor;
import org.citrusframework.message.MessageType;
-import org.springframework.core.io.Resource;
-import org.springframework.util.FileCopyUtils;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.util.FileUtils;
/**
* Message construction processor automatically converts message payloads to binary content. Supports String typed message payloads and
@@ -36,11 +34,7 @@ protected void processMessage(Message message, TestContext context) {
if (message.getPayload() instanceof String) {
message.setPayload(message.getPayload(String.class).getBytes(encoding));
} else if (message.getPayload() instanceof Resource) {
- try {
- message.setPayload(FileCopyUtils.copyToByteArray(message.getPayload(Resource.class).getInputStream()));
- } catch (IOException e) {
- throw new CitrusRuntimeException("Failed to build binary message payload from payload resource", e);
- }
+ message.setPayload(FileUtils.copyToByteArray(message.getPayload(Resource.class)));
} else {
message.setPayload(message.getPayload(byte[].class));
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/validation/interceptor/GzipMessageProcessor.java b/core/citrus-base/src/main/java/org/citrusframework/validation/interceptor/GzipMessageProcessor.java
index 72f8e09591..f56e1a8ccc 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/validation/interceptor/GzipMessageProcessor.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/validation/interceptor/GzipMessageProcessor.java
@@ -13,9 +13,8 @@
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageProcessor;
import org.citrusframework.message.MessageType;
-import org.springframework.core.io.Resource;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.util.StreamUtils;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.util.FileUtils;
/**
* Message processor automatically converts message payloads to gzipped content. Supports String typed message payloads and
@@ -45,9 +44,9 @@ protected void processMessage(Message message, TestContext context) {
if (message.getPayload() instanceof String) {
message.setPayload(getZipped(context.replaceDynamicContentInString(message.getPayload(String.class)).getBytes(encoding)));
} else if (message.getPayload() instanceof Resource) {
- message.setPayload(getZipped(FileCopyUtils.copyToByteArray(message.getPayload(Resource.class).getInputStream())));
+ message.setPayload(getZipped(FileUtils.copyToByteArray(message.getPayload(Resource.class))));
} else if (message.getPayload() instanceof InputStream) {
- message.setPayload(getZipped(FileCopyUtils.copyToByteArray(message.getPayload(InputStream.class))));
+ message.setPayload(getZipped(FileUtils.copyToByteArray(message.getPayload(InputStream.class))));
} else {
message.setPayload(getZipped(message.getPayload(byte[].class)));
}
@@ -97,7 +96,8 @@ public GzipMessageProcessor build() {
private byte[] getZipped(byte[] in) throws IOException {
try (ByteArrayOutputStream zipped = new ByteArrayOutputStream()) {
try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(zipped)) {
- StreamUtils.copy(in, gzipOutputStream);
+ gzipOutputStream.write(in);
+ gzipOutputStream.flush();
}
return zipped.toByteArray();
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/validation/json/JsonPathMessageValidationContext.java b/core/citrus-base/src/main/java/org/citrusframework/validation/json/JsonPathMessageValidationContext.java
index b55f02d2fd..bb5d9c352a 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/validation/json/JsonPathMessageValidationContext.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/validation/json/JsonPathMessageValidationContext.java
@@ -28,7 +28,7 @@
import org.citrusframework.validation.context.ValidationContext;
import org.citrusframework.variable.VariableExtractor;
import org.citrusframework.variable.VariableExtractorAdapter;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* Specialised validation context adds JSON path expressions for message validation.
diff --git a/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/CreateVariableValidationMatcher.java b/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/CreateVariableValidationMatcher.java
index c940ce4eb8..6272a8c35c 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/CreateVariableValidationMatcher.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/CreateVariableValidationMatcher.java
@@ -16,14 +16,13 @@
package org.citrusframework.validation.matcher.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.ValidationException;
import org.citrusframework.validation.matcher.ValidationMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
-
-import java.util.List;
/**
* Creates new variables from given field. Either uses field name or control value as variable name.
diff --git a/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/StringLengthValidationMatcher.java b/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/StringLengthValidationMatcher.java
index 7d8afaac73..46e39bf42f 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/StringLengthValidationMatcher.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/StringLengthValidationMatcher.java
@@ -16,23 +16,22 @@
package org.citrusframework.validation.matcher.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.ValidationException;
import org.citrusframework.validation.matcher.ValidationMatcher;
-import org.springframework.util.StringUtils;
-
-import java.util.List;
/**
* ValidationMatcher checks string length of given field.
- *
+ *
* @author Christoph Deppisch
*/
public class StringLengthValidationMatcher implements ValidationMatcher {
public void validate(String fieldName, String value, List controlParameters, TestContext context) throws ValidationException {
try {
- int control = Integer.valueOf(StringUtils.trimWhitespace(controlParameters.get(0)));
+ int control = Integer.parseInt(controlParameters.get(0).strip());
if (!(value.length() == control)) {
throw new ValidationException(this.getClass().getSimpleName()
diff --git a/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/TrimAllWhitespacesValidationMatcher.java b/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/TrimAllWhitespacesValidationMatcher.java
index 38196fdc69..81ecf88f78 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/TrimAllWhitespacesValidationMatcher.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/TrimAllWhitespacesValidationMatcher.java
@@ -16,29 +16,28 @@
package org.citrusframework.validation.matcher.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.ValidationException;
import org.citrusframework.validation.matcher.ValidationMatcher;
-import org.springframework.util.StringUtils;
-
-import java.util.List;
/**
* ValidationMatcher trims leading and trailing whitespaces in value and control value.
- *
+ *
* @author Christoph Deppisch
* @since 2.7.6
*/
public class TrimAllWhitespacesValidationMatcher implements ValidationMatcher {
public void validate(String fieldName, String value, List controlParameters, TestContext context) throws ValidationException {
- String control = controlParameters.get(0);
-
- if (!StringUtils.trimAllWhitespace(value).equalsIgnoreCase(StringUtils.trimAllWhitespace(control))) {
+ String controlNoWhitespace = controlParameters.get(0).replaceAll("\\s", "");
+ String valueNoWhitespace = value.replaceAll("\\s", "");
+ if (!valueNoWhitespace.equalsIgnoreCase(controlNoWhitespace)) {
throw new ValidationException(this.getClass().getSimpleName()
+ " failed for field '" + fieldName
- + "'. Received value is '" + StringUtils.trimAllWhitespace(value)
- + "', control value is '" + StringUtils.trimAllWhitespace(control) + "'.");
+ + "'. Received value is '" + valueNoWhitespace
+ + "', control value is '" + controlNoWhitespace + "'.");
}
}
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/TrimValidationMatcher.java b/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/TrimValidationMatcher.java
index 6f43300ddb..254fa18cde 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/TrimValidationMatcher.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/validation/matcher/core/TrimValidationMatcher.java
@@ -16,29 +16,27 @@
package org.citrusframework.validation.matcher.core;
+import java.util.List;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.ValidationException;
import org.citrusframework.validation.matcher.ValidationMatcher;
-import org.springframework.util.StringUtils;
-
-import java.util.List;
/**
* ValidationMatcher trims leading and trailing whitespaces in value and control value.
- *
+ *
* @author Christoph Deppisch
* @since 2.7.6
*/
public class TrimValidationMatcher implements ValidationMatcher {
public void validate(String fieldName, String value, List controlParameters, TestContext context) throws ValidationException {
- String control = controlParameters.get(0);
-
- if (!StringUtils.trimWhitespace(value).equalsIgnoreCase(StringUtils.trimWhitespace(control))) {
+ String control = controlParameters.get(0).strip();
+ if (!value.strip().equalsIgnoreCase(control)) {
throw new ValidationException(this.getClass().getSimpleName()
+ " failed for field '" + fieldName
- + "'. Received value is '" + StringUtils.trimWhitespace(value)
- + "', control value is '" + StringUtils.trimWhitespace(control) + "'.");
+ + "'. Received value is '" + value.strip()
+ + "', control value is '" + control + "'.");
}
}
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/validation/script/ScriptValidationContext.java b/core/citrus-base/src/main/java/org/citrusframework/validation/script/ScriptValidationContext.java
index d7cfb27923..2aa3ae4d37 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/validation/script/ScriptValidationContext.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/validation/script/ScriptValidationContext.java
@@ -23,10 +23,10 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.script.ScriptTypes;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
import org.citrusframework.validation.context.DefaultValidationContext;
import org.citrusframework.validation.context.ValidationContext;
-import org.springframework.core.io.Resource;
/**
* Basic script validation context providing the validation code either from file resource or
diff --git a/core/citrus-base/src/main/java/org/citrusframework/validation/script/TemplateBasedScriptBuilder.java b/core/citrus-base/src/main/java/org/citrusframework/validation/script/TemplateBasedScriptBuilder.java
index 14d6457446..4e134efa1d 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/validation/script/TemplateBasedScriptBuilder.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/validation/script/TemplateBasedScriptBuilder.java
@@ -16,44 +16,46 @@
package org.citrusframework.validation.script;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.Resource;
-
-import java.io.*;
/**
* Script builder builds a script with custom code body. Script header and tail come from static
* script template.
- *
+ *
* @author Christoph Deppisch
*/
public final class TemplateBasedScriptBuilder {
/** Placeholder identifier for script body in template */
private static final String BODY_PLACEHOLDER = "@SCRIPTBODY@";
-
+
/** Head and tail for script */
- private String scriptHead;
- private String scriptTail;
-
+ private final String scriptHead;
+ private final String scriptTail;
+
/** Code snippet which is dynamically added to the script */
private String scriptCode = "";
-
+
/**
* Constructor using script template string.
* @param scriptTemplate
*/
private TemplateBasedScriptBuilder(String scriptTemplate) {
if (!scriptTemplate.contains(BODY_PLACEHOLDER)) {
- throw new CitrusRuntimeException("Invalid script template - please define '" +
+ throw new CitrusRuntimeException("Invalid script template - please define '" +
BODY_PLACEHOLDER + "' placeholder where your code comes in");
}
-
+
scriptHead = scriptTemplate.substring(0, scriptTemplate.indexOf(BODY_PLACEHOLDER));
scriptTail = scriptTemplate.substring((scriptTemplate.indexOf(BODY_PLACEHOLDER) + BODY_PLACEHOLDER.length()));
}
-
+
/**
* Builds the final script.
*/
@@ -61,7 +63,7 @@ public String build() {
StringBuilder scriptBuilder = new StringBuilder();
StringBuilder scriptBody = new StringBuilder();
String importStmt = "import ";
-
+
try {
if (scriptCode.contains(importStmt)) {
BufferedReader reader = new BufferedReader(new StringReader(scriptCode));
@@ -81,17 +83,17 @@ public String build() {
} catch (IOException e) {
throw new CitrusRuntimeException("Failed to construct script from template", e);
}
-
+
scriptBuilder.append(scriptHead);
scriptBuilder.append(scriptBody.toString());
scriptBuilder.append(scriptTail);
-
+
return scriptBuilder.toString();
}
-
+
/**
* Adds custom code snippet to this builder.
- *
+ *
* @param code the custom code body
* @return
*/
@@ -99,7 +101,7 @@ public TemplateBasedScriptBuilder withCode(String code) {
this.scriptCode = code;
return this;
}
-
+
/**
* Static construction method returning a fully qualified instance of this builder.
* @param scriptTemplate the script template code.
@@ -108,7 +110,7 @@ public TemplateBasedScriptBuilder withCode(String code) {
public static TemplateBasedScriptBuilder fromTemplateScript(String scriptTemplate) {
return new TemplateBasedScriptBuilder(scriptTemplate);
}
-
+
/**
* Static construction method returning a fully qualified instance of this builder.
* @param scriptTemplateResource external file resource holding script template code.
diff --git a/core/citrus-base/src/main/java/org/citrusframework/validation/xml/XmlMessageValidationContext.java b/core/citrus-base/src/main/java/org/citrusframework/validation/xml/XmlMessageValidationContext.java
index 7553bd77eb..5354524b2a 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/validation/xml/XmlMessageValidationContext.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/validation/xml/XmlMessageValidationContext.java
@@ -24,7 +24,6 @@
import org.citrusframework.validation.context.DefaultValidationContext;
import org.citrusframework.validation.context.SchemaValidationContext;
import org.citrusframework.validation.context.ValidationContext;
-import org.springframework.core.io.Resource;
/**
* XML validation context holding validation specific information needed for XML
@@ -40,9 +39,6 @@ public class XmlMessageValidationContext extends DefaultValidationContext implem
/** Namespace definitions resolving namespaces in XML message validation */
private final Map namespaces;
- /** dtdResource for DTD validation */
- private final Resource dtdResource;
-
/** Map holding control namespaces for validation */
private final Map controlNamespaces;
@@ -70,7 +66,6 @@ public XmlMessageValidationContext(XmlValidationContextBuilder, ?> builder) {
this.ignoreExpressions = builder.ignoreExpressions;
this.namespaces = builder.namespaces;
this.controlNamespaces = builder.controlNamespaces;
- this.dtdResource = builder.dtdResource;
this.schemaValidation = builder.schemaValidation;
this.schemaRepository = builder.schemaRepository;
this.schema = builder.schema;
@@ -108,7 +103,6 @@ public XpathMessageValidationContext.Builder xpath() {
.schemaValidation(schemaValidation)
.schemaRepository(schemaRepository)
.schema(schema)
- .dtd(dtdResource)
.ignore(ignoreExpressions);
}
@@ -128,7 +122,6 @@ public static abstract class XmlValidationContextBuilder ignoreExpressions = new HashSet<>();
protected Map namespaces = new HashMap<>();
- protected Resource dtdResource;
protected final Map controlNamespaces = new HashMap<>();
protected boolean schemaValidation = true;
protected String schemaRepository;
@@ -217,17 +210,6 @@ public S schemaRepository(final String schemaRepository) {
return self;
}
- /**
- * Sets explicit DTD resource to use for validation.
- *
- * @param dtdResource
- * @return
- */
- public S dtd(final Resource dtdResource) {
- this.dtdResource = dtdResource;
- return self;
- }
-
/**
* Adds ignore path expression for message element.
*
@@ -272,14 +254,6 @@ public Map getNamespaces() {
return namespaces;
}
- /**
- * Get the dtd resource.
- * @return the dtdResource
- */
- public Resource getDTDResource() {
- return dtdResource;
- }
-
/**
* Get control namespace elements.
* @return the controlNamespaces
diff --git a/core/citrus-base/src/main/java/org/citrusframework/validation/xml/XpathMessageValidationContext.java b/core/citrus-base/src/main/java/org/citrusframework/validation/xml/XpathMessageValidationContext.java
index a29df717eb..7efbf376aa 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/validation/xml/XpathMessageValidationContext.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/validation/xml/XpathMessageValidationContext.java
@@ -26,7 +26,7 @@
import org.citrusframework.validation.DelegatingPayloadVariableExtractor;
import org.citrusframework.variable.VariableExtractor;
import org.citrusframework.variable.VariableExtractorAdapter;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* Specialised Xml validation context adds XPath expression evaluation.
diff --git a/core/citrus-base/src/main/java/org/citrusframework/variable/MessageHeaderVariableExtractor.java b/core/citrus-base/src/main/java/org/citrusframework/variable/MessageHeaderVariableExtractor.java
index 7a5f0f1b8e..344cd562e6 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/variable/MessageHeaderVariableExtractor.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/variable/MessageHeaderVariableExtractor.java
@@ -25,7 +25,6 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.UnknownElementException;
import org.citrusframework.message.Message;
-import org.springframework.util.CollectionUtils;
/**
* Variable extractor reading message headers and saves them to new test variables.
@@ -53,7 +52,7 @@ private MessageHeaderVariableExtractor(Builder builder) {
* Reads header information and saves new test variables.
*/
public void extractVariables(Message message, TestContext context) {
- if (CollectionUtils.isEmpty(headerMappings)) { return; }
+ if (headerMappings.isEmpty()) { return; }
for (Entry entry : headerMappings.entrySet()) {
String headerElementName = entry.getKey();
diff --git a/core/citrus-base/src/main/java/org/citrusframework/variable/dictionary/AbstractDataDictionary.java b/core/citrus-base/src/main/java/org/citrusframework/variable/dictionary/AbstractDataDictionary.java
index 6611b59288..a5952919a5 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/variable/dictionary/AbstractDataDictionary.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/variable/dictionary/AbstractDataDictionary.java
@@ -17,6 +17,7 @@
package org.citrusframework.variable.dictionary;
import java.io.IOException;
+import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
@@ -24,10 +25,9 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.AbstractMessageProcessor;
+import org.citrusframework.spi.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PropertiesLoaderUtils;
/**
* Abstract data dictionary implementation provides global scope handling.
@@ -75,12 +75,12 @@ public void initialize() {
if (mappingFile != null) {
if (logger.isDebugEnabled()) {
- logger.debug("Reading data dictionary mapping " + mappingFile.getFilename());
+ logger.debug("Reading data dictionary mapping " + mappingFile.getLocation());
}
- Properties props;
- try {
- props = PropertiesLoaderUtils.loadProperties(mappingFile);
+ Properties props = new Properties();
+ try (InputStream inputStream = mappingFile.getInputStream()) {
+ props.load(inputStream);
} catch (IOException e) {
throw new CitrusRuntimeException(e);
}
@@ -100,7 +100,7 @@ public void initialize() {
mappings.put(key, props.getProperty(key));
}
- logger.debug("Loaded data dictionary mapping " + mappingFile.getFilename());
+ logger.debug("Loaded data dictionary mapping " + mappingFile.getLocation());
}
}
diff --git a/core/citrus-base/src/main/java/org/citrusframework/xml/Jaxb2Marshaller.java b/core/citrus-base/src/main/java/org/citrusframework/xml/Jaxb2Marshaller.java
index 7c8eff6af9..33933c6bbb 100644
--- a/core/citrus-base/src/main/java/org/citrusframework/xml/Jaxb2Marshaller.java
+++ b/core/citrus-base/src/main/java/org/citrusframework/xml/Jaxb2Marshaller.java
@@ -19,12 +19,14 @@
package org.citrusframework.xml;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import javax.xml.XMLConstants;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
@@ -32,15 +34,14 @@
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
-import org.citrusframework.exceptions.CitrusRuntimeException;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.PropertyException;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.exceptions.ValidationException;
+import org.citrusframework.spi.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
@@ -72,7 +73,7 @@ public Jaxb2Marshaller(Class> ... classesToBeBound) {
public Jaxb2Marshaller(String ... contextPaths) {
this.classesToBeBound = null;
- this.contextPath = StringUtils.arrayToDelimitedString(contextPaths, ":");
+ this.contextPath = String.join(":", contextPaths);
this.schema = null;
}
@@ -84,7 +85,7 @@ public Jaxb2Marshaller(Resource schemaResource, Class> ... classesToBeBound) {
public Jaxb2Marshaller(Resource schemaResource, String ... contextPaths) {
this.classesToBeBound = null;
- this.contextPath = StringUtils.arrayToDelimitedString(contextPaths, ":");
+ this.contextPath = String.join(":", contextPaths);
this.schema = loadSchema(schemaResource);
}
@@ -96,7 +97,7 @@ public Jaxb2Marshaller(Resource[] schemaResources, Class> ... classesToBeBound
public Jaxb2Marshaller(Resource[] schemaResources, String ... contextPaths) {
this.classesToBeBound = null;
- this.contextPath = StringUtils.arrayToDelimitedString(contextPaths, ":");
+ this.contextPath = String.join(":", contextPaths);
this.schema = loadSchema(schemaResources);
}
@@ -164,7 +165,8 @@ public void setProperty(String key, Object value) {
private Schema loadSchema(Resource... schemas) {
if (logger.isDebugEnabled()) {
- logger.debug(String.format("Using marshaller validation schemas '%s'", StringUtils.arrayToCommaDelimitedString(schemas)));
+ logger.debug(String.format("Using marshaller validation schemas '%s'",
+ Stream.of(schemas).map(Object::toString).collect(Collectors.joining(","))));
}
try {
@@ -172,14 +174,18 @@ private Schema loadSchema(Resource... schemas) {
XMLReader xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
for (Resource resource : schemas) {
- Assert.isTrue(resource != null && resource.exists(), () -> "Resource does not exist: " + resource);
+ if (resource == null || !resource.exists()) {
+ throw new ValidationException(String.format("Resource does not exist: %s",
+ Optional.ofNullable(resource).map(Resource::getLocation).orElse("null")));
+ }
+
InputSource inputSource = new InputSource(resource.getInputStream());
inputSource.setSystemId(resource.getURI().toString());
schemaSources.add(new SAXSource(xmlReader, inputSource));
}
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
return schemaFactory.newSchema(schemaSources.toArray(new Source[0]));
- } catch (IOException | SAXException e) {
+ } catch (SAXException e) {
throw new CitrusRuntimeException("Failed to load schemas for marshaller", e);
}
}
diff --git a/core/citrus-base/src/test/java/org/citrusframework/actions/ReceiveMessageBuilderTest.java b/core/citrus-base/src/test/java/org/citrusframework/actions/ReceiveMessageBuilderTest.java
index aa6fa7a5c3..fbc1e3fca9 100644
--- a/core/citrus-base/src/test/java/org/citrusframework/actions/ReceiveMessageBuilderTest.java
+++ b/core/citrus-base/src/test/java/org/citrusframework/actions/ReceiveMessageBuilderTest.java
@@ -32,6 +32,7 @@
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageType;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.spi.Resource;
import org.citrusframework.validation.HeaderValidator;
import org.citrusframework.validation.MessageValidator;
import org.citrusframework.validation.ValidationProcessor;
@@ -49,18 +50,13 @@
import org.junit.jupiter.api.function.Executable;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.springframework.core.io.Resource;
import org.springframework.test.util.ReflectionTestUtils;
import static org.citrusframework.validation.json.JsonMessageValidationContext.Builder.json;
import static org.citrusframework.validation.json.JsonPathMessageValidationContext.Builder.jsonPath;
import static org.citrusframework.validation.xml.XmlMessageValidationContext.Builder.xml;
import static org.citrusframework.validation.xml.XpathMessageValidationContext.Builder.xpath;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-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 static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
diff --git a/core/citrus-base/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageActionBuilderTest.java b/core/citrus-base/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageActionBuilderTest.java
index 3273bcd68a..e2b01c84d9 100644
--- a/core/citrus-base/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageActionBuilderTest.java
+++ b/core/citrus-base/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageActionBuilderTest.java
@@ -41,6 +41,7 @@
import org.citrusframework.messaging.SelectiveConsumer;
import org.citrusframework.report.TestActionListeners;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.spi.Resource;
import org.citrusframework.validation.AbstractValidationProcessor;
import org.citrusframework.validation.TextEqualsMessageValidator;
import org.citrusframework.validation.builder.DefaultMessageBuilder;
@@ -54,7 +55,6 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.springframework.core.io.Resource;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -63,13 +63,7 @@
import static org.citrusframework.dsl.MessageSupport.MessageHeaderSupport.fromHeaders;
import static org.citrusframework.dsl.MessageSupport.message;
import static org.citrusframework.validation.xml.XmlMessageValidationContext.Builder.xml;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.anyLong;
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
/**
* @author Christoph Deppisch
diff --git a/core/citrus-base/src/test/java/org/citrusframework/actions/dsl/SendMessageActionBuilderTest.java b/core/citrus-base/src/test/java/org/citrusframework/actions/dsl/SendMessageActionBuilderTest.java
index ae3c5acd9d..b9e45e788e 100644
--- a/core/citrus-base/src/test/java/org/citrusframework/actions/dsl/SendMessageActionBuilderTest.java
+++ b/core/citrus-base/src/test/java/org/citrusframework/actions/dsl/SendMessageActionBuilderTest.java
@@ -39,6 +39,7 @@
import org.citrusframework.messaging.Producer;
import org.citrusframework.report.TestActionListeners;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.spi.Resource;
import org.citrusframework.validation.MessageValidator;
import org.citrusframework.validation.builder.DefaultMessageBuilder;
import org.citrusframework.validation.builder.StaticMessageBuilder;
@@ -48,8 +49,6 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.springframework.core.io.Resource;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -65,10 +64,10 @@
*/
public class SendMessageActionBuilderTest extends UnitTestSupport {
- private ReferenceResolver referenceResolver = Mockito.mock(ReferenceResolver.class);
- private Endpoint messageEndpoint = Mockito.mock(Endpoint.class);
- private Producer messageProducer = Mockito.mock(Producer.class);
- private Resource resource = Mockito.mock(Resource.class);
+ private final ReferenceResolver referenceResolver = Mockito.mock(ReferenceResolver.class);
+ private final Endpoint messageEndpoint = Mockito.mock(Endpoint.class);
+ private final Producer messageProducer = Mockito.mock(Producer.class);
+ private final Resource resource = Mockito.mock(Resource.class);
@Mock
private MessageValidator> validator;
@@ -125,7 +124,7 @@ public void testSendBuilderWithObjectMessageInstance() {
when(messageEndpoint.getActor()).thenReturn(null);
doAnswer(invocation -> {
Message message = (Message) invocation.getArguments()[0];
- Assert.assertEquals(message.getPayload(Integer.class), new Integer(10));
+ Assert.assertEquals(message.getPayload(Integer.class), Integer.valueOf(10));
Assert.assertNotNull(message.getHeader("operation"));
Assert.assertEquals(message.getHeader("operation"), "foo");
return null;
@@ -166,7 +165,7 @@ public void testSendBuilderWithObjectMessageInstanceAdditionalHeader() {
when(messageEndpoint.getActor()).thenReturn(null);
doAnswer(invocation -> {
Message message = (Message) invocation.getArguments()[0];
- Assert.assertEquals(message.getPayload(Integer.class), new Integer(10));
+ Assert.assertEquals(message.getPayload(Integer.class), Integer.valueOf(10));
Assert.assertNotNull(message.getHeader("operation"));
Assert.assertEquals(message.getHeader("operation"), "foo");
Assert.assertNotNull(message.getHeader("additional"));
@@ -652,7 +651,7 @@ public void testSendBuilderWithDictionary() {
when(messageEndpoint.getActor()).thenReturn(null);
doAnswer(invocation -> {
Message message = (Message) invocation.getArguments()[0];
- Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),
+ Assert.assertEquals(message.getPayload(String.class).replaceAll("\\s", ""),
"{\"TestRequest\":{\"Message\":\"HelloWorld!\"}}");
return null;
}).when(messageProducer).send(any(Message.class), any(TestContext.class));
@@ -685,7 +684,7 @@ public void testSendBuilderWithDictionaryName() {
when(messageEndpoint.getActor()).thenReturn(null);
doAnswer(invocation -> {
Message message = (Message) invocation.getArguments()[0];
- Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),
+ Assert.assertEquals(message.getPayload(String.class).replaceAll("\\s", ""),
"{\"TestRequest\":{\"Message\":\"HelloWorld!\"}}");
return null;
}).when(messageProducer).send(any(Message.class), any(TestContext.class));
diff --git a/core/citrus-base/src/test/java/org/citrusframework/container/TimerTest.java b/core/citrus-base/src/test/java/org/citrusframework/container/TimerTest.java
index 79f6aeba6d..6502a5de5c 100644
--- a/core/citrus-base/src/test/java/org/citrusframework/container/TimerTest.java
+++ b/core/citrus-base/src/test/java/org/citrusframework/container/TimerTest.java
@@ -41,9 +41,9 @@ public class TimerTest extends UnitTestSupport {
/** Logger */
private static final Logger logger = LoggerFactory.getLogger(TimerTest.class);
- private TestAction action = Mockito.mock(TestAction.class);
- private int defaultRepeatCount = 3;
- private long defaultInterval = 50L;
+ private final TestAction action = Mockito.mock(TestAction.class);
+ private final int defaultRepeatCount = 3;
+ private final long defaultInterval = 50L;
@Test
public void shouldSuccessfullyRunTimerWithNestedAction() {
diff --git a/core/citrus-base/src/test/java/org/citrusframework/endpoint/direct/DirectEndpointAdapterTest.java b/core/citrus-base/src/test/java/org/citrusframework/endpoint/direct/DirectEndpointAdapterTest.java
index bf6422c3bb..12e4b79f30 100644
--- a/core/citrus-base/src/test/java/org/citrusframework/endpoint/direct/DirectEndpointAdapterTest.java
+++ b/core/citrus-base/src/test/java/org/citrusframework/endpoint/direct/DirectEndpointAdapterTest.java
@@ -16,6 +16,8 @@
package org.citrusframework.endpoint.direct;
+import java.util.concurrent.Executors;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.context.TestContextFactory;
import org.citrusframework.message.DefaultMessage;
@@ -23,7 +25,6 @@
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageQueue;
import org.citrusframework.message.MessageSelector;
-import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
@@ -61,7 +62,7 @@ public void purgeQueue() {
public void testEndpointAdapter() {
final Message request = new DefaultMessage("Hi! ");
- new SimpleAsyncTaskExecutor().execute(() -> {
+ Executors.newSingleThreadExecutor().execute(() -> {
Message receivedMessage = endpointAdapter.getEndpoint().createConsumer().receive(context, endpointConfiguration.getTimeout());
Assert.assertNotNull(receivedMessage);
Assert.assertEquals(receivedMessage.getPayload(), request.getPayload());
diff --git a/core/citrus-base/src/test/java/org/citrusframework/endpoint/direct/DirectEndpointSyncConsumerTest.java b/core/citrus-base/src/test/java/org/citrusframework/endpoint/direct/DirectEndpointSyncConsumerTest.java
index ba30a917d5..4664201f32 100644
--- a/core/citrus-base/src/test/java/org/citrusframework/endpoint/direct/DirectEndpointSyncConsumerTest.java
+++ b/core/citrus-base/src/test/java/org/citrusframework/endpoint/direct/DirectEndpointSyncConsumerTest.java
@@ -46,12 +46,12 @@
*/
public class DirectEndpointSyncConsumerTest {
- private MessageQueue queue = Mockito.mock(MessageQueue.class);
- private MessageQueue replyQueue = Mockito.mock(MessageQueue.class);
+ private final MessageQueue queue = Mockito.mock(MessageQueue.class);
+ private final MessageQueue replyQueue = Mockito.mock(MessageQueue.class);
- private MessageCorrelator messageCorrelator = Mockito.mock(MessageCorrelator.class);
+ private final MessageCorrelator messageCorrelator = Mockito.mock(MessageCorrelator.class);
- private ReferenceResolver resolver = Mockito.mock(ReferenceResolver.class);
+ private final ReferenceResolver resolver = Mockito.mock(ReferenceResolver.class);
private TestContext context;
@@ -345,7 +345,7 @@ public void testNoCorrelationKeyFound() {
Assert.fail("Missing " + IllegalArgumentException.class + " because no reply destination found");
}
- @Test
+ @Test(expectedExceptions = CitrusRuntimeException.class, expectedExceptionsMessageRegExp = "Failed to find reply channel for message correlation key: 123456789")
public void testNoReplyDestinationFound() {
DirectSyncEndpoint endpoint = new DirectSyncEndpoint();
@@ -361,30 +361,15 @@ public void testNoReplyDestinationFound() {
Map headers = new HashMap<>();
final Message message = new DefaultMessage("Hello World! ", headers);
- try {
- DirectSyncConsumer channelSyncConsumer = (DirectSyncConsumer) endpoint.createConsumer();
- channelSyncConsumer.send(message, context);
- } catch(IllegalArgumentException e) {
- Assert.assertTrue(e.getMessage().startsWith("Failed to find reply channel"));
- return;
- }
-
- Assert.fail("Missing " + IllegalArgumentException.class + " because no reply destination found");
+ DirectSyncConsumer channelSyncConsumer = (DirectSyncConsumer) endpoint.createConsumer();
+ channelSyncConsumer.send(message, context);
}
- @Test
+ @Test(expectedExceptions = CitrusRuntimeException.class, expectedExceptionsMessageRegExp = "Can not send empty message")
public void testSendEmptyMessage() {
DirectSyncEndpoint endpoint = new DirectSyncEndpoint();
-
- try {
- DirectSyncConsumer channelSyncConsumer = (DirectSyncConsumer) endpoint.createConsumer();
- channelSyncConsumer.send(null, context);
- } catch(IllegalArgumentException e) {
- Assert.assertEquals(e.getMessage(), "Can not send empty message");
- return;
- }
-
- Assert.fail("Missing " + IllegalArgumentException.class + " because of sending empty message");
+ DirectSyncConsumer channelSyncConsumer = (DirectSyncConsumer) endpoint.createConsumer();
+ channelSyncConsumer.send(null, context);
}
@Test
diff --git a/core/citrus-base/src/test/java/org/citrusframework/functions/core/LoadMessageFunctionTest.java b/core/citrus-base/src/test/java/org/citrusframework/functions/core/LoadMessageFunctionTest.java
index eeb400bdbf..259aeecea6 100644
--- a/core/citrus-base/src/test/java/org/citrusframework/functions/core/LoadMessageFunctionTest.java
+++ b/core/citrus-base/src/test/java/org/citrusframework/functions/core/LoadMessageFunctionTest.java
@@ -31,9 +31,9 @@
*/
public class LoadMessageFunctionTest extends UnitTestSupport {
- private LoadMessageFunction function = new LoadMessageFunction();
+ private final LoadMessageFunction function = new LoadMessageFunction();
- private Message message = new DefaultMessage("This is a sample message")
+ private final Message message = new DefaultMessage("This is a sample message")
.setHeader("operation", "sampleOperation");
@Test
diff --git a/core/citrus-base/src/test/java/org/citrusframework/message/ZipMessageTest.java b/core/citrus-base/src/test/java/org/citrusframework/message/ZipMessageTest.java
index 9aa701b784..742b27b141 100644
--- a/core/citrus-base/src/test/java/org/citrusframework/message/ZipMessageTest.java
+++ b/core/citrus-base/src/test/java/org/citrusframework/message/ZipMessageTest.java
@@ -16,12 +16,7 @@
package org.citrusframework.message;
-import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.util.FileCopyUtils;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
@@ -29,6 +24,11 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.FileUtils;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
/**
* @author Christoph Deppisch
* @since 2.7.5
@@ -38,9 +38,9 @@ public class ZipMessageTest {
@Test
public void testAddSingleFile() throws Exception {
ZipMessage message = new ZipMessage();
- message.addEntry(new ClassPathResource("org/citrusframework/archive/foo.txt"));
+ message.addEntry(Resources.newClasspathResource("org/citrusframework/archive/foo.txt"));
File archive = new File (createTempDir().toFile(), "archive.zip");
- FileCopyUtils.copy(message.getPayload(), archive);
+ FileUtils.writeToFile(new ByteArrayInputStream(message.getPayload()), archive);
Assert.assertTrue(archive.exists());
@@ -54,9 +54,9 @@ public void testAddSingleFile() throws Exception {
@Test
public void testAddDirectory() throws Exception {
ZipMessage message = new ZipMessage();
- message.addEntry(new ClassPathResource("org/citrusframework/archive"));
+ message.addEntry(Resources.newClasspathResource("org/citrusframework/archive"));
File archive = new File (createTempDir().toFile(), "archive.zip");
- FileCopyUtils.copy(message.getPayload(), archive);
+ FileUtils.writeToFile(new ByteArrayInputStream(message.getPayload()), archive);
Assert.assertTrue(archive.exists());
@@ -80,10 +80,10 @@ public void testNewDirectoryStructure() throws Exception {
ZipMessage message = new ZipMessage();
message.addEntry(new ZipMessage.Entry("foos/")
.addEntry(new ZipMessage.Entry("foo.txt",
- new ClassPathResource("org/citrusframework/archive/foo.txt").getFile())));
+ Resources.newClasspathResource("org/citrusframework/archive/foo.txt").getFile())));
File archive = new File (createTempDir().toFile(), "archive.zip");
- FileCopyUtils.copy(message.getPayload(), archive);
+ FileUtils.writeToFile(new ByteArrayInputStream(message.getPayload()), archive);
Assert.assertTrue(archive.exists());
@@ -102,10 +102,10 @@ public void testEmptyDirectory() throws Exception {
message.addEntry(new ZipMessage.Entry("foos/"));
message.addEntry(new ZipMessage.Entry("bars/")
.addEntry(new ZipMessage.Entry("bar.txt",
- new ClassPathResource("org/citrusframework/archive/bar.txt").getFile())));
+ Resources.newClasspathResource("org/citrusframework/archive/bar.txt").getFile())));
File archive = new File (createTempDir().toFile(), "archive.zip");
- FileCopyUtils.copy(message.getPayload(), archive);
+ FileUtils.writeToFile(new ByteArrayInputStream(message.getPayload()), archive);
Assert.assertTrue(archive.exists());
diff --git a/core/citrus-base/src/test/java/org/citrusframework/util/FileUtilsTest.java b/core/citrus-base/src/test/java/org/citrusframework/util/FileUtilsTest.java
index c63f3bb4ac..4d5bd1a4fe 100644
--- a/core/citrus-base/src/test/java/org/citrusframework/util/FileUtilsTest.java
+++ b/core/citrus-base/src/test/java/org/citrusframework/util/FileUtilsTest.java
@@ -16,11 +16,11 @@
package org.citrusframework.util;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import org.citrusframework.CitrusSettings;
import org.citrusframework.UnitTestSupport;
-import org.springframework.core.io.Resource;
+import org.citrusframework.spi.Resource;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -48,7 +48,7 @@ public void testGetFileResourceExplicitCharset() throws Exception {
@Test
public void testGetCharset() throws Exception {
Assert.assertEquals(FileUtils.getCharset("/path/to/some/file.txt").displayName(), CitrusSettings.CITRUS_FILE_ENCODING);
- Assert.assertEquals(FileUtils.getCharset("/path/to/some/file.txt" + FileUtils.FILE_PATH_CHARSET_PARAMETER + "ISO-8859-1"), Charset.forName("ISO-8859-1"));
+ Assert.assertEquals(FileUtils.getCharset("/path/to/some/file.txt" + FileUtils.FILE_PATH_CHARSET_PARAMETER + "ISO-8859-1"), StandardCharsets.ISO_8859_1);
}
@Test
@@ -57,7 +57,19 @@ public void testGetBaseName() throws Exception {
Assert.assertEquals(FileUtils.getBaseName(""), "");
Assert.assertEquals(FileUtils.getBaseName("foo"), "foo");
Assert.assertEquals(FileUtils.getBaseName("foo.xml"), "foo");
+ Assert.assertEquals(FileUtils.getBaseName("/path/to/some/foo.xml"), "/path/to/some/foo");
Assert.assertEquals(FileUtils.getBaseName("foo.bar.java"), "foo.bar");
}
+ @Test
+ public void testGetFileName() throws Exception {
+ Assert.assertEquals(FileUtils.getFileName(null), "");
+ Assert.assertEquals(FileUtils.getFileName(""), "");
+ Assert.assertEquals(FileUtils.getFileName("foo"), "foo");
+ Assert.assertEquals(FileUtils.getFileName("foo.xml"), "foo.xml");
+ Assert.assertEquals(FileUtils.getFileName("/path/to/some/foo.xml"), "foo.xml");
+ Assert.assertEquals(FileUtils.getFileName("foo.bar.java"), "foo.bar.java");
+ Assert.assertEquals(FileUtils.getFileName("/path/to/some/foo.bar.java"), "foo.bar.java");
+ }
+
}
diff --git a/core/citrus-base/src/test/java/org/citrusframework/validation/TextEqualsMessageValidator.java b/core/citrus-base/src/test/java/org/citrusframework/validation/TextEqualsMessageValidator.java
index d8bfbb2484..0032120cae 100644
--- a/core/citrus-base/src/test/java/org/citrusframework/validation/TextEqualsMessageValidator.java
+++ b/core/citrus-base/src/test/java/org/citrusframework/validation/TextEqualsMessageValidator.java
@@ -1,10 +1,10 @@
package org.citrusframework.validation;
import org.citrusframework.context.TestContext;
+import org.citrusframework.exceptions.ValidationException;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageType;
import org.citrusframework.validation.context.ValidationContext;
-import org.springframework.util.Assert;
/**
* Basic message validator performs String equals on received message payloads. We add this validator in order to have a
@@ -15,8 +15,9 @@ public class TextEqualsMessageValidator extends DefaultMessageValidator {
@Override
public void validateMessage(Message receivedMessage, Message controlMessage, TestContext context, ValidationContext validationContext) {
- Assert.isTrue(receivedMessage.getPayload(String.class).equals(controlMessage.getPayload(String.class)), "Validation failed - " +
- "expected message contents not equal!");
+ if (!receivedMessage.getPayload(String.class).equals(controlMessage.getPayload(String.class))) {
+ throw new ValidationException("Validation failed - expected message contents not equal!");
+ }
}
@Override
diff --git a/core/citrus-base/src/test/java/org/citrusframework/validation/interceptor/BinaryMessageProcessorTest.java b/core/citrus-base/src/test/java/org/citrusframework/validation/interceptor/BinaryMessageProcessorTest.java
index e8bda3699e..d054a8e53b 100644
--- a/core/citrus-base/src/test/java/org/citrusframework/validation/interceptor/BinaryMessageProcessorTest.java
+++ b/core/citrus-base/src/test/java/org/citrusframework/validation/interceptor/BinaryMessageProcessorTest.java
@@ -7,17 +7,16 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.MessageType;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
-import org.springframework.util.FileCopyUtils;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.FileUtils;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
public class BinaryMessageProcessorTest extends UnitTestSupport {
- private BinaryMessageProcessor processor = new BinaryMessageProcessor();
+ private final BinaryMessageProcessor processor = new BinaryMessageProcessor();
@Test
public void testBinaryMessageStaysUntouched(){
@@ -59,7 +58,7 @@ public void testResourceMessageWithIsIntercepted() throws IOException {
processor.process(message, context);
//THEN
- assertEquals(message.getPayload(), FileCopyUtils.copyToByteArray(getTestFile().getInputStream()));
+ assertEquals(message.getPayload(), FileUtils.copyToByteArray(getTestFile().getInputStream()));
assertEquals(message.getType(), MessageType.BINARY.name());
}
@@ -67,7 +66,7 @@ public void testResourceMessageWithIsIntercepted() throws IOException {
public void testMessageResourceNotFound() {
//GIVEN
- final DefaultMessage message = new DefaultMessage(new FileSystemResource("unknown.txt"));
+ final DefaultMessage message = new DefaultMessage(Resources.newFileSystemResource("unknown.txt"));
message.setType(MessageType.PLAINTEXT);
//WHEN
@@ -77,6 +76,6 @@ public void testMessageResourceNotFound() {
}
private Resource getTestFile() {
- return new ClassPathResource("foo.txt", BinaryMessageProcessor.class);
+ return Resources.create("foo.txt", BinaryMessageProcessor.class);
}
}
diff --git a/core/citrus-base/src/test/java/org/citrusframework/validation/interceptor/GzipMessageProcessorTest.java b/core/citrus-base/src/test/java/org/citrusframework/validation/interceptor/GzipMessageProcessorTest.java
index 4eff2b4915..000c0f8e1d 100644
--- a/core/citrus-base/src/test/java/org/citrusframework/validation/interceptor/GzipMessageProcessorTest.java
+++ b/core/citrus-base/src/test/java/org/citrusframework/validation/interceptor/GzipMessageProcessorTest.java
@@ -11,11 +11,9 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.MessageType;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.util.StreamUtils;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.FileUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -26,13 +24,13 @@
*/
public class GzipMessageProcessorTest extends UnitTestSupport {
- private GzipMessageProcessor processor = new GzipMessageProcessor();
+ private final GzipMessageProcessor processor = new GzipMessageProcessor();
@Test
public void testGzipMessageStaysUntouched() throws IOException {
try (ByteArrayOutputStream zipped = new ByteArrayOutputStream()) {
try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(zipped)) {
- StreamUtils.copy("foo".getBytes(StandardCharsets.UTF_8), gzipOutputStream);
+ gzipOutputStream.write("foo".getBytes(StandardCharsets.UTF_8));
//GIVEN
final DefaultMessage message = new DefaultMessage(gzipOutputStream);
@@ -59,11 +57,11 @@ public void testTextMessageIsIntercepted() throws IOException {
//THEN
assertEquals(message.getType(), MessageType.GZIP.name());
- ByteArrayOutputStream unzipped = new ByteArrayOutputStream();
- GZIPInputStream gzipInputStream = new GZIPInputStream(
- new ByteArrayInputStream(message.getPayload(byte[].class)));
- StreamUtils.copy(gzipInputStream, unzipped);
- Assert.assertEquals(unzipped.toByteArray(), "foo".getBytes(StandardCharsets.UTF_8));
+ try (ByteArrayOutputStream unzipped = new ByteArrayOutputStream();
+ GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(message.getPayload(byte[].class)));) {
+ unzipped.write(gzipInputStream.readAllBytes());
+ Assert.assertEquals(unzipped.toByteArray(), "foo".getBytes(StandardCharsets.UTF_8));
+ }
}
@Test
@@ -78,11 +76,11 @@ public void testBinaryMessageIsIntercepted() throws IOException {
//THEN
assertEquals(message.getType(), MessageType.GZIP.name());
- ByteArrayOutputStream unzipped = new ByteArrayOutputStream();
- GZIPInputStream gzipInputStream = new GZIPInputStream(
- new ByteArrayInputStream(message.getPayload(byte[].class)));
- StreamUtils.copy(gzipInputStream, unzipped);
- Assert.assertEquals(unzipped.toByteArray(), "foo".getBytes(StandardCharsets.UTF_8));
+ try (ByteArrayOutputStream unzipped = new ByteArrayOutputStream();
+ GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(message.getPayload(byte[].class)));) {
+ unzipped.write(gzipInputStream.readAllBytes());
+ Assert.assertEquals(unzipped.toByteArray(), "foo".getBytes(StandardCharsets.UTF_8));
+ }
}
@Test
@@ -97,11 +95,11 @@ public void testInputStreamMessageIsIntercepted() throws IOException {
//THEN
assertEquals(message.getType(), MessageType.GZIP.name());
- ByteArrayOutputStream unzipped = new ByteArrayOutputStream();
- GZIPInputStream gzipInputStream = new GZIPInputStream(
- new ByteArrayInputStream(message.getPayload(byte[].class)));
- StreamUtils.copy(gzipInputStream, unzipped);
- Assert.assertEquals(unzipped.toByteArray(), "foo".getBytes(StandardCharsets.UTF_8));
+ try (ByteArrayOutputStream unzipped = new ByteArrayOutputStream();
+ GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(message.getPayload(byte[].class)));) {
+ unzipped.write(gzipInputStream.readAllBytes());
+ Assert.assertEquals(unzipped.toByteArray(), "foo".getBytes(StandardCharsets.UTF_8));
+ }
}
@Test
@@ -116,18 +114,18 @@ public void testResourceMessageIsIntercepted() throws IOException {
//THEN
assertEquals(message.getType(), MessageType.GZIP.name());
- ByteArrayOutputStream unzipped = new ByteArrayOutputStream();
- GZIPInputStream gzipInputStream = new GZIPInputStream(
- new ByteArrayInputStream(message.getPayload(byte[].class)));
- StreamUtils.copy(gzipInputStream, unzipped);
- Assert.assertEquals(unzipped.toByteArray(), FileCopyUtils.copyToByteArray(getTestFile().getInputStream()));
+ try (ByteArrayOutputStream unzipped = new ByteArrayOutputStream();
+ GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(message.getPayload(byte[].class)));) {
+ unzipped.write(gzipInputStream.readAllBytes());
+ Assert.assertEquals(unzipped.toByteArray(), FileUtils.copyToByteArray(getTestFile().getInputStream()));
+ }
}
@Test(expectedExceptions = CitrusRuntimeException.class)
public void testProcessMessageResourceNotFound() {
//GIVEN
- final DefaultMessage message = new DefaultMessage(new FileSystemResource("unknown.txt"));
+ final DefaultMessage message = new DefaultMessage(Resources.newFileSystemResource("unknown.txt"));
message.setType(MessageType.PLAINTEXT);
//WHEN
@@ -137,6 +135,6 @@ public void testProcessMessageResourceNotFound() {
}
private Resource getTestFile() {
- return new ClassPathResource("foo.txt", GzipMessageProcessor.class);
+ return Resources.create("foo.txt", GzipMessageProcessor.class);
}
}
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/common/SpringXmlTestLoader.java b/core/citrus-spring/src/main/java/org/citrusframework/common/SpringXmlTestLoader.java
index b1ddb971d0..1508c9b7c3 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/common/SpringXmlTestLoader.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/common/SpringXmlTestLoader.java
@@ -25,11 +25,11 @@
import org.citrusframework.config.CitrusNamespaceParserRegistry;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
-import org.springframework.util.StringUtils;
/**
* Loads test case as Spring bean from XML application context file. Loader holds application context file
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/CitrusConfigImport.java b/core/citrus-spring/src/main/java/org/citrusframework/config/CitrusConfigImport.java
index b87118b11d..6ed22ed16c 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/CitrusConfigImport.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/CitrusConfigImport.java
@@ -17,9 +17,9 @@
package org.citrusframework.config;
import org.citrusframework.CitrusSpringSettings;
+import org.citrusframework.util.StringUtils;
import org.springframework.context.annotation.DeferredImportSelector;
import org.springframework.core.type.AnnotationMetadata;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/CitrusSpringConfig.java b/core/citrus-spring/src/main/java/org/citrusframework/config/CitrusSpringConfig.java
index 1536ec8e32..9a77dd5ea5 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/CitrusSpringConfig.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/CitrusSpringConfig.java
@@ -16,6 +16,8 @@
package org.citrusframework.config;
+import java.util.Set;
+
import org.citrusframework.context.SpringBeanReferenceResolver;
import org.citrusframework.context.TestContextFactoryBean;
import org.citrusframework.endpoint.DefaultEndpointFactory;
@@ -30,6 +32,7 @@
import org.citrusframework.report.TestSuiteListenersFactory;
import org.citrusframework.reporter.ReporterConfig;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.spi.ResourceConverter;
import org.citrusframework.util.SpringBeanTypeConverter;
import org.citrusframework.util.TypeConverter;
import org.citrusframework.validation.MessageValidatorConfig;
@@ -40,6 +43,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
+import org.springframework.context.support.ConversionServiceFactoryBean;
/**
* @author Christoph Deppisch
@@ -118,4 +122,12 @@ public ComponentLifecycleProcessor componentInitializer() {
public SegmentVariableExtractorRegistry variableExtractorRegistry() {
return new SegmentVariableExtractorRegistry();
}
+
+ @Bean(name = "conversionService")
+ public ConversionServiceFactoryBean conversionService() {
+ ConversionServiceFactoryBean conversionServiceFactoryBean = new ConversionServiceFactoryBean();
+ conversionServiceFactoryBean.setConverters(Set.of(new ResourceConverter()));
+
+ return conversionServiceFactoryBean;
+ }
}
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/util/BeanDefinitionParserUtils.java b/core/citrus-spring/src/main/java/org/citrusframework/config/util/BeanDefinitionParserUtils.java
index 1adc9e6eaa..7c9a1c8c5c 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/util/BeanDefinitionParserUtils.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/util/BeanDefinitionParserUtils.java
@@ -16,17 +16,17 @@
package org.citrusframework.config.util;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
/**
* Provides shared utility methods for bean definition parsing.
- *
+ *
* @author Christoph Deppisch
*/
public abstract class BeanDefinitionParserUtils {
@@ -36,11 +36,11 @@ public abstract class BeanDefinitionParserUtils {
*/
private BeanDefinitionParserUtils() {
}
-
+
/**
- * Sets the property value on bean definition in case value
+ * Sets the property value on bean definition in case value
* is set properly.
- *
+ *
* @param builder the bean definition builder to be configured
* @param propertyValue the property value
* @param propertyName the name of the property
@@ -50,11 +50,11 @@ public static void setPropertyValue(BeanDefinitionBuilder builder, String proper
builder.addPropertyValue(propertyName, propertyValue);
}
}
-
+
/**
- * Sets the property value on bean definition as constructor argument in case value
+ * Sets the property value on bean definition as constructor argument in case value
* is not null.
- *
+ *
* @param builder the bean definition to be configured
* @param propertyValue the property value
*/
@@ -65,9 +65,9 @@ public static void setConstructorArgValue(BeanDefinitionBuilder builder, String
}
/**
- * Sets the property reference on bean definition in case reference
+ * Sets the property reference on bean definition in case reference
* is set properly.
- *
+ *
* @param builder the bean definition builder to be configured
* @param beanReference bean reference to populate the property
* @param propertyName the name of the property
@@ -77,11 +77,11 @@ public static void setPropertyReference(BeanDefinitionBuilder builder, String be
builder.addPropertyReference(propertyName, beanReference);
}
}
-
+
/**
- * Sets the property reference on bean definition in case reference
+ * Sets the property reference on bean definition in case reference
* is set properly.
- *
+ *
* @param builder the bean definition builder to be configured
* @param beanReference bean reference to add as constructor arg
*/
@@ -93,7 +93,7 @@ public static void addConstructorArgReference(BeanDefinitionBuilder builder, Str
/**
* Sets the property reference on bean definition. In case reference is not available a default value is set.
- *
+ *
* @param builder
* @param beanReference
* @param propertyName
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/util/ValidateMessageParserUtil.java b/core/citrus-spring/src/main/java/org/citrusframework/config/util/ValidateMessageParserUtil.java
index f897e9ecdc..c13f8d8752 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/util/ValidateMessageParserUtil.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/util/ValidateMessageParserUtil.java
@@ -16,14 +16,14 @@
package org.citrusframework.config.util;
-import org.springframework.util.StringUtils;
-import org.springframework.util.xml.DomUtils;
-import org.w3c.dom.Element;
-
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.citrusframework.util.StringUtils;
+import org.springframework.util.xml.DomUtils;
+import org.w3c.dom.Element;
+
/**
* Helper for parsing message validation elements.
*
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/AbstractMessageActionParser.java b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/AbstractMessageActionParser.java
index b9aa0158db..a78a2b9038 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/AbstractMessageActionParser.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/AbstractMessageActionParser.java
@@ -36,6 +36,7 @@
import org.citrusframework.message.builder.FileResourceHeaderDataBuilder;
import org.citrusframework.message.builder.FileResourcePayloadBuilder;
import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.builder.DefaultMessageBuilder;
import org.citrusframework.validation.context.HeaderValidationContext;
import org.citrusframework.validation.context.ValidationContext;
@@ -47,7 +48,6 @@
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/AbstractSuiteActionContainerParser.java b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/AbstractSuiteActionContainerParser.java
index a9bb372df1..9007f9b4cd 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/AbstractSuiteActionContainerParser.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/AbstractSuiteActionContainerParser.java
@@ -16,17 +16,19 @@
package org.citrusframework.config.xml;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.citrusframework.container.AbstractSuiteActionContainer;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
-import java.util.*;
-
/**
* @author Christoph Deppisch
* @since 2.0
@@ -40,12 +42,12 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
builder.addPropertyValue("name", element.getAttribute("id"));
if (element.hasAttribute("suites")) {
- List suiteNames = Arrays.asList(StringUtils.commaDelimitedListToStringArray(element.getAttribute("suites")));
+ List suiteNames = Arrays.asList(element.getAttribute("suites").split(","));
builder.addPropertyValue("suiteNames", suiteNames);
}
if (element.hasAttribute("groups")) {
- List groups = Arrays.asList(StringUtils.commaDelimitedListToStringArray(element.getAttribute("groups")));
+ List groups = Arrays.asList(element.getAttribute("groups").split(","));
builder.addPropertyValue("testGroups", groups);
}
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/AbstractTestBoundaryActionContainerParser.java b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/AbstractTestBoundaryActionContainerParser.java
index b9a17d5e09..1bee68abfa 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/AbstractTestBoundaryActionContainerParser.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/AbstractTestBoundaryActionContainerParser.java
@@ -16,18 +16,20 @@
package org.citrusframework.config.xml;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.citrusframework.config.util.BeanDefinitionParserUtils;
import org.citrusframework.container.AbstractTestBoundaryActionContainer;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
-import java.util.*;
-
/**
* @author Christoph Deppisch
* @since 2.0
@@ -44,7 +46,7 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
BeanDefinitionParserUtils.setPropertyValue(builder, element.getAttribute("package"), "packageNamePattern");
if (element.hasAttribute("groups")) {
- List groups = Arrays.asList(StringUtils.commaDelimitedListToStringArray(element.getAttribute("groups")));
+ List groups = Arrays.asList(element.getAttribute("groups").split(","));
builder.addPropertyValue("testGroups", groups);
}
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/ActionParser.java b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/ActionParser.java
index 0df60a5e02..7376d951d4 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/ActionParser.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/ActionParser.java
@@ -16,17 +16,17 @@
package org.citrusframework.config.xml;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
* Bean definition parser for generic test action element.
- *
+ *
* @author Christoph Deppisch
*/
public class ActionParser implements BeanDefinitionParser {
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/BaseTestCaseParser.java b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/BaseTestCaseParser.java
index b3ef3639b8..470f637b35 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/BaseTestCaseParser.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/BaseTestCaseParser.java
@@ -1,8 +1,14 @@
package org.citrusframework.config.xml;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
import org.citrusframework.TestCase;
import org.citrusframework.config.CitrusNamespaceParserRegistry;
import org.citrusframework.config.TestCaseFactory;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.variable.VariableUtils;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -10,15 +16,9 @@
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
/**
* Base test case for parsing the test case
*
@@ -150,4 +150,4 @@ private void parseMetaInfo(BeanDefinitionBuilder testCase, Element element, Pars
testCase.addPropertyValue("metaInfo", metaInfoDefinition);
}
}
-}
\ No newline at end of file
+}
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/IterateParser.java b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/IterateParser.java
index 97c3855eef..414cd6bc67 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/IterateParser.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/IterateParser.java
@@ -17,9 +17,9 @@
package org.citrusframework.config.xml;
import org.citrusframework.container.Iterate;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/JavaActionParser.java b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/JavaActionParser.java
index 46039f0dca..3f6f34623b 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/JavaActionParser.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/JavaActionParser.java
@@ -21,12 +21,12 @@
import org.citrusframework.actions.JavaAction;
import org.citrusframework.config.util.BeanDefinitionParserUtils;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/PurgeEndpointActionParser.java b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/PurgeEndpointActionParser.java
index f53f0407a3..d349ba9931 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/PurgeEndpointActionParser.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/PurgeEndpointActionParser.java
@@ -24,6 +24,7 @@
import org.citrusframework.config.util.BeanDefinitionParserUtils;
import org.citrusframework.context.SpringBeanReferenceResolver;
import org.citrusframework.endpoint.Endpoint;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -33,7 +34,6 @@
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/ReceiveMessageActionParser.java b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/ReceiveMessageActionParser.java
index 876677937f..523589ccfd 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/ReceiveMessageActionParser.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/ReceiveMessageActionParser.java
@@ -31,6 +31,7 @@
import org.citrusframework.config.util.BeanDefinitionParserUtils;
import org.citrusframework.config.util.ValidateMessageParserUtil;
import org.citrusframework.config.util.VariableExtractorParserUtil;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.builder.DefaultMessageBuilder;
import org.citrusframework.validation.context.HeaderValidationContext;
import org.citrusframework.validation.context.SchemaValidationContext;
@@ -48,7 +49,6 @@
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
@@ -301,7 +301,6 @@ private XpathMessageValidationContext getXPathMessageValidationContext(Element m
context.schema(parentContext.getSchema());
context.schemaRepository(parentContext.getSchemaRepository());
context.schemaValidation(parentContext.isSchemaValidationEnabled());
- context.dtd(parentContext.getDTDResource());
return context.build();
}
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/ReceiveTimeoutActionParser.java b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/ReceiveTimeoutActionParser.java
index 2c88be3f28..cad43e8717 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/ReceiveTimeoutActionParser.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/ReceiveTimeoutActionParser.java
@@ -21,12 +21,12 @@
import org.citrusframework.actions.ReceiveTimeoutAction;
import org.citrusframework.config.util.BeanDefinitionParserUtils;
import org.citrusframework.endpoint.Endpoint;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/SchemaRepositoryParser.java b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/SchemaRepositoryParser.java
index 2c487951a9..d23b539c58 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/SchemaRepositoryParser.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/SchemaRepositoryParser.java
@@ -22,6 +22,7 @@
import java.util.stream.Collectors;
import org.citrusframework.spi.ResourcePathTypeResolver;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -30,7 +31,6 @@
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/SendMessageActionParser.java b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/SendMessageActionParser.java
index 9826929283..690e66248e 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/SendMessageActionParser.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/SendMessageActionParser.java
@@ -16,22 +16,20 @@
package org.citrusframework.config.xml;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import org.citrusframework.CitrusSettings;
import org.citrusframework.actions.SendMessageAction;
import org.citrusframework.config.util.BeanDefinitionParserUtils;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.builder.DefaultMessageBuilder;
-import org.citrusframework.validation.context.SchemaValidationContext;
-import org.citrusframework.validation.context.ValidationContext;
-import org.citrusframework.validation.json.JsonMessageValidationContext;
-import org.citrusframework.validation.xml.XmlMessageValidationContext;
import org.citrusframework.variable.VariableExtractor;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/StaticResponseEndpointAdapterParser.java b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/StaticResponseEndpointAdapterParser.java
index a8763e44e4..c93303dee5 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/StaticResponseEndpointAdapterParser.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/StaticResponseEndpointAdapterParser.java
@@ -25,6 +25,7 @@
import org.citrusframework.endpoint.EndpointAdapter;
import org.citrusframework.endpoint.adapter.StaticResponseEndpointAdapter;
import org.citrusframework.message.MessageHeaderType;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,7 +33,6 @@
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/TemplateParser.java b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/TemplateParser.java
index 6f538c5145..3f1aaa0457 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/TemplateParser.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/TemplateParser.java
@@ -21,12 +21,12 @@
import org.citrusframework.TestAction;
import org.citrusframework.container.Template;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/WaitParser.java b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/WaitParser.java
index 344b44d06b..e56373fb85 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/config/xml/WaitParser.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/config/xml/WaitParser.java
@@ -16,6 +16,7 @@
package org.citrusframework.config.xml;
+import org.apache.xerces.util.DOMUtil;
import org.citrusframework.TestAction;
import org.citrusframework.condition.ActionCondition;
import org.citrusframework.condition.Condition;
@@ -26,13 +27,12 @@
import org.citrusframework.config.util.BeanDefinitionParserUtils;
import org.citrusframework.container.Wait;
import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.apache.xerces.util.DOMUtil;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/endpoint/adapter/mapping/ContextLoadingMappingStrategy.java b/core/citrus-spring/src/main/java/org/citrusframework/endpoint/adapter/mapping/ContextLoadingMappingStrategy.java
index 362bec80bf..bb487f9cea 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/endpoint/adapter/mapping/ContextLoadingMappingStrategy.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/endpoint/adapter/mapping/ContextLoadingMappingStrategy.java
@@ -18,11 +18,11 @@
import org.citrusframework.endpoint.EndpointAdapter;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.util.ObjectHelper;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
-import org.springframework.util.Assert;
/**
* Endpoint adapter mapping strategy loads new Spring Application contexts defined by one or more locations
@@ -44,7 +44,7 @@ public class ContextLoadingMappingStrategy implements EndpointAdapterMappingStra
@Override
public EndpointAdapter getEndpointAdapter(String mappingKey) {
- Assert.notNull(contextConfigLocation, "Spring bean application context location must be set properly");
+ ObjectHelper.assertNotNull(contextConfigLocation, "Spring bean application context location must be set properly");
ApplicationContext ctx;
if (loadOnce) {
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/functions/core/EnvironmentPropertyFunction.java b/core/citrus-spring/src/main/java/org/citrusframework/functions/core/EnvironmentPropertyFunction.java
index 85909aeac6..933384f4b6 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/functions/core/EnvironmentPropertyFunction.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/functions/core/EnvironmentPropertyFunction.java
@@ -42,7 +42,7 @@ public class EnvironmentPropertyFunction implements Function, EnvironmentAware {
@Override
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Invalid function parameters - must set environment property name");
}
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/spi/ResourceConverter.java b/core/citrus-spring/src/main/java/org/citrusframework/spi/ResourceConverter.java
new file mode 100644
index 0000000000..388158cac0
--- /dev/null
+++ b/core/citrus-spring/src/main/java/org/citrusframework/spi/ResourceConverter.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2023 the original author or authors.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.spi;
+
+import org.springframework.core.convert.TypeDescriptor;
+import org.springframework.core.convert.converter.ConditionalConverter;
+import org.springframework.core.convert.converter.Converter;
+
+/**
+ * Spring bean converter able to construct proper Citrus resource object from given file path as String.
+ */
+public class ResourceConverter implements Converter, ConditionalConverter {
+
+ @Override
+ public Resource convert(String filePath) {
+ return Resources.create(filePath);
+ }
+
+ @Override
+ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
+ return String.class.isAssignableFrom(sourceType.getObjectType()) && Resource.class.isAssignableFrom(targetType.getObjectType());
+ }
+}
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/util/SpringBeanTypeConverter.java b/core/citrus-spring/src/main/java/org/citrusframework/util/SpringBeanTypeConverter.java
index 7a3954dd54..0f4129d80e 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/util/SpringBeanTypeConverter.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/util/SpringBeanTypeConverter.java
@@ -1,6 +1,8 @@
package org.citrusframework.util;
+import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.io.StringReader;
import java.util.Map;
import java.util.Optional;
@@ -13,9 +15,9 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.SimpleTypeConverter;
import org.springframework.core.io.InputStreamSource;
+import org.springframework.core.io.Resource;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -44,6 +46,33 @@ protected Optional convertBefore(Object target, Class type) {
}
}
+ if (target.getClass().isAssignableFrom(Resource.class)) {
+ Resource resource = (Resource) target;
+ if (File.class.isAssignableFrom(type)) {
+ try {
+ return (Optional) Optional.of(resource.getFile());
+ } catch (IOException e) {
+ throw new CitrusRuntimeException("Failed to access file from resource", e);
+ }
+ }
+
+ if (InputStream.class.isAssignableFrom(type)) {
+ try {
+ return (Optional) Optional.of(resource.getInputStream());
+ } catch (IOException e) {
+ throw new CitrusRuntimeException("Failed to access input stream of resource", e);
+ }
+ }
+
+ if (byte[].class.isAssignableFrom(type)) {
+ try {
+ return (Optional) Optional.of(FileUtils.copyToByteArray(resource.getInputStream()));
+ } catch (IOException e) {
+ throw new CitrusRuntimeException("Failed to access content of resource", e);
+ }
+ }
+ }
+
if (MultiValueMap.class.isAssignableFrom(type)) {
String mapString = String.valueOf(target);
@@ -56,7 +85,7 @@ protected Optional convertBefore(Object target, Class type) {
MultiValueMap map = new LinkedMultiValueMap<>();
for (Map.Entry entry : props.entrySet()) {
String arrayString = String.valueOf(entry.getValue()).replaceAll("^\\[", "").replaceAll("\\]$", "").replaceAll(",\\s", ",");
- map.add(entry.getKey().toString(), StringUtils.commaDelimitedListToStringArray(String.valueOf(arrayString)));
+ map.add(entry.getKey().toString(), arrayString.split(","));
}
return (Optional) Optional.of(map);
diff --git a/core/citrus-spring/src/main/java/org/citrusframework/variable/GlobalVariablesPropertyLoader.java b/core/citrus-spring/src/main/java/org/citrusframework/variable/GlobalVariablesPropertyLoader.java
index 560b471122..69905971d9 100644
--- a/core/citrus-spring/src/main/java/org/citrusframework/variable/GlobalVariablesPropertyLoader.java
+++ b/core/citrus-spring/src/main/java/org/citrusframework/variable/GlobalVariablesPropertyLoader.java
@@ -25,13 +25,13 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.functions.FunctionRegistry;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.util.StringUtils;
/**
* Loads properties from an external property file and creates global test variables.
@@ -65,9 +65,12 @@ public void afterPropertiesSet() {
try {
if (propertyFilesSet()) {
for (String propertyFilePath : propertyFiles) {
- Resource propertyFile = new PathMatchingResourcePatternResolver().getResource(propertyFilePath.trim());
-
- logger.debug("Reading property file " + propertyFile.getFilename());
+ Resource propertyFile = Resources.create(propertyFilePath.trim());
+ if (!propertyFile.exists()) {
+ throw new CitrusRuntimeException(String.format("Error while loading property file %s - does not exist",
+ propertyFile.getLocation()));
+ }
+ logger.debug("Reading property file " + propertyFile.getLocation());
// Use input stream as this also allows to read from resources in a JAR file
reader = new BufferedReader(new InputStreamReader(propertyFile.getInputStream()));
@@ -110,7 +113,7 @@ public void afterPropertiesSet() {
context.setVariable(key, globalVariables.getVariables().get(key));
}
- logger.info("Loaded property file " + propertyFile.getFilename());
+ logger.info("Loaded property file " + propertyFile.getLocation());
}
}
} catch (IOException e) {
@@ -131,8 +134,7 @@ private boolean propertyFilesSet() {
}
private boolean isPropertyLine(String line) {
- return StringUtils.hasText(line) && !line.startsWith("#")
- && line.indexOf('=') > -1;
+ return StringUtils.hasText(line) && !line.startsWith("#") && line.indexOf('=') > -1;
}
/**
diff --git a/core/citrus-spring/src/test/java/org/citrusframework/config/xml/StaticResponseEndpointAdapterParserTest.java b/core/citrus-spring/src/test/java/org/citrusframework/config/xml/StaticResponseEndpointAdapterParserTest.java
index e9f905489f..9766c8be2a 100644
--- a/core/citrus-spring/src/test/java/org/citrusframework/config/xml/StaticResponseEndpointAdapterParserTest.java
+++ b/core/citrus-spring/src/test/java/org/citrusframework/config/xml/StaticResponseEndpointAdapterParserTest.java
@@ -20,7 +20,6 @@
import org.citrusframework.endpoint.adapter.StaticResponseEndpointAdapter;
import org.citrusframework.testng.AbstractBeanDefinitionParserTest;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -38,7 +37,7 @@ public void testParseBeanDefinition() throws Exception {
// 1st endpoint adapter
StaticResponseEndpointAdapter adapter = adapters.get("endpointAdapter1");
- Assert.assertEquals(StringUtils.trimAllWhitespace(adapter.getMessagePayload()), "Hello! ");
+ Assert.assertEquals(adapter.getMessagePayload().replaceAll("\\s", ""), "Hello! ");
Assert.assertEquals(adapter.getMessageHeader().get("Operation"), "sayHello");
adapter = adapters.get("endpointAdapter2");
diff --git a/core/citrus-spring/src/test/java/org/citrusframework/config/xml/TransformActionParserTest.java b/core/citrus-spring/src/test/java/org/citrusframework/config/xml/TransformActionParserTest.java
index 0c548513c2..64e02c4bd9 100644
--- a/core/citrus-spring/src/test/java/org/citrusframework/config/xml/TransformActionParserTest.java
+++ b/core/citrus-spring/src/test/java/org/citrusframework/config/xml/TransformActionParserTest.java
@@ -16,12 +16,11 @@
package org.citrusframework.config.xml;
-import org.springframework.util.StringUtils;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
import org.citrusframework.actions.TransformAction;
import org.citrusframework.testng.AbstractActionParserTest;
+import org.citrusframework.util.StringUtils;
+import org.testng.Assert;
+import org.testng.annotations.Test;
/**
* @author Christoph Deppisch
@@ -32,14 +31,14 @@ public class TransformActionParserTest extends AbstractActionParserTest routeIds) {
@Override
public final T build() {
if (camelContext == null) {
- Assert.notNull(referenceResolver, "Citrus bean reference resolver is not initialized!");
+ ObjectHelper.assertNotNull(referenceResolver, "Citrus bean reference resolver is not initialized!");
if (referenceResolver.isResolvable("citrusCamelContext")) {
camelContext = referenceResolver.resolve("citrusCamelContext", ModelCamelContext.class);
diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelActionBuilder.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelActionBuilder.java
index be45483218..fdc383a79e 100644
--- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelActionBuilder.java
+++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelActionBuilder.java
@@ -19,12 +19,12 @@
package org.citrusframework.camel.actions;
+import org.apache.camel.CamelContext;
import org.citrusframework.TestAction;
import org.citrusframework.TestActionBuilder;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
-import org.apache.camel.CamelContext;
-import org.springframework.util.Assert;
+import org.citrusframework.util.ObjectHelper;
/**
* @author Christoph Deppisch
@@ -85,7 +85,7 @@ public CamelActionBuilder withReferenceResolver(ReferenceResolver referenceResol
@Override
public TestAction build() {
- Assert.notNull(delegate, "Missing delegate action to build");
+ ObjectHelper.assertNotNull(delegate, "Missing delegate action to build");
return delegate.build();
}
diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelControlBusAction.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelControlBusAction.java
index d2eb2b3f3d..87dab4da8c 100644
--- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelControlBusAction.java
+++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelControlBusAction.java
@@ -16,18 +16,18 @@
package org.citrusframework.camel.actions;
+import org.apache.camel.ServiceStatus;
import org.citrusframework.CitrusSettings;
import org.citrusframework.camel.endpoint.CamelSyncEndpoint;
import org.citrusframework.camel.endpoint.CamelSyncEndpointConfiguration;
import org.citrusframework.context.TestContext;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.ValidationUtils;
import org.citrusframework.variable.VariableUtils;
-import org.apache.camel.ServiceStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRouteActionBuilder.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRouteActionBuilder.java
index a3c06b0cc4..0b352d38d7 100644
--- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRouteActionBuilder.java
+++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRouteActionBuilder.java
@@ -1,13 +1,13 @@
package org.citrusframework.camel.actions;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.ModelCamelContext;
import org.citrusframework.TestActionBuilder;
import org.citrusframework.camel.message.CamelRouteProcessor;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
-import org.apache.camel.CamelContext;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.model.ModelCamelContext;
-import org.springframework.util.Assert;
+import org.citrusframework.util.ObjectHelper;
/**
* Action builder.
@@ -44,7 +44,7 @@ public CamelRouteProcessor.Builder processor() {
* @return
*/
public CamelRouteActionBuilder context(String camelContext) {
- Assert.notNull(referenceResolver, "Citrus bean reference resolver is not initialized!");
+ ObjectHelper.assertNotNull(referenceResolver, "Citrus bean reference resolver is not initialized!");
this.camelContext = referenceResolver.resolve(camelContext, ModelCamelContext.class);
return this;
}
@@ -150,7 +150,7 @@ public CamelRouteActionBuilder withReferenceResolver(ReferenceResolver reference
@Override
public AbstractCamelRouteAction build() {
- Assert.notNull(delegate, "Missing delegate action to build");
+ ObjectHelper.assertNotNull(delegate, "Missing delegate action to build");
return delegate.build();
}
diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelRouteAction.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelRouteAction.java
index e7e9f0b437..065d14073e 100644
--- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelRouteAction.java
+++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelRouteAction.java
@@ -26,11 +26,10 @@
import org.citrusframework.camel.util.CamelUtils;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.xml.StringSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.BeanDefinitionStoreException;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -73,7 +72,7 @@ public void doExecute(TestContext context) {
CamelRouteContextFactoryBean.class, value.getClass()));
}
} catch (JAXBException e) {
- throw new BeanDefinitionStoreException("Failed to create the JAXB unmarshaller", e);
+ throw new CitrusRuntimeException("Failed to create the JAXB unmarshaller", e);
}
} else {
routesToUse = routes;
diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelEndpointConfigParser.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelEndpointConfigParser.java
index 06f0d6a875..9796306ef7 100644
--- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelEndpointConfigParser.java
+++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelEndpointConfigParser.java
@@ -19,14 +19,14 @@
package org.citrusframework.camel.config.annotation;
+import org.apache.camel.CamelContext;
import org.citrusframework.TestActor;
import org.citrusframework.camel.endpoint.CamelEndpoint;
import org.citrusframework.camel.endpoint.CamelEndpointBuilder;
import org.citrusframework.camel.message.CamelMessageConverter;
import org.citrusframework.config.annotation.AnnotationConfigParser;
import org.citrusframework.spi.ReferenceResolver;
-import org.apache.camel.CamelContext;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelSyncEndpointConfigParser.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelSyncEndpointConfigParser.java
index 95096e6238..3e0cdcb2a7 100644
--- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelSyncEndpointConfigParser.java
+++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelSyncEndpointConfigParser.java
@@ -19,6 +19,7 @@
package org.citrusframework.camel.config.annotation;
+import org.apache.camel.CamelContext;
import org.citrusframework.TestActor;
import org.citrusframework.camel.endpoint.CamelSyncEndpoint;
import org.citrusframework.camel.endpoint.CamelSyncEndpointBuilder;
@@ -26,8 +27,7 @@
import org.citrusframework.config.annotation.AnnotationConfigParser;
import org.citrusframework.message.MessageCorrelator;
import org.citrusframework.spi.ReferenceResolver;
-import org.apache.camel.CamelContext;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelSyncConsumer.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelSyncConsumer.java
index f45114e3ff..1d461a2062 100644
--- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelSyncConsumer.java
+++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelSyncConsumer.java
@@ -18,6 +18,7 @@
import java.util.Map;
+import org.apache.camel.Exchange;
import org.citrusframework.camel.message.CamelMessageHeaders;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
@@ -27,10 +28,9 @@
import org.citrusframework.message.correlation.CorrelationManager;
import org.citrusframework.message.correlation.PollingCorrelationManager;
import org.citrusframework.messaging.ReplyProducer;
-import org.apache.camel.Exchange;
+import org.citrusframework.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
/**
* @author Christoph Deppisch
@@ -100,12 +100,12 @@ public Message receive(TestContext context, long timeout) {
@Override
public void send(Message message, TestContext context) {
- Assert.notNull(message, "Message is empty - unable to send empty message");
+ ObjectHelper.assertNotNull(message, "Message is empty - unable to send empty message");
String correlationKeyName = endpointConfiguration.getCorrelator().getCorrelationKeyName(getName());
String correlationKey = correlationManager.getCorrelationKey(correlationKeyName, context);
Exchange exchange = correlationManager.find(correlationKey, endpointConfiguration.getTimeout());
- Assert.notNull(exchange, "Failed to find camel exchange for message correlation key: '" + correlationKey + "'");
+ ObjectHelper.assertNotNull(exchange, "Failed to find camel exchange for message correlation key: '" + correlationKey + "'");
buildOutMessage(exchange, message);
diff --git a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CreateCamelRouteActionParserTest.java b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CreateCamelRouteActionParserTest.java
index 159d0d7ecf..a580f5eaa8 100644
--- a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CreateCamelRouteActionParserTest.java
+++ b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CreateCamelRouteActionParserTest.java
@@ -16,10 +16,9 @@
package org.citrusframework.camel.config.xml;
+import org.apache.camel.CamelContext;
import org.citrusframework.camel.actions.CreateCamelRouteAction;
import org.citrusframework.testng.AbstractActionParserTest;
-import org.apache.camel.CamelContext;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -33,7 +32,7 @@ public void testCreateRouteActionParser() {
CreateCamelRouteAction action = getNextTestActionFromTest();
Assert.assertNotNull(action.getCamelContext());
Assert.assertEquals(action.getCamelContext(), beanDefinitionContext.getBean("citrusCamelContext", CamelContext.class));
- Assert.assertEquals(StringUtils.trimAllWhitespace(action.getRouteContext()), ("" +
+ Assert.assertEquals(action.getRouteContext().replaceAll("\\s", ""), ("" +
"" +
"" +
"" +
@@ -49,7 +48,7 @@ public void testCreateRouteActionParser() {
action = getNextTestActionFromTest();
Assert.assertNotNull(action.getCamelContext());
Assert.assertEquals(action.getCamelContext(), beanDefinitionContext.getBean("camelContext", CamelContext.class));
- Assert.assertEquals(StringUtils.trimAllWhitespace(action.getRouteContext()), ("" +
+ Assert.assertEquals(action.getRouteContext().replaceAll("\\s", ""), ("" +
"" +
"" +
"" +
diff --git a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/groovy/CreateRoutesTest.java b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/groovy/CreateRoutesTest.java
index 4db33b885a..be68e1d02f 100644
--- a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/groovy/CreateRoutesTest.java
+++ b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/groovy/CreateRoutesTest.java
@@ -25,7 +25,6 @@
import org.citrusframework.TestCaseMetaInfo;
import org.citrusframework.camel.actions.CreateCamelRouteAction;
import org.citrusframework.groovy.GroovyTestLoader;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -59,7 +58,7 @@ public void shouldLoadCamelActions() throws Exception {
CreateCamelRouteAction action = (CreateCamelRouteAction) result.getTestAction(actionIndex++);
Assert.assertNotNull(action.getCamelContext());
Assert.assertEquals(action.getCamelContext(), context.getReferenceResolver().resolve("citrusCamelContext", CamelContext.class));
- Assert.assertEquals(StringUtils.trimAllWhitespace(action.getRouteContext()), ("" +
+ Assert.assertEquals(action.getRouteContext().replaceAll("\\s", ""), ("" +
"" +
"" +
"" +
@@ -74,7 +73,7 @@ public void shouldLoadCamelActions() throws Exception {
action = (CreateCamelRouteAction) result.getTestAction(actionIndex);
Assert.assertNotNull(action.getCamelContext());
Assert.assertEquals(action.getCamelContext(), context.getReferenceResolver().resolve("camelContext", CamelContext.class));
- Assert.assertEquals(StringUtils.trimAllWhitespace(action.getRouteContext()), ("" +
+ Assert.assertEquals(action.getRouteContext().replaceAll("\\s", ""), ("" +
"" +
"" +
"" +
diff --git a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/yaml/CreateRoutesTest.java b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/yaml/CreateRoutesTest.java
index ee0c64c576..651429f234 100644
--- a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/yaml/CreateRoutesTest.java
+++ b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/yaml/CreateRoutesTest.java
@@ -25,7 +25,6 @@
import org.citrusframework.TestCaseMetaInfo;
import org.citrusframework.camel.actions.CreateCamelRouteAction;
import org.citrusframework.yaml.YamlTestLoader;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -59,7 +58,7 @@ public void shouldLoadCamelActions() throws Exception {
CreateCamelRouteAction action = (CreateCamelRouteAction) result.getTestAction(actionIndex++);
Assert.assertNotNull(action.getCamelContext());
Assert.assertEquals(action.getCamelContext(), context.getReferenceResolver().resolve("citrusCamelContext", CamelContext.class));
- Assert.assertEquals(StringUtils.trimAllWhitespace(action.getRouteContext()), ("" +
+ Assert.assertEquals(action.getRouteContext().replaceAll("\\s", ""), ("" +
"" +
"" +
"" +
@@ -74,7 +73,7 @@ public void shouldLoadCamelActions() throws Exception {
action = (CreateCamelRouteAction) result.getTestAction(actionIndex);
Assert.assertNotNull(action.getCamelContext());
Assert.assertEquals(action.getCamelContext(), context.getReferenceResolver().resolve("camelContext", CamelContext.class));
- Assert.assertEquals(StringUtils.trimAllWhitespace(action.getRouteContext()), ("" +
+ Assert.assertEquals(action.getRouteContext().replaceAll("\\s", ""), ("" +
"" +
"" +
"" +
diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/FtpClient.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/FtpClient.java
index db79fef625..76602f898d 100644
--- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/FtpClient.java
+++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/FtpClient.java
@@ -27,6 +27,15 @@
import java.util.Optional;
import java.util.TimeZone;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.net.ProtocolCommandEvent;
+import org.apache.commons.net.ProtocolCommandListener;
+import org.apache.commons.net.ftp.FTP;
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.ftp.FTPClientConfig;
+import org.apache.commons.net.ftp.FTPFile;
+import org.apache.commons.net.ftp.FTPReply;
+import org.apache.ftpserver.ftplet.DataType;
import org.citrusframework.common.InitializingPhase;
import org.citrusframework.common.ShutdownPhase;
import org.citrusframework.context.TestContext;
@@ -47,19 +56,9 @@
import org.citrusframework.messaging.ReplyConsumer;
import org.citrusframework.messaging.SelectiveConsumer;
import org.citrusframework.util.FileUtils;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.net.ProtocolCommandEvent;
-import org.apache.commons.net.ProtocolCommandListener;
-import org.apache.commons.net.ftp.FTP;
-import org.apache.commons.net.ftp.FTPClient;
-import org.apache.commons.net.ftp.FTPClientConfig;
-import org.apache.commons.net.ftp.FTPFile;
-import org.apache.commons.net.ftp.FTPReply;
-import org.apache.ftpserver.ftplet.DataType;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.util.StringUtils;
import static org.apache.commons.net.ftp.FTPReply.FILE_ACTION_OK;
@@ -343,7 +342,7 @@ protected FtpMessage retrieveFile(GetCommand command, TestContext context) {
if (getEndpointConfiguration().isAutoReadFiles()) {
String fileContent;
if (command.getFile().getType().equals(DataType.BINARY.name())) {
- fileContent = Base64.encodeBase64String(FileCopyUtils.copyToByteArray(FileUtils.getFileResource(localFilePath).getInputStream()));
+ fileContent = Base64.encodeBase64String(FileUtils.copyToByteArray(FileUtils.getFileResource(localFilePath)));
} else {
fileContent = FileUtils.readToString(FileUtils.getFileResource(localFilePath));
}
diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/ScpClient.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/ScpClient.java
index 2decb862ce..2dc0d54c87 100644
--- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/ScpClient.java
+++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/ScpClient.java
@@ -20,6 +20,14 @@
import java.io.IOException;
import java.util.Optional;
+import org.apache.sshd.client.SshClient;
+import org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier;
+import org.apache.sshd.client.keyverifier.KnownHostsServerKeyVerifier;
+import org.apache.sshd.client.keyverifier.RejectAllServerKeyVerifier;
+import org.apache.sshd.client.session.ClientSession;
+import org.apache.sshd.common.keyprovider.ClassLoadableResourceKeyPairProvider;
+import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
+import org.apache.sshd.scp.client.DefaultScpClientCreator;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.ftp.message.FtpMessage;
@@ -28,19 +36,11 @@
import org.citrusframework.ftp.model.GetCommand;
import org.citrusframework.ftp.model.ListCommand;
import org.citrusframework.ftp.model.PutCommand;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
-import org.apache.sshd.client.SshClient;
-import org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier;
-import org.apache.sshd.client.keyverifier.KnownHostsServerKeyVerifier;
-import org.apache.sshd.client.keyverifier.RejectAllServerKeyVerifier;
-import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.common.keyprovider.ClassLoadableResourceKeyPairProvider;
-import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
-import org.apache.sshd.scp.client.DefaultScpClientCreator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
/**
* @author Christoph Deppisch
@@ -135,8 +135,8 @@ protected void connectAndLogin() {
if (getPrivateKeyPath() != null) {
Resource privateKey = FileUtils.getFileResource(getPrivateKeyPath());
- if (privateKey instanceof ClassPathResource) {
- new ClassLoadableResourceKeyPairProvider(privateKey.getFile().getPath()).loadKeys(session).forEach(session::addPublicKeyIdentity);
+ if (privateKey instanceof Resources.ClasspathResource) {
+ new ClassLoadableResourceKeyPairProvider(privateKey.getLocation()).loadKeys(session).forEach(session::addPublicKeyIdentity);
} else {
new FileKeyPairProvider(privateKey.getFile().toPath()).loadKeys(session).forEach(session::addPublicKeyIdentity);
}
diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/SftpClient.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/SftpClient.java
index 0920c57161..18365d133d 100644
--- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/SftpClient.java
+++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/SftpClient.java
@@ -29,15 +29,6 @@
import java.util.Optional;
import java.util.Vector;
-import org.citrusframework.context.TestContext;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.ftp.message.FtpMessage;
-import org.citrusframework.ftp.model.CommandType;
-import org.citrusframework.ftp.model.DeleteCommand;
-import org.citrusframework.ftp.model.GetCommand;
-import org.citrusframework.ftp.model.ListCommand;
-import org.citrusframework.ftp.model.PutCommand;
-import org.citrusframework.util.FileUtils;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
@@ -50,11 +41,19 @@
import org.apache.commons.net.ftp.FTPReply;
import org.apache.ftpserver.ftplet.DataType;
import org.apache.sshd.client.keyverifier.KnownHostsServerKeyVerifier;
+import org.citrusframework.context.TestContext;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.ftp.message.FtpMessage;
+import org.citrusframework.ftp.model.CommandType;
+import org.citrusframework.ftp.model.DeleteCommand;
+import org.citrusframework.ftp.model.GetCommand;
+import org.citrusframework.ftp.model.ListCommand;
+import org.citrusframework.ftp.model.PutCommand;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.util.ResourceUtils;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -220,7 +219,7 @@ protected FtpMessage retrieveFile(GetCommand command, TestContext context) {
String localFilePath = addFileNameToTargetPath(remoteFilePath, context.replaceDynamicContentInString(command.getTarget().getPath()));
try (InputStream inputStream = sftp.get(remoteFilePath)) {
- byte[] bytes = FileCopyUtils.copyToByteArray(inputStream);
+ byte[] bytes = FileUtils.copyToByteArray(inputStream);
// create intermediate directories if necessary
Path localFilePathObj = Paths.get(localFilePath);
@@ -234,7 +233,7 @@ protected FtpMessage retrieveFile(GetCommand command, TestContext context) {
if (getEndpointConfiguration().isAutoReadFiles()) {
String fileContent;
if (command.getFile().getType().equals(DataType.BINARY.name())) {
- fileContent = Base64.encodeBase64String(FileCopyUtils.copyToByteArray(FileUtils.getFileResource(localFilePath).getInputStream()));
+ fileContent = Base64.encodeBase64String(FileUtils.copyToByteArray(FileUtils.getFileResource(localFilePath)));
} else {
fileContent = FileUtils.readToString(FileUtils.getFileResource(localFilePath));
}
@@ -303,21 +302,22 @@ private void setKnownHosts() {
ssh.setKnownHosts(FileUtils.getFileResource(getEndpointConfiguration().getKnownHosts()).getInputStream());
} catch (JSchException e) {
throw new CitrusRuntimeException("Cannot add known hosts from " + getEndpointConfiguration().getKnownHosts() + ": " + e,e);
- } catch (IOException e) {
- throw new CitrusRuntimeException("Cannot find known hosts file " + getEndpointConfiguration().getKnownHosts() + ": " + e,e);
}
}
protected String getPrivateKeyPath() throws IOException {
if (!StringUtils.hasText(getEndpointConfiguration().getPrivateKeyPath())) {
return null;
- } else if (getEndpointConfiguration().getPrivateKeyPath().startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
+ } else if (getEndpointConfiguration().getPrivateKeyPath().startsWith(Resources.CLASSPATH_RESOURCE_PREFIX)) {
File priv = File.createTempFile("citrus-sftp","priv");
- InputStream is = getClass().getClassLoader().getResourceAsStream(getEndpointConfiguration().getPrivateKeyPath().substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()));
- if (is == null) {
- throw new CitrusRuntimeException("No private key found at " + getEndpointConfiguration().getPrivateKeyPath());
+ try (InputStream is = getClass().getClassLoader().getResourceAsStream(getEndpointConfiguration().getPrivateKeyPath().substring(Resources.CLASSPATH_RESOURCE_PREFIX.length()));
+ FileOutputStream fos = new FileOutputStream(priv)) {
+ if (is == null) {
+ throw new CitrusRuntimeException("No private key found at " + getEndpointConfiguration().getPrivateKeyPath());
+ }
+ fos.write(is.readAllBytes());
+ fos.flush();
}
- FileCopyUtils.copy(is, new FileOutputStream(priv));
return priv.getAbsolutePath();
} else {
return getEndpointConfiguration().getPrivateKeyPath();
diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/FtpClientConfigParser.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/FtpClientConfigParser.java
index 405158455f..3fd7895d26 100644
--- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/FtpClientConfigParser.java
+++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/FtpClientConfigParser.java
@@ -22,7 +22,7 @@
import org.citrusframework.ftp.client.FtpClientBuilder;
import org.citrusframework.message.MessageCorrelator;
import org.citrusframework.spi.ReferenceResolver;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/FtpServerConfigParser.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/FtpServerConfigParser.java
index 2c5fecf6d5..d4e2603efd 100644
--- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/FtpServerConfigParser.java
+++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/FtpServerConfigParser.java
@@ -16,15 +16,15 @@
package org.citrusframework.ftp.config.annotation;
+import org.apache.ftpserver.ftplet.UserManager;
import org.citrusframework.TestActor;
import org.citrusframework.config.annotation.AnnotationConfigParser;
import org.citrusframework.endpoint.EndpointAdapter;
import org.citrusframework.ftp.server.FtpServer;
import org.citrusframework.ftp.server.FtpServerBuilder;
import org.citrusframework.spi.ReferenceResolver;
-import org.apache.ftpserver.ftplet.UserManager;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.util.StringUtils;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -59,7 +59,7 @@ public FtpServer parse(FtpServerConfig annotation, ReferenceResolver referenceRe
}
if (StringUtils.hasText(annotation.userManagerProperties())) {
- builder.userManagerProperties(new PathMatchingResourcePatternResolver().getResource(annotation.userManagerProperties()));
+ builder.userManagerProperties(Resources.create(annotation.userManagerProperties()));
}
if (StringUtils.hasText(annotation.actor())) {
diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/ScpClientConfigParser.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/ScpClientConfigParser.java
index 1bcd16bc24..c3002e490f 100644
--- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/ScpClientConfigParser.java
+++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/ScpClientConfigParser.java
@@ -22,7 +22,7 @@
import org.citrusframework.ftp.client.ScpClientBuilder;
import org.citrusframework.message.MessageCorrelator;
import org.citrusframework.spi.ReferenceResolver;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/SftpClientConfigParser.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/SftpClientConfigParser.java
index c458204d65..896c86d4c1 100644
--- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/SftpClientConfigParser.java
+++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/SftpClientConfigParser.java
@@ -24,7 +24,7 @@
import org.citrusframework.ftp.client.SftpClientBuilder;
import org.citrusframework.message.MessageCorrelator;
import org.citrusframework.spi.ReferenceResolver;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/SftpServerConfigParser.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/SftpServerConfigParser.java
index 2fa14a60c0..023acc1f34 100644
--- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/SftpServerConfigParser.java
+++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/config/annotation/SftpServerConfigParser.java
@@ -22,7 +22,7 @@
import org.citrusframework.ftp.server.SftpServer;
import org.citrusframework.ftp.server.SftpServerBuilder;
import org.citrusframework.spi.ReferenceResolver;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/message/FtpMarshaller.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/message/FtpMarshaller.java
index 681d8c930c..dc25f658b1 100644
--- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/message/FtpMarshaller.java
+++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/message/FtpMarshaller.java
@@ -22,6 +22,11 @@
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import jakarta.xml.bind.JAXBException;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.ftp.model.Command;
import org.citrusframework.ftp.model.CommandResult;
@@ -35,18 +40,13 @@
import org.citrusframework.ftp.model.PutCommand;
import org.citrusframework.ftp.model.PutCommandResult;
import org.citrusframework.message.MessageType;
+import org.citrusframework.spi.Resources;
import org.citrusframework.xml.Jaxb2Marshaller;
import org.citrusframework.xml.Marshaller;
import org.citrusframework.xml.StringResult;
import org.citrusframework.xml.Unmarshaller;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import jakarta.xml.bind.JAXBException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
/**
* @author Christoph Deppisch
@@ -83,7 +83,7 @@ public class FtpMarshaller implements Marshaller, Unmarshaller {
*/
public FtpMarshaller() {
this.mapper = new ObjectMapper();
- this.marshaller = new Jaxb2Marshaller(new ClassPathResource("org/citrusframework/schema/citrus-ftp-message.xsd"), classesToBeBound);
+ this.marshaller = new Jaxb2Marshaller(Resources.newClasspathResource("org/citrusframework/schema/citrus-ftp-message.xsd"), classesToBeBound);
type = System.getProperty(JDBC_MARSHALLER_TYPE_PROPERTY, MessageType.XML.name());
diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/message/FtpMessage.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/message/FtpMessage.java
index 4c9b70965b..32a5eb54a6 100644
--- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/message/FtpMessage.java
+++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/message/FtpMessage.java
@@ -19,6 +19,9 @@
import java.util.List;
import java.util.Optional;
+import org.apache.commons.net.ftp.FTPCmd;
+import org.apache.commons.net.ftp.FTPReply;
+import org.apache.ftpserver.ftplet.DataType;
import org.citrusframework.ftp.model.Command;
import org.citrusframework.ftp.model.CommandResult;
import org.citrusframework.ftp.model.CommandResultType;
@@ -35,12 +38,9 @@
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.xml.StringResult;
import org.citrusframework.xml.StringSource;
-import org.apache.commons.net.ftp.FTPCmd;
-import org.apache.commons.net.ftp.FTPReply;
-import org.apache.ftpserver.ftplet.DataType;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -53,7 +53,7 @@ public class FtpMessage extends DefaultMessage {
private CommandType command;
private CommandResultType commandResult;
- private FtpMarshaller marshaller = new FtpMarshaller();
+ private final FtpMarshaller marshaller = new FtpMarshaller();
/**
* Constructs copy of given message.
@@ -122,7 +122,7 @@ public static FtpMessage put(String localPath) {
* @return
*/
public static FtpMessage put(String localPath, DataType type) {
- return put(localPath, FileUtils.getFileResource(localPath).getFilename(), type);
+ return put(localPath, FileUtils.getFileName(FileUtils.getFileResource(localPath).getLocation()), type);
}
/**
@@ -163,7 +163,7 @@ public static FtpMessage get(String remotePath) {
* @return
*/
public static FtpMessage get(String remotePath, DataType type) {
- return get(remotePath, FileUtils.getFileResource(remotePath).getFilename(), type);
+ return get(remotePath, FileUtils.getFileName(FileUtils.getFileResource(remotePath).getLocation()), type);
}
/**
diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServer.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServer.java
index fa2e8b79f7..34c5071ec3 100644
--- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServer.java
+++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServer.java
@@ -16,13 +16,9 @@
package org.citrusframework.ftp.server;
-import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.ftp.client.FtpEndpointConfiguration;
-import org.citrusframework.server.AbstractServer;
import org.apache.ftpserver.FtpServerFactory;
import org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory;
import org.apache.ftpserver.ftplet.FtpException;
@@ -30,7 +26,10 @@
import org.apache.ftpserver.ftplet.UserManager;
import org.apache.ftpserver.listener.ListenerFactory;
import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory;
-import org.springframework.core.io.Resource;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.ftp.client.FtpEndpointConfiguration;
+import org.citrusframework.server.AbstractServer;
+import org.citrusframework.spi.Resource;
/**
* @author Christoph Deppisch
@@ -49,8 +48,8 @@ public class FtpServer extends AbstractServer {
/** Property file holding ftp user information */
private Resource userManagerProperties;
- /** Do only start one instance after another so we need a static lock object */
- private static Object serverLock = new Object();
+ /** Do only start one instance after another, so we need a static lock object */
+ private static final Object serverLock = new Object();
/**
* Default constructor using default endpoint configuration.
@@ -78,11 +77,7 @@ protected void startup() {
serverFactory.setUserManager(userManager);
} else if (userManagerProperties != null) {
PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
- try {
- userManagerFactory.setFile(userManagerProperties.getFile());
- } catch (IOException e) {
- throw new CitrusRuntimeException("Failed to load user manager properties", e);
- }
+ userManagerFactory.setFile(userManagerProperties.getFile());
serverFactory.setUserManager(userManagerFactory.createUserManager());
}
diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServerBuilder.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServerBuilder.java
index 97c23e8430..276fde95fa 100644
--- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServerBuilder.java
+++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServerBuilder.java
@@ -16,13 +16,13 @@
package org.citrusframework.ftp.server;
+import org.apache.ftpserver.ftplet.UserManager;
+import org.apache.ftpserver.listener.ListenerFactory;
import org.citrusframework.ftp.message.FtpMarshaller;
import org.citrusframework.message.ErrorHandlingStrategy;
import org.citrusframework.message.MessageCorrelator;
import org.citrusframework.server.AbstractServerBuilder;
-import org.apache.ftpserver.ftplet.UserManager;
-import org.apache.ftpserver.listener.ListenerFactory;
-import org.springframework.core.io.Resource;
+import org.citrusframework.spi.Resource;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServerFtpLet.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServerFtpLet.java
index ebe9c8a33e..9c210bafb6 100644
--- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServerFtpLet.java
+++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServerFtpLet.java
@@ -38,7 +38,6 @@
import org.apache.ftpserver.ftplet.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
/**
* Ftp servlet implementation that logs incoming connections and commands forwarding those to
@@ -118,7 +117,7 @@ public FtpletResult beforeCommand(FtpSession session, FtpRequest request) {
return FtpletResult.DEFAULT;
}
- if (Stream.of(StringUtils.commaDelimitedListToStringArray(endpointConfiguration.getAutoHandleCommands())).anyMatch(cmd -> cmd.trim().equals(command))) {
+ if (Stream.of(endpointConfiguration.getAutoHandleCommands().split(",")).anyMatch(cmd -> cmd.trim().equals(command))) {
return FtpletResult.DEFAULT;
}
diff --git a/endpoints/citrus-ftp/src/test/java/org/citrusframework/ftp/client/SftpClientTest.java b/endpoints/citrus-ftp/src/test/java/org/citrusframework/ftp/client/SftpClientTest.java
index 2d41fd408c..fda36843f6 100644
--- a/endpoints/citrus-ftp/src/test/java/org/citrusframework/ftp/client/SftpClientTest.java
+++ b/endpoints/citrus-ftp/src/test/java/org/citrusframework/ftp/client/SftpClientTest.java
@@ -23,21 +23,24 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.apache.sshd.common.keyprovider.ClassLoadableResourceKeyPairProvider;
+import org.apache.sshd.server.SshServer;
+import org.apache.sshd.server.subsystem.SubsystemFactory;
+import org.apache.sshd.sftp.server.SftpSubsystemFactory;
import org.citrusframework.ftp.message.FtpMessage;
import org.citrusframework.ftp.model.DeleteCommand;
import org.citrusframework.ftp.model.DeleteCommandResult;
import org.citrusframework.ftp.model.GetCommandResult;
import org.citrusframework.ftp.model.ListCommandResult;
import org.citrusframework.ftp.model.PutCommandResult;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.TestNGUtils;
import org.citrusframework.util.FileUtils;
-import org.apache.sshd.common.keyprovider.ClassLoadableResourceKeyPairProvider;
-import org.apache.sshd.server.SshServer;
-import org.apache.sshd.server.subsystem.SubsystemFactory;
-import org.apache.sshd.sftp.server.SftpSubsystemFactory;
-import org.springframework.core.io.ClassPathResource;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -70,7 +73,7 @@ public void setUp() throws Exception {
targetPath = System.getProperty("project.build.directory");
localFilePath = "classpath:ftp/input/hello.xml";
remoteFilePath = targetPath + "/hello.xml";
- inputFileAsString = FileUtils.readToString(new ClassPathResource("ftp/input/hello.xml"), StandardCharsets.UTF_8);
+ inputFileAsString = FileUtils.readToString(Resources.newClasspathResource("ftp/input/hello.xml"), StandardCharsets.UTF_8);
sshServer = startSftpMockServer();
sftpClient = createSftpClient();
}
diff --git a/endpoints/citrus-ftp/src/test/java/org/citrusframework/ftp/config/annotation/FtpServerConfigParserTest.java b/endpoints/citrus-ftp/src/test/java/org/citrusframework/ftp/config/annotation/FtpServerConfigParserTest.java
index a6df35786f..4b0e7dd2e4 100644
--- a/endpoints/citrus-ftp/src/test/java/org/citrusframework/ftp/config/annotation/FtpServerConfigParserTest.java
+++ b/endpoints/citrus-ftp/src/test/java/org/citrusframework/ftp/config/annotation/FtpServerConfigParserTest.java
@@ -18,6 +18,7 @@
import java.io.IOException;
+import org.apache.ftpserver.ftplet.UserManager;
import org.citrusframework.TestActor;
import org.citrusframework.annotations.CitrusAnnotations;
import org.citrusframework.annotations.CitrusEndpoint;
@@ -25,11 +26,10 @@
import org.citrusframework.endpoint.EndpointAdapter;
import org.citrusframework.ftp.server.FtpServer;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.spi.Resource;
import org.citrusframework.testng.AbstractTestNGUnitTest;
-import org.apache.ftpserver.ftplet.UserManager;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.springframework.core.io.Resource;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
diff --git a/endpoints/citrus-ftp/src/test/java/org/citrusframework/ftp/config/xml/FtpServerParserTest.java b/endpoints/citrus-ftp/src/test/java/org/citrusframework/ftp/config/xml/FtpServerParserTest.java
index 85d9f3016f..09ca7a73d3 100644
--- a/endpoints/citrus-ftp/src/test/java/org/citrusframework/ftp/config/xml/FtpServerParserTest.java
+++ b/endpoints/citrus-ftp/src/test/java/org/citrusframework/ftp/config/xml/FtpServerParserTest.java
@@ -31,7 +31,6 @@
import org.citrusframework.testng.AbstractBeanDefinitionParserTest;
import jakarta.jms.ConnectionFactory;
import org.springframework.context.ApplicationContext;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -126,7 +125,7 @@ public void testEndpointAdapter() {
Assert.assertEquals(server.getEndpointConfiguration().getPort(), 22222);
Assert.assertNotNull(server.getEndpointAdapter());
Assert.assertEquals(server.getEndpointAdapter().getClass(), StaticResponseEndpointAdapter.class);
- Assert.assertEquals(StringUtils.trimAllWhitespace(((StaticResponseEndpointAdapter) server.getEndpointAdapter()).getMessagePayload()), "Hello! ");
+ Assert.assertEquals((((StaticResponseEndpointAdapter) server.getEndpointAdapter()).getMessagePayload()).replaceAll("\\s", ""), "Hello! ");
Assert.assertEquals(((StaticResponseEndpointAdapter) server.getEndpointAdapter()).getMessageHeader().get("Operation"), "sayHello");
// 5th message sender
diff --git a/endpoints/citrus-ftp/src/test/resources/org/citrusframework/context/citrus-unit-context.xml b/endpoints/citrus-ftp/src/test/resources/org/citrusframework/context/citrus-unit-context.xml
index 6ebc3ce93d..b65fff440e 100644
--- a/endpoints/citrus-ftp/src/test/resources/org/citrusframework/context/citrus-unit-context.xml
+++ b/endpoints/citrus-ftp/src/test/resources/org/citrusframework/context/citrus-unit-context.xml
@@ -4,4 +4,14 @@
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+
+
+
+
+
+
+
+
diff --git a/endpoints/citrus-http/pom.xml b/endpoints/citrus-http/pom.xml
index fedc539351..1a69ec95ae 100644
--- a/endpoints/citrus-http/pom.xml
+++ b/endpoints/citrus-http/pom.xml
@@ -65,6 +65,10 @@
provided
+
+ org.springframework
+ spring-core
+
org.springframework
spring-web
diff --git a/endpoints/citrus-http/src/main/java/org/citrusframework/http/actions/HttpActionBuilder.java b/endpoints/citrus-http/src/main/java/org/citrusframework/http/actions/HttpActionBuilder.java
index f54260e6ea..dc3faf9e4d 100644
--- a/endpoints/citrus-http/src/main/java/org/citrusframework/http/actions/HttpActionBuilder.java
+++ b/endpoints/citrus-http/src/main/java/org/citrusframework/http/actions/HttpActionBuilder.java
@@ -20,10 +20,9 @@
import org.citrusframework.TestActionBuilder;
import org.citrusframework.endpoint.Endpoint;
import org.citrusframework.http.client.HttpClient;
-import org.citrusframework.http.server.HttpServer;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
-import org.springframework.util.Assert;
+import org.citrusframework.util.ObjectHelper;
/**
* Action executes http client and server operations.
@@ -97,7 +96,7 @@ public HttpActionBuilder withReferenceResolver(ReferenceResolver referenceResolv
@Override
public TestAction build() {
- Assert.notNull(delegate, "Missing delegate action to build");
+ ObjectHelper.assertNotNull(delegate, "Missing delegate action to build");
return delegate.build();
}
diff --git a/endpoints/citrus-http/src/main/java/org/citrusframework/http/actions/HttpClientActionBuilder.java b/endpoints/citrus-http/src/main/java/org/citrusframework/http/actions/HttpClientActionBuilder.java
index 31c9be721d..b722f8817e 100644
--- a/endpoints/citrus-http/src/main/java/org/citrusframework/http/actions/HttpClientActionBuilder.java
+++ b/endpoints/citrus-http/src/main/java/org/citrusframework/http/actions/HttpClientActionBuilder.java
@@ -18,13 +18,13 @@
import org.citrusframework.TestAction;
import org.citrusframework.TestActionBuilder;
-import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.endpoint.Endpoint;
+import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.util.ObjectHelper;
+import org.citrusframework.util.StringUtils;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
/**
* Action executes http client operations such as sending requests and receiving responses.
@@ -268,7 +268,7 @@ public HttpClientResponseActionBuilder response(HttpStatus status) {
@Override
public TestAction build() {
- Assert.notNull(delegate, "Missing delegate action to build");
+ ObjectHelper.assertNotNull(delegate, "Missing delegate action to build");
return delegate.build();
}
diff --git a/endpoints/citrus-http/src/main/java/org/citrusframework/http/actions/HttpServerActionBuilder.java b/endpoints/citrus-http/src/main/java/org/citrusframework/http/actions/HttpServerActionBuilder.java
index af4c2cd2bf..ebe65dc94e 100644
--- a/endpoints/citrus-http/src/main/java/org/citrusframework/http/actions/HttpServerActionBuilder.java
+++ b/endpoints/citrus-http/src/main/java/org/citrusframework/http/actions/HttpServerActionBuilder.java
@@ -18,13 +18,13 @@
import org.citrusframework.TestAction;
import org.citrusframework.TestActionBuilder;
-import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.endpoint.Endpoint;
+import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.util.ObjectHelper;
+import org.citrusframework.util.StringUtils;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
/**
* Action executes http server operations such as receiving requests and sending response messages.
@@ -285,7 +285,7 @@ public HttpServerRequestActionBuilder patch(String path) {
@Override
public TestAction build() {
- Assert.notNull(delegate, "Missing delegate action to build");
+ ObjectHelper.assertNotNull(delegate, "Missing delegate action to build");
return delegate.build();
}
diff --git a/endpoints/citrus-http/src/main/java/org/citrusframework/http/client/BasicAuthClientHttpRequestFactory.java b/endpoints/citrus-http/src/main/java/org/citrusframework/http/client/BasicAuthClientHttpRequestFactory.java
index a4c1fb5baa..05a773922d 100644
--- a/endpoints/citrus-http/src/main/java/org/citrusframework/http/client/BasicAuthClientHttpRequestFactory.java
+++ b/endpoints/citrus-http/src/main/java/org/citrusframework/http/client/BasicAuthClientHttpRequestFactory.java
@@ -18,7 +18,6 @@
import java.net.URI;
-import org.citrusframework.common.InitializingPhase;
import org.apache.hc.client5.http.auth.AuthCache;
import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.Credentials;
@@ -30,10 +29,11 @@
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.protocol.HttpContext;
+import org.citrusframework.common.InitializingPhase;
+import org.citrusframework.util.ObjectHelper;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
-import org.springframework.util.Assert;
/**
* Factory bean constructing a client request factory with
@@ -57,7 +57,7 @@ public class BasicAuthClientHttpRequestFactory implements FactoryBean> headerEntry : headers.entrySet()) {
builder.append(headerEntry.getKey());
builder.append(":");
- builder.append(StringUtils.arrayToCommaDelimitedString(headerEntry.getValue().toArray()));
+ builder.append(headerEntry.getValue().stream().collect(Collectors.joining(",")));
builder.append(NEWLINE);
}
}
@@ -205,11 +205,7 @@ public HttpHeaders getHeaders() {
@Override
public InputStream getBody() throws IOException {
if (this.body == null) {
- if (response.getBody() != null) {
- this.body = FileCopyUtils.copyToByteArray(response.getBody());
- } else {
- body = new byte[] {};
- }
+ this.body = FileUtils.copyToByteArray(response.getBody());
}
return new ByteArrayInputStream(this.body);
}
diff --git a/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/CookieConverter.java b/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/CookieConverter.java
index bd6a6580ec..430ddfebdc 100644
--- a/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/CookieConverter.java
+++ b/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/CookieConverter.java
@@ -16,16 +16,16 @@
package org.citrusframework.http.message;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.util.StringUtils;
-
-import jakarta.servlet.http.Cookie;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
+import jakarta.servlet.http.Cookie;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.util.StringUtils;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+
/**
* Class to convert Objects from or to Cookies
*
diff --git a/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpMessage.java b/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpMessage.java
index 03b144c2bb..6f3464723d 100644
--- a/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpMessage.java
+++ b/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpMessage.java
@@ -29,15 +29,15 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import jakarta.servlet.http.Cookie;
import org.citrusframework.endpoint.resolver.EndpointUriResolver;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
-import jakarta.servlet.http.Cookie;
+import org.citrusframework.util.StringUtils;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
-import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMethod;
/**
@@ -209,8 +209,14 @@ public HttpMessage queryParams(final String queryParamString) {
header(EndpointUriResolver.QUERY_PARAM_HEADER_NAME, queryParamString);
Stream.of(queryParamString.split(","))
- .map(keyValue -> Optional.ofNullable(StringUtils.split(keyValue, "=")).orElse(new String[]{keyValue, ""}))
+ .map(keyValue -> keyValue.split("="))
.filter(keyValue -> StringUtils.hasText(keyValue[0]))
+ .map(keyValue -> {
+ if (keyValue.length < 2) {
+ return new String[]{keyValue[0], ""};
+ }
+ return keyValue;
+ })
.forEach(keyValue -> this.addQueryParam(keyValue[0], keyValue[1]));
return this;
diff --git a/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpMessageConverter.java b/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpMessageConverter.java
index 540fbac5ec..6b15778dd4 100644
--- a/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpMessageConverter.java
+++ b/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpMessageConverter.java
@@ -16,17 +16,24 @@
package org.citrusframework.http.message;
-import java.util.*;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import jakarta.servlet.http.Cookie;
import org.citrusframework.context.TestContext;
import org.citrusframework.http.client.HttpEndpointConfiguration;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageConverter;
import org.citrusframework.message.MessageHeaderUtils;
import org.citrusframework.message.MessageHeaders;
-import jakarta.servlet.http.Cookie;
-import org.springframework.http.*;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMethod;
/**
@@ -37,7 +44,7 @@
*/
public class HttpMessageConverter implements MessageConverter, HttpEntity>, HttpEndpointConfiguration> {
- private CookieConverter cookieConverter;
+ private final CookieConverter cookieConverter;
public HttpMessageConverter() {
cookieConverter = new CookieConverter();
@@ -122,7 +129,7 @@ private Map getCustomHeaders(HttpHeaders httpHeaders, Map> header : httpHeaders.entrySet()) {
if (!mappedHeaders.containsKey(header.getKey())) {
- customHeaders.put(header.getKey(), StringUtils.collectionToCommaDelimitedString(header.getValue()));
+ customHeaders.put(header.getKey(), String.join(",", header.getValue()));
}
}
@@ -141,7 +148,7 @@ private Map convertHeaderTypes(Map headers) {
for (Map.Entry header : headers.entrySet()) {
if (header.getValue() instanceof Collection>) {
Collection> value = (Collection>)header.getValue();
- convertedHeaders.put(header.getKey(), StringUtils.collectionToCommaDelimitedString(value));
+ convertedHeaders.put(header.getKey(), value.stream().map(String::valueOf).collect(Collectors.joining(",")));
} else if (header.getValue() instanceof MediaType) {
convertedHeaders.put(header.getKey(), header.getValue().toString());
} else {
diff --git a/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpQueryParamHeaderValidator.java b/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpQueryParamHeaderValidator.java
index 9a6a771bb6..1844ed0221 100644
--- a/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpQueryParamHeaderValidator.java
+++ b/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpQueryParamHeaderValidator.java
@@ -16,17 +16,17 @@
package org.citrusframework.http.message;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.ValidationException;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.DefaultHeaderValidator;
import org.citrusframework.validation.context.HeaderValidationContext;
import org.citrusframework.validation.matcher.ValidationMatcherUtils;
-import org.springframework.util.StringUtils;
-
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
/**
* @author Christoph Deppisch
@@ -69,7 +69,14 @@ private Map convertToMap(Object expression) {
.map(Object::toString)
.orElse("")
.split(","))
- .map(keyValue -> Optional.ofNullable(StringUtils.split(keyValue, "=")).orElse(new String[] {keyValue, ""}))
+ .map(keyValue -> keyValue.split("="))
+ .filter(keyValue -> StringUtils.hasText(keyValue[0]))
+ .map(keyValue -> {
+ if (keyValue.length < 2) {
+ return new String[]{keyValue[0], ""};
+ }
+ return keyValue;
+ })
.collect(Collectors.toMap(keyValue -> keyValue[0], keyValue -> keyValue[1]));
}
diff --git a/endpoints/citrus-http/src/main/java/org/citrusframework/http/model/FormMarshaller.java b/endpoints/citrus-http/src/main/java/org/citrusframework/http/model/FormMarshaller.java
index 8ed709887e..1513af5648 100644
--- a/endpoints/citrus-http/src/main/java/org/citrusframework/http/model/FormMarshaller.java
+++ b/endpoints/citrus-http/src/main/java/org/citrusframework/http/model/FormMarshaller.java
@@ -16,15 +16,15 @@
package org.citrusframework.http.model;
-import jakarta.xml.bind.JAXBException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
+import jakarta.xml.bind.JAXBException;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resources;
import org.citrusframework.xml.Jaxb2Marshaller;
import org.citrusframework.xml.Marshaller;
import org.citrusframework.xml.Unmarshaller;
-import org.springframework.core.io.ClassPathResource;
/**
* @author Christoph Deppisch
@@ -35,7 +35,7 @@ public class FormMarshaller implements Marshaller, Unmarshaller {
public FormMarshaller() {
this.marshaller = new Jaxb2Marshaller(
- new ClassPathResource("org/citrusframework/schema/citrus-http-message.xsd"), FormData.class, Control.class);
+ Resources.newClasspathResource("org/citrusframework/schema/citrus-http-message.xsd"), FormData.class, Control.class);
}
public void marshal(Object graph, Result result) {
diff --git a/endpoints/citrus-http/src/main/java/org/citrusframework/http/server/HttpServer.java b/endpoints/citrus-http/src/main/java/org/citrusframework/http/server/HttpServer.java
index cc999a7db8..3de137fa38 100644
--- a/endpoints/citrus-http/src/main/java/org/citrusframework/http/server/HttpServer.java
+++ b/endpoints/citrus-http/src/main/java/org/citrusframework/http/server/HttpServer.java
@@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;
+import jakarta.servlet.Filter;
import org.citrusframework.context.SpringBeanReferenceResolver;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.http.context.ParentDelegatingWebApplicationContext;
@@ -31,7 +32,7 @@
import org.citrusframework.http.servlet.RequestCachingServletFilter;
import org.citrusframework.report.MessageListeners;
import org.citrusframework.server.AbstractServer;
-import jakarta.servlet.Filter;
+import org.citrusframework.util.StringUtils;
import org.eclipse.jetty.security.SecurityHandler;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
@@ -47,8 +48,6 @@
import org.eclipse.jetty.servlet.ServletMapping;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
@@ -186,7 +185,7 @@ protected void startup() {
servletHandler.addFilter(filterHolder, filterMapping);
}
- if (CollectionUtils.isEmpty(filters)) {
+ if (filters == null || filters.isEmpty()) {
addRequestCachingFilter();
addGzipFilter();
}
diff --git a/endpoints/citrus-http/src/main/java/org/citrusframework/http/servlet/CachingHttpServletRequestWrapper.java b/endpoints/citrus-http/src/main/java/org/citrusframework/http/servlet/CachingHttpServletRequestWrapper.java
index 2a8226fd10..773da3f5b0 100644
--- a/endpoints/citrus-http/src/main/java/org/citrusframework/http/servlet/CachingHttpServletRequestWrapper.java
+++ b/endpoints/citrus-http/src/main/java/org/citrusframework/http/servlet/CachingHttpServletRequestWrapper.java
@@ -16,10 +16,6 @@
package org.citrusframework.http.servlet;
-import jakarta.servlet.ReadListener;
-import jakarta.servlet.ServletInputStream;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletRequestWrapper;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
@@ -30,14 +26,18 @@
import java.util.Optional;
import java.util.StringTokenizer;
+import jakarta.servlet.ReadListener;
+import jakarta.servlet.ServletInputStream;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletRequestWrapper;
import org.citrusframework.CitrusSettings;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.InvalidMediaTypeException;
import org.springframework.http.MediaType;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMethod;
/**
@@ -81,7 +81,7 @@ public Map getParameterMap() {
if (RequestMethod.POST.name().equals(getMethod()) || RequestMethod.PUT.name().equals(getMethod())) {
if (new MediaType(contentType.getType(), contentType.getSubtype()).equals(MediaType.APPLICATION_FORM_URLENCODED)) {
try {
- fillParams(params, new String(FileCopyUtils.copyToByteArray(getInputStream()), charset), charset);
+ fillParams(params, new String(FileUtils.copyToByteArray(getInputStream()), charset), charset);
} catch (IOException e) {
throw new CitrusRuntimeException("Failed to read request body", e);
}
@@ -97,7 +97,7 @@ public Map getParameterMap() {
public ServletInputStream getInputStream() throws IOException {
if (body == null) {
if (super.getInputStream() != null) {
- body = FileCopyUtils.copyToByteArray(super.getInputStream());
+ body = FileUtils.copyToByteArray(super.getInputStream());
} else {
body = new byte[] {};
}
diff --git a/endpoints/citrus-http/src/main/java/org/citrusframework/http/validation/FormUrlEncodedMessageValidator.java b/endpoints/citrus-http/src/main/java/org/citrusframework/http/validation/FormUrlEncodedMessageValidator.java
index 219f2ab73c..e805b6a7c0 100644
--- a/endpoints/citrus-http/src/main/java/org/citrusframework/http/validation/FormUrlEncodedMessageValidator.java
+++ b/endpoints/citrus-http/src/main/java/org/citrusframework/http/validation/FormUrlEncodedMessageValidator.java
@@ -24,6 +24,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.StringTokenizer;
+import java.util.stream.Collectors;
import org.citrusframework.CitrusSettings;
import org.citrusframework.context.TestContext;
@@ -36,6 +37,7 @@
import org.citrusframework.http.model.ObjectFactory;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.MessageValidator;
import org.citrusframework.validation.context.ValidationContext;
import org.citrusframework.validation.xml.XmlMessageValidationContext;
@@ -43,7 +45,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.MultiValueMap;
-import org.springframework.util.StringUtils;
/**
* Validates x-www-form-urlencoded HTML form data content by marshalling form fields to Xml representation.
@@ -159,7 +160,7 @@ private FormData createFormData(Message message) {
for (Map.Entry> entry : formValueMap.entrySet()) {
Control control = new ObjectFactory().createControl();
control.setName(entry.getKey());
- control.setValue(StringUtils.arrayToCommaDelimitedString(entry.getValue().toArray()));
+ control.setValue(entry.getValue().stream().map(String::valueOf).collect(Collectors.joining(",")));
formData.addControl(control);
}
} else {
diff --git a/endpoints/citrus-http/src/test/java/org/citrusframework/http/config/xml/HttpClientParserTest.java b/endpoints/citrus-http/src/test/java/org/citrusframework/http/config/xml/HttpClientParserTest.java
index e6676bb43a..ec96eb37fa 100644
--- a/endpoints/citrus-http/src/test/java/org/citrusframework/http/config/xml/HttpClientParserTest.java
+++ b/endpoints/citrus-http/src/test/java/org/citrusframework/http/config/xml/HttpClientParserTest.java
@@ -17,7 +17,6 @@
package org.citrusframework.http.config.xml;
import java.util.Map;
-import java.util.Objects;
import org.citrusframework.TestActor;
import org.citrusframework.http.client.HttpClient;
@@ -26,6 +25,7 @@
import org.citrusframework.message.DefaultMessageCorrelator;
import org.citrusframework.message.ErrorHandlingStrategy;
import org.citrusframework.testng.AbstractBeanDefinitionParserTest;
+import org.citrusframework.util.ObjectHelper;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.http.MediaType;
import org.springframework.http.client.InterceptingClientHttpRequestFactory;
@@ -104,7 +104,7 @@ public void testBothRestTemplateAndRequestFactorySet() {
createApplicationContext("failed1");
Assert.fail("Missing bean creation exception due to rest template and request factory property set");
} catch (BeanDefinitionParsingException e) {
- Assert.assertTrue(Objects.requireNonNull(e.getMessage()).contains("no 'request-factory' should be set"), e.getMessage());
+ Assert.assertTrue(ObjectHelper.assertNotNull(e.getMessage()).contains("no 'request-factory' should be set"), e.getMessage());
}
}
@@ -114,7 +114,7 @@ public void testMissingRequestUrlOrEndpointResolver() {
createApplicationContext("failed2");
Assert.fail("Missing bean creation exception due to missing request url or endpoint resolver");
} catch (BeanDefinitionParsingException e) {
- Assert.assertTrue(Objects.requireNonNull(e.getMessage()).contains("One of the properties 'request-url' or 'endpoint-resolver' is required"));
+ Assert.assertTrue(ObjectHelper.assertNotNull(e.getMessage()).contains("One of the properties 'request-url' or 'endpoint-resolver' is required"));
}
}
diff --git a/endpoints/citrus-http/src/test/java/org/citrusframework/http/config/xml/HttpServerParserTest.java b/endpoints/citrus-http/src/test/java/org/citrusframework/http/config/xml/HttpServerParserTest.java
index 420d15341b..041f02d85d 100644
--- a/endpoints/citrus-http/src/test/java/org/citrusframework/http/config/xml/HttpServerParserTest.java
+++ b/endpoints/citrus-http/src/test/java/org/citrusframework/http/config/xml/HttpServerParserTest.java
@@ -34,7 +34,6 @@
import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -186,7 +185,7 @@ public void testEndpointAdapter() {
Assert.assertEquals(server.getPort(), 8084);
Assert.assertNotNull(server.getEndpointAdapter());
Assert.assertEquals(server.getEndpointAdapter().getClass(), StaticResponseEndpointAdapter.class);
- Assert.assertEquals(StringUtils.trimAllWhitespace(((StaticResponseEndpointAdapter) server.getEndpointAdapter()).getMessagePayload()), "Hello! ");
+ Assert.assertEquals(((StaticResponseEndpointAdapter) server.getEndpointAdapter()).getMessagePayload().replaceAll("\\s", ""), "Hello! ");
Assert.assertEquals(((StaticResponseEndpointAdapter) server.getEndpointAdapter()).getMessageHeader().get("Operation"), "sayHello");
// 5th message sender
diff --git a/endpoints/citrus-http/src/test/java/org/citrusframework/http/integration/HttpServerZipFileJavaIT.java b/endpoints/citrus-http/src/test/java/org/citrusframework/http/integration/HttpServerZipFileJavaIT.java
index e1f79a53c1..0fbb218443 100644
--- a/endpoints/citrus-http/src/test/java/org/citrusframework/http/integration/HttpServerZipFileJavaIT.java
+++ b/endpoints/citrus-http/src/test/java/org/citrusframework/http/integration/HttpServerZipFileJavaIT.java
@@ -19,8 +19,8 @@
import org.citrusframework.annotations.CitrusTest;
import org.citrusframework.message.MessageType;
import org.citrusframework.message.ZipMessage;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
-import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpStatus;
import org.testng.annotations.Test;
@@ -36,7 +36,7 @@ public class HttpServerZipFileJavaIT extends TestNGCitrusSpringSupport {
@CitrusTest
public void httpServerZipFile() {
- ZipMessage zipMessage = new ZipMessage().addEntry(new ClassPathResource("schemas"));
+ ZipMessage zipMessage = new ZipMessage().addEntry(Resources.newClasspathResource("schemas"));
given(http().client("echoHttpClient")
.send()
diff --git a/endpoints/citrus-http/src/test/java/org/citrusframework/http/servlet/CachingHttpServletRequestWrapperTest.java b/endpoints/citrus-http/src/test/java/org/citrusframework/http/servlet/CachingHttpServletRequestWrapperTest.java
index f074682802..bc2f244e17 100644
--- a/endpoints/citrus-http/src/test/java/org/citrusframework/http/servlet/CachingHttpServletRequestWrapperTest.java
+++ b/endpoints/citrus-http/src/test/java/org/citrusframework/http/servlet/CachingHttpServletRequestWrapperTest.java
@@ -27,8 +27,8 @@
import jakarta.servlet.ServletInputStream;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.hc.core5.http.ContentType;
+import org.citrusframework.util.ObjectHelper;
import org.springframework.http.MediaType;
-import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
@@ -216,7 +216,7 @@ class DelegatingServletInputStream extends ServletInputStream {
* @param sourceStream the source stream (never null
)
*/
DelegatingServletInputStream(final InputStream sourceStream) {
- Assert.notNull(sourceStream, "Source InputStream must not be null");
+ ObjectHelper.assertNotNull(sourceStream, "Source InputStream must not be null");
this.sourceStream = sourceStream;
}
diff --git a/endpoints/citrus-jms/pom.xml b/endpoints/citrus-jms/pom.xml
index 45a07400e9..d6b81efc71 100644
--- a/endpoints/citrus-jms/pom.xml
+++ b/endpoints/citrus-jms/pom.xml
@@ -53,6 +53,10 @@
provided
+
+ org.springframework
+ spring-core
+
org.springframework
spring-jms
diff --git a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/annotation/JmsEndpointConfigParser.java b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/annotation/JmsEndpointConfigParser.java
index 22ad8565f4..e164d63490 100644
--- a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/annotation/JmsEndpointConfigParser.java
+++ b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/annotation/JmsEndpointConfigParser.java
@@ -18,7 +18,6 @@
import jakarta.jms.ConnectionFactory;
import jakarta.jms.Destination;
-
import org.citrusframework.TestActor;
import org.citrusframework.config.annotation.AnnotationConfigParser;
import org.citrusframework.endpoint.resolver.EndpointUriResolver;
@@ -27,9 +26,9 @@
import org.citrusframework.jms.endpoint.JmsEndpointBuilder;
import org.citrusframework.jms.message.JmsMessageConverter;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.util.StringUtils;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.support.destination.DestinationResolver;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/annotation/JmsSyncEndpointConfigParser.java b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/annotation/JmsSyncEndpointConfigParser.java
index 5e03a20a98..30c6d2833a 100644
--- a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/annotation/JmsSyncEndpointConfigParser.java
+++ b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/annotation/JmsSyncEndpointConfigParser.java
@@ -18,7 +18,6 @@
import jakarta.jms.ConnectionFactory;
import jakarta.jms.Destination;
-
import org.citrusframework.TestActor;
import org.citrusframework.config.annotation.AnnotationConfigParser;
import org.citrusframework.endpoint.resolver.EndpointUriResolver;
@@ -28,9 +27,9 @@
import org.citrusframework.jms.message.JmsMessageConverter;
import org.citrusframework.message.MessageCorrelator;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.util.StringUtils;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.support.destination.DestinationResolver;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/xml/AbstractJmsEndpointParser.java b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/xml/AbstractJmsEndpointParser.java
index 52106f0560..0474e50e73 100644
--- a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/xml/AbstractJmsEndpointParser.java
+++ b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/xml/AbstractJmsEndpointParser.java
@@ -18,9 +18,9 @@
import org.citrusframework.config.util.BeanDefinitionParserUtils;
import org.citrusframework.config.xml.AbstractEndpointParser;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
diff --git a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/xml/PurgeJmsQueuesActionParser.java b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/xml/PurgeJmsQueuesActionParser.java
index 78c8799f59..9e14ac9949 100644
--- a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/xml/PurgeJmsQueuesActionParser.java
+++ b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/config/xml/PurgeJmsQueuesActionParser.java
@@ -25,13 +25,13 @@
import org.citrusframework.config.xml.AbstractTestActionFactoryBean;
import org.citrusframework.config.xml.DescriptionElementParser;
import org.citrusframework.jms.actions.PurgeJmsQueuesAction;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
diff --git a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsConsumer.java b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsConsumer.java
index 464c78924e..a211d2ba71 100644
--- a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsConsumer.java
+++ b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsConsumer.java
@@ -17,15 +17,14 @@
package org.citrusframework.jms.endpoint;
import jakarta.jms.Destination;
-
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.MessageTimeoutException;
import org.citrusframework.message.Message;
import org.citrusframework.messaging.AbstractSelectiveMessageConsumer;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsEndpoint.java b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsEndpoint.java
index 3aac7f752f..3d7cfe86cd 100644
--- a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsEndpoint.java
+++ b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsEndpoint.java
@@ -21,11 +21,11 @@
import org.citrusframework.context.TestContextFactory;
import org.citrusframework.context.TestContextFactoryBean;
import org.citrusframework.endpoint.AbstractEndpoint;
+import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.messaging.Producer;
import org.citrusframework.messaging.SelectiveConsumer;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
-import org.springframework.util.Assert;
/**
* Jms message endpoint capable of sending/receiving messages from Jms message destination. Either uses a Jms connection factory or
@@ -114,9 +114,10 @@ public void destroy() {
@Override
public void initialize() {
if (getEndpointConfiguration().isAutoStart()) {
- Assert.isTrue(getEndpointConfiguration().isPubSubDomain(),
- "Invalid endpoint configuration - " +
+ if (!getEndpointConfiguration().isPubSubDomain()) {
+ throw new CitrusRuntimeException( "Invalid endpoint configuration - " +
"caching subscriber enabled but pubSubDomain is set to false - please enable pubSubDomain");
+ }
createConsumer();
}
diff --git a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsEndpointConfiguration.java b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsEndpointConfiguration.java
index e48b1770e2..4541834f71 100644
--- a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsEndpointConfiguration.java
+++ b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsEndpointConfiguration.java
@@ -24,6 +24,7 @@
import org.citrusframework.endpoint.AbstractPollableEndpointConfiguration;
import org.citrusframework.endpoint.resolver.EndpointUriResolver;
+import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.jms.endpoint.resolver.DynamicDestinationNameResolver;
import org.citrusframework.jms.message.JmsMessageConverter;
import org.citrusframework.jms.message.JmsMessageHeaderMapper;
@@ -32,7 +33,6 @@
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.support.JmsHeaderMapper;
import org.springframework.jms.support.destination.DestinationResolver;
-import org.springframework.util.Assert;
/**
* @author Christoph Deppisch
@@ -107,8 +107,9 @@ public String getDestinationName(Destination destination) {
* Creates default JmsTemplate instance from connection factory and destination.
*/
private void createJmsTemplate() {
- Assert.isTrue(this.connectionFactory != null,
- "Neither 'jmsTemplate' nor 'connectionFactory' is set correctly.");
+ if (this.connectionFactory == null) {
+ throw new CitrusRuntimeException("Neither 'jmsTemplate' nor 'connectionFactory' is set correctly.");
+ }
jmsTemplate = new JmsTemplate();
diff --git a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsProducer.java b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsProducer.java
index 755d569e38..1b3b68f9ab 100644
--- a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsProducer.java
+++ b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsProducer.java
@@ -16,16 +16,15 @@
package org.citrusframework.jms.endpoint;
+import jakarta.jms.Destination;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
import org.citrusframework.messaging.Producer;
+import org.citrusframework.util.ObjectHelper;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
-
-import jakarta.jms.Destination;
/**
* @author Christoph Deppisch
@@ -54,7 +53,7 @@ public JmsProducer(String name, JmsEndpointConfiguration endpointConfiguration)
@Override
public void send(final Message message, final TestContext context) {
- Assert.notNull(message, "Message is empty - unable to send empty message");
+ ObjectHelper.assertNotNull(message, "Message is empty - unable to send empty message");
if (endpointConfiguration.getDestination() != null) {
send(message, endpointConfiguration.getDestination(), context);
diff --git a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsSyncConsumer.java b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsSyncConsumer.java
index dcda758ba8..44e56e12c9 100644
--- a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsSyncConsumer.java
+++ b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsSyncConsumer.java
@@ -16,17 +16,16 @@
package org.citrusframework.jms.endpoint;
+import jakarta.jms.Destination;
import org.citrusframework.context.TestContext;
import org.citrusframework.jms.message.JmsMessage;
import org.citrusframework.message.Message;
import org.citrusframework.message.correlation.CorrelationManager;
import org.citrusframework.message.correlation.PollingCorrelationManager;
import org.citrusframework.messaging.ReplyProducer;
+import org.citrusframework.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
-
-import jakarta.jms.*;
/**
* @author Christoph Deppisch
@@ -73,12 +72,12 @@ public Message receive(String selector, TestContext context, long timeout) {
@Override
public void send(final Message message, final TestContext context) {
- Assert.notNull(message, "Message is empty - unable to send empty message");
+ ObjectHelper.assertNotNull(message, "Message is empty - unable to send empty message");
String correlationKeyName = endpointConfiguration.getCorrelator().getCorrelationKeyName(getName());
String correlationKey = correlationManager.getCorrelationKey(correlationKeyName, context);
Destination replyDestination = correlationManager.find(correlationKey, endpointConfiguration.getTimeout());
- Assert.notNull(replyDestination, "Failed to find JMS reply destination for message correlation key: '" + correlationKey + "'");
+ ObjectHelper.assertNotNull(replyDestination, "Failed to find JMS reply destination for message correlation key: '" + correlationKey + "'");
if (logger.isDebugEnabled()) {
logger.debug("Sending JMS message to destination: '" + endpointConfiguration.getDestinationName(replyDestination) + "'");
diff --git a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsSyncProducer.java b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsSyncProducer.java
index 20b6e07a6d..7a0d576943 100644
--- a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsSyncProducer.java
+++ b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsSyncProducer.java
@@ -18,6 +18,7 @@
import java.util.Objects;
+import jakarta.jms.*;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.ReplyMessageTimeoutException;
@@ -26,14 +27,13 @@
import org.citrusframework.message.correlation.CorrelationManager;
import org.citrusframework.message.correlation.PollingCorrelationManager;
import org.citrusframework.messaging.ReplyConsumer;
-import jakarta.jms.*;
+import org.citrusframework.util.ObjectHelper;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.connection.ConnectionFactoryUtils;
import org.springframework.jms.support.JmsUtils;
import org.springframework.jms.support.destination.DynamicDestinationResolver;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -70,7 +70,7 @@ public JmsSyncProducer(String name, JmsSyncEndpointConfiguration endpointConfigu
@Override
public void send(Message message, TestContext context) {
- Assert.notNull(message, "Message is empty - unable to send empty message");
+ ObjectHelper.assertNotNull(message, "Message is empty - unable to send empty message");
String correlationKeyName = endpointConfiguration.getCorrelator().getCorrelationKeyName(getName());
String correlationKey = endpointConfiguration.getCorrelator().getCorrelationKey(message);
diff --git a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsTopicSubscriber.java b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsTopicSubscriber.java
index c75b9e184c..2d26df97fb 100644
--- a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsTopicSubscriber.java
+++ b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsTopicSubscriber.java
@@ -24,6 +24,13 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.JMSException;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicConnection;
+import jakarta.jms.TopicConnectionFactory;
+import jakarta.jms.TopicSession;
+import jakarta.jms.TopicSubscriber;
import org.citrusframework.context.TestContext;
import org.citrusframework.context.TestContextFactory;
import org.citrusframework.endpoint.direct.DirectEndpoint;
@@ -32,16 +39,9 @@
import org.citrusframework.message.DefaultMessageQueue;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageQueue;
-import jakarta.jms.ConnectionFactory;
-import jakarta.jms.JMSException;
-import jakarta.jms.Topic;
-import jakarta.jms.TopicConnection;
-import jakarta.jms.TopicConnectionFactory;
-import jakarta.jms.TopicSession;
-import jakarta.jms.TopicSubscriber;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/resolver/DynamicDestinationNameResolver.java b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/resolver/DynamicDestinationNameResolver.java
index 9b3e0e6dd0..64089fe892 100644
--- a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/resolver/DynamicDestinationNameResolver.java
+++ b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/resolver/DynamicDestinationNameResolver.java
@@ -16,13 +16,13 @@
package org.citrusframework.jms.endpoint.resolver;
+import java.util.Map;
+
import org.citrusframework.endpoint.resolver.EndpointUriResolver;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageHeaders;
-import org.springframework.util.StringUtils;
-
-import java.util.Map;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/message/SoapJmsMessageConverter.java b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/message/SoapJmsMessageConverter.java
index e5014933ee..5dd50e469c 100644
--- a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/message/SoapJmsMessageConverter.java
+++ b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/message/SoapJmsMessageConverter.java
@@ -26,6 +26,8 @@
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
+import jakarta.jms.Message;
+import jakarta.jms.Session;
import org.citrusframework.CitrusSettings;
import org.citrusframework.common.InitializingPhase;
import org.citrusframework.context.TestContext;
@@ -35,13 +37,11 @@
import org.citrusframework.message.MessageHeaders;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.util.ObjectHelper;
import org.citrusframework.xml.StringResult;
import org.citrusframework.xml.StringSource;
-import jakarta.jms.Message;
-import jakarta.jms.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
import org.springframework.ws.soap.SoapHeader;
import org.springframework.ws.soap.SoapHeaderElement;
import org.springframework.ws.soap.SoapMessage;
@@ -61,14 +61,14 @@ public class SoapJmsMessageConverter extends JmsMessageConverter implements Init
/** Logger */
private static final Logger logger = LoggerFactory.getLogger(SoapJmsMessageConverter.class);
- /** Soap message factory - either set explicitly or auto configured through application context */
+ /** Soap message factory - either set explicitly or autoconfigured through application context */
private SoapMessageFactory soapMessageFactory;
- /** Reference resolver used for auto configuration of soap message factory */
+ /** Reference resolver used for autoconfiguration of soap message factory */
private ReferenceResolver referenceResolver;
/** Message transformer */
- private TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ private final TransformerFactory transformerFactory = TransformerFactory.newInstance();
/** Special SOAP action header */
private static final String SOAP_ACTION_HEADER = MessageHeaders.PREFIX + "soap_action";
@@ -180,7 +180,7 @@ public String getJmsSoapActionHeader() {
@Override
public void initialize() {
if (soapMessageFactory == null) {
- Assert.notNull(referenceResolver, "Missing reference resolver for auto configuration of soap message factory");
+ ObjectHelper.assertNotNull(referenceResolver, "Missing reference resolver for auto configuration of soap message factory");
soapMessageFactory = referenceResolver.resolve(SoapMessageFactory.class);
}
}
diff --git a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/endpoint/JmsEndpointProducerTest.java b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/endpoint/JmsEndpointProducerTest.java
index 10406f7c00..66355aa1ab 100644
--- a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/endpoint/JmsEndpointProducerTest.java
+++ b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/endpoint/JmsEndpointProducerTest.java
@@ -16,6 +16,16 @@
package org.citrusframework.jms.endpoint;
+import java.util.HashMap;
+
+import jakarta.jms.Connection;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.Destination;
+import jakarta.jms.JMSException;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.Queue;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
@@ -23,12 +33,8 @@
import org.mockito.Mockito;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
-import org.testng.Assert;
import org.testng.annotations.Test;
-import jakarta.jms.*;
-import java.util.HashMap;
-
import static org.mockito.Mockito.*;
/**
@@ -36,20 +42,20 @@
*/
public class JmsEndpointProducerTest extends AbstractTestNGUnitTest {
- private ConnectionFactory connectionFactory = Mockito.mock(ConnectionFactory.class);
- private Connection connection = Mockito.mock(Connection.class);
- private Session session = Mockito.mock(Session.class);
- private Destination destination = Mockito.mock(Destination.class);
- private Queue destinationQueue = Mockito.mock(Queue.class);
- private MessageProducer messageProducer = Mockito.mock(MessageProducer.class);
-
- private JmsTemplate jmsTemplate = Mockito.mock(JmsTemplate.class);
-
+ private final ConnectionFactory connectionFactory = Mockito.mock(ConnectionFactory.class);
+ private final Connection connection = Mockito.mock(Connection.class);
+ private final Session session = Mockito.mock(Session.class);
+ private final Destination destination = Mockito.mock(Destination.class);
+ private final Queue destinationQueue = Mockito.mock(Queue.class);
+ private final MessageProducer messageProducer = Mockito.mock(MessageProducer.class);
+
+ private final JmsTemplate jmsTemplate = Mockito.mock(JmsTemplate.class);
+
@Test
public void testSendMessageWithJmsTemplate() {
JmsEndpoint endpoint = new JmsEndpoint();
endpoint.getEndpointConfiguration().setJmsTemplate(jmsTemplate);
-
+
final Message message = new DefaultMessage("Hello World! ");
reset(jmsTemplate, connectionFactory, destination, messageProducer);
@@ -67,7 +73,7 @@ public void testSendMessageWithDestination() throws JMSException {
endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);
endpoint.getEndpointConfiguration().setDestination(destination);
-
+
final Message message = new DefaultMessage("Hello World! ");
reset(jmsTemplate, connectionFactory, destination, messageProducer, connection, session);
@@ -86,14 +92,14 @@ public void testSendMessageWithDestination() throws JMSException {
verify(messageProducer).send((TextMessage)any());
}
-
+
@Test
public void testSendMessageWithDestinationName() throws JMSException {
JmsEndpoint endpoint = new JmsEndpoint();
endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);
endpoint.getEndpointConfiguration().setDestinationName("myDestination");
-
+
final Message message = new DefaultMessage("Hello World! ");
reset(jmsTemplate, connectionFactory, destination, messageProducer, connection, session);
@@ -114,22 +120,14 @@ public void testSendMessageWithDestinationName() throws JMSException {
verify(messageProducer).send((TextMessage)any());
}
-
- @Test
+
+ @Test(expectedExceptions = CitrusRuntimeException.class, expectedExceptionsMessageRegExp = "Message is empty - unable to send empty message")
public void testSendEmptyMessage() throws JMSException {
JmsEndpoint endpoint = new JmsEndpoint();
endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);
endpoint.getEndpointConfiguration().setDestination(destination);
-
- try {
- endpoint.createProducer().send(null, context);
- } catch(IllegalArgumentException e) {
- Assert.assertEquals(e.getMessage(), "Message is empty - unable to send empty message");
- return;
- }
-
- Assert.fail("Missing " + CitrusRuntimeException.class + " because of sending empty message");
+ endpoint.createProducer().send(null, context);
}
-
+
}
diff --git a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/endpoint/JmsEndpointSyncConsumerTest.java b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/endpoint/JmsEndpointSyncConsumerTest.java
index fdbb9e5e45..786582fdc1 100644
--- a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/endpoint/JmsEndpointSyncConsumerTest.java
+++ b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/endpoint/JmsEndpointSyncConsumerTest.java
@@ -16,10 +16,23 @@
package org.citrusframework.jms.endpoint;
+import java.util.HashMap;
+import java.util.Map;
+
+import jakarta.jms.Connection;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.Destination;
+import jakarta.jms.JMSException;
+import jakarta.jms.MessageConsumer;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.jms.message.JmsMessage;
-import org.citrusframework.message.*;
+import org.citrusframework.message.DefaultMessage;
+import org.citrusframework.message.DefaultMessageCorrelator;
import org.citrusframework.message.Message;
+import org.citrusframework.message.MessageCorrelator;
import org.citrusframework.testng.AbstractTestNGUnitTest;
import org.mockito.Mockito;
import org.springframework.jms.core.JmsTemplate;
@@ -27,10 +40,6 @@
import org.testng.Assert;
import org.testng.annotations.Test;
-import jakarta.jms.*;
-import java.util.HashMap;
-import java.util.Map;
-
import static org.mockito.Mockito.*;
/**
@@ -38,15 +47,15 @@
*/
public class JmsEndpointSyncConsumerTest extends AbstractTestNGUnitTest {
- private ConnectionFactory connectionFactory = Mockito.mock(ConnectionFactory.class);
- private Connection connection = Mockito.mock(Connection.class);
- private Session session = Mockito.mock(Session.class);
- private Destination destination = Mockito.mock(Destination.class);
- private Destination replyDestination = Mockito.mock(Destination.class);
- private MessageConsumer messageConsumer = Mockito.mock(MessageConsumer.class);
- private MessageProducer messageProducer = Mockito.mock(MessageProducer.class);
+ private final ConnectionFactory connectionFactory = Mockito.mock(ConnectionFactory.class);
+ private final Connection connection = Mockito.mock(Connection.class);
+ private final Session session = Mockito.mock(Session.class);
+ private final Destination destination = Mockito.mock(Destination.class);
+ private final Destination replyDestination = Mockito.mock(Destination.class);
+ private final MessageConsumer messageConsumer = Mockito.mock(MessageConsumer.class);
+ private final MessageProducer messageProducer = Mockito.mock(MessageProducer.class);
- private JmsTemplate jmsTemplate = Mockito.mock(JmsTemplate.class);
+ private final JmsTemplate jmsTemplate = Mockito.mock(JmsTemplate.class);
@Test
public void testWithReplyDestination() throws JMSException {
@@ -54,18 +63,18 @@ public void testWithReplyDestination() throws JMSException {
endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);
endpoint.getEndpointConfiguration().setDestination(destination);
-
+
final Message controlMessage = new DefaultMessage("Hello World! ");
Map headers = new HashMap();
-
+
reset(connectionFactory, destination, connection, session, messageConsumer);
when(connectionFactory.createConnection()).thenReturn(connection);
when(connection.createSession(anyBoolean(), anyInt())).thenReturn(session);
when(session.getTransacted()).thenReturn(false);
when(session.getAcknowledgeMode()).thenReturn(Session.AUTO_ACKNOWLEDGE);
-
+
when(session.createConsumer(destination, null)).thenReturn(messageConsumer);
TextMessageImpl jmsTestMessage = new TextMessageImpl(
@@ -90,21 +99,21 @@ public void testWithMessageCorrelator() throws JMSException {
endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);
endpoint.getEndpointConfiguration().setDestination(destination);
-
+
MessageCorrelator correlator = new DefaultMessageCorrelator();
endpoint.getEndpointConfiguration().setCorrelator(correlator);
-
+
final Message controlMessage = new DefaultMessage("Hello World! ");
Map headers = new HashMap();
-
+
reset(connectionFactory, destination, connection, session, messageConsumer);
when(connectionFactory.createConnection()).thenReturn(connection);
when(connection.createSession(anyBoolean(), anyInt())).thenReturn(session);
when(session.getTransacted()).thenReturn(false);
when(session.getAcknowledgeMode()).thenReturn(Session.AUTO_ACKNOWLEDGE);
-
+
when(session.createConsumer(destination, null)).thenReturn(messageConsumer);
TextMessageImpl jmsTestMessage = new TextMessageImpl(
@@ -235,7 +244,8 @@ public void testNoCorrelationKeyFound() {
Assert.fail("Missing " + IllegalArgumentException.class + " because no reply destination found");
}
- @Test
+ @Test(expectedExceptions = CitrusRuntimeException.class,
+ expectedExceptionsMessageRegExp = "Failed to find JMS reply destination for message correlation key: '123456789'")
public void testSendMessageWithMissingReplyTo() throws JMSException {
JmsSyncEndpoint endpoint = new JmsSyncEndpoint();
endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);
@@ -251,20 +261,14 @@ public void testSendMessageWithMissingReplyTo() throws JMSException {
final Message message = new DefaultMessage("Hello World! ");
- try {
- JmsSyncConsumer jmsSyncConsumer = (JmsSyncConsumer)endpoint.createConsumer();
- jmsSyncConsumer.saveReplyDestination(requestMessage, context);
- jmsSyncConsumer.send(message, context);
- } catch(IllegalArgumentException e) {
- Assert.assertTrue(e.getMessage().startsWith("Failed to find JMS reply destination"), e.getMessage());
- return;
- }
-
- Assert.fail("Missing " + IllegalArgumentException.class + " because of missing correlation key");
+ JmsSyncConsumer jmsSyncConsumer = (JmsSyncConsumer)endpoint.createConsumer();
+ jmsSyncConsumer.saveReplyDestination(requestMessage, context);
+ jmsSyncConsumer.send(message, context);
}
- @Test
- public void testNoReplyDestinationFound() throws JMSException {
+ @Test(expectedExceptions = CitrusRuntimeException.class,
+ expectedExceptionsMessageRegExp = "Failed to find JMS reply destination for message correlation key: '123456789'")
+ public void testNoReplyDestinationFound() {
JmsSyncEndpoint endpoint = new JmsSyncEndpoint();
endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);
@@ -278,30 +282,17 @@ public void testNoReplyDestinationFound() throws JMSException {
Map headers = new HashMap();
final Message message = new DefaultMessage("Hello World! ", headers);
- try {
- JmsSyncConsumer jmsSyncConsumer = (JmsSyncConsumer)endpoint.createConsumer();
- jmsSyncConsumer.send(message, context);
- } catch(IllegalArgumentException e) {
- Assert.assertTrue(e.getMessage().startsWith("Failed to find JMS reply destination for message correlation key"));
- return;
- }
-
- Assert.fail("Missing " + IllegalArgumentException.class + " because no reply destination found");
+ JmsSyncConsumer jmsSyncConsumer = (JmsSyncConsumer)endpoint.createConsumer();
+ jmsSyncConsumer.send(message, context);
}
- @Test
- public void testSendEmptyMessage() throws JMSException {
+ @Test(expectedExceptions = CitrusRuntimeException.class,
+ expectedExceptionsMessageRegExp = "Message is empty - unable to send empty message")
+ public void testSendEmptyMessage() {
JmsSyncEndpoint endpoint = new JmsSyncEndpoint();
endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);
- try {
- JmsSyncConsumer jmsSyncConsumer = (JmsSyncConsumer)endpoint.createConsumer();
- jmsSyncConsumer.send(null, context);
- } catch(IllegalArgumentException e) {
- Assert.assertEquals(e.getMessage(), "Message is empty - unable to send empty message");
- return;
- }
-
- Assert.fail("Missing " + IllegalArgumentException.class + " because of sending empty message");
+ JmsSyncConsumer jmsSyncConsumer = (JmsSyncConsumer)endpoint.createConsumer();
+ jmsSyncConsumer.send(null, context);
}
}
diff --git a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/endpoint/JmsEndpointSyncProducerTest.java b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/endpoint/JmsEndpointSyncProducerTest.java
index 63bd2ac786..4905719254 100644
--- a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/endpoint/JmsEndpointSyncProducerTest.java
+++ b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/endpoint/JmsEndpointSyncProducerTest.java
@@ -16,20 +16,31 @@
package org.citrusframework.jms.endpoint;
+import java.util.HashMap;
+import java.util.Map;
+
+import jakarta.jms.Connection;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.Destination;
+import jakarta.jms.JMSException;
+import jakarta.jms.MessageConsumer;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.Queue;
+import jakarta.jms.Session;
+import jakarta.jms.TemporaryQueue;
+import jakarta.jms.TextMessage;
import org.citrusframework.exceptions.ActionTimeoutException;
import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.message.*;
+import org.citrusframework.message.DefaultMessage;
+import org.citrusframework.message.DefaultMessageCorrelator;
import org.citrusframework.message.Message;
+import org.citrusframework.message.MessageCorrelator;
import org.citrusframework.message.correlation.ObjectStore;
import org.citrusframework.testng.AbstractTestNGUnitTest;
import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.Test;
-import jakarta.jms.*;
-import java.util.HashMap;
-import java.util.Map;
-
import static org.mockito.Mockito.*;
/**
@@ -37,18 +48,18 @@
*/
public class JmsEndpointSyncProducerTest extends AbstractTestNGUnitTest {
- private ConnectionFactory connectionFactory = Mockito.mock(ConnectionFactory.class);
- private Connection connection = Mockito.mock(Connection.class);
- private Session session = Mockito.mock(Session.class);
- private Destination destination = Mockito.mock(Destination.class);
- private Queue destinationQueue = Mockito.mock(Queue.class);
- private MessageConsumer messageConsumer = Mockito.mock(MessageConsumer.class);
- private MessageProducer messageProducer = Mockito.mock(MessageProducer.class);
- private Queue replyDestinationQueue = Mockito.mock(Queue.class);
- private TemporaryQueue tempReplyQueue = Mockito.mock(TemporaryQueue.class);
+ private final ConnectionFactory connectionFactory = Mockito.mock(ConnectionFactory.class);
+ private final Connection connection = Mockito.mock(Connection.class);
+ private final Session session = Mockito.mock(Session.class);
+ private final Destination destination = Mockito.mock(Destination.class);
+ private final Queue destinationQueue = Mockito.mock(Queue.class);
+ private final MessageConsumer messageConsumer = Mockito.mock(MessageConsumer.class);
+ private final MessageProducer messageProducer = Mockito.mock(MessageProducer.class);
+ private final Queue replyDestinationQueue = Mockito.mock(Queue.class);
+ private final TemporaryQueue tempReplyQueue = Mockito.mock(TemporaryQueue.class);
private int retryCount = 0;
-
+
@Test
public void testSendMessageWithReplyDestination() throws JMSException {
JmsSyncEndpoint endpoint = new JmsSyncEndpoint();
@@ -56,12 +67,12 @@ public void testSendMessageWithReplyDestination() throws JMSException {
endpoint.getEndpointConfiguration().setDestination(destination);
endpoint.getEndpointConfiguration().setReplyDestination(replyDestinationQueue);
-
+
final Message message = new DefaultMessage("Hello World! ");
Map responseHeaders = new HashMap();
TextMessage jmsResponse = new TextMessageImpl("Hello World! ", responseHeaders);
-
+
reset(connectionFactory, destination, connection, session, messageConsumer, messageProducer);
when(connectionFactory.createConnection()).thenReturn(connection);
@@ -80,7 +91,7 @@ public void testSendMessageWithReplyDestination() throws JMSException {
verify(messageProducer).send((TextMessage)any());
verify(connection).start();
}
-
+
@Test
public void testSendMessageWithReplyDestinationName() throws JMSException {
JmsSyncEndpoint endpoint = new JmsSyncEndpoint();
@@ -88,12 +99,12 @@ public void testSendMessageWithReplyDestinationName() throws JMSException {
endpoint.getEndpointConfiguration().setDestinationName("myDestination");
endpoint.getEndpointConfiguration().setReplyDestinationName("replyDestination");
-
+
final Message message = new DefaultMessage("Hello World! ");
Map responseHeaders = new HashMap();
TextMessage jmsResponse = new TextMessageImpl("Hello World! ", responseHeaders);
-
+
reset(connectionFactory, destination, connection, session, messageConsumer, messageProducer);
when(connectionFactory.createConnection()).thenReturn(connection);
@@ -116,19 +127,19 @@ public void testSendMessageWithReplyDestinationName() throws JMSException {
verify(messageProducer).send((TextMessage)any());
verify(connection).start();
}
-
+
@Test
public void testSendMessageWithTemporaryReplyDestination() throws JMSException {
JmsSyncEndpoint endpoint = new JmsSyncEndpoint();
endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);
endpoint.getEndpointConfiguration().setDestination(destination);
-
+
final Message message = new DefaultMessage("Hello World! ");
Map responseHeaders = new HashMap();
TextMessage jmsResponse = new TextMessageImpl("Hello World! ", responseHeaders);
-
+
reset(connectionFactory, destination, connection, session, messageConsumer, messageProducer, tempReplyQueue);
when(connectionFactory.createConnection()).thenReturn(connection);
@@ -159,12 +170,12 @@ public void testSendMessageWithReplyHandler() throws JMSException {
endpoint.getEndpointConfiguration().setDestination(destination);
endpoint.getEndpointConfiguration().setReplyDestination(replyDestinationQueue);
-
+
final Message message = new DefaultMessage("Hello World! ");
Map responseHeaders = new HashMap();
TextMessage jmsResponse = new TextMessageImpl("Hello World! ", responseHeaders);
-
+
reset(connectionFactory, destination, connection, session, messageConsumer, messageProducer);
when(connectionFactory.createConnection()).thenReturn(connection);
@@ -183,7 +194,7 @@ public void testSendMessageWithReplyHandler() throws JMSException {
verify(messageProducer).send((TextMessage)any());
verify(connection).start();
}
-
+
@Test
@SuppressWarnings("rawtypes")
public void testSendMessageWithReplyMessageCorrelator() throws JMSException {
@@ -200,7 +211,7 @@ public void testSendMessageWithReplyMessageCorrelator() throws JMSException {
Map responseHeaders = new HashMap();
TextMessage jmsResponse = new TextMessageImpl("Hello World! ", responseHeaders);
-
+
reset(connectionFactory, destination, connection, session, messageConsumer, messageProducer);
when(connectionFactory.createConnection()).thenReturn(connection);
@@ -219,22 +230,14 @@ public void testSendMessageWithReplyMessageCorrelator() throws JMSException {
verify(connection).start();
verify(messageProducer).send((TextMessage)any());
}
-
- @Test
+
+ @Test(expectedExceptions = CitrusRuntimeException.class, expectedExceptionsMessageRegExp = "Message is empty - unable to send empty message")
public void testSendEmptyMessage() throws JMSException {
JmsSyncEndpoint endpoint = new JmsSyncEndpoint();
endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);
endpoint.getEndpointConfiguration().setDestination(destination);
-
- try {
- endpoint.createProducer().send(null, context);
- } catch(IllegalArgumentException e) {
- Assert.assertEquals(e.getMessage(), "Message is empty - unable to send empty message");
- return;
- }
-
- Assert.fail("Missing " + CitrusRuntimeException.class + " because of sending empty message");
+ endpoint.createProducer().send(null, context);
}
@Test
diff --git a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsByteMessageJavaIT.java b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsByteMessageJavaIT.java
index 943acdb1e7..4c392c4ac7 100644
--- a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsByteMessageJavaIT.java
+++ b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsByteMessageJavaIT.java
@@ -23,7 +23,6 @@
import org.citrusframework.message.MessageType;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
import org.citrusframework.util.FileUtils;
-import org.springframework.util.FileCopyUtils;
import org.testng.annotations.Test;
import static org.citrusframework.actions.ReceiveMessageAction.Builder.receive;
@@ -40,7 +39,7 @@ public class JmsByteMessageJavaIT extends TestNGCitrusSpringSupport {
public void jmsByteMessage() throws IOException {
when(send("jms:queue:jms.binary.queue")
.message(new DefaultMessage(
- FileCopyUtils.copyToByteArray(
+ FileUtils.copyToByteArray(
FileUtils.getFileResource("org/citrusframework/jms/integration/button.png")
.getInputStream())))
.process(toBinary()));
diff --git a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsCommunicationJavaIT.java b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsCommunicationJavaIT.java
index ebe4d8e3b9..50f555d3d5 100644
--- a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsCommunicationJavaIT.java
+++ b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsCommunicationJavaIT.java
@@ -17,8 +17,8 @@
package org.citrusframework.jms.integration;
import org.citrusframework.annotations.CitrusTest;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
-import org.springframework.core.io.ClassPathResource;
import org.testng.annotations.Test;
import static org.citrusframework.actions.ReceiveMessageAction.Builder.receive;
@@ -64,13 +64,13 @@ public void jmsQueues() {
when(send("helloServiceJmsEndpoint")
.message()
- .body(new ClassPathResource("org/citrusframework/jms/integration/helloRequest.xml"))
+ .body(Resources.newClasspathResource("org/citrusframework/jms/integration/helloRequest.xml"))
.header("Operation", operation)
.header("CorrelationId", "${correlationId}"));
then(receive("helloServiceResponseJmsEndpoint")
.message()
- .body(new ClassPathResource("org/citrusframework/jms/integration/helloResponse.xml"))
+ .body(Resources.newClasspathResource("org/citrusframework/jms/integration/helloResponse.xml"))
.header("Operation", operation)
.header("CorrelationId", "${correlationId}"));
}
@@ -100,7 +100,7 @@ public void JmsCommunicationEmptyReceiveIT() {
when(send("helloServiceJmsEndpoint")
.message()
- .body(new ClassPathResource("org/citrusframework/jms/integration/helloRequest.xml"))
+ .body(Resources.newClasspathResource("org/citrusframework/jms/integration/helloRequest.xml"))
.header("Operation", operation)
.header("CorrelationId", "${correlationId}"));
diff --git a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsGzipMessageJavaIT.java b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsGzipMessageJavaIT.java
index 198a3009e4..ee2d433453 100644
--- a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsGzipMessageJavaIT.java
+++ b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsGzipMessageJavaIT.java
@@ -23,7 +23,6 @@
import org.citrusframework.message.MessageType;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
import org.citrusframework.util.FileUtils;
-import org.springframework.util.FileCopyUtils;
import org.testng.annotations.Test;
import static org.citrusframework.actions.ReceiveMessageAction.Builder.receive;
@@ -40,7 +39,7 @@ public class JmsGzipMessageJavaIT extends TestNGCitrusSpringSupport {
public void jmsByteMessage() throws IOException {
when(send("jms:queue:jms.gzip.queue")
.message(new DefaultMessage(
- FileCopyUtils.copyToByteArray(
+ FileUtils.copyToByteArray(
FileUtils.getFileResource("org/citrusframework/jms/integration/button.png")
.getInputStream())))
.process(toGzip()));
diff --git a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsSendReceiveJavaIT.java b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsSendReceiveJavaIT.java
index aebdb974b9..c0a643e89c 100644
--- a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsSendReceiveJavaIT.java
+++ b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsSendReceiveJavaIT.java
@@ -19,8 +19,8 @@
import java.util.Collections;
import org.citrusframework.annotations.CitrusTest;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
-import org.springframework.core.io.ClassPathResource;
import org.testng.annotations.Test;
import static org.citrusframework.actions.EchoAction.Builder.echo;
@@ -72,13 +72,13 @@ public void JmsSendReceiveJavaIT() {
when(send("helloServiceJmsEndpoint")
.message()
- .body(new ClassPathResource("org/citrusframework/jms/integration/helloRequest.xml"))
+ .body(Resources.newClasspathResource("org/citrusframework/jms/integration/helloRequest.xml"))
.header("Operation", "sayHello")
.header("CorrelationId", "${correlationId}"));
then(receive("helloServiceResponseJmsEndpoint")
.message()
- .body(new ClassPathResource("org/citrusframework/jms/integration/helloResponse.xml"))
+ .body(Resources.newClasspathResource("org/citrusframework/jms/integration/helloResponse.xml"))
.header("Operation", "sayHello")
.header("CorrelationId", "${correlationId}"));
diff --git a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsSyncSendReceiveJavaIT.java b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsSyncSendReceiveJavaIT.java
index 3eb88c51a5..db3c209bee 100644
--- a/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsSyncSendReceiveJavaIT.java
+++ b/endpoints/citrus-jms/src/test/java/org/citrusframework/jms/integration/JmsSyncSendReceiveJavaIT.java
@@ -17,8 +17,8 @@
package org.citrusframework.jms.integration;
import org.citrusframework.annotations.CitrusTest;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
-import org.springframework.core.io.ClassPathResource;
import org.testng.annotations.Test;
import static org.citrusframework.actions.EchoAction.Builder.echo;
@@ -65,13 +65,13 @@ public void JmsSyncSendReceiveJavaIT() {
when(send("helloServiceJmsSyncEndpoint")
.message()
- .body(new ClassPathResource("org/citrusframework/jms/integration/helloRequest.xml"))
+ .body(Resources.newClasspathResource("org/citrusframework/jms/integration/helloRequest.xml"))
.header("Operation", "sayHello")
.header("CorrelationId", "${correlationId}"));
then(receive("helloServiceJmsSyncEndpoint")
.message()
- .body(new ClassPathResource("org/citrusframework/jms/integration/helloResponse.xml"))
+ .body(Resources.newClasspathResource("org/citrusframework/jms/integration/helloResponse.xml"))
.header("Operation", "sayHello")
.header("CorrelationId", "${correlationId}"));
}
diff --git a/endpoints/citrus-jmx/pom.xml b/endpoints/citrus-jmx/pom.xml
index db235d9d7c..dce1eb2a80 100644
--- a/endpoints/citrus-jmx/pom.xml
+++ b/endpoints/citrus-jmx/pom.xml
@@ -52,6 +52,11 @@
provided
+
+ org.springframework
+ spring-beans
+
+
jakarta.xml.bind
jakarta.xml.bind-api
diff --git a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/client/JmxClient.java b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/client/JmxClient.java
index ef05f3addc..7d1d9aad7e 100644
--- a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/client/JmxClient.java
+++ b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/client/JmxClient.java
@@ -16,6 +16,12 @@
package org.citrusframework.jmx.client;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.util.Collections;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
import javax.management.Attribute;
import javax.management.InstanceNotFoundException;
import javax.management.JMException;
@@ -29,12 +35,6 @@
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
-import java.io.IOException;
-import java.lang.management.ManagementFactory;
-import java.util.Collections;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
import org.citrusframework.context.TestContext;
import org.citrusframework.endpoint.AbstractEndpoint;
@@ -50,9 +50,9 @@
import org.citrusframework.messaging.Producer;
import org.citrusframework.messaging.ReplyConsumer;
import org.citrusframework.messaging.SelectiveConsumer;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -64,7 +64,7 @@ public class JmxClient extends AbstractEndpoint implements Producer, ReplyConsum
private static final Logger logger = LoggerFactory.getLogger(JmxClient.class);
/** Store of reply messages */
- private CorrelationManager correlationManager;
+ private final CorrelationManager correlationManager;
/** Saves the network connection id */
private String connectionId;
@@ -76,7 +76,7 @@ public class JmxClient extends AbstractEndpoint implements Producer, ReplyConsum
private NotificationListener notificationListener;
/** Scheduler */
- private ScheduledExecutorService scheduledExecutor = new ScheduledThreadPoolExecutor(1);
+ private final ScheduledExecutorService scheduledExecutor = new ScheduledThreadPoolExecutor(1);
/**
* Default constructor initializing endpoint configuration.
diff --git a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/config/annotation/JmxClientConfigParser.java b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/config/annotation/JmxClientConfigParser.java
index 19c3c1de43..15a3e6f0be 100644
--- a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/config/annotation/JmxClientConfigParser.java
+++ b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/config/annotation/JmxClientConfigParser.java
@@ -25,7 +25,7 @@
import org.citrusframework.jmx.message.JmxMessageConverter;
import org.citrusframework.message.MessageCorrelator;
import org.citrusframework.spi.ReferenceResolver;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/config/annotation/JmxServerConfigParser.java b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/config/annotation/JmxServerConfigParser.java
index d758e38cef..e68c0a4228 100644
--- a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/config/annotation/JmxServerConfigParser.java
+++ b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/config/annotation/JmxServerConfigParser.java
@@ -29,8 +29,7 @@
import org.citrusframework.jmx.server.JmxServer;
import org.citrusframework.jmx.server.JmxServerBuilder;
import org.citrusframework.spi.ReferenceResolver;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -89,15 +88,15 @@ public JmxServer parse(JmxServerConfig annotation, ReferenceResolver referenceRe
ManagedBeanInvocation.Operation op = new ManagedBeanInvocation.Operation();
op.setName(mbeanOperationConfig.name());
- Class[] parameter = mbeanOperationConfig.parameter();
+ Class>[] parameter = mbeanOperationConfig.parameter();
ManagedBeanInvocation.Parameter params = new ManagedBeanInvocation.Parameter();
- for (Class paramType : parameter) {
+ for (Class> paramType : parameter) {
OperationParam p = new OperationParam();
p.setType(paramType.getName());
params.getParameter().add(p);
}
- if (!CollectionUtils.isEmpty(params.getParameter())) {
+ if (params.getParameter() != null && !params.getParameter().isEmpty()) {
op.setParameter(params);
}
diff --git a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/endpoint/JmxEndpointConfiguration.java b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/endpoint/JmxEndpointConfiguration.java
index a3b060249d..7bb53b4197 100644
--- a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/endpoint/JmxEndpointConfiguration.java
+++ b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/endpoint/JmxEndpointConfiguration.java
@@ -16,10 +16,10 @@
package org.citrusframework.jmx.endpoint;
-import javax.management.NotificationFilter;
import java.rmi.registry.Registry;
import java.util.HashMap;
import java.util.Map;
+import javax.management.NotificationFilter;
import org.citrusframework.endpoint.AbstractPollableEndpointConfiguration;
import org.citrusframework.jmx.message.JmxMessageConverter;
@@ -28,7 +28,7 @@
import org.citrusframework.message.MessageCorrelator;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/message/JmxMessageConverter.java b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/message/JmxMessageConverter.java
index 4ed559bbd4..d9c8b3f7c0 100644
--- a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/message/JmxMessageConverter.java
+++ b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/message/JmxMessageConverter.java
@@ -25,8 +25,8 @@
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageConverter;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.xml.StringResult;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -54,7 +54,7 @@ public void convertOutbound(ManagedBeanInvocation mBeanInvocation, Message inter
}
if (internalMessage.getHeader(JmxMessageHeaders.JMX_OPERATION_PARAMS) != null) {
- String[] params = StringUtils.commaDelimitedListToStringArray(internalMessage.getHeader(JmxMessageHeaders.JMX_OPERATION_PARAMS).toString());
+ String[] params = String.valueOf(internalMessage.getHeader(JmxMessageHeaders.JMX_OPERATION_PARAMS)).split(",");
for (String param : params) {
OperationParam operationParam = new OperationParam();
operationParam.setType(String.class.getName());
@@ -122,7 +122,7 @@ private ManagedBeanInvocation getServiceInvocation(Message message, JmxEndpointC
if (payload != null) {
if (payload instanceof ManagedBeanInvocation) {
serviceInvocation = (ManagedBeanInvocation) payload;
- } else if (payload != null && StringUtils.hasText(message.getPayload(String.class))) {
+ } else if (StringUtils.hasText(message.getPayload(String.class))) {
serviceInvocation = (ManagedBeanInvocation) endpointConfiguration.getMarshaller()
.unmarshal(message.getPayload(Source.class));
} else {
diff --git a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/JmxMarshaller.java b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/JmxMarshaller.java
index 5416ea1c61..69b1f7b0c3 100644
--- a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/JmxMarshaller.java
+++ b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/JmxMarshaller.java
@@ -16,15 +16,15 @@
package org.citrusframework.jmx.model;
-import jakarta.xml.bind.JAXBException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
+import jakarta.xml.bind.JAXBException;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resources;
import org.citrusframework.xml.Jaxb2Marshaller;
import org.citrusframework.xml.Marshaller;
import org.citrusframework.xml.Unmarshaller;
-import org.springframework.core.io.ClassPathResource;
/**
* @author Christoph Deppisch
@@ -36,7 +36,7 @@ public class JmxMarshaller implements Marshaller, Unmarshaller {
public JmxMarshaller() {
this.marshaller = new Jaxb2Marshaller(
- new ClassPathResource("org/citrusframework/schema/citrus-jmx-message.xsd"), ManagedBeanInvocation.class, ManagedBeanResult.class);
+ Resources.newClasspathResource("org/citrusframework/schema/citrus-jmx-message.xsd"), ManagedBeanInvocation.class, ManagedBeanResult.class);
}
public void marshal(Object graph, Result result) {
diff --git a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/ManagedBeanDefinition.java b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/ManagedBeanDefinition.java
index c1783287ae..e5ed4c75b9 100644
--- a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/ManagedBeanDefinition.java
+++ b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/ManagedBeanDefinition.java
@@ -16,13 +16,22 @@
package org.citrusframework.jmx.model;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.springframework.util.ReflectionUtils;
-import org.springframework.util.StringUtils;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanParameterInfo;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
-import javax.management.*;
-import java.lang.reflect.*;
-import java.util.*;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.util.ReflectionHelper;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -32,7 +41,7 @@ public class ManagedBeanDefinition {
public static final String OPERATION_DESCRIPTION = "Operation exposed for management";
public static final String ATTRIBUTE_DESCRIPTION = "Attribute exposed for management";
- private Class type;
+ private Class> type;
private String objectDomain;
private String objectName;
@@ -96,20 +105,16 @@ private MBeanOperationInfo[] getOperationInfo() {
final List infoList = new ArrayList<>();
if (type != null) {
- ReflectionUtils.doWithMethods(type, new ReflectionUtils.MethodCallback() {
- @Override
- public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
- infoList.add(new MBeanOperationInfo(OPERATION_DESCRIPTION, method));
- }
- }, new ReflectionUtils.MethodFilter() {
- @Override
- public boolean matches(Method method) {
- return method.getDeclaringClass().equals(type)
- && !method.getName().startsWith("set")
- && !method.getName().startsWith("get")
- && !method.getName().startsWith("is")
- && !method.getName().startsWith("$jacoco"); // Fix for code coverage
+ ReflectionHelper.doWithMethods(type, method -> {
+ if (!method.getDeclaringClass().equals(type)
+ || method.getName().startsWith("set")
+ || method.getName().startsWith("get")
+ || method.getName().startsWith("is")
+ || method.getName().startsWith("$jacoco")) { // Fix for code coverage
+ return;
}
+
+ infoList.add(new MBeanOperationInfo(OPERATION_DESCRIPTION, method));
});
} else {
for (ManagedBeanInvocation.Operation operation : operations) {
@@ -135,7 +140,7 @@ private MBeanConstructorInfo[] getConstructorInfo() {
final List infoList = new ArrayList<>();
if (type != null) {
- for (Constructor constructor : type.getConstructors()) {
+ for (Constructor> constructor : type.getConstructors()) {
infoList.add(new MBeanConstructorInfo(constructor.toGenericString(), constructor));
}
}
@@ -154,41 +159,34 @@ private MBeanAttributeInfo[] getAttributeInfo() {
final List attributes = new ArrayList<>();
if (type.isInterface()) {
- ReflectionUtils.doWithMethods(type, new ReflectionUtils.MethodCallback() {
- @Override
- public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
- String attributeName;
-
- if (method.getName().startsWith("get")) {
- attributeName = method.getName().substring(3);
- } else if (method.getName().startsWith("is")) {
- attributeName = method.getName().substring(2);
- } else {
- attributeName = method.getName();
- }
-
- if (!attributes.contains(attributeName)) {
- infoList.add(new MBeanAttributeInfo(attributeName, method.getReturnType().getName(), ATTRIBUTE_DESCRIPTION, true, true, method.getName().startsWith("is")));
- attributes.add(attributeName);
- }
+ ReflectionHelper.doWithMethods(type, method -> {
+ if (!method.getDeclaringClass().equals(type) ||
+ !(method.getName().startsWith("get") || method.getName().startsWith("is"))) {
+ return;
+ }
+
+ String attributeName;
+
+ if (method.getName().startsWith("get")) {
+ attributeName = method.getName().substring(3);
+ } else if (method.getName().startsWith("is")) {
+ attributeName = method.getName().substring(2);
+ } else {
+ attributeName = method.getName();
}
- }, new ReflectionUtils.MethodFilter() {
- @Override
- public boolean matches(Method method) {
- return method.getDeclaringClass().equals(type) && (method.getName().startsWith("get") || method.getName().startsWith("is"));
+
+ if (!attributes.contains(attributeName)) {
+ infoList.add(new MBeanAttributeInfo(attributeName, method.getReturnType().getName(), ATTRIBUTE_DESCRIPTION, true, true, method.getName().startsWith("is")));
+ attributes.add(attributeName);
}
});
} else {
- ReflectionUtils.doWithFields(type, new ReflectionUtils.FieldCallback() {
- @Override
- public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
- infoList.add(new MBeanAttributeInfo(field.getName(), field.getType().getName(), ATTRIBUTE_DESCRIPTION, true, true, field.getType().equals(Boolean.class)));
- }
- }, new ReflectionUtils.FieldFilter() {
- @Override
- public boolean matches(Field field) {
- return !Modifier.isStatic(field.getModifiers()) && !Modifier.isFinal(field.getModifiers());
+ ReflectionHelper.doWithFields(type, field -> {
+ if (Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())) {
+ return;
}
+
+ infoList.add(new MBeanAttributeInfo(field.getName(), field.getType().getName(), ATTRIBUTE_DESCRIPTION, true, true, field.getType().equals(Boolean.class)));
});
}
} else {
diff --git a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/ManagedBeanInvocation.java b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/ManagedBeanInvocation.java
index f1898ed6fa..68b2f8114a 100644
--- a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/ManagedBeanInvocation.java
+++ b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/ManagedBeanInvocation.java
@@ -24,8 +24,6 @@
import java.util.Map;
import java.util.Properties;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.spi.ReferenceResolver;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
@@ -33,9 +31,10 @@
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlTransient;
import jakarta.xml.bind.annotation.XmlType;
-import org.springframework.beans.ConversionNotSupportedException;
-import org.springframework.beans.SimpleTypeConverter;
-import org.springframework.util.StringUtils;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.util.StringUtils;
+import org.citrusframework.util.TypeConverter;
/**
* @author Christoph Deppisch
@@ -114,15 +113,7 @@ public java.lang.Object getAttributeValue(ReferenceResolver referenceResolver) {
return map;
} else {
- try {
- return new SimpleTypeConverter().convertIfNecessary(value, argType);
- } catch (ConversionNotSupportedException e) {
- if (String.class.equals(argType)) {
- return value.toString();
- }
-
- throw e;
- }
+ return TypeConverter.lookupDefault().convertIfNecessary(value, argType);
}
} catch (ClassNotFoundException e) {
throw new CitrusRuntimeException("Failed to construct attribute object", e);
@@ -473,15 +464,7 @@ public Object[] getParamValues(ReferenceResolver referenceResolver) {
argValues.add(map);
} else {
- try {
- argValues.add(new SimpleTypeConverter().convertIfNecessary(value, argType));
- } catch (ConversionNotSupportedException e) {
- if (String.class.equals(argType)) {
- argValues.add(value.toString());
- }
-
- throw e;
- }
+ argValues.add(TypeConverter.lookupDefault().convertIfNecessary(value, argType));
}
}
}
diff --git a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/ManagedBeanResult.java b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/ManagedBeanResult.java
index a4bf8d1343..c0a71c66b3 100644
--- a/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/ManagedBeanResult.java
+++ b/endpoints/citrus-jmx/src/main/java/org/citrusframework/jmx/model/ManagedBeanResult.java
@@ -22,8 +22,6 @@
import java.util.Map;
import java.util.Properties;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.spi.ReferenceResolver;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
@@ -31,9 +29,10 @@
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlTransient;
import jakarta.xml.bind.annotation.XmlType;
-import org.springframework.beans.ConversionNotSupportedException;
-import org.springframework.beans.SimpleTypeConverter;
-import org.springframework.util.StringUtils;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.util.StringUtils;
+import org.citrusframework.util.TypeConverter;
/**
* @author Christoph Deppisch
@@ -116,15 +115,7 @@ public java.lang.Object getResultObject(ReferenceResolver referenceResolver) {
return map;
} else {
- try {
- return new SimpleTypeConverter().convertIfNecessary(value, argType);
- } catch (ConversionNotSupportedException e) {
- if (String.class.equals(argType)) {
- return value.toString();
- }
-
- throw e;
- }
+ return TypeConverter.lookupDefault().convertIfNecessary(value, argType);
}
} catch (ClassNotFoundException e) {
throw new CitrusRuntimeException("Failed to construct service result object", e);
diff --git a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/config/annotation/KafkaEndpointConfigParser.java b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/config/annotation/KafkaEndpointConfigParser.java
index 3e08becad3..14a43aa6da 100644
--- a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/config/annotation/KafkaEndpointConfigParser.java
+++ b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/config/annotation/KafkaEndpointConfigParser.java
@@ -26,7 +26,7 @@
import org.citrusframework.kafka.message.KafkaMessageConverter;
import org.citrusframework.kafka.message.KafkaMessageHeaderMapper;
import org.citrusframework.spi.ReferenceResolver;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/embedded/EmbeddedKafkaServer.java b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/embedded/EmbeddedKafkaServer.java
index e9efe1a9bc..283c4b217f 100644
--- a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/embedded/EmbeddedKafkaServer.java
+++ b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/embedded/EmbeddedKafkaServer.java
@@ -21,6 +21,7 @@
import java.net.InetSocketAddress;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -50,7 +51,6 @@
import org.apache.zookeeper.server.ZooKeeperServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
/**
* Embedded Kafka server with reference to embedded Zookeeper cluster for testing purpose. Starts single Zookeeper instance with logs in Java temp directory. Starts single Kafka server
@@ -128,7 +128,7 @@ public void start() {
kafkaServer.startup();
kafkaServer.boundPort(ListenerName.forSecurityProtocol(SecurityProtocol.PLAINTEXT));
- createKafkaTopics(StringUtils.commaDelimitedListToSet(topics));
+ createKafkaTopics(Arrays.stream(topics.split(",")).collect(Collectors.toSet()));
}
/**
diff --git a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/embedded/EmbeddedKafkaServerBuilder.java b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/embedded/EmbeddedKafkaServerBuilder.java
index 6553e75d5d..43a1acaefc 100644
--- a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/embedded/EmbeddedKafkaServerBuilder.java
+++ b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/embedded/EmbeddedKafkaServerBuilder.java
@@ -16,8 +16,6 @@
package org.citrusframework.kafka.embedded;
-import org.springframework.util.StringUtils;
-
import java.util.Map;
/**
@@ -83,7 +81,7 @@ public EmbeddedKafkaServerBuilder topics(String topics) {
* @return
*/
public EmbeddedKafkaServerBuilder topics(String ... topics) {
- return topics(StringUtils.arrayToCommaDelimitedString(topics));
+ return topics(String.join(",", topics));
}
/**
diff --git a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaConsumer.java b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaConsumer.java
index 0bd25288b2..7c9dbd6344 100644
--- a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaConsumer.java
+++ b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaConsumer.java
@@ -22,19 +22,18 @@
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
+import java.util.stream.Collectors;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.MessageTimeoutException;
import org.citrusframework.kafka.message.KafkaMessageHeaders;
import org.citrusframework.message.Message;
import org.citrusframework.messaging.AbstractMessageConsumer;
-import org.apache.kafka.clients.consumer.ConsumerConfig;
-import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -71,8 +70,8 @@ public Message receive(TestContext context, long timeout) {
logger.debug("Receiving Kafka message on topic: '" + topic);
}
- if (CollectionUtils.isEmpty(consumer.subscription())) {
- consumer.subscribe(Arrays.asList(StringUtils.commaDelimitedListToStringArray(topic)));
+ if (consumer.subscription() == null || consumer.subscription().isEmpty()) {
+ consumer.subscribe(Arrays.stream(topic.split(",")).collect(Collectors.toList()));
}
ConsumerRecords records = consumer.poll(Duration.ofMillis(timeout));
@@ -100,7 +99,7 @@ public Message receive(TestContext context, long timeout) {
*/
public void stop() {
try {
- if (!CollectionUtils.isEmpty(consumer.subscription())) {
+ if (consumer.subscription() != null && !consumer.subscription().isEmpty()) {
consumer.unsubscribe();
}
} finally {
diff --git a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaProducer.java b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaProducer.java
index b7c4be9711..cc7e2271a4 100644
--- a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaProducer.java
+++ b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaProducer.java
@@ -24,17 +24,16 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.kafka.message.KafkaMessageHeaders;
import org.citrusframework.message.Message;
import org.citrusframework.messaging.Producer;
-import org.apache.kafka.clients.producer.ProducerConfig;
-import org.apache.kafka.clients.producer.ProducerRecord;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -67,7 +66,9 @@ public KafkaProducer(String name, KafkaEndpointConfiguration endpointConfigurati
@Override
public void send(final Message message, final TestContext context) {
- Assert.notNull(message, "Message is empty - unable to send empty message");
+ if (message == null) {
+ throw new CitrusRuntimeException("Message is empty - unable to send empty message");
+ }
String topic = Optional.ofNullable(message.getHeader(KafkaMessageHeaders.TOPIC))
.map(Object::toString)
@@ -101,11 +102,11 @@ public void send(final Message message, final TestContext context) {
private org.apache.kafka.clients.producer.KafkaProducer createKafkaProducer() {
Map producerProps = new HashMap<>();
producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, endpointConfiguration.getServer());
- producerProps.put(ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, new Long(endpointConfiguration.getTimeout()).intValue());
+ producerProps.put(ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, Long.valueOf(endpointConfiguration.getTimeout()).intValue());
producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, endpointConfiguration.getKeySerializer());
producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, endpointConfiguration.getValueSerializer());
- producerProps.put(ProducerConfig.CLIENT_ID_CONFIG, Optional.ofNullable(endpointConfiguration.getClientId()).orElse(KafkaMessageHeaders.KAFKA_PREFIX + "producer_" + UUID.randomUUID().toString()));
+ producerProps.put(ProducerConfig.CLIENT_ID_CONFIG, Optional.ofNullable(endpointConfiguration.getClientId()).orElse(KafkaMessageHeaders.KAFKA_PREFIX + "producer_" + UUID.randomUUID()));
producerProps.putAll(endpointConfiguration.getProducerProperties());
diff --git a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/message/KafkaMessageConverter.java b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/message/KafkaMessageConverter.java
index 378ba55640..6add10679d 100644
--- a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/message/KafkaMessageConverter.java
+++ b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/message/KafkaMessageConverter.java
@@ -19,15 +19,15 @@
import java.io.IOException;
import java.util.Optional;
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.clients.producer.ProducerRecord;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.kafka.endpoint.KafkaEndpointConfiguration;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageConverter;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
-import org.apache.kafka.clients.consumer.ConsumerRecord;
-import org.apache.kafka.clients.producer.ProducerRecord;
-import org.springframework.core.io.Resource;
/**
* Basic message converter for converting Spring Integration message implementations to Kafka
diff --git a/endpoints/citrus-kafka/src/test/java/org/citrusframework/kafka/endpoint/KafkaProducerTest.java b/endpoints/citrus-kafka/src/test/java/org/citrusframework/kafka/endpoint/KafkaProducerTest.java
index 78c5cca619..08127b6c12 100644
--- a/endpoints/citrus-kafka/src/test/java/org/citrusframework/kafka/endpoint/KafkaProducerTest.java
+++ b/endpoints/citrus-kafka/src/test/java/org/citrusframework/kafka/endpoint/KafkaProducerTest.java
@@ -131,20 +131,13 @@ public void testSendMessageTimeout() {
Assert.fail("Missing " + CitrusRuntimeException.class + " because of message timeout");
}
- @Test
+ @Test(expectedExceptions = CitrusRuntimeException.class, expectedExceptionsMessageRegExp = "Message is empty - unable to send empty message")
public void testSendEmptyMessage() {
KafkaEndpoint endpoint = new KafkaEndpoint();
endpoint.getEndpointConfiguration().setServer("localhost:9092");
endpoint.getEndpointConfiguration().setTopic("test");
- try {
- endpoint.createProducer().send(null, context);
- } catch(IllegalArgumentException e) {
- Assert.assertEquals(e.getMessage(), "Message is empty - unable to send empty message");
- return;
- }
-
- Assert.fail("Missing " + CitrusRuntimeException.class + " because of sending empty message");
+ endpoint.createProducer().send(null, context);
}
}
diff --git a/endpoints/citrus-mail/pom.xml b/endpoints/citrus-mail/pom.xml
index f22a1f6fdd..89e917d6d6 100644
--- a/endpoints/citrus-mail/pom.xml
+++ b/endpoints/citrus-mail/pom.xml
@@ -52,6 +52,10 @@
provided
+
+ org.springframework
+ spring-core
+
org.springframework
spring-context-support
diff --git a/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/client/MailClient.java b/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/client/MailClient.java
index 0c586c7fab..2028af39fc 100644
--- a/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/client/MailClient.java
+++ b/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/client/MailClient.java
@@ -16,6 +16,9 @@
package org.citrusframework.mail.client;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
import jakarta.mail.Authenticator;
import jakarta.mail.MessagingException;
import jakarta.mail.PasswordAuthentication;
@@ -27,13 +30,10 @@
import org.citrusframework.message.RawMessage;
import org.citrusframework.messaging.Consumer;
import org.citrusframework.messaging.Producer;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.mail.javamail.MimeMailMessage;
-import org.springframework.util.StringUtils;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/config/annotation/MailClientConfigParser.java b/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/config/annotation/MailClientConfigParser.java
index 3198a31d99..5695910364 100644
--- a/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/config/annotation/MailClientConfigParser.java
+++ b/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/config/annotation/MailClientConfigParser.java
@@ -25,7 +25,7 @@
import org.citrusframework.mail.message.MailMessageConverter;
import org.citrusframework.mail.model.MailMarshaller;
import org.citrusframework.spi.ReferenceResolver;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/config/annotation/MailServerConfigParser.java b/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/config/annotation/MailServerConfigParser.java
index 838f592d8f..49b30a1100 100644
--- a/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/config/annotation/MailServerConfigParser.java
+++ b/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/config/annotation/MailServerConfigParser.java
@@ -26,7 +26,7 @@
import org.citrusframework.mail.server.MailServer;
import org.citrusframework.mail.server.MailServerBuilder;
import org.citrusframework.spi.ReferenceResolver;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/message/MailMessageConverter.java b/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/message/MailMessageConverter.java
index 24924f0809..2a6555cb38 100644
--- a/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/message/MailMessageConverter.java
+++ b/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/message/MailMessageConverter.java
@@ -16,12 +16,6 @@
package org.citrusframework.mail.message;
-import jakarta.mail.MessagingException;
-import jakarta.mail.Multipart;
-import jakarta.mail.Session;
-import jakarta.mail.internet.MimeMessage;
-import jakarta.mail.internet.MimePart;
-import javax.xml.transform.Source;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -29,10 +23,19 @@
import java.io.StringReader;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
+import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
+import javax.xml.transform.Source;
+import jakarta.mail.MessagingException;
+import jakarta.mail.Multipart;
+import jakarta.mail.Session;
+import jakarta.mail.internet.MimeMessage;
+import jakarta.mail.internet.MimePart;
+import org.apache.commons.codec.binary.Base64;
import org.citrusframework.CitrusSettings;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
@@ -44,14 +47,13 @@
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageConverter;
import org.citrusframework.util.FileUtils;
-import org.apache.commons.codec.binary.Base64;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ByteArrayResource;
+import org.springframework.core.io.Resource;
import org.springframework.mail.javamail.MimeMailMessage;
import org.springframework.mail.javamail.MimeMessageHelper;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -93,14 +95,14 @@ public void convertOutbound(MimeMailMessage mimeMailMessage, Message message, Ma
try {
mimeMailMessage.setFrom(mailRequest.getFrom());
- mimeMailMessage.setTo(StringUtils.commaDelimitedListToStringArray(mailRequest.getTo()));
+ mimeMailMessage.setTo(mailRequest.getTo().split(","));
if (StringUtils.hasText(mailRequest.getCc())) {
- mimeMailMessage.setCc(StringUtils.commaDelimitedListToStringArray(mailRequest.getCc()));
+ mimeMailMessage.setCc(mailRequest.getCc().split(","));
}
if (StringUtils.hasText(mailRequest.getBcc())) {
- mimeMailMessage.setBcc(StringUtils.commaDelimitedListToStringArray(mailRequest.getBcc()));
+ mimeMailMessage.setBcc(mailRequest.getBcc().split(","));
}
mimeMailMessage.setReplyTo(mailRequest.getReplyTo() != null ? mailRequest.getReplyTo() : mailRequest.getFrom());
@@ -110,8 +112,8 @@ public void convertOutbound(MimeMailMessage mimeMailMessage, Message message, Ma
if (mailRequest.getBody().hasAttachments()) {
for (AttachmentPart attachmentPart : mailRequest.getBody().getAttachments().getAttachments()) {
- ByteArrayResource inputStreamSource = new ByteArrayResource(attachmentPart.getContent().getBytes(Charset.forName(parseCharsetFromContentType(attachmentPart.getContentType()))));
- mimeMailMessage.getMimeMessageHelper().addAttachment(attachmentPart.getFileName(), inputStreamSource,
+ Resource attachmentSource = new ByteArrayResource(attachmentPart.getContent().getBytes(Charset.forName(parseCharsetFromContentType(attachmentPart.getContentType()))));
+ mimeMailMessage.getMimeMessageHelper().addAttachment(attachmentPart.getFileName(), attachmentSource,
attachmentPart.getContentType());
}
}
@@ -156,11 +158,11 @@ protected MailMessage createMailRequest(Map messageHeaders, Body
protected Map createMessageHeaders(MimeMailMessage msg) throws MessagingException, IOException {
Map headers = new HashMap<>();
headers.put(CitrusMailMessageHeaders.MAIL_MESSAGE_ID, msg.getMimeMessage().getMessageID());
- headers.put(CitrusMailMessageHeaders.MAIL_FROM, StringUtils.arrayToCommaDelimitedString(msg.getMimeMessage().getFrom()));
- headers.put(CitrusMailMessageHeaders.MAIL_TO, StringUtils.arrayToCommaDelimitedString((msg.getMimeMessage().getRecipients(jakarta.mail.Message.RecipientType.TO))));
- headers.put(CitrusMailMessageHeaders.MAIL_CC, StringUtils.arrayToCommaDelimitedString((msg.getMimeMessage().getRecipients(jakarta.mail.Message.RecipientType.CC))));
- headers.put(CitrusMailMessageHeaders.MAIL_BCC, StringUtils.arrayToCommaDelimitedString((msg.getMimeMessage().getRecipients(jakarta.mail.Message.RecipientType.BCC))));
- headers.put(CitrusMailMessageHeaders.MAIL_REPLY_TO, StringUtils.arrayToCommaDelimitedString((msg.getMimeMessage().getReplyTo())));
+ headers.put(CitrusMailMessageHeaders.MAIL_FROM, String.join(",", Optional.ofNullable(msg.getMimeMessage().getFrom()).stream().flatMap(Arrays::stream).map(Object::toString).toList()));
+ headers.put(CitrusMailMessageHeaders.MAIL_TO, String.join(",", Optional.ofNullable(msg.getMimeMessage().getRecipients(jakarta.mail.Message.RecipientType.TO)).stream().flatMap(Arrays::stream).map(Object::toString).toList()));
+ headers.put(CitrusMailMessageHeaders.MAIL_CC, String.join(",", Optional.ofNullable(msg.getMimeMessage().getRecipients(jakarta.mail.Message.RecipientType.CC)).stream().flatMap(Arrays::stream).map(Object::toString).toList()));
+ headers.put(CitrusMailMessageHeaders.MAIL_BCC, String.join(",", Optional.ofNullable(msg.getMimeMessage().getRecipients(jakarta.mail.Message.RecipientType.BCC)).stream().flatMap(Arrays::stream).map(Object::toString).toList()));
+ headers.put(CitrusMailMessageHeaders.MAIL_REPLY_TO, String.join(",", Optional.ofNullable(msg.getMimeMessage().getReplyTo()).stream().flatMap(Arrays::stream).map(Object::toString).toList()));
headers.put(CitrusMailMessageHeaders.MAIL_DATE, msg.getMimeMessage().getSentDate() != null ? dateFormat.format(msg.getMimeMessage().getSentDate()) : null);
headers.put(CitrusMailMessageHeaders.MAIL_SUBJECT, msg.getMimeMessage().getSubject());
headers.put(CitrusMailMessageHeaders.MAIL_CONTENT_TYPE, parseContentType(msg.getMimeMessage().getContentType()));
@@ -249,7 +251,10 @@ protected BodyPart handleApplicationContentPart(MimePart applicationData, String
*/
protected BodyPart handleImageBinaryPart(MimePart image, String contentType) throws IOException, MessagingException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- FileCopyUtils.copy(image.getInputStream(), bos);
+ try (InputStream in = image.getInputStream()) {
+ bos.write(in.readAllBytes());
+ bos.flush();
+ }
String base64 = Base64.encodeBase64String(bos.toByteArray());
return new BodyPart(base64, contentType);
}
diff --git a/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/model/BodyPart.java b/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/model/BodyPart.java
index b389ef8d59..dccdb2a982 100644
--- a/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/model/BodyPart.java
+++ b/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/model/BodyPart.java
@@ -24,7 +24,6 @@
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlSeeAlso;
import jakarta.xml.bind.annotation.XmlType;
-import org.springframework.util.CollectionUtils;
/**
* Body part representation holds content as String and optional attachment parts.
@@ -129,7 +128,7 @@ public void setAttachments(Attachments attachments) {
* @return
*/
public boolean hasAttachments() {
- return attachments != null && !CollectionUtils.isEmpty(attachments.getAttachments());
+ return attachments != null && attachments.getAttachments() != null && !attachments.getAttachments().isEmpty();
}
@XmlAccessorType(XmlAccessType.FIELD)
diff --git a/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/model/MailMarshaller.java b/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/model/MailMarshaller.java
index 9474201964..91263abd62 100644
--- a/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/model/MailMarshaller.java
+++ b/endpoints/citrus-mail/src/main/java/org/citrusframework/mail/model/MailMarshaller.java
@@ -16,25 +16,25 @@
package org.citrusframework.mail.model;
-import jakarta.xml.bind.JAXBException;
+import java.io.IOException;
+import java.io.StringWriter;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
-import java.io.IOException;
-import java.io.StringWriter;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import jakarta.xml.bind.JAXBException;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.MessageType;
+import org.citrusframework.spi.Resources;
import org.citrusframework.xml.Jaxb2Marshaller;
import org.citrusframework.xml.Marshaller;
import org.citrusframework.xml.StringResult;
import org.citrusframework.xml.Unmarshaller;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
/**
* @author Christoph Deppisch
@@ -61,7 +61,7 @@ public class MailMarshaller implements Marshaller, Unmarshaller {
*/
public MailMarshaller() {
this.mapper = new ObjectMapper();
- this.marshaller = new Jaxb2Marshaller(new ClassPathResource("org/citrusframework/schema/citrus-mail-message.xsd"), classesToBeBound);
+ this.marshaller = new Jaxb2Marshaller(Resources.newClasspathResource("org/citrusframework/schema/citrus-mail-message.xsd"), classesToBeBound);
type = System.getProperty(MAIL_MARSHALLER_TYPE_PROPERTY, MessageType.XML.name());
}
diff --git a/endpoints/citrus-mail/src/test/java/org/citrusframework/mail/client/MailClientTest.java b/endpoints/citrus-mail/src/test/java/org/citrusframework/mail/client/MailClientTest.java
index a03254a4f9..17badf2f44 100644
--- a/endpoints/citrus-mail/src/test/java/org/citrusframework/mail/client/MailClientTest.java
+++ b/endpoints/citrus-mail/src/test/java/org/citrusframework/mail/client/MailClientTest.java
@@ -16,6 +16,8 @@
package org.citrusframework.mail.client;
+import javax.xml.transform.stream.StreamSource;
+
import jakarta.mail.Address;
import jakarta.mail.Message;
import jakarta.mail.internet.InternetAddress;
@@ -25,22 +27,17 @@
import org.citrusframework.mail.model.MailRequest;
import org.citrusframework.mail.server.MailServer;
import org.citrusframework.message.DefaultMessage;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.AbstractTestNGUnitTest;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.mail.javamail.JavaMailSenderImpl;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import javax.xml.transform.stream.StreamSource;
-
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.doReturn;
/**
* @author Christoph Deppisch
@@ -67,7 +64,7 @@ public void beforeMethodSetup() {
void testSendMailMessageObject() throws Exception {
MailRequest mailRequest = (MailRequest) new MailMarshaller().unmarshal(
new StreamSource(
- new ClassPathResource("text_mail.xml", MailServer.class).getInputStream()
+ Resources.create("text_mail.xml", MailServer.class).getInputStream()
)
);
@@ -93,7 +90,7 @@ void testSendMailMessageObject() throws Exception {
void testSendMultipartMailMessageObject() throws Exception {
MailRequest mailRequest = (MailRequest) new MailMarshaller().unmarshal(
new StreamSource(
- new ClassPathResource("multipart_mail.xml", MailServer.class).getInputStream()
+ Resources.create("multipart_mail.xml", MailServer.class).getInputStream()
)
);
@@ -116,7 +113,7 @@ void testSendMultipartMailMessageObject() throws Exception {
Assert.assertEquals(((MimeMultipart) multipart.getBodyPart(0).getContent()).getCount(), 1L);
Assert.assertEquals(((MimeMultipart) multipart.getBodyPart(0).getContent()).getBodyPart(0).getContent().toString(), "Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua.");
Assert.assertEquals(((MimeMultipart) multipart.getBodyPart(0).getContent()).getBodyPart(0).getContentType(), "text/plain");
- Assert.assertEquals(StringUtils.trimAllWhitespace(multipart.getBodyPart(1).getContent().toString()), "HTMLAttachment ");
+ Assert.assertEquals(multipart.getBodyPart(1).getContent().toString().replaceAll("\\s", ""), "HTMLAttachment ");
Assert.assertEquals(multipart.getBodyPart(1).getFileName(), "index.html");
Assert.assertEquals(multipart.getBodyPart(1).getDisposition(), "attachment");
return null;
diff --git a/endpoints/citrus-mail/src/test/java/org/citrusframework/mail/model/MailMarshallerTest.java b/endpoints/citrus-mail/src/test/java/org/citrusframework/mail/model/MailMarshallerTest.java
index 840d795fa4..0dda87afdd 100644
--- a/endpoints/citrus-mail/src/test/java/org/citrusframework/mail/model/MailMarshallerTest.java
+++ b/endpoints/citrus-mail/src/test/java/org/citrusframework/mail/model/MailMarshallerTest.java
@@ -16,10 +16,10 @@
package org.citrusframework.mail.model;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
import org.citrusframework.xml.StringResult;
import org.citrusframework.xml.StringSource;
-import org.springframework.core.io.ClassPathResource;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -29,12 +29,12 @@
*/
public class MailMarshallerTest {
- private MailMarshaller mailMarshaller = new MailMarshaller();
+ private final MailMarshaller mailMarshaller = new MailMarshaller();
@Test(dataProvider = "mailSourceProvider")
public void testUnmarshalMail(String requestSource, String responseSource) throws Exception {
- MailRequest request = (MailRequest) mailMarshaller.unmarshal(new StringSource(FileUtils.readToString(new ClassPathResource(requestSource))));
- MailResponse response = (MailResponse) mailMarshaller.unmarshal(new StringSource(FileUtils.readToString(new ClassPathResource(responseSource))));
+ MailRequest request = (MailRequest) mailMarshaller.unmarshal(new StringSource(FileUtils.readToString(Resources.newClasspathResource(requestSource))));
+ MailResponse response = (MailResponse) mailMarshaller.unmarshal(new StringSource(FileUtils.readToString(Resources.newClasspathResource(responseSource))));
Assert.assertEquals(request.getFrom(), "foo@mail.com");
Assert.assertEquals(request.getTo(), "bar@mail.com,copy@mail.com");
@@ -45,8 +45,8 @@ public void testUnmarshalMail(String requestSource, String responseSource) throw
@Test(dataProvider = "acceptSourceProvider")
public void testUnmarshalAccept(String requestSource, String responseSource) throws Exception {
- AcceptRequest request = (AcceptRequest) mailMarshaller.unmarshal(new StringSource(FileUtils.readToString(new ClassPathResource(requestSource))));
- AcceptResponse response = (AcceptResponse) mailMarshaller.unmarshal(new StringSource(FileUtils.readToString(new ClassPathResource(responseSource))));
+ AcceptRequest request = (AcceptRequest) mailMarshaller.unmarshal(new StringSource(FileUtils.readToString(Resources.newClasspathResource(requestSource))));
+ AcceptResponse response = (AcceptResponse) mailMarshaller.unmarshal(new StringSource(FileUtils.readToString(Resources.newClasspathResource(responseSource))));
Assert.assertEquals(request.getFrom(), "foo@mail.com");
diff --git a/endpoints/citrus-mail/src/test/java/org/citrusframework/mail/server/MailServerTest.java b/endpoints/citrus-mail/src/test/java/org/citrusframework/mail/server/MailServerTest.java
index 082ab25708..f68818b555 100644
--- a/endpoints/citrus-mail/src/test/java/org/citrusframework/mail/server/MailServerTest.java
+++ b/endpoints/citrus-mail/src/test/java/org/citrusframework/mail/server/MailServerTest.java
@@ -16,6 +16,11 @@
package org.citrusframework.mail.server;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.Date;
+
import com.icegreen.greenmail.mail.MailAddress;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
@@ -24,23 +29,16 @@
import org.citrusframework.mail.message.CitrusMailMessageHeaders;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.FileUtils;
import org.citrusframework.util.TestUtils;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.text.SimpleDateFormat;
-import java.util.Collections;
-import java.util.Date;
-
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.when;
@@ -48,7 +46,7 @@
/**
* @author Christoph Deppisch
*/
-class MailServerTest {
+public class MailServerTest {
private AutoCloseable mockitoContext;
@@ -83,14 +81,8 @@ void testTextMessage() throws IOException, MessagingException {
try {
Assert.assertEquals(
- StringUtils.trimAllWhitespace(message.getPayload(String.class)),
- StringUtils.trimAllWhitespace(
- FileCopyUtils.copyToString(
- new InputStreamReader(
- new ClassPathResource("text_mail.xml", MailServer.class).getInputStream()
- )
- )
- )
+ message.getPayload(String.class).replaceAll("\\s", ""),
+ FileUtils.readToString(Resources.create("text_mail.xml", MailServer.class)).replaceAll("\\s", "")
);
} catch (IOException e) {
Assert.fail(e.getMessage());
@@ -100,7 +92,7 @@ void testTextMessage() throws IOException, MessagingException {
})
.when(endpointAdapterMock).handleMessage(any(Message.class));
- MimeMessage message = new MimeMessage(fixture.getSession(), new ClassPathResource("text_mail.txt", MailServer.class).getInputStream());
+ MimeMessage message = new MimeMessage(fixture.getSession(), Resources.create("text_mail.txt", MailServer.class).getInputStream());
fixture.deliver(message);
// Because of autoAccept = true
@@ -133,16 +125,10 @@ void testMultipartMessage() throws IOException, MessagingException {
try {
Assert.assertEquals(
TestUtils.normalizeLineEndings(
- StringUtils.trimAllWhitespace(message.getPayload(String.class))
+ message.getPayload(String.class).replaceAll("\\s", "")
),
TestUtils.normalizeLineEndings(
- StringUtils.trimAllWhitespace(
- FileCopyUtils.copyToString(
- new InputStreamReader(
- new ClassPathResource("multipart_mail.xml", MailServer.class).getInputStream()
- )
- )
- )
+ FileUtils.readToString(Resources.create("multipart_mail.xml", MailServer.class)).replaceAll("\\s", "")
)
);
} catch (IOException e) {
@@ -152,7 +138,7 @@ void testMultipartMessage() throws IOException, MessagingException {
return null;
}).when(endpointAdapterMock).handleMessage(any(Message.class));
- MimeMessage message = new MimeMessage(fixture.getSession(), new ClassPathResource("multipart_mail.txt", MailServer.class).getInputStream());
+ MimeMessage message = new MimeMessage(fixture.getSession(), Resources.create("multipart_mail.txt", MailServer.class).getInputStream());
fixture.deliver(message);
// Because of autoAccept = true
@@ -183,9 +169,10 @@ void testBinaryMessage() throws IOException, MessagingException {
Assert.assertEquals(message.getHeader(CitrusMailMessageHeaders.MAIL_CONTENT_TYPE), "multipart/mixed");
try {
- Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),
- StringUtils.trimAllWhitespace(FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("binary_mail.xml",
- MailServer.class).getInputStream()))));
+ Assert.assertEquals(
+ message.getPayload(String.class).replaceAll("\\s", ""),
+ FileUtils.readToString(Resources.create("binary_mail.xml", MailServer.class)).replaceAll("\\s", "")
+ );
} catch (IOException e) {
Assert.fail(e.getMessage());
}
@@ -193,7 +180,7 @@ void testBinaryMessage() throws IOException, MessagingException {
return null;
}).when(endpointAdapterMock).handleMessage(any(Message.class));
- MimeMessage message = new MimeMessage(fixture.getSession(), new ClassPathResource("binary_mail.txt", MailServer.class).getInputStream());
+ MimeMessage message = new MimeMessage(fixture.getSession(), Resources.create("binary_mail.txt", MailServer.class).getInputStream());
fixture.deliver(message);
// Because of autoAccept = true
@@ -209,24 +196,15 @@ void testAutoAcceptDisabled() {
try {
Assert.assertEquals(
- StringUtils.trimAllWhitespace(message.getPayload(String.class)),
- StringUtils.trimAllWhitespace(
- FileCopyUtils.copyToString(
- new InputStreamReader(
- new ClassPathResource("accept-request.xml", MailServer.class).getInputStream())
- )
- )
+ message.getPayload(String.class).replaceAll("\\s", ""),
+ FileUtils.readToString(Resources.create("accept-request.xml", MailServer.class)).replaceAll("\\s", "")
);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
return new DefaultMessage(
- FileCopyUtils.copyToString(
- new InputStreamReader(
- new ClassPathResource("accept-response.xml",MailServer.class).getInputStream()
- )
- )
+ FileUtils.readToString(Resources.create("accept-response.xml",MailServer.class))
);
}).when(endpointAdapterMock).handleMessage(any(Message.class));
@@ -280,13 +258,8 @@ void testTextMessageSplitting() throws IOException, MessagingException {
try {
Assert.assertEquals(
- StringUtils.trimAllWhitespace(message.getPayload(String.class)),
- StringUtils.trimAllWhitespace(
- FileCopyUtils.copyToString(
- new InputStreamReader(
- new ClassPathResource("text_mail.xml", MailServer.class).getInputStream())
- )
- )
+ message.getPayload(String.class).replaceAll("\\s", ""),
+ FileUtils.readToString(Resources.create("text_mail.xml", MailServer.class)).replaceAll("\\s", "")
);
} catch (IOException e) {
Assert.fail(e.getMessage());
@@ -295,7 +268,7 @@ void testTextMessageSplitting() throws IOException, MessagingException {
return null;
}).when(endpointAdapterMock).handleMessage(any(Message.class));
- MimeMessage message = new MimeMessage(fixture.getSession(), new ClassPathResource("text_mail.txt", MailServer.class).getInputStream());
+ MimeMessage message = new MimeMessage(fixture.getSession(), Resources.create("text_mail.txt", MailServer.class).getInputStream());
fixture.deliver(message);
// Because of autoAccept = true
@@ -328,9 +301,10 @@ void testMultipartMessageSplitting() throws IOException, MessagingException {
Assert.assertEquals(message.getHeader(CitrusMailMessageHeaders.MAIL_CONTENT_TYPE), "text/plain; charset=utf-8");
try {
- Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),
- StringUtils.trimAllWhitespace(FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("multipart_mail_1.xml",
- MailServer.class).getInputStream()))));
+ Assert.assertEquals(
+ message.getPayload(String.class).replaceAll("\\s", ""),
+ FileUtils.readToString(Resources.create("multipart_mail_1.xml", MailServer.class)).replaceAll("\\s", "")
+ );
} catch (IOException e) {
Assert.fail(e.getMessage());
}
@@ -359,12 +333,10 @@ void testMultipartMessageSplitting() throws IOException, MessagingException {
try {
Assert.assertEquals(
TestUtils.normalizeLineEndings(
- StringUtils.trimAllWhitespace(message.getPayload(String.class))
+ message.getPayload(String.class).replaceAll("\\s", "")
),
TestUtils.normalizeLineEndings(
- StringUtils.trimAllWhitespace(
- FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("multipart_mail_2.xml", MailServer.class).getInputStream()))
- )
+ FileUtils.readToString(Resources.create("multipart_mail_2.xml", MailServer.class)).replaceAll("\\s", "")
)
);
} catch (IOException e) {
@@ -374,7 +346,7 @@ void testMultipartMessageSplitting() throws IOException, MessagingException {
return null;
}).when(endpointAdapterMock).handleMessage(any(Message.class));
- MimeMessage message = new MimeMessage(fixture.getSession(), new ClassPathResource("multipart_mail.txt", MailServer.class).getInputStream());
+ MimeMessage message = new MimeMessage(fixture.getSession(), Resources.create("multipart_mail.txt", MailServer.class).getInputStream());
fixture.deliver(message);
// Because of autoAccept = true
@@ -407,9 +379,10 @@ void testBinaryMessageSplitting() throws IOException, MessagingException {
Assert.assertEquals(message.getHeader(CitrusMailMessageHeaders.MAIL_CONTENT_TYPE), "text/plain; charset=ISO-8859-15; format=flowed");
try {
- Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),
- StringUtils.trimAllWhitespace(FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("binary_mail_1.xml",
- MailServer.class).getInputStream()))));
+ Assert.assertEquals(
+ message.getPayload(String.class).replaceAll("\\s", ""),
+ FileUtils.readToString(Resources.create("binary_mail_1.xml", MailServer.class)).replaceAll("\\s", "")
+ );
} catch (IOException e) {
Assert.fail(e.getMessage());
}
@@ -436,9 +409,10 @@ void testBinaryMessageSplitting() throws IOException, MessagingException {
Assert.assertEquals(message.getHeader(CitrusMailMessageHeaders.MAIL_FILENAME), "brand_logo.png");
try {
- Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),
- StringUtils.trimAllWhitespace(FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("binary_mail_2.xml",
- MailServer.class).getInputStream()))));
+ Assert.assertEquals(
+ message.getPayload(String.class).replaceAll("\\s", ""),
+ FileUtils.readToString(Resources.create("binary_mail_2.xml", MailServer.class)).replaceAll("\\s", "")
+ );
} catch (IOException e) {
Assert.fail(e.getMessage());
}
@@ -446,7 +420,7 @@ void testBinaryMessageSplitting() throws IOException, MessagingException {
return null;
}).when(endpointAdapterMock).handleMessage(any(Message.class));
- MimeMessage message = new MimeMessage(fixture.getSession(), new ClassPathResource("binary_mail.txt", MailServer.class).getInputStream());
+ MimeMessage message = new MimeMessage(fixture.getSession(), Resources.create("binary_mail.txt", MailServer.class).getInputStream());
fixture.deliver(message);
// Because of autoAccept = true
@@ -470,18 +444,19 @@ void testSimulateError() throws IOException, MessagingException {
Assert.assertEquals(message.getHeader(CitrusMailMessageHeaders.MAIL_CONTENT_TYPE), "text/plain");
try {
- Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),
- StringUtils.trimAllWhitespace(FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("text_mail.xml",
- MailServer.class).getInputStream()))));
+ Assert.assertEquals(
+ message.getPayload(String.class).replaceAll("\\s", ""),
+ FileUtils.readToString(Resources.create("text_mail.xml", MailServer.class)).replaceAll("\\s", "")
+ );
} catch (IOException e) {
Assert.fail(e.getMessage());
}
- return new DefaultMessage(FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("error-response.xml",
- MailServer.class).getInputStream())));
+ return new DefaultMessage(
+ FileUtils.readToString(Resources.create("error-response.xml", MailServer.class)));
}).when(endpointAdapterMock).handleMessage(any(Message.class));
- MimeMessage message = new MimeMessage(fixture.getSession(), new ClassPathResource("text_mail.txt", MailServer.class).getInputStream());
+ MimeMessage message = new MimeMessage(fixture.getSession(), Resources.create("text_mail.txt", MailServer.class).getInputStream());
Assert.assertTrue(fixture.accept("foo@mail.com", Collections.singletonList(new MailAddress("bar@mail.com"))));
try {
diff --git a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/client/RmiClient.java b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/client/RmiClient.java
index 522f8893ec..2758176f6e 100644
--- a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/client/RmiClient.java
+++ b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/client/RmiClient.java
@@ -40,11 +40,11 @@
import org.citrusframework.rmi.message.RmiMessageHeaders;
import org.citrusframework.rmi.model.RmiServiceInvocation;
import org.citrusframework.rmi.model.RmiServiceResult;
+import org.citrusframework.util.ReflectionHelper;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.xml.StringResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.ReflectionUtils;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -94,14 +94,18 @@ public void send(final Message message, TestContext context) {
final Method[] method = new Method[1];
if (StringUtils.hasText(invocation.getMethod())) {
- method[0] = ReflectionUtils.findMethod(remoteTarget.getClass(), invocation.getMethod(), invocation.getArgTypes());
+ method[0] = ReflectionHelper.findMethod(remoteTarget.getClass(), invocation.getMethod(), invocation.getArgTypes());
} else {
- ReflectionUtils.doWithMethods(remoteTarget.getClass(), declaredMethod -> {
+ ReflectionHelper.doWithMethods(remoteTarget.getClass(), declaredMethod -> {
+ if (!Arrays.asList(declaredMethod.getExceptionTypes()).contains(RemoteException.class) ||
+ !declaredMethod.getDeclaringClass().equals(remoteTarget.getClass())) {
+ return;
+ }
+
if (method[0] == null) {
method[0] = declaredMethod;
}
- }, declaredMethod -> Arrays.asList(declaredMethod.getExceptionTypes()).contains(RemoteException.class) &&
- declaredMethod.getDeclaringClass().equals(remoteTarget.getClass()));
+ });
}
if (method[0] == null) {
diff --git a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/config/annotation/RmiClientConfigParser.java b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/config/annotation/RmiClientConfigParser.java
index 2aee12eff7..17f559e063 100644
--- a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/config/annotation/RmiClientConfigParser.java
+++ b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/config/annotation/RmiClientConfigParser.java
@@ -23,7 +23,7 @@
import org.citrusframework.rmi.client.RmiClientBuilder;
import org.citrusframework.rmi.message.RmiMessageConverter;
import org.citrusframework.spi.ReferenceResolver;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/config/annotation/RmiServerConfigParser.java b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/config/annotation/RmiServerConfigParser.java
index 85675c319f..fe0ade29f7 100644
--- a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/config/annotation/RmiServerConfigParser.java
+++ b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/config/annotation/RmiServerConfigParser.java
@@ -24,7 +24,7 @@
import org.citrusframework.rmi.server.RmiServer;
import org.citrusframework.rmi.server.RmiServerBuilder;
import org.citrusframework.spi.ReferenceResolver;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/endpoint/RmiEndpointConfiguration.java b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/endpoint/RmiEndpointConfiguration.java
index f049723c7c..52e38edd5f 100644
--- a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/endpoint/RmiEndpointConfiguration.java
+++ b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/endpoint/RmiEndpointConfiguration.java
@@ -27,7 +27,7 @@
import org.citrusframework.rmi.model.RmiMarshaller;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/message/RmiMessageConverter.java b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/message/RmiMessageConverter.java
index 9d37ba7a64..1b39941c74 100644
--- a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/message/RmiMessageConverter.java
+++ b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/message/RmiMessageConverter.java
@@ -24,8 +24,8 @@
import org.citrusframework.message.MessageConverter;
import org.citrusframework.rmi.endpoint.RmiEndpointConfiguration;
import org.citrusframework.rmi.model.RmiServiceInvocation;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.xml.StringResult;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/model/RmiMarshaller.java b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/model/RmiMarshaller.java
index abb7913487..75b267cdea 100644
--- a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/model/RmiMarshaller.java
+++ b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/model/RmiMarshaller.java
@@ -19,12 +19,12 @@
import javax.xml.transform.Result;
import javax.xml.transform.Source;
+import jakarta.xml.bind.JAXBException;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resources;
import org.citrusframework.xml.Jaxb2Marshaller;
import org.citrusframework.xml.Marshaller;
import org.citrusframework.xml.Unmarshaller;
-import jakarta.xml.bind.JAXBException;
-import org.springframework.core.io.ClassPathResource;
/**
* @author Christoph Deppisch
@@ -36,7 +36,7 @@ public class RmiMarshaller implements Marshaller, Unmarshaller {
public RmiMarshaller() {
this.marshaller = new Jaxb2Marshaller(
- new ClassPathResource("org/citrusframework/schema/citrus-rmi-message.xsd"), RmiServiceInvocation.class, RmiServiceResult.class);
+ Resources.newClasspathResource("org/citrusframework/schema/citrus-rmi-message.xsd"), RmiServiceInvocation.class, RmiServiceResult.class);
}
public void marshal(Object graph, Result result) {
diff --git a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/model/RmiServiceInvocation.java b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/model/RmiServiceInvocation.java
index 0ae3ba69f6..b4f6b76a8c 100644
--- a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/model/RmiServiceInvocation.java
+++ b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/model/RmiServiceInvocation.java
@@ -26,16 +26,15 @@
import java.util.Map;
import java.util.Properties;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.spi.ReferenceResolver;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlType;
-import org.springframework.beans.ConversionNotSupportedException;
-import org.springframework.beans.SimpleTypeConverter;
-import org.springframework.util.StringUtils;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.util.StringUtils;
+import org.citrusframework.util.TypeConverter;
/**
* @author Christoph Deppisch
@@ -155,15 +154,7 @@ public Object[] getArgValues(ReferenceResolver referenceResolver) {
argValues.add(map);
} else {
- try {
- argValues.add(new SimpleTypeConverter().convertIfNecessary(value, argType));
- } catch (ConversionNotSupportedException e) {
- if (String.class.equals(argType)) {
- argValues.add(value.toString());
- }
-
- throw e;
- }
+ argValues.add(TypeConverter.lookupDefault().convertIfNecessary(value, argType));
}
}
}
diff --git a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/model/RmiServiceResult.java b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/model/RmiServiceResult.java
index ec0297fa59..ae7c793981 100644
--- a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/model/RmiServiceResult.java
+++ b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/model/RmiServiceResult.java
@@ -22,8 +22,6 @@
import java.util.Map;
import java.util.Properties;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.spi.ReferenceResolver;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
@@ -31,9 +29,10 @@
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlTransient;
import jakarta.xml.bind.annotation.XmlType;
-import org.springframework.beans.ConversionNotSupportedException;
-import org.springframework.beans.SimpleTypeConverter;
-import org.springframework.util.StringUtils;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.util.StringUtils;
+import org.citrusframework.util.TypeConverter;
/**
* @author Christoph Deppisch
@@ -144,15 +143,7 @@ public java.lang.Object getResultObject(ReferenceResolver referenceResolver) {
return map;
} else {
- try {
- return new SimpleTypeConverter().convertIfNecessary(value, argType);
- } catch (ConversionNotSupportedException e) {
- if (String.class.equals(argType)) {
- return value.toString();
- }
-
- throw e;
- }
+ return TypeConverter.lookupDefault().convertIfNecessary(value, argType);
}
} catch (ClassNotFoundException e) {
throw new CitrusRuntimeException("Failed to construct service result object", e);
diff --git a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/server/RmiServer.java b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/server/RmiServer.java
index 845ccb8053..98e3353fbf 100644
--- a/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/server/RmiServer.java
+++ b/endpoints/citrus-rmi/src/main/java/org/citrusframework/rmi/server/RmiServer.java
@@ -16,7 +16,6 @@
package org.citrusframework.rmi.server;
-import javax.xml.transform.Source;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
@@ -27,6 +26,7 @@
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.List;
+import javax.xml.transform.Source;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
@@ -34,10 +34,9 @@
import org.citrusframework.rmi.model.RmiServiceInvocation;
import org.citrusframework.rmi.model.RmiServiceResult;
import org.citrusframework.server.AbstractServer;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -116,7 +115,7 @@ public RmiEndpointConfiguration getEndpointConfiguration() {
* @return
*/
public ClassLoader getClassLoader() {
- if (!CollectionUtils.isEmpty(remoteInterfaces)) {
+ if (remoteInterfaces != null && !remoteInterfaces.isEmpty()) {
return remoteInterfaces.get(0).getClassLoader();
} else {
return this.getClassLoader();
diff --git a/endpoints/citrus-rmi/src/test/java/org/citrusframework/rmi/client/RmiClientTest.java b/endpoints/citrus-rmi/src/test/java/org/citrusframework/rmi/client/RmiClientTest.java
index 4ac35d7326..fb4b6ec9bb 100644
--- a/endpoints/citrus-rmi/src/test/java/org/citrusframework/rmi/client/RmiClientTest.java
+++ b/endpoints/citrus-rmi/src/test/java/org/citrusframework/rmi/client/RmiClientTest.java
@@ -16,7 +16,6 @@
package org.citrusframework.rmi.client;
-import java.io.InputStreamReader;
import java.rmi.registry.Registry;
import org.citrusframework.message.Message;
@@ -24,13 +23,12 @@
import org.citrusframework.rmi.endpoint.RmiEndpointConfiguration;
import org.citrusframework.rmi.message.RmiMessage;
import org.citrusframework.rmi.remote.HelloService;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.AbstractTestNGUnitTest;
+import org.citrusframework.util.FileUtils;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -59,8 +57,7 @@ public void testRmiClient() throws Exception {
RmiClient rmiClient = new RmiClient(endpointConfiguration);
String binding = "helloService";
- final String responseBody = FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("service-result.xml",
- RmiClient.class).getInputStream()));
+ final String responseBody = FileUtils.readToString(Resources.create("service-result.xml", RmiClient.class));
endpointConfiguration.setBinding(binding);
@@ -76,8 +73,10 @@ public void testRmiClient() throws Exception {
rmiClient.send(requestMessage, context);
Message responseMessage = rmiClient.receive(context, endpointConfiguration.getTimeout());
- Assert.assertEquals(StringUtils.trimAllWhitespace(responseMessage.getPayload(String.class)),
- StringUtils.trimAllWhitespace(responseBody));
+ Assert.assertEquals(
+ responseMessage.getPayload(String.class).replaceAll("\\s", ""),
+ responseBody.replaceAll("\\s", "")
+ );
}
@Test
@@ -86,8 +85,7 @@ public void testRmiClientWithArgument() throws Exception {
RmiClient rmiClient = new RmiClient(endpointConfiguration);
String binding = "helloService";
- final String responseBody = FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("service-result-2.xml",
- RmiClient.class).getInputStream()));
+ final String responseBody = FileUtils.readToString(Resources.create("service-result-2.xml", RmiClient.class));
endpointConfiguration.setBinding(binding);
@@ -102,8 +100,10 @@ public void testRmiClientWithArgument() throws Exception {
rmiClient.send(requestMessage, context);
Message responseMessage = rmiClient.receive(context, endpointConfiguration.getTimeout());
- Assert.assertEquals(StringUtils.trimAllWhitespace(responseMessage.getPayload(String.class)),
- StringUtils.trimAllWhitespace(responseBody));
+ Assert.assertEquals(
+ responseMessage.getPayload(String.class).replaceAll("\\s", ""),
+ responseBody.replaceAll("\\s", "")
+ );
verify(remoteInterface).sayHello(eq("Christoph"));
}
@@ -114,8 +114,7 @@ public void testReplyMessageCorrelator() throws Exception {
RmiClient rmiClient = new RmiClient(endpointConfiguration);
String binding = "helloService";
- String responseBody = FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("service-result-3.xml",
- RmiClient.class).getInputStream()));
+ String responseBody = FileUtils.readToString(Resources.create("service-result-3.xml", RmiClient.class));
endpointConfiguration.setBinding(binding);
@@ -139,8 +138,10 @@ public void testReplyMessageCorrelator() throws Exception {
rmiClient.send(requestMessage, context);
Message responseMessage = rmiClient.receive("correlationKey", context, endpointConfiguration.getTimeout());
- Assert.assertEquals(StringUtils.trimAllWhitespace(responseMessage.getPayload(String.class)),
- StringUtils.trimAllWhitespace(responseBody));
+ Assert.assertEquals(
+ responseMessage.getPayload(String.class).replaceAll("\\s", ""),
+ responseBody.replaceAll("\\s", "")
+ );
}
}
diff --git a/endpoints/citrus-rmi/src/test/java/org/citrusframework/rmi/server/RmiServerTest.java b/endpoints/citrus-rmi/src/test/java/org/citrusframework/rmi/server/RmiServerTest.java
index 44cecb860b..193b9793d7 100644
--- a/endpoints/citrus-rmi/src/test/java/org/citrusframework/rmi/server/RmiServerTest.java
+++ b/endpoints/citrus-rmi/src/test/java/org/citrusframework/rmi/server/RmiServerTest.java
@@ -17,7 +17,6 @@
package org.citrusframework.rmi.server;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.rmi.Remote;
import java.rmi.registry.Registry;
import java.util.List;
@@ -28,13 +27,12 @@
import org.citrusframework.rmi.message.RmiMessage;
import org.citrusframework.rmi.message.RmiMessageHeaders;
import org.citrusframework.rmi.remote.HelloService;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.AbstractTestNGUnitTest;
+import org.citrusframework.util.FileUtils;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.stubbing.Answer;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -85,9 +83,10 @@ public void testServiceInvocationWithArgument() throws Exception {
Assert.assertEquals(message.getHeader(RmiMessageHeaders.RMI_METHOD), "sayHello");
try {
- Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),
- StringUtils.trimAllWhitespace(FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("service-invocation.xml",
- RmiServer.class).getInputStream()))));
+ Assert.assertEquals(
+ message.getPayload(String.class).replaceAll("\\s", ""),
+ FileUtils.readToString(Resources.create("service-invocation.xml", RmiServer.class)).replaceAll("\\s", "")
+ );
} catch (IOException e) {
Assert.fail(e.getMessage());
}
@@ -129,15 +128,15 @@ public void testServiceInvocationWithResult() throws Exception {
Assert.assertEquals(message.getHeader(RmiMessageHeaders.RMI_METHOD), "getHelloCount");
try {
- Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),
- StringUtils.trimAllWhitespace(FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("service-invocation-2.xml",
- RmiServer.class).getInputStream()))));
+ Assert.assertEquals(
+ message.getPayload(String.class).replaceAll("\\s", ""),
+ FileUtils.readToString(Resources.create("service-invocation-2.xml", RmiServer.class)).replaceAll("\\s", "")
+ );
} catch (IOException e) {
Assert.fail(e.getMessage());
}
- return new DefaultMessage(FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("service-result.xml",
- RmiServer.class).getInputStream())));
+ return new DefaultMessage(FileUtils.readToString(Resources.create("service-result.xml", RmiServer.class)));
}).when(endpointAdapter).handleMessage(any(Message.class));
rmiServer.startup();
diff --git a/endpoints/citrus-spring-integration/pom.xml b/endpoints/citrus-spring-integration/pom.xml
index be9f8eaeff..5845d1d1c8 100644
--- a/endpoints/citrus-spring-integration/pom.xml
+++ b/endpoints/citrus-spring-integration/pom.xml
@@ -67,6 +67,10 @@
+
+ org.springframework
+ spring-core
+
org.springframework.integration
spring-integration-core
diff --git a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/ChannelConsumer.java b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/ChannelConsumer.java
index b7cadb5e49..3dcbd09de0 100644
--- a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/ChannelConsumer.java
+++ b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/ChannelConsumer.java
@@ -24,13 +24,13 @@
import org.citrusframework.exceptions.MessageTimeoutException;
import org.citrusframework.message.Message;
import org.citrusframework.messaging.AbstractSelectiveMessageConsumer;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.core.MessageSelector;
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -42,7 +42,7 @@ public class ChannelConsumer extends AbstractSelectiveMessageConsumer {
private static final Logger logger = LoggerFactory.getLogger(ChannelConsumer.class);
/** Endpoint configuration */
- private ChannelEndpointConfiguration endpointConfiguration;
+ private final ChannelEndpointConfiguration endpointConfiguration;
/**
* Default constructor using endpoint configuration.
diff --git a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/ChannelProducer.java b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/ChannelProducer.java
index 0ee8a3bc2d..12b9f68266 100644
--- a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/ChannelProducer.java
+++ b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/ChannelProducer.java
@@ -22,13 +22,13 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
import org.citrusframework.messaging.Producer;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageDeliveryException;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/ChannelSyncConsumer.java b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/ChannelSyncConsumer.java
index 8542cc5584..89da0deb72 100644
--- a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/ChannelSyncConsumer.java
+++ b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/ChannelSyncConsumer.java
@@ -22,12 +22,12 @@
import org.citrusframework.message.correlation.CorrelationManager;
import org.citrusframework.message.correlation.PollingCorrelationManager;
import org.citrusframework.messaging.ReplyProducer;
+import org.citrusframework.util.ObjectHelper;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageDeliveryException;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -65,12 +65,12 @@ public Message receive(String selector, TestContext context, long timeout) {
@Override
public void send(Message message, TestContext context) {
- Assert.notNull(message, "Can not send empty message");
+ ObjectHelper.assertNotNull(message, "Can not send empty message");
String correlationKeyName = endpointConfiguration.getCorrelator().getCorrelationKeyName(getName());
String correlationKey = correlationManager.getCorrelationKey(correlationKeyName, context);
MessageChannel replyChannel = correlationManager.find(correlationKey, endpointConfiguration.getTimeout());
- Assert.notNull(replyChannel, "Failed to find reply channel for message correlation key: " + correlationKey);
+ ObjectHelper.assertNotNull(replyChannel, "Failed to find reply channel for message correlation key: " + correlationKey);
if (logger.isDebugEnabled()) {
logger.debug("Sending message to reply channel: '" + replyChannel + "'");
diff --git a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/selector/JsonPathPayloadMessageSelector.java b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/selector/JsonPathPayloadMessageSelector.java
index 68a28de1da..788236eb79 100644
--- a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/selector/JsonPathPayloadMessageSelector.java
+++ b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/selector/JsonPathPayloadMessageSelector.java
@@ -19,8 +19,8 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.json.JsonPathUtils;
+import org.citrusframework.util.StringUtils;
import org.springframework.messaging.Message;
-import org.springframework.util.StringUtils;
/**
* Message selector accepts JSON messages in case JsonPath expression evaluation result matches
diff --git a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/selector/RootQNameMessageSelector.java b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/selector/RootQNameMessageSelector.java
index 961c59bc1a..7c43513f55 100644
--- a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/selector/RootQNameMessageSelector.java
+++ b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/selector/RootQNameMessageSelector.java
@@ -15,23 +15,22 @@
*/
package org.citrusframework.channel.selector;
+import javax.xml.namespace.QName;
+
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.util.XMLUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.messaging.Message;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
import org.springframework.xml.namespace.QNameUtils;
import org.w3c.dom.Document;
import org.w3c.dom.ls.LSException;
-import javax.xml.namespace.QName;
-
/**
* Message selector accepts XML messages according to specified root element QName.
- *
+ *
* @author Christoph Deppisch
*/
public class RootQNameMessageSelector extends AbstractMessageSelector {
@@ -44,16 +43,17 @@ public class RootQNameMessageSelector extends AbstractMessageSelector {
/** Logger */
private static final Logger logger = LoggerFactory.getLogger(RootQNameMessageSelector.class);
-
+
/**
* Default constructor using fields.
*/
public RootQNameMessageSelector(String name, String value, TestContext context) {
super(name, value, context);
- Assert.isTrue(selectKey.equals(SELECTOR_ID),
- String.format("Invalid usage of root QName message selector - " +
- "usage restricted to key '%s' but was '%s'", SELECTOR_ID, selectKey));
+ if (!selectKey.equals(SELECTOR_ID)) {
+ throw new CitrusRuntimeException(String.format("Invalid usage of root QName message selector - " +
+ "usage restricted to key '%s' but was '%s'", SELECTOR_ID, selectKey));
+ }
if (QNameUtils.validateQName(value)) {
this.rootQName = QNameUtils.parseQNameString(value);
@@ -61,20 +61,20 @@ public RootQNameMessageSelector(String name, String value, TestContext context)
throw new CitrusRuntimeException("Invalid root QName string '" + value + "'");
}
}
-
+
@Override
public boolean accept(Message> message) {
Document doc;
-
+
try {
doc = XMLUtils.parseMessagePayload(getPayloadAsString(message));
} catch (LSException e) {
logger.warn("Root QName message selector ignoring not well-formed XML message payload", e);
return false; // non XML message - not accepted
}
-
+
if (StringUtils.hasText(rootQName.getNamespaceURI())) {
- return rootQName.equals(QNameUtils.getQNameForNode(doc.getFirstChild()));
+ return rootQName.equals(QNameUtils.getQNameForNode(doc.getFirstChild()));
} else {
return rootQName.getLocalPart().equals(doc.getFirstChild().getLocalName());
}
diff --git a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/config/annotation/ChannelEndpointConfigParser.java b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/config/annotation/ChannelEndpointConfigParser.java
index fe732b7f16..4ca9700147 100644
--- a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/config/annotation/ChannelEndpointConfigParser.java
+++ b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/config/annotation/ChannelEndpointConfigParser.java
@@ -17,12 +17,14 @@
package org.citrusframework.config.annotation;
import org.citrusframework.TestActor;
-import org.citrusframework.channel.*;
+import org.citrusframework.channel.ChannelEndpoint;
+import org.citrusframework.channel.ChannelEndpointBuilder;
+import org.citrusframework.channel.ChannelMessageConverter;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.util.StringUtils;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.core.DestinationResolver;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/config/annotation/ChannelSyncEndpointConfigParser.java b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/config/annotation/ChannelSyncEndpointConfigParser.java
index 5dedd5ed44..b375f3e627 100644
--- a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/config/annotation/ChannelSyncEndpointConfigParser.java
+++ b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/config/annotation/ChannelSyncEndpointConfigParser.java
@@ -17,13 +17,15 @@
package org.citrusframework.config.annotation;
import org.citrusframework.TestActor;
-import org.citrusframework.channel.*;
-import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.channel.ChannelMessageConverter;
+import org.citrusframework.channel.ChannelSyncEndpoint;
+import org.citrusframework.channel.ChannelSyncEndpointBuilder;
import org.citrusframework.message.MessageCorrelator;
+import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.util.StringUtils;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.core.DestinationResolver;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/config/xml/PurgeMessageChannelActionParser.java b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/config/xml/PurgeMessageChannelActionParser.java
index 6c47f8a242..9d79ce5d98 100644
--- a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/config/xml/PurgeMessageChannelActionParser.java
+++ b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/config/xml/PurgeMessageChannelActionParser.java
@@ -21,6 +21,7 @@
import org.citrusframework.actions.PurgeMessageChannelAction;
import org.citrusframework.config.util.BeanDefinitionParserUtils;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanFactory;
@@ -33,7 +34,6 @@
import org.springframework.integration.core.MessageSelector;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.core.DestinationResolver;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
diff --git a/endpoints/citrus-spring-integration/src/test/java/org/citrusframework/channel/ChannelEndpointSyncConsumerTest.java b/endpoints/citrus-spring-integration/src/test/java/org/citrusframework/channel/ChannelEndpointSyncConsumerTest.java
index e060aaad30..794aa5da2d 100644
--- a/endpoints/citrus-spring-integration/src/test/java/org/citrusframework/channel/ChannelEndpointSyncConsumerTest.java
+++ b/endpoints/citrus-spring-integration/src/test/java/org/citrusframework/channel/ChannelEndpointSyncConsumerTest.java
@@ -54,14 +54,14 @@
*/
public class ChannelEndpointSyncConsumerTest extends AbstractTestNGUnitTest {
- private MessagingTemplate messagingTemplate = Mockito.mock(MessagingTemplate.class);
+ private final MessagingTemplate messagingTemplate = Mockito.mock(MessagingTemplate.class);
- private PollableChannel channel = Mockito.mock(PollableChannel.class);
- private MessageChannel replyChannel = Mockito.mock(MessageChannel.class);
+ private final PollableChannel channel = Mockito.mock(PollableChannel.class);
+ private final MessageChannel replyChannel = Mockito.mock(MessageChannel.class);
- private MessageCorrelator messageCorrelator = Mockito.mock(MessageCorrelator.class);
+ private final MessageCorrelator messageCorrelator = Mockito.mock(MessageCorrelator.class);
- private DestinationResolver channelResolver = Mockito.mock(DestinationResolver.class);
+ private final DestinationResolver channelResolver = Mockito.mock(DestinationResolver.class);
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -394,7 +394,7 @@ public void testNoCorrelationKeyFound() {
Assert.fail("Missing " + IllegalArgumentException.class + " because no reply destination found");
}
- @Test
+ @Test(expectedExceptions = CitrusRuntimeException.class, expectedExceptionsMessageRegExp = "Failed to find reply channel for message correlation key: 123456789")
public void testNoReplyDestinationFound() {
ChannelSyncEndpoint endpoint = new ChannelSyncEndpoint();
endpoint.getEndpointConfiguration().setMessagingTemplate(messagingTemplate);
@@ -411,31 +411,17 @@ public void testNoReplyDestinationFound() {
Map headers = new HashMap();
final Message message = new DefaultMessage("Hello World! ", headers);
- try {
- ChannelSyncConsumer channelSyncConsumer = (ChannelSyncConsumer) endpoint.createConsumer();
- channelSyncConsumer.send(message, context);
- } catch(IllegalArgumentException e) {
- Assert.assertTrue(e.getMessage().startsWith("Failed to find reply channel"));
- return;
- }
-
- Assert.fail("Missing " + IllegalArgumentException.class + " because no reply destination found");
+ ChannelSyncConsumer channelSyncConsumer = (ChannelSyncConsumer) endpoint.createConsumer();
+ channelSyncConsumer.send(message, context);
}
- @Test
+ @Test(expectedExceptions = CitrusRuntimeException.class, expectedExceptionsMessageRegExp = "Can not send empty message")
public void testSendEmptyMessage() {
ChannelSyncEndpoint endpoint = new ChannelSyncEndpoint();
endpoint.getEndpointConfiguration().setMessagingTemplate(messagingTemplate);
- try {
- ChannelSyncConsumer channelSyncConsumer = (ChannelSyncConsumer) endpoint.createConsumer();
- channelSyncConsumer.send(null, context);
- } catch(IllegalArgumentException e) {
- Assert.assertEquals(e.getMessage(), "Can not send empty message");
- return;
- }
-
- Assert.fail("Missing " + IllegalArgumentException.class + " because of sending empty message");
+ ChannelSyncConsumer channelSyncConsumer = (ChannelSyncConsumer) endpoint.createConsumer();
+ channelSyncConsumer.send(null, context);
}
@Test
diff --git a/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/client/SshClient.java b/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/client/SshClient.java
index 6ea40cb25b..9545d10eba 100644
--- a/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/client/SshClient.java
+++ b/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/client/SshClient.java
@@ -23,6 +23,12 @@
import java.io.InputStream;
import java.io.OutputStream;
+import com.jcraft.jsch.ChannelExec;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Session;
+import com.jcraft.jsch.UserInfo;
+import org.apache.sshd.client.keyverifier.KnownHostsServerKeyVerifier;
import org.citrusframework.context.TestContext;
import org.citrusframework.endpoint.AbstractEndpoint;
import org.citrusframework.exceptions.CitrusRuntimeException;
@@ -33,18 +39,11 @@
import org.citrusframework.messaging.Producer;
import org.citrusframework.messaging.ReplyConsumer;
import org.citrusframework.messaging.SelectiveConsumer;
+import org.citrusframework.spi.Resources;
import org.citrusframework.ssh.model.SshRequest;
import org.citrusframework.ssh.model.SshResponse;
import org.citrusframework.util.FileUtils;
-import com.jcraft.jsch.ChannelExec;
-import com.jcraft.jsch.JSch;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-import com.jcraft.jsch.UserInfo;
-import org.apache.sshd.client.keyverifier.KnownHostsServerKeyVerifier;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.util.ResourceUtils;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* Ssh client connects to ssh server and sends commands to that server.
@@ -284,21 +283,22 @@ private void setKnownHosts() {
jsch.setKnownHosts(khIs);
} catch (JSchException e) {
throw new CitrusRuntimeException("Cannot add known hosts from " + getEndpointConfiguration().getKnownHosts() + ": " + e,e);
- } catch (IOException e) {
- throw new CitrusRuntimeException("Cannot find known hosts file " + getEndpointConfiguration().getKnownHosts() + ": " + e,e);
}
}
private String getPrivateKeyPath() throws IOException {
if (!StringUtils.hasText(getEndpointConfiguration().getPrivateKeyPath())) {
return null;
- } else if (getEndpointConfiguration().getPrivateKeyPath().startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
+ } else if (getEndpointConfiguration().getPrivateKeyPath().startsWith(Resources.CLASSPATH_RESOURCE_PREFIX)) {
File priv = File.createTempFile("citrus-ssh","priv");
- InputStream is = getClass().getClassLoader().getResourceAsStream(getEndpointConfiguration().getPrivateKeyPath().substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()));
- if (is == null) {
- throw new CitrusRuntimeException("No private key found at " + getEndpointConfiguration().getPrivateKeyPath());
+ try (InputStream is = getClass().getClassLoader().getResourceAsStream(getEndpointConfiguration().getPrivateKeyPath().substring(Resources.CLASSPATH_RESOURCE_PREFIX.length()));
+ FileOutputStream fos = new FileOutputStream(priv)) {
+ if (is == null) {
+ throw new CitrusRuntimeException("No private key found at " + getEndpointConfiguration().getPrivateKeyPath());
+ }
+ fos.write(is.readAllBytes());
+ fos.flush();
}
- FileCopyUtils.copy(is, new FileOutputStream(priv));
return priv.getAbsolutePath();
} else {
return getEndpointConfiguration().getPrivateKeyPath();
diff --git a/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/config/annotation/SshClientConfigParser.java b/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/config/annotation/SshClientConfigParser.java
index b309a105ad..1815a585a3 100644
--- a/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/config/annotation/SshClientConfigParser.java
+++ b/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/config/annotation/SshClientConfigParser.java
@@ -23,7 +23,7 @@
import org.citrusframework.ssh.client.SshClient;
import org.citrusframework.ssh.client.SshClientBuilder;
import org.citrusframework.ssh.message.SshMessageConverter;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/config/annotation/SshServerConfigParser.java b/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/config/annotation/SshServerConfigParser.java
index c6f9d53e7c..c5d0c8e163 100644
--- a/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/config/annotation/SshServerConfigParser.java
+++ b/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/config/annotation/SshServerConfigParser.java
@@ -23,7 +23,7 @@
import org.citrusframework.ssh.message.SshMessageConverter;
import org.citrusframework.ssh.server.SshServer;
import org.citrusframework.ssh.server.SshServerBuilder;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/model/SshMarshaller.java b/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/model/SshMarshaller.java
index 2e8af920fe..5d3e72eb54 100644
--- a/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/model/SshMarshaller.java
+++ b/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/model/SshMarshaller.java
@@ -19,14 +19,12 @@
import javax.xml.transform.Result;
import javax.xml.transform.Source;
+import jakarta.xml.bind.JAXBException;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resources;
import org.citrusframework.xml.Jaxb2Marshaller;
import org.citrusframework.xml.Marshaller;
import org.citrusframework.xml.Unmarshaller;
-import jakarta.xml.bind.JAXBException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
/**
* @author Christoph Deppisch
@@ -34,14 +32,11 @@
*/
public class SshMarshaller implements Marshaller, Unmarshaller {
- /** Logger */
- private static final Logger logger = LoggerFactory.getLogger(SshMarshaller.class);
-
private final Jaxb2Marshaller marshaller;
public SshMarshaller() {
this.marshaller = new Jaxb2Marshaller(
- new ClassPathResource("org/citrusframework/schema/citrus-ssh-message.xsd"), SshRequest.class, SshResponse.class);
+ Resources.newClasspathResource("org/citrusframework/schema/citrus-ssh-message.xsd"), SshRequest.class, SshResponse.class);
}
public void marshal(Object graph, Result result) {
diff --git a/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/server/SinglePublicKeyAuthenticator.java b/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/server/SinglePublicKeyAuthenticator.java
index cf52e6996c..c95d21168b 100644
--- a/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/server/SinglePublicKeyAuthenticator.java
+++ b/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/server/SinglePublicKeyAuthenticator.java
@@ -16,21 +16,22 @@
package org.citrusframework.ssh.server;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.util.FileUtils;
-import org.apache.sshd.common.util.io.IoUtils;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.security.PublicKey;
+
import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;
import org.apache.sshd.server.session.ServerSession;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openssl.PEMKeyPair;
import org.bouncycastle.openssl.PEMParser;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.util.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.*;
-import java.security.PublicKey;
-
/**
* Public key authenticator which verifies a single provided public key. The public key
* itself must be in PEM format.
@@ -43,10 +44,8 @@ class SinglePublicKeyAuthenticator implements PublickeyAuthenticator {
/** Logger */
private static final Logger logger = LoggerFactory.getLogger(SinglePublicKeyAuthenticator.class);
- private PublicKey allowedKey;
- private String user;
-
- private BouncyCastleProvider provider = new BouncyCastleProvider();
+ private final PublicKey allowedKey;
+ private final String user;
/**
* Constructor
@@ -57,9 +56,10 @@ class SinglePublicKeyAuthenticator implements PublickeyAuthenticator {
*/
public SinglePublicKeyAuthenticator(String username, String publicKeyPath) {
this.user = username;
- InputStream is = null;
- try {
- is = FileUtils.getFileResource(publicKeyPath).getInputStream();
+ try (InputStream is = FileUtils.getFileResource(publicKeyPath).getInputStream()){
+ if (is == null) {
+ throw new CitrusRuntimeException(String.format("Failed to read public key - no public key found at %s", publicKeyPath));
+ }
allowedKey = readKey(is);
if (allowedKey == null) {
throw new CitrusRuntimeException("No public key found at " + publicKeyPath + ", although the file/resource exists. " +
@@ -67,8 +67,6 @@ public SinglePublicKeyAuthenticator(String username, String publicKeyPath) {
}
} catch (IOException e) {
throw new CitrusRuntimeException(String.format("Failed to read public key file at %s", publicKeyPath),e);
- } finally {
- IoUtils.closeQuietly(is);
}
}
@@ -80,29 +78,26 @@ public boolean authenticate(String pUser, PublicKey pKey, ServerSession pSession
}
/**
- * Read the key with bouncycastle's PEM tools
+ * Read the key with bouncycastle's PEM tools
* @param is
* @return
*/
private PublicKey readKey(InputStream is) {
- InputStreamReader isr = new InputStreamReader(is);
- PEMParser r = new PEMParser(isr);
- try {
+ try (InputStreamReader isr = new InputStreamReader(is);
+ PEMParser r = new PEMParser(isr)) {
Object o = r.readObject();
if (o instanceof PEMKeyPair) {
PEMKeyPair keyPair = (PEMKeyPair) o;
if (keyPair.getPublicKeyInfo() != null &&
keyPair.getPublicKeyInfo().getEncoded().length > 0) {
- return provider.getPublicKey(keyPair.getPublicKeyInfo());
+ return BouncyCastleProvider.getPublicKey(keyPair.getPublicKeyInfo());
}
} else if (o instanceof SubjectPublicKeyInfo) {
- return provider.getPublicKey((SubjectPublicKeyInfo) o);
+ return BouncyCastleProvider.getPublicKey((SubjectPublicKeyInfo) o);
}
} catch (IOException e) {
// Ignoring, returning null
logger.warn("Failed to get key from PEM file", e);
- } finally {
- IoUtils.closeQuietly(isr,r);
}
return null;
diff --git a/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/server/SshServer.java b/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/server/SshServer.java
index 4069d530d9..3f2ea84ef8 100644
--- a/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/server/SshServer.java
+++ b/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/server/SshServer.java
@@ -25,14 +25,6 @@
import java.util.List;
import java.util.Optional;
-import org.citrusframework.endpoint.AbstractPollableEndpointConfiguration;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.server.AbstractServer;
-import org.citrusframework.ssh.SshCommand;
-import org.citrusframework.ssh.client.SshEndpointConfiguration;
-import org.citrusframework.ssh.message.SshMessageConverter;
-import org.citrusframework.ssh.model.SshMarshaller;
-import org.citrusframework.util.FileUtils;
import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
import org.apache.sshd.common.keyprovider.ClassLoadableResourceKeyPairProvider;
@@ -45,9 +37,17 @@
import org.apache.sshd.sftp.server.AbstractSftpEventListenerAdapter;
import org.apache.sshd.sftp.server.SftpEventListener;
import org.apache.sshd.sftp.server.SftpSubsystemFactory;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
-import org.springframework.util.StringUtils;
+import org.citrusframework.endpoint.AbstractPollableEndpointConfiguration;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.server.AbstractServer;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.ssh.SshCommand;
+import org.citrusframework.ssh.client.SshEndpointConfiguration;
+import org.citrusframework.ssh.message.SshMessageConverter;
+import org.citrusframework.ssh.model.SshMarshaller;
+import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
/**
* SSH Server implemented with Apache SSHD (http://mina.apache.org/sshd/).
@@ -145,16 +145,12 @@ protected void startup() {
if (hostKeyPath != null) {
Resource hostKey = FileUtils.getFileResource(hostKeyPath);
- if (hostKey instanceof ClassPathResource) {
- ClassLoadableResourceKeyPairProvider resourceKeyPairProvider = new ClassLoadableResourceKeyPairProvider(Collections.singletonList(((ClassPathResource) hostKey).getPath()));
+ if (hostKey instanceof Resources.ClasspathResource) {
+ ClassLoadableResourceKeyPairProvider resourceKeyPairProvider = new ClassLoadableResourceKeyPairProvider(Collections.singletonList(hostKey.getLocation()));
sshd.setKeyPairProvider(resourceKeyPairProvider);
} else {
- try {
- FileKeyPairProvider fileKeyPairProvider = new FileKeyPairProvider(Collections.singletonList(hostKey.getFile().toPath()));
- sshd.setKeyPairProvider(fileKeyPairProvider);
- } catch (IOException e) {
- throw new CitrusRuntimeException("Failed to read host key path", e);
- }
+ FileKeyPairProvider fileKeyPairProvider = new FileKeyPairProvider(Collections.singletonList(hostKey.getFile().toPath()));
+ sshd.setKeyPairProvider(fileKeyPairProvider);
}
} else {
ClassLoadableResourceKeyPairProvider resourceKeyPairProvider = new ClassLoadableResourceKeyPairProvider(Collections.singletonList("org/citrusframework/ssh/citrus.pem"));
diff --git a/endpoints/citrus-ssh/src/test/java/org/citrusframework/ssh/server/SinglePublicKeyAuthenticatorTest.java b/endpoints/citrus-ssh/src/test/java/org/citrusframework/ssh/server/SinglePublicKeyAuthenticatorTest.java
index c2f66f14e1..0d0940e47d 100644
--- a/endpoints/citrus-ssh/src/test/java/org/citrusframework/ssh/server/SinglePublicKeyAuthenticatorTest.java
+++ b/endpoints/citrus-ssh/src/test/java/org/citrusframework/ssh/server/SinglePublicKeyAuthenticatorTest.java
@@ -16,19 +16,25 @@
package org.citrusframework.ssh.server;
-import org.citrusframework.exceptions.CitrusRuntimeException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.security.PublicKey;
+
import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.common.util.security.SecurityUtils;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openssl.PEMKeyPair;
import org.bouncycastle.openssl.PEMParser;
-import org.springframework.util.FileCopyUtils;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.testng.Assert;
import org.testng.annotations.Test;
-import java.io.*;
-import java.security.PublicKey;
-
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
@@ -86,7 +92,7 @@ public void notInClasspath() {
public void invalidFilePath() {
new SinglePublicKeyAuthenticator("roland","/no/valid/path");
}
-
+
/**
* Gets public key instance from resource.
* @param pResource
@@ -105,18 +111,22 @@ private PublicKey getPublicKey(String pResource) throws IOException {
*/
private File copyToTempFile(String pResource) throws IOException {
File temp = File.createTempFile("citrus-ssh", "pem");
- FileCopyUtils.copy(getClass().getResourceAsStream(pResource),
- new FileOutputStream(temp));
+ try (InputStream in = getClass().getResourceAsStream(pResource);
+ FileOutputStream fos = new FileOutputStream(temp)) {
+ Assert.assertNotNull(in);
+ fos.write(in.readAllBytes());
+ fos.flush();
+ }
return temp;
}
-
+
/**
* Create public key instance from file input stream.
* @param is
* @return
* @throws IOException
*/
- private PublicKey getPublicKeyFromStream(InputStream is) throws IOException {
+ private PublicKey getPublicKeyFromStream(InputStream is) {
Reader reader = new InputStreamReader(is);
try {
Object o = new PEMParser(reader).readObject();
diff --git a/endpoints/citrus-ssh/src/test/java/org/citrusframework/ssh/server/SshServerTest.java b/endpoints/citrus-ssh/src/test/java/org/citrusframework/ssh/server/SshServerTest.java
index f0761c8e02..1fe97e75a9 100644
--- a/endpoints/citrus-ssh/src/test/java/org/citrusframework/ssh/server/SshServerTest.java
+++ b/endpoints/citrus-ssh/src/test/java/org/citrusframework/ssh/server/SshServerTest.java
@@ -16,28 +16,23 @@
package org.citrusframework.ssh.server;
-import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
-import java.net.URI;
import java.security.GeneralSecurityException;
import java.security.KeyPair;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.ssh.SshCommand;
-import org.citrusframework.util.FileUtils;
import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
import org.apache.sshd.common.session.SessionContext;
import org.apache.sshd.server.channel.ChannelSession;
import org.apache.sshd.server.command.Command;
import org.apache.sshd.server.command.CommandFactory;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.ssh.SshCommand;
import org.mockito.Mockito;
-import org.springframework.core.io.FileSystemResource;
import org.springframework.test.util.ReflectionTestUtils;
-import org.springframework.util.ResourceUtils;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
diff --git a/endpoints/citrus-vertx/src/main/java/org/citrusframework/vertx/config/annotation/VertxEndpointConfigParser.java b/endpoints/citrus-vertx/src/main/java/org/citrusframework/vertx/config/annotation/VertxEndpointConfigParser.java
index ca812dc27c..d00cc36300 100644
--- a/endpoints/citrus-vertx/src/main/java/org/citrusframework/vertx/config/annotation/VertxEndpointConfigParser.java
+++ b/endpoints/citrus-vertx/src/main/java/org/citrusframework/vertx/config/annotation/VertxEndpointConfigParser.java
@@ -19,11 +19,11 @@
import org.citrusframework.TestActor;
import org.citrusframework.config.annotation.AnnotationConfigParser;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.vertx.endpoint.VertxEndpoint;
import org.citrusframework.vertx.endpoint.VertxEndpointBuilder;
import org.citrusframework.vertx.factory.VertxInstanceFactory;
import org.citrusframework.vertx.message.VertxMessageConverter;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-vertx/src/main/java/org/citrusframework/vertx/config/annotation/VertxSyncEndpointConfigParser.java b/endpoints/citrus-vertx/src/main/java/org/citrusframework/vertx/config/annotation/VertxSyncEndpointConfigParser.java
index 7ba404701b..87ab680693 100644
--- a/endpoints/citrus-vertx/src/main/java/org/citrusframework/vertx/config/annotation/VertxSyncEndpointConfigParser.java
+++ b/endpoints/citrus-vertx/src/main/java/org/citrusframework/vertx/config/annotation/VertxSyncEndpointConfigParser.java
@@ -20,11 +20,11 @@
import org.citrusframework.config.annotation.AnnotationConfigParser;
import org.citrusframework.message.MessageCorrelator;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.vertx.endpoint.VertxSyncEndpoint;
import org.citrusframework.vertx.endpoint.VertxSyncEndpointBuilder;
import org.citrusframework.vertx.factory.VertxInstanceFactory;
import org.citrusframework.vertx.message.VertxMessageConverter;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-vertx/src/main/java/org/citrusframework/vertx/endpoint/VertxSyncConsumer.java b/endpoints/citrus-vertx/src/main/java/org/citrusframework/vertx/endpoint/VertxSyncConsumer.java
index 55beaa1ba9..49fd4afde0 100644
--- a/endpoints/citrus-vertx/src/main/java/org/citrusframework/vertx/endpoint/VertxSyncConsumer.java
+++ b/endpoints/citrus-vertx/src/main/java/org/citrusframework/vertx/endpoint/VertxSyncConsumer.java
@@ -16,16 +16,16 @@
package org.citrusframework.vertx.endpoint;
+import io.vertx.core.Vertx;
import org.citrusframework.context.TestContext;
import org.citrusframework.message.Message;
import org.citrusframework.message.correlation.CorrelationManager;
import org.citrusframework.message.correlation.PollingCorrelationManager;
import org.citrusframework.messaging.ReplyProducer;
+import org.citrusframework.util.ObjectHelper;
import org.citrusframework.vertx.message.CitrusVertxMessageHeaders;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
-import io.vertx.core.Vertx;
/**
* @author Christoph Deppisch
@@ -69,12 +69,12 @@ public Message receive(TestContext context, long timeout) {
@Override
public void send(Message message, TestContext context) {
- Assert.notNull(message, "Message is empty - unable to send empty message");
+ ObjectHelper.assertNotNull(message, "Message is empty - unable to send empty message");
String correlationKeyName = endpointConfiguration.getCorrelator().getCorrelationKeyName(getName());
String correlationKey = correlationManager.getCorrelationKey(correlationKeyName, context);
String replyAddress = correlationManager.find(correlationKey, endpointConfiguration.getTimeout());
- Assert.notNull(replyAddress, "Failed to find reply address for message correlation key: '" + correlationKey + "'");
+ ObjectHelper.assertNotNull(replyAddress, "Failed to find reply address for message correlation key: '" + correlationKey + "'");
if (logger.isDebugEnabled()) {
logger.debug("Sending Vert.x message to event bus address: '" + replyAddress + "'");
diff --git a/endpoints/citrus-websocket/pom.xml b/endpoints/citrus-websocket/pom.xml
index d9d34eef50..8fa7a70532 100644
--- a/endpoints/citrus-websocket/pom.xml
+++ b/endpoints/citrus-websocket/pom.xml
@@ -56,6 +56,10 @@
provided
+
+ org.springframework
+ spring-core
+
org.springframework
spring-messaging
diff --git a/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/config/annotation/WebSocketClientConfigParser.java b/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/config/annotation/WebSocketClientConfigParser.java
index eee487f88a..c55dadd9ca 100644
--- a/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/config/annotation/WebSocketClientConfigParser.java
+++ b/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/config/annotation/WebSocketClientConfigParser.java
@@ -20,10 +20,10 @@
import org.citrusframework.config.annotation.AnnotationConfigParser;
import org.citrusframework.endpoint.resolver.EndpointUriResolver;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.websocket.client.WebSocketClient;
import org.citrusframework.websocket.client.WebSocketClientBuilder;
import org.citrusframework.websocket.message.WebSocketMessageConverter;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/config/annotation/WebSocketServerConfigParser.java b/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/config/annotation/WebSocketServerConfigParser.java
index fe7d558220..9f3eca05a0 100644
--- a/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/config/annotation/WebSocketServerConfigParser.java
+++ b/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/config/annotation/WebSocketServerConfigParser.java
@@ -24,6 +24,7 @@
import org.citrusframework.endpoint.EndpointAdapter;
import org.citrusframework.http.message.HttpMessageConverter;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.websocket.endpoint.WebSocketEndpoint;
import org.citrusframework.websocket.message.WebSocketMessageConverter;
import org.citrusframework.websocket.server.WebSocketServer;
@@ -32,7 +33,6 @@
import org.eclipse.jetty.security.SecurityHandler;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.servlet.ServletHandler;
-import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
/**
diff --git a/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/config/xml/WebSocketServerParser.java b/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/config/xml/WebSocketServerParser.java
index a3287e6ad6..fde9297a33 100644
--- a/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/config/xml/WebSocketServerParser.java
+++ b/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/config/xml/WebSocketServerParser.java
@@ -16,6 +16,8 @@
package org.citrusframework.websocket.config.xml;
+import java.util.List;
+
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.http.config.xml.HttpServerParser;
import org.citrusframework.server.AbstractServer;
@@ -24,12 +26,9 @@
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.CollectionUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
-import java.util.List;
-
/**
* @author Christoph Deppisch
* @since 2.3
@@ -45,7 +44,7 @@ protected void parseServer(BeanDefinitionBuilder builder, Element element, Parse
if (socketsElement != null) {
List socketElements = DomUtils.getChildElements(socketsElement);
- if (CollectionUtils.isEmpty(socketElements)) {
+ if (socketElements.isEmpty()) {
throw new CitrusRuntimeException("Invalid '.. ' configuration - at least one ' ' must be defined");
}
diff --git a/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/endpoint/WebSocketProducer.java b/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/endpoint/WebSocketProducer.java
index 015d149fb7..9d6bd9d3ef 100644
--- a/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/endpoint/WebSocketProducer.java
+++ b/endpoints/citrus-websocket/src/main/java/org/citrusframework/websocket/endpoint/WebSocketProducer.java
@@ -19,9 +19,9 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.message.Message;
import org.citrusframework.messaging.Producer;
+import org.citrusframework.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
import org.springframework.web.socket.WebSocketMessage;
/**
@@ -51,7 +51,7 @@ public WebSocketProducer(String name, WebSocketEndpointConfiguration endpointCon
@Override
public void send(Message message, TestContext context) {
- Assert.notNull(message, "Message is empty - unable to send empty message");
+ ObjectHelper.assertNotNull(message, "Message is empty - unable to send empty message");
logger.info("Sending WebSocket message ...");
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/AssertSoapFault.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/AssertSoapFault.java
index a46b50cd70..287c568cdf 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/AssertSoapFault.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/AssertSoapFault.java
@@ -33,7 +33,9 @@
import org.citrusframework.message.builder.MessageBuilderSupport;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.ws.message.SoapFault;
import org.citrusframework.ws.validation.SimpleSoapFaultValidator;
import org.citrusframework.ws.validation.SoapFaultDetailValidationContext;
@@ -41,8 +43,6 @@
import org.citrusframework.ws.validation.SoapFaultValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
-import org.springframework.util.StringUtils;
import org.springframework.ws.soap.client.SoapFaultClientException;
/**
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/ReceiveSoapMessageAction.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/ReceiveSoapMessageAction.java
index 1bfc83ba3b..7c2eb54d83 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/ReceiveSoapMessageAction.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/ReceiveSoapMessageAction.java
@@ -27,6 +27,7 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
import org.citrusframework.message.builder.ReceiveMessageBuilderSupport;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
import org.citrusframework.validation.builder.StaticMessageBuilder;
import org.citrusframework.ws.message.SoapAttachment;
@@ -35,7 +36,6 @@
import org.citrusframework.ws.message.SoapMessageUtils;
import org.citrusframework.ws.validation.SimpleSoapAttachmentValidator;
import org.citrusframework.ws.validation.SoapAttachmentValidator;
-import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
/**
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SendSoapFaultAction.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SendSoapFaultAction.java
index 7932715699..f7db154ef2 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SendSoapFaultAction.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SendSoapFaultAction.java
@@ -25,14 +25,14 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.MessageHeaders;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.builder.StaticMessageBuilder;
import org.citrusframework.ws.message.SoapAttachment;
import org.citrusframework.ws.message.SoapFault;
import org.citrusframework.ws.message.SoapMessage;
-import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SendSoapMessageAction.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SendSoapMessageAction.java
index 3b13974746..c157b80d57 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SendSoapMessageAction.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SendSoapMessageAction.java
@@ -22,6 +22,8 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Hex;
import org.citrusframework.TestAction;
import org.citrusframework.actions.SendMessageAction;
import org.citrusframework.context.TestContext;
@@ -29,17 +31,15 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
import org.citrusframework.message.builder.SendMessageBuilderSupport;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
import org.citrusframework.validation.builder.StaticMessageBuilder;
import org.citrusframework.ws.message.SoapAttachment;
import org.citrusframework.ws.message.SoapMessage;
import org.citrusframework.ws.message.SoapMessageHeaders;
import org.citrusframework.ws.message.SoapMessageUtils;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.codec.binary.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
/**
* Message send action able to add SOAP attachment support to normal message sending action.
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SoapActionBuilder.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SoapActionBuilder.java
index 80d9fc079d..aca13c34f2 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SoapActionBuilder.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SoapActionBuilder.java
@@ -20,9 +20,9 @@
import org.citrusframework.TestActionBuilder;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.util.ObjectHelper;
import org.citrusframework.ws.client.WebServiceClient;
import org.citrusframework.ws.server.WebServiceServer;
-import org.springframework.util.Assert;
/**
* Action executes soap client and server operations.
@@ -96,7 +96,7 @@ public SoapActionBuilder withReferenceResolver(ReferenceResolver referenceResolv
@Override
public TestAction build() {
- Assert.notNull(delegate, "Missing delegate action to build");
+ ObjectHelper.assertNotNull(delegate, "Missing delegate action to build");
return delegate.build();
}
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SoapClientActionBuilder.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SoapClientActionBuilder.java
index 5f8feacbbe..f891cdf7a7 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SoapClientActionBuilder.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SoapClientActionBuilder.java
@@ -21,7 +21,7 @@
import org.citrusframework.endpoint.Endpoint;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
-import org.springframework.util.Assert;
+import org.citrusframework.util.ObjectHelper;
/**
* Action executes soap client operations such as sending requests and receiving responses.
@@ -119,7 +119,7 @@ public SoapClientActionBuilder withReferenceResolver(ReferenceResolver reference
@Override
public TestAction build() {
- Assert.notNull(delegate, "Missing delegate action to build");
+ ObjectHelper.assertNotNull(delegate, "Missing delegate action to build");
return delegate.build();
}
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SoapServerActionBuilder.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SoapServerActionBuilder.java
index c3f408d676..e95b44b42f 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SoapServerActionBuilder.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/actions/SoapServerActionBuilder.java
@@ -21,7 +21,7 @@
import org.citrusframework.endpoint.Endpoint;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
-import org.springframework.util.Assert;
+import org.citrusframework.util.ObjectHelper;
/**
* Action executes soap server operations such as receiving requests and sending response messsages.
@@ -119,7 +119,7 @@ public SoapServerActionBuilder withReferenceResolver(ReferenceResolver reference
@Override
public TestAction build() {
- Assert.notNull(delegate, "Missing delegate action to build");
+ ObjectHelper.assertNotNull(delegate, "Missing delegate action to build");
return delegate.build();
}
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/client/WebServiceClient.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/client/WebServiceClient.java
index ba4471acc3..9e71f81ca0 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/client/WebServiceClient.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/client/WebServiceClient.java
@@ -16,10 +16,10 @@
package org.citrusframework.ws.client;
+import java.io.IOException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
-import java.io.IOException;
import org.citrusframework.context.TestContext;
import org.citrusframework.endpoint.AbstractEndpoint;
@@ -33,6 +33,7 @@
import org.citrusframework.messaging.Producer;
import org.citrusframework.messaging.ReplyConsumer;
import org.citrusframework.messaging.SelectiveConsumer;
+import org.citrusframework.util.ObjectHelper;
import org.citrusframework.ws.interceptor.LoggingClientInterceptor;
import org.citrusframework.ws.message.SoapMessage;
import org.citrusframework.ws.message.callback.SoapRequestMessageCallback;
@@ -40,7 +41,6 @@
import org.citrusframework.xml.StringResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.core.FaultMessageResolver;
import org.springframework.ws.client.core.SimpleFaultMessageResolver;
@@ -83,7 +83,7 @@ public WebServiceEndpointConfiguration getEndpointConfiguration() {
@Override
public void send(Message message, TestContext context) {
- Assert.notNull(message, "Message is empty - unable to send empty message");
+ ObjectHelper.assertNotNull(message, "Message is empty - unable to send empty message");
getEndpointConfiguration().getInterceptors()
.stream()
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/annotation/WebServiceClientConfigParser.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/annotation/WebServiceClientConfigParser.java
index 09abe4cd35..701af4f783 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/annotation/WebServiceClientConfigParser.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/annotation/WebServiceClientConfigParser.java
@@ -25,10 +25,10 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.MessageCorrelator;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.ws.client.WebServiceClient;
import org.citrusframework.ws.client.WebServiceClientBuilder;
import org.citrusframework.ws.message.converter.WebServiceMessageConverter;
-import org.springframework.util.StringUtils;
import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/annotation/WebServiceServerConfigParser.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/annotation/WebServiceServerConfigParser.java
index 00dbdaba33..a8b08425d3 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/annotation/WebServiceServerConfigParser.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/annotation/WebServiceServerConfigParser.java
@@ -20,13 +20,13 @@
import org.citrusframework.config.annotation.AnnotationConfigParser;
import org.citrusframework.endpoint.EndpointAdapter;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.ws.message.converter.WebServiceMessageConverter;
import org.citrusframework.ws.server.WebServiceServer;
import org.citrusframework.ws.server.WebServiceServerBuilder;
import org.eclipse.jetty.security.SecurityHandler;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.servlet.ServletHandler;
-import org.springframework.util.StringUtils;
import org.springframework.ws.server.EndpointInterceptor;
/**
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/xml/AssertSoapFaultParser.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/xml/AssertSoapFaultParser.java
index ec0e5a53ea..27e047644e 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/xml/AssertSoapFaultParser.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/xml/AssertSoapFaultParser.java
@@ -25,17 +25,16 @@
import org.citrusframework.config.xml.AbstractTestActionFactoryBean;
import org.citrusframework.config.xml.DescriptionElementParser;
import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.ws.actions.AssertSoapFault;
import org.citrusframework.ws.validation.SoapFaultDetailValidationContext;
import org.citrusframework.ws.validation.SoapFaultValidationContext;
import org.citrusframework.ws.validation.SoapFaultValidator;
-import org.apache.xerces.util.DOMUtil;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
@@ -105,17 +104,20 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
beanDefinition.addPropertyValue("validationContext", validationContext);
}
- Element action = DOMUtil.getFirstChildElement(DomUtils.getChildElementByTagName(element, "when"));
- if (action != null) {
- BeanDefinitionParser parser = null;
- if (action.getNamespaceURI().equals("http://www.citrusframework.org/schema/testcase")) {
- parser = CitrusNamespaceParserRegistry.getBeanParser(action.getLocalName());
- }
+ Element when = DomUtils.getChildElementByTagName(element, "when");
+ if (when != null) {
+ Element action = DomUtils.getChildElements(when).stream().findFirst().orElse(null);
+ if (action != null) {
+ BeanDefinitionParser parser = null;
+ if (action.getNamespaceURI().equals("http://www.citrusframework.org/schema/testcase")) {
+ parser = CitrusNamespaceParserRegistry.getBeanParser(action.getLocalName());
+ }
- if (parser == null) {
- beanDefinition.addPropertyValue("action", parserContext.getReaderContext().getNamespaceHandlerResolver().resolve(action.getNamespaceURI()).parse(action, parserContext));
- } else {
- beanDefinition.addPropertyValue("action", parser.parse(action, parserContext));
+ if (parser == null) {
+ beanDefinition.addPropertyValue("action", parserContext.getReaderContext().getNamespaceHandlerResolver().resolve(action.getNamespaceURI()).parse(action, parserContext));
+ } else {
+ beanDefinition.addPropertyValue("action", parser.parse(action, parserContext));
+ }
}
}
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/xml/SendSoapFaultActionParser.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/xml/SendSoapFaultActionParser.java
index 3a927b0271..be226b2c00 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/xml/SendSoapFaultActionParser.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/xml/SendSoapFaultActionParser.java
@@ -21,12 +21,12 @@
import org.citrusframework.config.xml.AbstractSendMessageActionFactoryBean;
import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.ws.actions.SendSoapFaultAction;
import org.citrusframework.ws.message.SoapAttachment;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/xml/WebServiceServerParser.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/xml/WebServiceServerParser.java
index 162282704c..1b48384070 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/xml/WebServiceServerParser.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/config/xml/WebServiceServerParser.java
@@ -19,15 +19,15 @@
import org.citrusframework.config.util.BeanDefinitionParserUtils;
import org.citrusframework.config.xml.AbstractServerParser;
import org.citrusframework.server.AbstractServer;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.ws.server.WebServiceServer;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
* Parser for jetty-server component in Citrus ws namespace.
- *
+ *
* @author Christoph Deppisch
*/
public class WebServiceServerParser extends AbstractServerParser {
@@ -45,7 +45,7 @@ protected void parseServer(BeanDefinitionBuilder builder, Element element, Parse
if (StringUtils.hasText(useRootContext)) {
builder.addPropertyValue("useRootContextAsParent", Boolean.valueOf(useRootContext));
}
-
+
BeanDefinitionParserUtils.setPropertyValue(builder, element.getAttribute("servlet-name"), "servletName");
BeanDefinitionParserUtils.setPropertyValue(builder, element.getAttribute("servlet-mapping-path"), "servletMappingPath");
BeanDefinitionParserUtils.setPropertyValue(builder, element.getAttribute("context-path"), "contextPath");
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/message/SoapAttachment.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/message/SoapAttachment.java
index 4faf26deaf..2af3914588 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/message/SoapAttachment.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/message/SoapAttachment.java
@@ -31,12 +31,11 @@
import org.citrusframework.CitrusSettings;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.citrusframework.util.StringUtils;
import org.springframework.http.MediaType;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.util.StringUtils;
import org.springframework.ws.mime.Attachment;
/**
@@ -222,14 +221,14 @@ public String getContent() {
} else if (StringUtils.hasText(getContentResourcePath()) &&
(getContentType().startsWith("text/") || getContentType().equals(MediaType.APPLICATION_XML_VALUE))) {
try {
- String fileContent = FileUtils.readToString(new PathMatchingResourcePatternResolver().getResource(getContentResourcePath()).getInputStream(), Charset.forName(charsetName));
+ String fileContent = FileUtils.readToString(Resources.create(getContentResourcePath()).getInputStream(), Charset.forName(charsetName));
return context != null ? context.replaceDynamicContentInString(fileContent) : fileContent;
} catch (IOException e) {
throw new CitrusRuntimeException("Failed to read SOAP attachment file resource", e);
}
} else {
try {
- byte[] binaryData = FileCopyUtils.copyToByteArray(getDataHandler().getInputStream());
+ byte[] binaryData = FileUtils.copyToByteArray(getDataHandler().getInputStream());
if (encodingType.equals(SoapAttachment.ENCODING_BASE64_BINARY)) {
return Base64.encodeBase64String(binaryData);
} else if (encodingType.equals(SoapAttachment.ENCODING_HEX_BINARY)) {
@@ -257,11 +256,15 @@ public void setContent(String content) {
* @return the content resource path
*/
public String getContentResourcePath() {
- if (contentResourcePath != null && context != null) {
- return context.replaceDynamicContentInString(contentResourcePath);
- } else {
- return contentResourcePath;
+ if (contentResourcePath != null) {
+ if (context != null) {
+ return context.replaceDynamicContentInString(contentResourcePath);
+ } else {
+ return contentResourcePath;
+ }
}
+
+ return null;
}
/**
@@ -398,7 +401,7 @@ public String getContentType() {
@Override
public String getName() {
- return getFileResource().getFilename();
+ return FileUtils.getFileName(getFileResource().getLocation());
}
@Override
@@ -407,7 +410,7 @@ public OutputStream getOutputStream() throws IOException {
}
private Resource getFileResource() {
- return new PathMatchingResourcePatternResolver().getResource(SoapAttachment.this.getContentResourcePath());
+ return Resources.create(SoapAttachment.this.getContentResourcePath());
}
}
}
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/message/SoapFault.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/message/SoapFault.java
index 51d83c8657..fee4199870 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/message/SoapFault.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/message/SoapFault.java
@@ -16,21 +16,21 @@
package org.citrusframework.ws.message;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
import javax.xml.namespace.QName;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.xml.StringResult;
import org.springframework.beans.propertyeditors.LocaleEditor;
-import org.springframework.util.StringUtils;
import org.springframework.ws.soap.SoapFaultDetailElement;
import org.springframework.xml.namespace.QNameEditor;
import org.springframework.xml.namespace.QNameUtils;
@@ -260,9 +260,9 @@ public String toString() {
StringBuilder builder = new StringBuilder();
QName faultCodeQName = getFaultCodeQName();
- if (StringUtils.hasLength(faultCodeQName.getNamespaceURI()) && StringUtils.hasLength(faultCodeQName.getPrefix())) {
+ if (StringUtils.hasText(faultCodeQName.getNamespaceURI()) && StringUtils.hasText(faultCodeQName.getPrefix())) {
builder.append(decorate(decorate(faultCodeQName.getNamespaceURI()) + faultCodeQName.getPrefix() + ":" + faultCodeQName.getLocalPart()));
- } else if (StringUtils.hasLength(faultCodeQName.getNamespaceURI())) {
+ } else if (StringUtils.hasText(faultCodeQName.getNamespaceURI())) {
builder.append(decorate(decorate(faultCodeQName.getNamespaceURI()) + faultCodeQName.getLocalPart()));
} else {
builder.append(decorate(faultCodeQName.getLocalPart()));
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/message/converter/SoapMessageConverter.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/message/converter/SoapMessageConverter.java
index 2b9c46cde9..c5fcaa8d71 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/message/converter/SoapMessageConverter.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/message/converter/SoapMessageConverter.java
@@ -32,24 +32,24 @@
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.xml.soap.MimeHeader;
+import jakarta.xml.soap.MimeHeaders;
import org.citrusframework.CitrusSettings;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageHeaderUtils;
import org.citrusframework.message.MessageHeaders;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.ws.client.WebServiceEndpointConfiguration;
import org.citrusframework.ws.message.SoapAttachment;
import org.citrusframework.ws.message.SoapMessage;
import org.citrusframework.ws.message.SoapMessageHeaders;
import org.citrusframework.xml.StringResult;
import org.citrusframework.xml.StringSource;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.xml.soap.MimeHeader;
-import jakarta.xml.soap.MimeHeaders;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
import org.springframework.web.util.UrlPathHelper;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.context.MessageContext;
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/server/WebServiceEndpoint.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/server/WebServiceEndpoint.java
index 22e597e113..905dd4c8cf 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/server/WebServiceEndpoint.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/server/WebServiceEndpoint.java
@@ -27,23 +27,22 @@
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
+import jakarta.xml.soap.MimeHeaders;
import org.citrusframework.endpoint.EndpointAdapter;
import org.citrusframework.endpoint.adapter.EmptyResponseEndpointAdapter;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageHeaderUtils;
import org.citrusframework.message.MessageHeaders;
+import org.citrusframework.util.ObjectHelper;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.ws.client.WebServiceEndpointConfiguration;
import org.citrusframework.ws.message.SoapAttachment;
import org.citrusframework.ws.message.SoapFault;
import org.citrusframework.ws.message.SoapMessageHeaders;
import org.citrusframework.xml.StringSource;
-import jakarta.xml.soap.MimeHeaders;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
import org.springframework.ws.context.MessageContext;
import org.springframework.ws.mime.MimeMessage;
import org.springframework.ws.server.endpoint.MessageEndpoint;
@@ -94,7 +93,7 @@ public class WebServiceEndpoint implements MessageEndpoint {
* @throws CitrusRuntimeException
*/
public void invoke(final MessageContext messageContext) throws Exception {
- Assert.notNull(messageContext.getRequest(), "Request must not be null - unable to send message");
+ ObjectHelper.assertNotNull(messageContext.getRequest(), "Request must not be null - unable to send message");
Message requestMessage = endpointConfiguration.getMessageConverter().convertInbound(messageContext.getRequest(), messageContext, endpointConfiguration);
@@ -158,7 +157,7 @@ private void addSoapAttachments(MimeMessage response, Message replyMessage) {
* @throws IOException
*/
private boolean simulateHttpStatusCode(Message replyMessage) throws IOException {
- if (replyMessage == null || CollectionUtils.isEmpty(replyMessage.getHeaders())) {
+ if (replyMessage == null || replyMessage.getHeaders() == null || replyMessage.getHeaders().isEmpty()) {
return false;
}
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/server/WebServiceServer.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/server/WebServiceServer.java
index c1355b711b..9d461ad97f 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/server/WebServiceServer.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/server/WebServiceServer.java
@@ -22,6 +22,7 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.report.MessageListeners;
import org.citrusframework.server.AbstractServer;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.ws.context.ParentDelegatingWebApplicationContext;
import org.citrusframework.ws.interceptor.LoggingEndpointInterceptor;
import org.citrusframework.ws.message.converter.SoapMessageConverter;
@@ -38,7 +39,6 @@
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.servlet.ServletMapping;
-import org.springframework.util.StringUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/servlet/CitrusMessageDispatcherServlet.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/servlet/CitrusMessageDispatcherServlet.java
index da029e8319..6ffa054e66 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/servlet/CitrusMessageDispatcherServlet.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/servlet/CitrusMessageDispatcherServlet.java
@@ -16,19 +16,19 @@
package org.citrusframework.ws.servlet;
+import java.util.ArrayList;
+import java.util.List;
+
import org.citrusframework.endpoint.EndpointAdapter;
-import org.citrusframework.ws.server.WebServiceEndpoint;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.ws.client.WebServiceEndpointConfiguration;
import org.citrusframework.ws.interceptor.DelegatingEndpointInterceptor;
+import org.citrusframework.ws.server.WebServiceEndpoint;
import org.citrusframework.ws.server.WebServiceServer;
import org.springframework.context.ApplicationContext;
-import org.springframework.util.StringUtils;
import org.springframework.ws.server.EndpointInterceptor;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* Citrus message dispatcher servlet extends Spring's message dispatcher servlet and just
* adds optional configuration settings for default mapping strategies, interceptors and so on.
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/AbstractFaultDetailValidator.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/AbstractFaultDetailValidator.java
index 642b9daa7a..e260937de4 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/AbstractFaultDetailValidator.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/AbstractFaultDetailValidator.java
@@ -24,7 +24,6 @@
import org.citrusframework.ws.message.SoapFault;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
/**
* Abstract implementation of {@link SoapFaultValidator} converting soap fault detail objects to simple String content for
@@ -62,7 +61,7 @@ protected void validateFaultDetail(SoapFault receivedDetail, SoapFault controlDe
String controlDetailString = controlDetailElements.get(i);
SoapFaultDetailValidationContext detailValidationContext;
- if (CollectionUtils.isEmpty(validationContext.getValidationContexts())) {
+ if (validationContext.getValidationContexts() == null || validationContext.getValidationContexts().isEmpty()) {
detailValidationContext = new SoapFaultDetailValidationContext.Builder().build();
} else {
detailValidationContext = validationContext.getValidationContexts().get(i++);
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/AbstractSoapAttachmentValidator.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/AbstractSoapAttachmentValidator.java
index 0982095fb4..45b0ffa23e 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/AbstractSoapAttachmentValidator.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/AbstractSoapAttachmentValidator.java
@@ -16,24 +16,23 @@
package org.citrusframework.ws.validation;
+import java.util.List;
+
import org.citrusframework.exceptions.ValidationException;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.ws.message.SoapAttachment;
import org.citrusframework.ws.message.SoapMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
import org.springframework.ws.mime.Attachment;
-import java.util.List;
-
/**
* Abstract SOAP attachment validator tries to find attachment within received message and compares
- * its attachment contentId, contentType and content body to a control attachment definition.
- *
- * Validator will create a {@link SoapAttachment} and automatically handle contentId and
+ * its attachment contentId, contentType and content body to a control attachment definition.
+ *
+ * Validator will create a {@link SoapAttachment} and automatically handle contentId and
* contentType validation. Content body validation is delegated to subclasses.
- *
+ *
* @author Christoph Deppisch
*/
public abstract class AbstractSoapAttachmentValidator implements SoapAttachmentValidator {
@@ -41,7 +40,7 @@ public abstract class AbstractSoapAttachmentValidator implements SoapAttachmentV
* Logger
*/
private static final Logger logger = LoggerFactory.getLogger(AbstractSoapAttachmentValidator.class);
-
+
@Override
public void validateAttachment(SoapMessage soapMessage, List controlAttachments) {
logger.debug("Validating SOAP attachments ...");
@@ -103,29 +102,30 @@ protected SoapAttachment findAttachment(SoapMessage soapMessage, SoapAttachment
* @param controlAttachment
*/
protected void validateAttachmentContentId(SoapAttachment receivedAttachment, SoapAttachment controlAttachment) {
- //in case contentId was not set in test case, skip validation
+ //in case contentId was not set in test case, skip validation
if (!StringUtils.hasText(controlAttachment.getContentId())) { return; }
-
+
if (receivedAttachment.getContentId() != null) {
- Assert.isTrue(controlAttachment.getContentId() != null,
- buildValidationErrorMessage("Values not equal for attachment contentId",
+ if (controlAttachment.getContentId() == null) {
+ throw new ValidationException(buildValidationErrorMessage("Values not equal for attachment contentId",
null, receivedAttachment.getContentId()));
+ }
- Assert.isTrue(receivedAttachment.getContentId().equals(controlAttachment.getContentId()),
- buildValidationErrorMessage("Values not equal for attachment contentId",
+ if (!receivedAttachment.getContentId().equals(controlAttachment.getContentId())) {
+ throw new ValidationException(buildValidationErrorMessage("Values not equal for attachment contentId",
controlAttachment.getContentId(), receivedAttachment.getContentId()));
- } else {
- Assert.isTrue(controlAttachment.getContentId() == null || controlAttachment.getContentId().length() == 0,
- buildValidationErrorMessage("Values not equal for attachment contentId",
- controlAttachment.getContentId(), null));
+ }
+ } else if (StringUtils.hasText(controlAttachment.getContentId())) {
+ throw new ValidationException(buildValidationErrorMessage("Values not equal for attachment contentId",
+ controlAttachment.getContentId(), null));
}
-
+
if (logger.isDebugEnabled()) {
- logger.debug("Validating attachment contentId: " + receivedAttachment.getContentId() +
+ logger.debug("Validating attachment contentId: " + receivedAttachment.getContentId() +
"='" + controlAttachment.getContentId() + "': OK.");
}
}
-
+
/**
* Validating SOAP attachment content type.
* @param receivedAttachment
@@ -134,27 +134,28 @@ protected void validateAttachmentContentId(SoapAttachment receivedAttachment, So
protected void validateAttachmentContentType(SoapAttachment receivedAttachment, SoapAttachment controlAttachment) {
//in case contentType was not set in test case, skip validation
if (!StringUtils.hasText(controlAttachment.getContentType())) { return; }
-
+
if (receivedAttachment.getContentType() != null) {
- Assert.isTrue(controlAttachment.getContentType() != null,
- buildValidationErrorMessage("Values not equal for attachment contentType",
+ if (controlAttachment.getContentType() == null) {
+ throw new ValidationException(buildValidationErrorMessage("Values not equal for attachment contentType",
null, receivedAttachment.getContentType()));
+ }
- Assert.isTrue(receivedAttachment.getContentType().equals(controlAttachment.getContentType()),
- buildValidationErrorMessage("Values not equal for attachment contentType",
+ if (!receivedAttachment.getContentType().equals(controlAttachment.getContentType())) {
+ throw new ValidationException(buildValidationErrorMessage("Values not equal for attachment contentType",
controlAttachment.getContentType(), receivedAttachment.getContentType()));
- } else {
- Assert.isTrue(controlAttachment.getContentType() == null || controlAttachment.getContentType().length() == 0,
- buildValidationErrorMessage("Values not equal for attachment contentType",
- controlAttachment.getContentType(), null));
+ }
+ } else if (StringUtils.hasText(controlAttachment.getContentType())) {
+ throw new ValidationException(buildValidationErrorMessage("Values not equal for attachment contentType",
+ controlAttachment.getContentType(), null));
}
-
+
if (logger.isDebugEnabled()) {
- logger.debug("Validating attachment contentType: " + receivedAttachment.getContentType() +
+ logger.debug("Validating attachment contentType: " + receivedAttachment.getContentType() +
"='" + controlAttachment.getContentType() + "': OK.");
}
}
-
+
/**
* Constructs proper error message with expected value and actual value.
* @param message the base error message.
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/AbstractSoapFaultValidator.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/AbstractSoapFaultValidator.java
index 0aca55a846..f78fc0ca56 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/AbstractSoapFaultValidator.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/AbstractSoapFaultValidator.java
@@ -19,13 +19,11 @@
import org.citrusframework.CitrusSettings;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.ValidationException;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.matcher.ValidationMatcherUtils;
import org.citrusframework.ws.message.SoapFault;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
/**
* Abstract soap fault validation implementation offering basic faultCode and faultString validation.
@@ -58,9 +56,10 @@ public void validateSoapFault(SoapFault receivedFault, SoapFault controlFault,
//fault code validation
if (StringUtils.hasText(controlFault.getFaultCodeQName().getLocalPart())) {
- Assert.isTrue(controlFault.getFaultCodeQName().equals(receivedFault.getFaultCodeQName()),
- "SOAP fault validation failed! Fault code does not match - expected: '" +
+ if (!controlFault.getFaultCodeQName().equals(receivedFault.getFaultCodeQName())) {
+ throw new ValidationException("SOAP fault validation failed! Fault code does not match - expected: '" +
controlFault.getFaultCodeQName() + "' but was: '" + receivedFault.getFaultCodeQName() + "'");
+ }
}
//fault actor validation
@@ -68,14 +67,13 @@ public void validateSoapFault(SoapFault receivedFault, SoapFault controlFault,
if (controlFault.getFaultActor().startsWith(CitrusSettings.VALIDATION_MATCHER_PREFIX) &&
controlFault.getFaultActor().endsWith(CitrusSettings.VALIDATION_MATCHER_SUFFIX)) {
ValidationMatcherUtils.resolveValidationMatcher("SOAP fault actor", receivedFault.getFaultActor(), controlFault.getFaultActor(), context);
- } else {
- Assert.isTrue(controlFault.getFaultActor().equals(receivedFault.getFaultActor()),
- "SOAP fault validation failed! Fault actor does not match - expected: '" +
- controlFault.getFaultActor() + "' but was: '" + receivedFault.getFaultActor() + "'");
+ } else if (!controlFault.getFaultActor().equals(receivedFault.getFaultActor())) {
+ throw new ValidationException("SOAP fault validation failed! Fault actor does not match - expected: '" +
+ controlFault.getFaultActor() + "' but was: '" + receivedFault.getFaultActor() + "'");
}
}
- if (!CollectionUtils.isEmpty(controlFault.getFaultDetails())) {
+ if (controlFault.getFaultDetails() != null && !controlFault.getFaultDetails().isEmpty()) {
validateFaultDetail(receivedFault, controlFault, context, validationContext);
}
}
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/BinarySoapAttachmentValidator.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/BinarySoapAttachmentValidator.java
index 9c29161a27..710225000f 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/BinarySoapAttachmentValidator.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/BinarySoapAttachmentValidator.java
@@ -16,15 +16,15 @@
package org.citrusframework.ws.validation;
+import java.io.IOException;
+import java.util.Optional;
+
+import org.apache.commons.io.IOUtils;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.exceptions.ValidationException;
import org.citrusframework.ws.message.SoapAttachment;
-import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
-
-import java.io.IOException;
-import java.util.Optional;
/**
* Soap attachment validator performs binary content validation by comparing attachment content binary input streams.
@@ -44,9 +44,10 @@ protected void validateAttachmentContent(SoapAttachment receivedAttachment, Soap
}
try {
- Assert.isTrue(IOUtils.contentEquals(receivedAttachment.getInputStream(), controlAttachment.getInputStream()),
- "Values not equal for binary attachment content '"
+ if (!IOUtils.contentEquals(receivedAttachment.getInputStream(), controlAttachment.getInputStream())) {
+ throw new ValidationException("Values not equal for binary attachment content '"
+ Optional.ofNullable(controlAttachment.getContentId()).orElse(Optional.ofNullable(receivedAttachment.getContentId()).orElse("unknown")) + "'");
+ }
} catch(IOException e) {
throw new CitrusRuntimeException("Binary SOAP attachment validation failed", e);
}
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/SimpleSoapAttachmentValidator.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/SimpleSoapAttachmentValidator.java
index 0d827d5564..933ccaffcc 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/SimpleSoapAttachmentValidator.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/SimpleSoapAttachmentValidator.java
@@ -15,11 +15,11 @@
*/
package org.citrusframework.ws.validation;
+import org.citrusframework.exceptions.ValidationException;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.ws.message.SoapAttachment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
/**
* Simple implementation of a {@link AbstractSoapAttachmentValidator}.
@@ -37,8 +37,8 @@ public class SimpleSoapAttachmentValidator extends AbstractSoapAttachmentValidat
@Override
protected void validateAttachmentContent(SoapAttachment receivedAttachment, SoapAttachment controlAttachment) {
- String receivedContent = StringUtils.trimWhitespace(receivedAttachment.getContent());
- String controlContent = StringUtils.trimWhitespace(controlAttachment.getContent());
+ String receivedContent = receivedAttachment.getContent().replaceAll("\\s", "");
+ String controlContent = controlAttachment.getContent().replaceAll("\\s", "");
if (logger.isDebugEnabled()) {
logger.debug("Validating SOAP attachment content ...");
@@ -46,20 +46,20 @@ protected void validateAttachmentContent(SoapAttachment receivedAttachment, Soap
logger.debug("Control attachment content: " + controlContent);
}
- if (receivedContent != null) {
- Assert.isTrue(controlContent != null,
- "Values not equal for attachment content '"
+ if (StringUtils.hasText(receivedContent)) {
+ if (!StringUtils.hasText(controlContent)) {
+ throw new ValidationException("Values not equal for attachment content '"
+ controlAttachment.getContentId() + "', expected '"
- + null + "' but was '"
+ + controlContent + "' but was '"
+ receivedContent + "'");
+ }
validateAttachmentContentData(receivedContent, controlContent, controlAttachment.getContentId());
- } else {
- Assert.isTrue(!StringUtils.hasLength(controlContent),
- "Values not equal for attachment content '"
- + controlAttachment.getContentId() + "', expected '"
- + controlContent + "' but was '"
- + null + "'");
+ } else if (StringUtils.hasText(controlContent)) {
+ throw new ValidationException("Values not equal for attachment content '"
+ + controlAttachment.getContentId() + "', expected '"
+ + controlContent + "' but was '"
+ + receivedContent + "'");
}
if (logger.isDebugEnabled()) {
@@ -75,15 +75,16 @@ protected void validateAttachmentContent(SoapAttachment receivedAttachment, Soap
*/
protected void validateAttachmentContentData(String receivedContent, String controlContent, String controlContentId) {
if (ignoreAllWhitespaces) {
- controlContent = StringUtils.trimAllWhitespace(controlContent);
- receivedContent = StringUtils.trimAllWhitespace(receivedContent);
+ controlContent = controlContent.replaceAll("\\s", "");
+ receivedContent = receivedContent.replaceAll("\\s", "");
}
- Assert.isTrue(receivedContent.equals(controlContent),
- "Values not equal for attachment content '"
+ if (!receivedContent.equals(controlContent)) {
+ throw new ValidationException("Values not equal for attachment content '"
+ controlContentId + "', expected '"
+ controlContent.trim() + "' but was '"
+ receivedContent.trim() + "'");
+ }
}
/**
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/SimpleSoapFaultValidator.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/SimpleSoapFaultValidator.java
index 53a2a63ec5..807dfad65d 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/SimpleSoapFaultValidator.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/SimpleSoapFaultValidator.java
@@ -21,7 +21,6 @@
import org.citrusframework.exceptions.ValidationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
/**
* Simple soap fault validator implementation just performing String equals on soap fault detail
@@ -40,12 +39,12 @@ protected void validateFaultDetailString(String received, String control,
logger.debug("Validating SOAP fault detail ...");
- String receivedDetail = StringUtils.trimAllWhitespace(received);
- String controlDetail = StringUtils.trimAllWhitespace(control);
+ String receivedDetail = received.replaceAll("\\s", "");
+ String controlDetail = control.replaceAll("\\s", "");
if (logger.isDebugEnabled()) {
- logger.debug("Received fault detail:\n" + StringUtils.trimWhitespace(received));
- logger.debug("Control fault detail:\n" + StringUtils.trimWhitespace(control));
+ logger.debug("Received fault detail:\n" + received.strip());
+ logger.debug("Control fault detail:\n" + control.strip());
}
if (!receivedDetail.equals(controlDetail)) {
diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/SoapFaultDetailValidationContext.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/SoapFaultDetailValidationContext.java
index 7265b6a1bd..73f791a1e4 100644
--- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/SoapFaultDetailValidationContext.java
+++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/validation/SoapFaultDetailValidationContext.java
@@ -64,7 +64,6 @@ public XpathMessageValidationContext.Builder xpath() {
.schemaValidation(schemaValidation)
.schemaRepository(schemaRepository)
.schema(schema)
- .dtd(dtdResource)
.ignore(ignoreExpressions);
}
diff --git a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/AssertSoapFaultTest.java b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/AssertSoapFaultTest.java
index 0d2eb5462d..b48c3476dd 100644
--- a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/AssertSoapFaultTest.java
+++ b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/AssertSoapFaultTest.java
@@ -16,10 +16,10 @@
package org.citrusframework.ws.actions;
+import java.util.Locale;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
-import java.util.Locale;
import org.citrusframework.TestAction;
import org.citrusframework.context.SpringBeanReferenceResolver;
@@ -155,7 +155,7 @@ public void testNoPrefix() throws Exception {
assertAction.execute(context);
}
- @Test
+ @Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "SOAP fault validation failed! Fault code does not match - expected: '\\{http://citrusframework.org}TEC-1001' but was: '\\{http://citrusframework.org}TEC-2002'")
public void testWrongFaultCode() throws Exception {
TestAction action = action(context -> {
SoapMessage faultMessage;
@@ -175,17 +175,10 @@ public void testWrongFaultCode() throws Exception {
.faultCode("{http://citrusframework.org}ws:TEC-1001")
.faultString("Internal server error")
.build();
- try {
- assertAction.execute(context);
- } catch(IllegalArgumentException e) {
- Assert.assertEquals(e.getMessage(), "SOAP fault validation failed! Fault code does not match - expected: '{http://citrusframework.org}TEC-1001' but was: '{http://citrusframework.org}TEC-2002'");
- return;
- }
-
- Assert.fail("Missing validation exception");
+ assertAction.execute(context);
}
- @Test
+ @Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "SOAP fault validation failed! Fault actor does not match - expected: 'SERVER' but was: 'CLIENT'")
public void testWrongFaultActor() throws Exception {
TestAction action = action(context -> {
SoapMessage faultMessage;
@@ -208,14 +201,7 @@ public void testWrongFaultActor() throws Exception {
.faultCode("{http://citrusframework.org}ws:TEC-1001")
.faultString("Internal server error")
.build();
- try {
- assertAction.execute(context);
- } catch(IllegalArgumentException e) {
- Assert.assertEquals(e.getMessage(), "SOAP fault validation failed! Fault actor does not match - expected: 'SERVER' but was: 'CLIENT'");
- return;
- }
-
- Assert.fail("Missing validation exception");
+ assertAction.execute(context);
}
@Test
diff --git a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/AssertSoapFaultBuilderTest.java b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/AssertSoapFaultBuilderTest.java
index 7da7460cd6..998011da13 100644
--- a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/AssertSoapFaultBuilderTest.java
+++ b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/AssertSoapFaultBuilderTest.java
@@ -29,13 +29,13 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.report.TestActionListeners;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.spi.Resource;
import org.citrusframework.ws.UnitTestSupport;
import org.citrusframework.ws.actions.AssertSoapFault;
import org.citrusframework.ws.validation.SoapFaultValidationContext;
import org.citrusframework.ws.validation.SoapFaultValidator;
import org.citrusframework.xml.StringSource;
import org.mockito.Mockito;
-import org.springframework.core.io.Resource;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapFault;
import org.springframework.ws.soap.SoapFaultDetail;
diff --git a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/ReceiveSoapMessageTestActionBuilderTest.java b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/ReceiveSoapMessageTestActionBuilderTest.java
index f5557a8113..5c8b204672 100644
--- a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/ReceiveSoapMessageTestActionBuilderTest.java
+++ b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/ReceiveSoapMessageTestActionBuilderTest.java
@@ -33,6 +33,7 @@
import org.citrusframework.messaging.Consumer;
import org.citrusframework.report.TestActionListeners;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.spi.Resource;
import org.citrusframework.validation.builder.StaticMessageBuilder;
import org.citrusframework.validation.context.HeaderValidationContext;
import org.citrusframework.validation.json.JsonMessageValidationContext;
@@ -43,7 +44,6 @@
import org.citrusframework.ws.message.SoapMessage;
import org.citrusframework.ws.server.WebServiceServer;
import org.mockito.Mockito;
-import org.springframework.core.io.Resource;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
diff --git a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/SendSoapFaultTestActionBuilderTest.java b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/SendSoapFaultTestActionBuilderTest.java
index 8925d83779..4e457f6e74 100644
--- a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/SendSoapFaultTestActionBuilderTest.java
+++ b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/SendSoapFaultTestActionBuilderTest.java
@@ -30,13 +30,13 @@
import org.citrusframework.messaging.Producer;
import org.citrusframework.report.TestActionListeners;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.spi.Resource;
import org.citrusframework.validation.builder.StaticMessageBuilder;
import org.citrusframework.ws.UnitTestSupport;
import org.citrusframework.ws.actions.SendSoapFaultAction;
import org.citrusframework.ws.message.SoapFault;
import org.citrusframework.ws.server.WebServiceServer;
import org.mockito.Mockito;
-import org.springframework.core.io.Resource;
import org.testng.Assert;
import org.testng.annotations.Test;
diff --git a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/SendSoapMessageTestActionBuilderTest.java b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/SendSoapMessageTestActionBuilderTest.java
index 5398af05db..6e7d960d07 100644
--- a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/SendSoapMessageTestActionBuilderTest.java
+++ b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/actions/dsl/SendSoapMessageTestActionBuilderTest.java
@@ -34,6 +34,7 @@
import org.citrusframework.messaging.Producer;
import org.citrusframework.report.TestActionListeners;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.spi.Resource;
import org.citrusframework.validation.builder.StaticMessageBuilder;
import org.citrusframework.ws.UnitTestSupport;
import org.citrusframework.ws.actions.SendSoapMessageAction;
@@ -42,7 +43,6 @@
import org.citrusframework.ws.message.SoapMessage;
import org.citrusframework.ws.message.SoapMessageHeaders;
import org.mockito.Mockito;
-import org.springframework.core.io.Resource;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
diff --git a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/integration/SendSoapAttachmentJavaIT.java b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/integration/SendSoapAttachmentJavaIT.java
index ac29e3e256..c58d2b0851 100644
--- a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/integration/SendSoapAttachmentJavaIT.java
+++ b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/integration/SendSoapAttachmentJavaIT.java
@@ -17,8 +17,8 @@
package org.citrusframework.ws.integration;
import org.citrusframework.annotations.CitrusTest;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
-import org.springframework.core.io.ClassPathResource;
import org.testng.annotations.Test;
import static org.citrusframework.container.Parallel.Builder.parallel;
@@ -42,7 +42,7 @@ public void sendSoapAttachment() {
.body("" +
"Read the attachment " +
" ")
- .attachment("MySoapAttachment", "text/plain", new ClassPathResource("org/citrusframework/ws/soapAttachment.txt")),
+ .attachment("MySoapAttachment", "text/plain", Resources.newClasspathResource("org/citrusframework/ws/soapAttachment.txt")),
sequential().actions(
soap().server("soapRequestEndpoint")
.receive()
@@ -53,7 +53,7 @@ public void sendSoapAttachment() {
.validate(xml().schemaValidation(false))
.extract(fromHeaders()
.header("citrus_jms_messageId", "internal_correlation_id"))
- .attachment("MySoapAttachment", "text/plain", new ClassPathResource("org/citrusframework/ws/soapAttachment.txt"))
+ .attachment("MySoapAttachment", "text/plain", Resources.newClasspathResource("org/citrusframework/ws/soapAttachment.txt"))
.timeout(5000L),
soap().server("soapResponseEndpoint")
.send()
diff --git a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/message/SoapAttachmentTest.java b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/message/SoapAttachmentTest.java
index 355fa24c0c..766d1ba223 100644
--- a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/message/SoapAttachmentTest.java
+++ b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/message/SoapAttachmentTest.java
@@ -16,18 +16,17 @@
package org.citrusframework.ws.message;
-import jakarta.activation.DataHandler;
-import jakarta.activation.DataSource;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
+import jakarta.activation.DataHandler;
+import jakarta.activation.DataSource;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.mockito.Mockito;
@@ -106,14 +105,14 @@ public void testFileResourceTextContent() {
@Test
public void testFileResourceBinaryContent() throws Exception {
- String imageUrl = "/org/citrusframework/ws/actions/test-attachment.png";
+ String imageUrl = "org/citrusframework/ws/actions/test-attachment.png";
SoapAttachment soapAttachment = new SoapAttachment();
soapAttachment.setContentResourcePath("classpath:" + imageUrl);
soapAttachment.setContentType("image/png");
String attachmentContent = soapAttachment.getContent();
- byte[] resourceContent = Files.readAllBytes(Paths.get(getClass().getResource(imageUrl).toURI()));
+ byte[] resourceContent = Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource(imageUrl).toURI()));
Assert.assertEquals(attachmentContent, Base64.encodeBase64String(resourceContent));
Assert.assertEquals(soapAttachment.getSize(), resourceContent.length);
diff --git a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/message/converter/SoapMessageConverterTest.java b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/message/converter/SoapMessageConverterTest.java
index d135528543..7214444049 100644
--- a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/message/converter/SoapMessageConverterTest.java
+++ b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/message/converter/SoapMessageConverterTest.java
@@ -42,7 +42,6 @@
import jakarta.xml.soap.MimeHeaders;
import jakarta.xml.soap.SOAPMessage;
import org.springframework.core.io.InputStreamSource;
-import org.springframework.util.StringUtils;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.mime.Attachment;
import org.springframework.ws.soap.SoapBody;
@@ -75,7 +74,7 @@ public class SoapMessageConverterTest extends AbstractTestNGUnitTest {
private SoapHeader soapHeader;
private SoapHeaderElement soapHeaderElement;
- private String payload = "Hello ";
+ private final String payload = "Hello ";
@BeforeMethod
public void resetMocks() {
@@ -579,7 +578,7 @@ public void testInboundSoapKeepEnvelope() throws IOException {
final WebServiceEndpointConfiguration endpointConfiguration = new WebServiceEndpointConfiguration();
endpointConfiguration.setKeepSoapEnvelope(true);
final Message responseMessage = soapMessageConverter.convertInbound(soapMessage, endpointConfiguration, context);
- Assert.assertEquals(StringUtils.trimAllWhitespace(responseMessage.getPayload(String.class)), StringUtils.trimAllWhitespace(XML_PROCESSING_INSTRUCTION + getSoapRequestPayload()));
+ Assert.assertEquals(responseMessage.getPayload(String.class).replaceAll("\\s", ""), (XML_PROCESSING_INSTRUCTION + getSoapRequestPayload()).replaceAll("\\s", ""));
Assert.assertEquals(responseMessage.getHeaderData().size(), 1L);
Assert.assertEquals(responseMessage.getHeaderData().get(0), XML_PROCESSING_INSTRUCTION + "");
}
@@ -606,7 +605,7 @@ private String getSoapRequestPayload() {
}
private String getSoapRequestPayload(final String payload, final String ... namespaces) {
- return "\n" +
+ return "\n" +
" \n" +
"\n" +
payload +
diff --git a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/validation/SimpleSoapAttachmentValidatorTest.java b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/validation/SimpleSoapAttachmentValidatorTest.java
index 451d2a5fca..a2a7b688fb 100644
--- a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/validation/SimpleSoapAttachmentValidatorTest.java
+++ b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/validation/SimpleSoapAttachmentValidatorTest.java
@@ -16,19 +16,19 @@
package org.citrusframework.ws.validation;
+import java.io.IOException;
+import java.util.Collections;
+
import org.citrusframework.exceptions.ValidationException;
import org.citrusframework.ws.message.SoapAttachment;
import org.citrusframework.ws.message.SoapMessage;
import org.testng.annotations.Test;
-import java.io.IOException;
-import java.util.Collections;
-
/**
* @author Christoph Deppisch
*/
public class SimpleSoapAttachmentValidatorTest {
-
+
@Test
public void testSimpleValidation() throws IOException {
SoapAttachment controlAttachment = new SoapAttachment();
@@ -42,7 +42,7 @@ public void testSimpleValidation() throws IOException {
SimpleSoapAttachmentValidator validator = new SimpleSoapAttachmentValidator();
validator.validateAttachment(testMessage, Collections.singletonList(controlAttachment));
}
-
+
@Test
public void testSimpleValidationNoControlContentId() throws IOException {
SoapAttachment receivedAttachment = new SoapAttachment();
@@ -56,11 +56,11 @@ public void testSimpleValidationNoControlContentId() throws IOException {
SoapAttachment controlAttachment = new SoapAttachment();
controlAttachment.setContentType("text/plain");
controlAttachment.setContent("This is a test!");
-
+
SimpleSoapAttachmentValidator validator = new SimpleSoapAttachmentValidator();
validator.validateAttachment(testMessage, Collections.singletonList(controlAttachment));
}
-
+
@Test(expectedExceptions = ValidationException.class)
public void testSimpleValidationWrongContentId() throws IOException {
SoapAttachment receivedAttachment = new SoapAttachment();
@@ -75,12 +75,12 @@ public void testSimpleValidationWrongContentId() throws IOException {
controlAttachment.setContentId("wrongAttachmentId");
controlAttachment.setContentType("text/plain");
controlAttachment.setContent("This is a test!");
-
+
SimpleSoapAttachmentValidator validator = new SimpleSoapAttachmentValidator();
validator.validateAttachment(testMessage, Collections.singletonList(controlAttachment));
}
-
- @Test(expectedExceptions = IllegalArgumentException.class)
+
+ @Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Values not equal for attachment content 'soapAttachmentId', expected 'ThisisnotOK!' but was 'Thisisatest!'")
public void testSimpleValidationWrongContent() throws IOException {
SoapAttachment receivedAttachment = new SoapAttachment();
receivedAttachment.setContentId("soapAttachmentId");
@@ -94,12 +94,12 @@ public void testSimpleValidationWrongContent() throws IOException {
controlAttachment.setContentId("soapAttachmentId");
controlAttachment.setContentType("text/plain");
controlAttachment.setContent("This is not OK!");
-
+
SimpleSoapAttachmentValidator validator = new SimpleSoapAttachmentValidator();
validator.validateAttachment(testMessage, Collections.singletonList(controlAttachment));
}
-
- @Test(expectedExceptions = IllegalArgumentException.class)
+
+ @Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Values not equal for attachment contentType, expected 'text/xml' but was 'text/plain'")
public void testSimpleValidationWrongContentType() throws IOException {
SoapAttachment receivedAttachment = new SoapAttachment();
receivedAttachment.setContentId("soapAttachmentId");
@@ -113,7 +113,7 @@ public void testSimpleValidationWrongContentType() throws IOException {
controlAttachment.setContentId("soapAttachmentId");
controlAttachment.setContentType("text/xml");
controlAttachment.setContent("This is a test!");
-
+
SimpleSoapAttachmentValidator validator = new SimpleSoapAttachmentValidator();
validator.validateAttachment(testMessage, Collections.singletonList(controlAttachment));
}
diff --git a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/validation/XmlSoapFaultValidatorTest.java b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/validation/XmlSoapFaultValidatorTest.java
index 45d3193ef5..1b6519aa4a 100644
--- a/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/validation/XmlSoapFaultValidatorTest.java
+++ b/endpoints/citrus-ws/src/test/java/org/citrusframework/ws/validation/XmlSoapFaultValidatorTest.java
@@ -55,7 +55,7 @@ public void testFaultDetailValidation() {
soapFaultValidator.validateFaultDetail(receivedDetail, controlDetail, context, new SoapFaultValidationContext());
}
- @Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Validation failed: Node value not equal for element 'code', expected '1001' but was '1002'")
+ @Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Node value not equal for element 'code', expected '1001' but was '1002'")
public void testFaultDetailValidationError() {
SoapFault receivedDetail = new SoapFault();
receivedDetail.addFaultDetail(error.replaceFirst("1001", "1002"));
@@ -77,7 +77,7 @@ public void testMultipleFaultDetailValidation() {
soapFaultValidator.validateFaultDetail(receivedDetail, controlDetail, context, new SoapFaultValidationContext());
}
- @Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Validation failed: Node value not equal for element 'code', expected '1002' but was '1001'")
+ @Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Node value not equal for element 'code', expected '1002' but was '1001'")
public void testMultipleFaultDetailValidationError() {
SoapFault receivedDetail = new SoapFault();
receivedDetail.addFaultDetail(error);
diff --git a/endpoints/citrus-zookeeper/src/main/java/org/citrusframework/zookeeper/actions/ZooExecuteAction.java b/endpoints/citrus-zookeeper/src/main/java/org/citrusframework/zookeeper/actions/ZooExecuteAction.java
index 5e32c738c4..79ff6c6b27 100644
--- a/endpoints/citrus-zookeeper/src/main/java/org/citrusframework/zookeeper/actions/ZooExecuteAction.java
+++ b/endpoints/citrus-zookeeper/src/main/java/org/citrusframework/zookeeper/actions/ZooExecuteAction.java
@@ -21,6 +21,8 @@
import java.util.List;
import java.util.Optional;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.citrusframework.AbstractTestActionBuilder;
import org.citrusframework.actions.AbstractTestAction;
import org.citrusframework.context.TestContext;
@@ -30,6 +32,7 @@
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageProcessor;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.MessageValidator;
import org.citrusframework.validation.context.ValidationContext;
import org.citrusframework.validation.json.JsonMessageValidationContext;
@@ -48,11 +51,8 @@
import org.citrusframework.zookeeper.command.SetData;
import org.citrusframework.zookeeper.command.ZooCommand;
import org.citrusframework.zookeeper.command.ZooResponse;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
/**
* Executes zookeeper command with given zookeeper client implementation. Possible command result is stored within command object.
diff --git a/endpoints/citrus-zookeeper/src/main/java/org/citrusframework/zookeeper/config/xml/ZooExecuteActionParser.java b/endpoints/citrus-zookeeper/src/main/java/org/citrusframework/zookeeper/config/xml/ZooExecuteActionParser.java
index 15b91ac960..bd620335d9 100644
--- a/endpoints/citrus-zookeeper/src/main/java/org/citrusframework/zookeeper/config/xml/ZooExecuteActionParser.java
+++ b/endpoints/citrus-zookeeper/src/main/java/org/citrusframework/zookeeper/config/xml/ZooExecuteActionParser.java
@@ -42,7 +42,6 @@
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.CollectionUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -56,7 +55,7 @@
public class ZooExecuteActionParser implements BeanDefinitionParser {
/** ZooKeeper command to execute */
- private Class extends ZooCommand>> zookeeperCommandClass;
+ private final Class extends ZooCommand>> zookeeperCommandClass;
/**
* Constructor using zookeeper command.
@@ -117,7 +116,7 @@ private List getVariableExtractors(Element extractElement) {
Map extractJsonPath = new LinkedHashMap<>();
List> messageValueElements = DomUtils.getChildElementsByTagName(extractElement, "message");
VariableExtractorParserUtil.parseMessageElement(messageValueElements, extractJsonPath);
- if (!CollectionUtils.isEmpty(extractJsonPath)) {
+ if (!extractJsonPath.isEmpty()) {
VariableExtractorParserUtil.addPayloadVariableExtractors(extractElement, variableExtractors, extractJsonPath);
}
return variableExtractors;
diff --git a/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/CucumberTestEngine.java b/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/CucumberTestEngine.java
index 12b6d29148..17729051da 100644
--- a/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/CucumberTestEngine.java
+++ b/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/CucumberTestEngine.java
@@ -26,13 +26,9 @@
import java.util.Arrays;
import java.util.List;
+import io.cucumber.core.backend.ObjectFactory;
import io.cucumber.core.eventbus.RandomUuidGenerator;
import io.cucumber.core.eventbus.UuidGenerator;
-import org.citrusframework.TestClass;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.main.AbstractTestEngine;
-import org.citrusframework.main.TestRunConfiguration;
-import io.cucumber.core.backend.ObjectFactory;
import io.cucumber.core.options.CommandlineOptionsParser;
import io.cucumber.core.options.CucumberOptionsAnnotationParser;
import io.cucumber.core.options.CucumberProperties;
@@ -41,10 +37,13 @@
import io.cucumber.core.resource.ClasspathSupport;
import io.cucumber.core.runtime.Runtime;
import io.cucumber.core.snippets.SnippetType;
+import org.citrusframework.TestClass;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.main.AbstractTestEngine;
+import org.citrusframework.main.TestRunConfiguration;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -63,7 +62,7 @@ public void run() {
RuntimeOptions propertiesFileOptions = new CucumberPropertiesParser().parse(CucumberProperties.fromPropertiesFile()).build();
RuntimeOptions annotationOptions;
- if (CollectionUtils.isEmpty(getConfiguration().getTestClasses())) {
+ if (getConfiguration().getTestClasses() == null || getConfiguration().getTestClasses().isEmpty()) {
annotationOptions = propertiesFileOptions;
} else {
TestClass testClass = getConfiguration().getTestClasses().get(0);
@@ -85,7 +84,7 @@ public void run() {
List args = new ArrayList<>();
List packagesToRun = getConfiguration().getPackages();
- if (CollectionUtils.isEmpty(packagesToRun)) {
+ if (packagesToRun == null || packagesToRun.isEmpty()) {
logger.info("Running all tests in project");
} else if (StringUtils.hasText(packagesToRun.get(0))) {
logger.info(String.format("Running tests in package %s", packagesToRun.get(0)));
diff --git a/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/CitrusBackendProviderService.java b/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/CitrusBackendProviderService.java
index a1f1280fbf..c57c547391 100644
--- a/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/CitrusBackendProviderService.java
+++ b/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/CitrusBackendProviderService.java
@@ -7,7 +7,7 @@
import io.cucumber.core.backend.BackendProviderService;
import io.cucumber.core.backend.Container;
import io.cucumber.core.backend.Lookup;
-import org.springframework.util.ClassUtils;
+import org.citrusframework.spi.Resources;
/**
* @author Christoph Deppisch
@@ -15,7 +15,7 @@
public class CitrusBackendProviderService implements BackendProviderService {
@Override
public Backend create(Lookup lookup, Container container, Supplier classLoader) {
- if (ClassUtils.isPresent("org.citrusframework.CitrusSpringContext", getClass().getClassLoader())) {
+ if (Resources.newClasspathResource("org/citrusframework/CitrusSpringContext.class").exists()) {
return new CitrusSpringBackend(lookup, container);
} else {
return new CitrusBackend(lookup, container);
diff --git a/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/CitrusHookDefinition.java b/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/CitrusHookDefinition.java
index febf26437c..27d1734ca5 100644
--- a/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/CitrusHookDefinition.java
+++ b/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/CitrusHookDefinition.java
@@ -6,7 +6,7 @@
import io.cucumber.core.backend.HookDefinition;
import io.cucumber.core.backend.Lookup;
import io.cucumber.core.backend.TestCaseState;
-import org.springframework.util.ReflectionUtils;
+import org.citrusframework.util.ReflectionHelper;
/**
* @author Christoph Deppisch
@@ -35,7 +35,7 @@ public void execute(TestCaseState state) {
}
try {
- ReflectionUtils.invokeMethod(method, lookup.getInstance(method.getDeclaringClass()), args);
+ ReflectionHelper.invokeMethod(method, lookup.getInstance(method.getDeclaringClass()), args);
} catch (IllegalArgumentException | IllegalStateException e) {
throw new CucumberBackendException("Failed to invoke " + method, e);
}
diff --git a/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/config/xml/StepTemplateParser.java b/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/config/xml/StepTemplateParser.java
index 3d1b031a4a..154627f251 100644
--- a/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/config/xml/StepTemplateParser.java
+++ b/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/config/xml/StepTemplateParser.java
@@ -24,11 +24,11 @@
import org.citrusframework.config.xml.ActionContainerParser;
import org.citrusframework.config.xml.DescriptionElementParser;
import org.citrusframework.cucumber.container.StepTemplate;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
@@ -56,7 +56,7 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
}
if (element.hasAttribute("parameter-names")) {
- builder.addPropertyValue("parameterNames", StringUtils.commaDelimitedListToStringArray(element.getAttribute("parameter-names")));
+ builder.addPropertyValue("parameterNames", element.getAttribute("parameter-names").split(","));
}
String globalContext = element.getAttribute("global-context");
diff --git a/runtime/citrus-cucumber/src/test/java/org/citrusframework/cucumber/integration/TextEqualsMessageValidator.java b/runtime/citrus-cucumber/src/test/java/org/citrusframework/cucumber/integration/TextEqualsMessageValidator.java
index 2a5a4ce05b..6f918ca3f0 100644
--- a/runtime/citrus-cucumber/src/test/java/org/citrusframework/cucumber/integration/TextEqualsMessageValidator.java
+++ b/runtime/citrus-cucumber/src/test/java/org/citrusframework/cucumber/integration/TextEqualsMessageValidator.java
@@ -1,11 +1,11 @@
package org.citrusframework.cucumber.integration;
import org.citrusframework.context.TestContext;
+import org.citrusframework.exceptions.ValidationException;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageType;
import org.citrusframework.validation.DefaultMessageValidator;
import org.citrusframework.validation.context.ValidationContext;
-import org.springframework.util.Assert;
/**
* Basic message validator performs String equals on received message payloads. We add this validator in order to have a
@@ -16,8 +16,9 @@ public class TextEqualsMessageValidator extends DefaultMessageValidator {
@Override
public void validateMessage(Message receivedMessage, Message controlMessage, TestContext context, ValidationContext validationContext) {
- Assert.isTrue(receivedMessage.getPayload(String.class).equals(controlMessage.getPayload(String.class)), "Validation failed - " +
- "expected message contents not equal!");
+ if (!receivedMessage.getPayload(String.class).equals(controlMessage.getPayload(String.class))) {
+ throw new ValidationException("Validation failed - expected message contents not equal!");
+ }
}
@Override
diff --git a/runtime/citrus-groovy/src/main/java/org/citrusframework/config/xml/GroovyActionParser.java b/runtime/citrus-groovy/src/main/java/org/citrusframework/config/xml/GroovyActionParser.java
index 32f791b1ff..25c6306a98 100644
--- a/runtime/citrus-groovy/src/main/java/org/citrusframework/config/xml/GroovyActionParser.java
+++ b/runtime/citrus-groovy/src/main/java/org/citrusframework/config/xml/GroovyActionParser.java
@@ -17,11 +17,11 @@
package org.citrusframework.config.xml;
import org.citrusframework.script.GroovyAction;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
diff --git a/runtime/citrus-groovy/src/main/java/org/citrusframework/config/xml/parser/GroovyScriptMessageBuilderParser.java b/runtime/citrus-groovy/src/main/java/org/citrusframework/config/xml/parser/GroovyScriptMessageBuilderParser.java
index 12f1452ea6..01848c85f2 100644
--- a/runtime/citrus-groovy/src/main/java/org/citrusframework/config/xml/parser/GroovyScriptMessageBuilderParser.java
+++ b/runtime/citrus-groovy/src/main/java/org/citrusframework/config/xml/parser/GroovyScriptMessageBuilderParser.java
@@ -21,8 +21,8 @@
import org.citrusframework.message.builder.script.GroovyFileResourcePayloadBuilder;
import org.citrusframework.message.builder.script.GroovyScriptPayloadBuilder;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.builder.DefaultMessageBuilder;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
diff --git a/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/GroovyTemplateLoader.java b/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/GroovyTemplateLoader.java
index a8c9001d24..00f82764b7 100644
--- a/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/GroovyTemplateLoader.java
+++ b/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/GroovyTemplateLoader.java
@@ -10,9 +10,9 @@
import org.citrusframework.groovy.dsl.actions.TemplateConfiguration;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
-import org.springframework.core.io.Resource;
public class GroovyTemplateLoader implements TemplateLoader, ReferenceResolverAware {
diff --git a/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/GroovyTestLoader.java b/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/GroovyTestLoader.java
index d20b8ea4d2..15515b090f 100644
--- a/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/GroovyTestLoader.java
+++ b/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/GroovyTestLoader.java
@@ -26,11 +26,11 @@
import org.citrusframework.common.TestSourceAware;
import org.citrusframework.groovy.dsl.GroovyShellUtils;
import org.citrusframework.groovy.dsl.test.TestCaseScript;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -44,9 +44,11 @@ protected void doLoad() {
Resource scriptSource = FileUtils.getFileResource(this.getSource(), context);
ImportCustomizer ic = new ImportCustomizer();
- String basePath = scriptSource.getFile().getParent();
- if (scriptSource instanceof ClassPathResource) {
- basePath = FileUtils.getBasePath(((ClassPathResource) scriptSource).getPath());
+ String basePath;
+ if (scriptSource instanceof Resources.ClasspathResource) {
+ basePath = FileUtils.getBasePath(scriptSource.getLocation());
+ } else {
+ basePath = scriptSource.getFile().getParent();
}
String source = FileUtils.readToString(scriptSource);
diff --git a/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/actions/ActionsBuilder.java b/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/actions/ActionsBuilder.java
index daa2c89c2d..6b501fb421 100644
--- a/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/actions/ActionsBuilder.java
+++ b/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/actions/ActionsBuilder.java
@@ -29,7 +29,7 @@
import org.citrusframework.TestAction;
import org.citrusframework.TestActionBuilder;
import org.citrusframework.groovy.dsl.test.TestCaseScript;
-import org.springframework.util.ReflectionUtils;
+import org.citrusframework.util.ReflectionHelper;
import static org.citrusframework.actions.EchoAction.Builder.echo;
@@ -138,7 +138,7 @@ private TestActionBuilder> findTestActionBuilder(String id, Object[] args) {
private TestActionBuilder> initializeActionBuilder(TestActionBuilder> builder, String id, Object... args) {
try {
Class>[] paramTypes = Arrays.stream(args).map(Object::getClass).toArray(Class[]::new);
- Method initializer = ReflectionUtils.findMethod(builder.getClass(), id, paramTypes);
+ Method initializer = ReflectionHelper.findMethod(builder.getClass(), id, paramTypes);
if (initializer == null) {
throw new GroovyRuntimeException(String.format("Failed to find initializing method %s(%s) for " +
"action builder type %s", Arrays.toString(paramTypes), id, builder.getClass().getName()));
diff --git a/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/configuration/ContextConfiguration.java b/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/configuration/ContextConfiguration.java
index 0b2fd8c4fa..b20c311e6c 100644
--- a/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/configuration/ContextConfiguration.java
+++ b/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/configuration/ContextConfiguration.java
@@ -21,6 +21,8 @@
import java.io.IOException;
+import groovy.lang.Closure;
+import groovy.lang.DelegatesTo;
import org.citrusframework.Citrus;
import org.citrusframework.common.InitializingPhase;
import org.citrusframework.context.TestContext;
@@ -29,11 +31,9 @@
import org.citrusframework.groovy.dsl.configuration.beans.BeansConfiguration;
import org.citrusframework.groovy.dsl.configuration.beans.QueueConfiguration;
import org.citrusframework.groovy.dsl.configuration.endpoints.EndpointsConfiguration;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
-import groovy.lang.Closure;
-import groovy.lang.DelegatesTo;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
-import org.springframework.core.io.Resource;
/**
* @author Christoph Deppisch
diff --git a/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/configuration/beans/BeansConfiguration.java b/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/configuration/beans/BeansConfiguration.java
index 29bc69fad0..e09783148a 100644
--- a/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/configuration/beans/BeansConfiguration.java
+++ b/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/configuration/beans/BeansConfiguration.java
@@ -20,15 +20,15 @@
package org.citrusframework.groovy.dsl.configuration.beans;
import java.lang.reflect.InvocationTargetException;
+import java.util.Locale;
-import org.citrusframework.Citrus;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.message.DefaultMessageQueue;
import groovy.lang.Closure;
import groovy.lang.GroovyObjectSupport;
import groovy.lang.GroovyRuntimeException;
import groovy.lang.MissingMethodException;
-import org.springframework.util.StringUtils;
+import org.citrusframework.Citrus;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.message.DefaultMessageQueue;
/**
* @author Christoph Deppisch
@@ -42,7 +42,7 @@ public BeansConfiguration(Citrus citrus) {
}
public void bean(Class> type) {
- bean(StringUtils.uncapitalize(type.getSimpleName()), type);
+ bean(sanitizeBeanName(type.getSimpleName()), type);
}
public void bean(String name, Class> type) {
@@ -96,4 +96,13 @@ public Object methodMissing(String name, Object argLine) {
throw new MissingMethodException(name, BeansConfiguration.class, args);
}
+
+ /**
+ * Uncapitalize given bean name.
+ * @param name
+ * @return
+ */
+ private static String sanitizeBeanName(String name) {
+ return name.substring(0, 1).toLowerCase(Locale.US) + name.substring(1);
+ }
}
diff --git a/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/configuration/endpoints/EndpointBuilderConfiguration.java b/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/configuration/endpoints/EndpointBuilderConfiguration.java
index 56c0478295..fffecb5b57 100644
--- a/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/configuration/endpoints/EndpointBuilderConfiguration.java
+++ b/runtime/citrus-groovy/src/main/java/org/citrusframework/groovy/dsl/configuration/endpoints/EndpointBuilderConfiguration.java
@@ -28,7 +28,7 @@
import org.citrusframework.endpoint.Endpoint;
import org.citrusframework.endpoint.EndpointBuilder;
import groovy.lang.MissingPropertyException;
-import org.springframework.util.ReflectionUtils;
+import org.citrusframework.util.ReflectionHelper;
/**
* @author Christoph Deppisch
@@ -56,11 +56,11 @@ public EndpointBuilderConfiguration(EndpointBuilder builder) {
}
public void propertyMissing(String name, Object value) {
- Method m = ReflectionUtils.findMethod(builder.getClass(), name, value.getClass());
+ Method m = ReflectionHelper.findMethod(builder.getClass(), name, value.getClass());
if (m == null) {
if (isWrapperForPrimitive(value.getClass())) {
- m = ReflectionUtils.findMethod(builder.getClass(), name, WRAPPER_TO_PRIMITIVE.get(value.getClass()));
+ m = ReflectionHelper.findMethod(builder.getClass(), name, WRAPPER_TO_PRIMITIVE.get(value.getClass()));
}
if (m == null) {
diff --git a/runtime/citrus-groovy/src/main/java/org/citrusframework/message/builder/script/GroovyFileResourcePayloadBuilder.java b/runtime/citrus-groovy/src/main/java/org/citrusframework/message/builder/script/GroovyFileResourcePayloadBuilder.java
index 0f11f43740..e6612dcffa 100644
--- a/runtime/citrus-groovy/src/main/java/org/citrusframework/message/builder/script/GroovyFileResourcePayloadBuilder.java
+++ b/runtime/citrus-groovy/src/main/java/org/citrusframework/message/builder/script/GroovyFileResourcePayloadBuilder.java
@@ -21,7 +21,7 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.message.builder.FileResourcePayloadBuilder;
-import org.springframework.core.io.Resource;
+import org.citrusframework.spi.Resource;
/**
* @author Christoph Deppisch
diff --git a/runtime/citrus-groovy/src/main/java/org/citrusframework/message/builder/script/GroovyScriptPayloadBuilder.java b/runtime/citrus-groovy/src/main/java/org/citrusframework/message/builder/script/GroovyScriptPayloadBuilder.java
index 17c6acf9a1..6e05720be3 100644
--- a/runtime/citrus-groovy/src/main/java/org/citrusframework/message/builder/script/GroovyScriptPayloadBuilder.java
+++ b/runtime/citrus-groovy/src/main/java/org/citrusframework/message/builder/script/GroovyScriptPayloadBuilder.java
@@ -24,10 +24,10 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.ScriptPayloadBuilder;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.citrusframework.validation.script.TemplateBasedScriptBuilder;
import org.codehaus.groovy.control.CompilationFailedException;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
/**
* @author Christoph Deppisch
@@ -35,7 +35,7 @@
public class GroovyScriptPayloadBuilder implements ScriptPayloadBuilder {
/** Default path to script template */
- private final Resource scriptTemplateResource = new ClassPathResource("org/citrusframework/script/markup-builder-template.groovy");
+ private final Resource scriptTemplateResource = Resources.newClasspathResource("org/citrusframework/script/markup-builder-template.groovy");
private String script;
diff --git a/runtime/citrus-groovy/src/main/java/org/citrusframework/script/GroovyAction.java b/runtime/citrus-groovy/src/main/java/org/citrusframework/script/GroovyAction.java
index ce91e4d5b3..48643dbeaf 100644
--- a/runtime/citrus-groovy/src/main/java/org/citrusframework/script/GroovyAction.java
+++ b/runtime/citrus-groovy/src/main/java/org/citrusframework/script/GroovyAction.java
@@ -21,18 +21,18 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
+import groovy.lang.GroovyClassLoader;
+import groovy.lang.GroovyObject;
import org.citrusframework.AbstractTestActionBuilder;
import org.citrusframework.actions.AbstractTestAction;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.script.TemplateBasedScriptBuilder;
-import groovy.lang.GroovyClassLoader;
-import groovy.lang.GroovyObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
-import org.springframework.util.StringUtils;
/**
* Action executes groovy scripts either specified inline or from external file resource.
@@ -81,7 +81,7 @@ public GroovyAction(Builder builder) {
@Override
public void doExecute(TestContext context) {
try {
- GroovyClassLoader loader = AccessController.doPrivileged(new PrivilegedAction() {
+ GroovyClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<>() {
public GroovyClassLoader run() {
ClassLoader parent = getClass().getClassLoader();
return new GroovyClassLoader(parent);
diff --git a/runtime/citrus-groovy/src/test/java/org/citrusframework/actions/dsl/GroovyTestActionBuilderTest.java b/runtime/citrus-groovy/src/test/java/org/citrusframework/actions/dsl/GroovyTestActionBuilderTest.java
index 40fa59c2ba..495aa8cd7b 100644
--- a/runtime/citrus-groovy/src/test/java/org/citrusframework/actions/dsl/GroovyTestActionBuilderTest.java
+++ b/runtime/citrus-groovy/src/test/java/org/citrusframework/actions/dsl/GroovyTestActionBuilderTest.java
@@ -23,9 +23,9 @@
import org.citrusframework.TestCase;
import org.citrusframework.UnitTestSupport;
import org.citrusframework.script.GroovyAction;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.mockito.Mockito;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -74,7 +74,7 @@ public void testGroovyBuilderWithScript() {
public void testGroovyBuilderWithTemplate() throws IOException {
DefaultTestCaseRunner builder = new DefaultTestCaseRunner(context);
builder.$(groovy().script("context.setVariable('message', 'Groovy!')")
- .template(new ClassPathResource("org/citrusframework/script/script-template.groovy")));
+ .template(Resources.newClasspathResource("org/citrusframework/script/script-template.groovy")));
Assert.assertNotNull(context.getVariable("message"));
Assert.assertEquals(context.getVariable("message"), "Groovy!");
diff --git a/runtime/citrus-groovy/src/test/java/org/citrusframework/groovy/dsl/TransformTest.java b/runtime/citrus-groovy/src/test/java/org/citrusframework/groovy/dsl/TransformTest.java
index b2e39da989..e9ef6eeb08 100644
--- a/runtime/citrus-groovy/src/test/java/org/citrusframework/groovy/dsl/TransformTest.java
+++ b/runtime/citrus-groovy/src/test/java/org/citrusframework/groovy/dsl/TransformTest.java
@@ -23,7 +23,7 @@
import org.citrusframework.TestCaseMetaInfo;
import org.citrusframework.actions.TransformAction;
import org.citrusframework.groovy.GroovyTestLoader;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
diff --git a/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/dsl/ActionsScriptIT.java b/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/dsl/ActionsScriptIT.java
index 0845338fbd..435b8bdfaf 100644
--- a/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/dsl/ActionsScriptIT.java
+++ b/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/dsl/ActionsScriptIT.java
@@ -26,9 +26,9 @@
import org.citrusframework.annotations.CitrusTest;
import org.citrusframework.context.TestContext;
import org.citrusframework.groovy.dsl.actions.ActionsScript;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.ClassPathResource;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
@@ -40,7 +40,7 @@ public class ActionsScriptIT extends TestNGCitrusSpringSupport {
@CitrusTest
public void shouldRunActionsScript(@Optional @CitrusResource TestActionRunner runner,
@Optional @CitrusResource TestContext context) throws IOException {
- ActionsScript script = new ActionsScript(FileUtils.readToString(new ClassPathResource("org/citrusframework/groovy/dsl/actions.groovy")), citrus);
+ ActionsScript script = new ActionsScript(FileUtils.readToString(Resources.newClasspathResource("org/citrusframework/groovy/dsl/actions.groovy")), citrus);
script.execute(runner, context);
}
}
diff --git a/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/dsl/ConfigurationScriptIT.java b/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/dsl/ConfigurationScriptIT.java
index 773a23515d..b5d57444be 100644
--- a/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/dsl/ConfigurationScriptIT.java
+++ b/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/dsl/ConfigurationScriptIT.java
@@ -28,9 +28,9 @@
import org.citrusframework.endpoint.direct.DirectEndpoint;
import org.citrusframework.groovy.dsl.configuration.ConfigurationScript;
import org.citrusframework.message.MessageQueue;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.ClassPathResource;
import org.testng.Assert;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
@@ -43,7 +43,7 @@ public class ConfigurationScriptIT extends TestNGCitrusSpringSupport {
@CitrusTest
public void shouldRunConfigurationScript(@Optional @CitrusResource TestActionRunner runner,
@Optional @CitrusResource TestContext context) throws IOException {
- ConfigurationScript script = new ConfigurationScript(FileUtils.readToString(new ClassPathResource("org/citrusframework/groovy/dsl/configuration.groovy")), citrus);
+ ConfigurationScript script = new ConfigurationScript(FileUtils.readToString(Resources.newClasspathResource("org/citrusframework/groovy/dsl/configuration.groovy")), citrus);
script.execute(context);
Assert.assertTrue(context.getReferenceResolver().isResolvable("say-hello", MessageQueue.class));
diff --git a/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/dsl/EndpointConfigurationScriptIT.java b/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/dsl/EndpointConfigurationScriptIT.java
index 605f44db3b..f8aacde6a6 100644
--- a/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/dsl/EndpointConfigurationScriptIT.java
+++ b/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/dsl/EndpointConfigurationScriptIT.java
@@ -29,9 +29,9 @@
import org.citrusframework.groovy.dsl.configuration.endpoints.EndpointConfigurationScript;
import org.citrusframework.message.DefaultMessageQueue;
import org.citrusframework.message.MessageQueue;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.ClassPathResource;
import org.testng.Assert;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
@@ -47,7 +47,7 @@ public void shouldLoadEndpointsFromScript(@Optional @CitrusResource TestActionRu
context.getReferenceResolver().bind("say-hello", new DefaultMessageQueue("say-hello"));
context.getReferenceResolver().bind("say-goodbye", new DefaultMessageQueue("say-goodbye"));
- EndpointConfigurationScript script = new EndpointConfigurationScript(FileUtils.readToString(new ClassPathResource("org/citrusframework/groovy/dsl/endpoints.groovy")), citrus);
+ EndpointConfigurationScript script = new EndpointConfigurationScript(FileUtils.readToString(Resources.newClasspathResource("org/citrusframework/groovy/dsl/endpoints.groovy")), citrus);
script.execute(context);
Assert.assertTrue(context.getReferenceResolver().isResolvable("say-hello", MessageQueue.class));
@@ -71,7 +71,7 @@ public void shouldLoadEndpointFromScript(@Optional @CitrusResource TestActionRun
@Optional @CitrusResource TestContext context) throws IOException {
context.getReferenceResolver().bind("say-hello", new DefaultMessageQueue("say-hello"));
- EndpointConfigurationScript script = new EndpointConfigurationScript(FileUtils.readToString(new ClassPathResource("org/citrusframework/groovy/dsl/endpoint.groovy")), citrus);
+ EndpointConfigurationScript script = new EndpointConfigurationScript(FileUtils.readToString(Resources.newClasspathResource("org/citrusframework/groovy/dsl/endpoint.groovy")), citrus);
script.execute(context);
Assert.assertTrue(context.getReferenceResolver().isResolvable("say-hello", MessageQueue.class));
diff --git a/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/script/GroovyActionJavaIT.java b/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/script/GroovyActionJavaIT.java
index ae59165d7b..20d30987c5 100644
--- a/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/script/GroovyActionJavaIT.java
+++ b/runtime/citrus-groovy/src/test/java/org/citrusframework/integration/script/GroovyActionJavaIT.java
@@ -17,8 +17,8 @@
package org.citrusframework.integration.script;
import org.citrusframework.annotations.CitrusTest;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
-import org.springframework.core.io.ClassPathResource;
import org.testng.annotations.Test;
import static org.citrusframework.script.GroovyAction.Builder.groovy;
@@ -77,6 +77,6 @@ public void groovyAction() {
"}" + NEWLINE +
"}"));
- run(groovy(new ClassPathResource("org/citrusframework/integration/script/example.groovy")));
+ run(groovy(Resources.newClasspathResource("org/citrusframework/integration/script/example.groovy")));
}
}
diff --git a/runtime/citrus-groovy/src/test/java/org/citrusframework/validation/script/TemplateBasedScriptBuilderTest.java b/runtime/citrus-groovy/src/test/java/org/citrusframework/validation/script/TemplateBasedScriptBuilderTest.java
index 88fa2f577c..153ba3efbc 100644
--- a/runtime/citrus-groovy/src/test/java/org/citrusframework/validation/script/TemplateBasedScriptBuilderTest.java
+++ b/runtime/citrus-groovy/src/test/java/org/citrusframework/validation/script/TemplateBasedScriptBuilderTest.java
@@ -16,8 +16,8 @@
package org.citrusframework.validation.script;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.TestUtils;
-import org.springframework.core.io.ClassPathResource;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -31,8 +31,7 @@ public void testTemplateScriptResource() {
Assert.assertEquals(
TestUtils.normalizeLineEndings(
TemplateBasedScriptBuilder.fromTemplateResource(
- new ClassPathResource(
- "org/citrusframework/validation/script/script-template.groovy")
+ Resources.newClasspathResource("org/citrusframework/validation/script/script-template.groovy")
).withCode("BODY")
.build()
),
diff --git a/runtime/citrus-junit/src/main/java/org/citrusframework/junit/CitrusJUnit4Runner.java b/runtime/citrus-junit/src/main/java/org/citrusframework/junit/CitrusJUnit4Runner.java
index 7915ea30c5..d57e5ef831 100644
--- a/runtime/citrus-junit/src/main/java/org/citrusframework/junit/CitrusJUnit4Runner.java
+++ b/runtime/citrus-junit/src/main/java/org/citrusframework/junit/CitrusJUnit4Runner.java
@@ -24,13 +24,13 @@
import org.citrusframework.annotations.CitrusXmlTest;
import org.citrusframework.common.TestLoader;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.util.StringUtils;
import org.junit.Test;
import org.junit.internal.runners.statements.InvokeMethod;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
-import org.springframework.util.StringUtils;
/**
* JUnit runner reads Citrus test annotation for XML test cases and prepares test execution within proper Citrus
diff --git a/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4Helper.java b/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4Helper.java
index 7fd4288008..edd9a062cc 100644
--- a/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4Helper.java
+++ b/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4Helper.java
@@ -21,8 +21,10 @@
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import org.citrusframework.CitrusSettings;
import org.citrusframework.DefaultTestCase;
@@ -30,13 +32,13 @@
import org.citrusframework.TestCaseRunner;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.ClasspathResourceResolver;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.ReflectionHelper;
+import org.citrusframework.util.StringUtils;
import org.junit.runners.model.FrameworkMethod;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.ResourceLoader;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.util.ReflectionUtils;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -60,7 +62,7 @@ private JUnit4Helper() {
*/
public static void invokeTestMethod(Object target, CitrusFrameworkMethod frameworkMethod, TestContext context) {
Object[] params = JUnit4ParameterHelper.resolveParameter(frameworkMethod, context);
- ReflectionUtils.invokeMethod(frameworkMethod.getMethod(), target, params);
+ ReflectionHelper.invokeMethod(frameworkMethod.getMethod(), target, params);
}
/**
@@ -109,15 +111,15 @@ public static List findInterceptedMethods(FrameworkMethod metho
Resource file = FileUtils.getFileResource(source);
String sourceFilePackageName = "";
- if (source.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX)) {
- sourceFilePackageName = source.substring(ResourceLoader.CLASSPATH_URL_PREFIX.length());
+ if (source.startsWith(Resources.CLASSPATH_RESOURCE_PREFIX)) {
+ sourceFilePackageName = source.substring(Resources.CLASSPATH_RESOURCE_PREFIX.length());
}
- if (StringUtils.hasLength(sourceFilePackageName) && sourceFilePackageName.contains("/")) {
+ if (StringUtils.hasText(sourceFilePackageName) && sourceFilePackageName.contains("/")) {
sourceFilePackageName = sourceFilePackageName.substring(0, sourceFilePackageName.lastIndexOf("/"));
}
- CitrusFrameworkMethod frameworkMethod = new CitrusFrameworkMethod(method.getMethod(), type, FileUtils.getBaseName(file.getFilename()),
+ CitrusFrameworkMethod frameworkMethod = new CitrusFrameworkMethod(method.getMethod(), type, FileUtils.getBaseName(FileUtils.getFileName(file.getLocation())),
sourceFilePackageName.replace("/","."));
frameworkMethod.setSource(source);
interceptedMethods.add(frameworkMethod);
@@ -126,9 +128,9 @@ public static List findInterceptedMethods(FrameworkMethod metho
for (String packageScan : packagesToScan) {
try {
for (String fileNamePattern : CitrusSettings.getTestFileNamePattern(type)) {
- Resource[] fileResources = new PathMatchingResourcePatternResolver().getResources(packageScan.replace('.', File.separatorChar) + fileNamePattern);
- for (Resource fileResource : fileResources) {
- String filePath = fileResource.getFile().getParentFile().getCanonicalPath();
+ Set fileResources = new ClasspathResourceResolver().getResources(packageScan.replace('.', File.separatorChar), fileNamePattern);
+ for (Path fileResource : fileResources) {
+ String filePath = fileResource.getParent().toFile().getCanonicalPath();
if (packageScan.startsWith("file:")) {
filePath = "file:" + filePath;
@@ -137,7 +139,7 @@ public static List findInterceptedMethods(FrameworkMethod metho
filePath = filePath.substring(filePath.indexOf(packageScan.replace('.', File.separatorChar)));
interceptedMethods.add(new CitrusFrameworkMethod(method.getMethod(), type,
- FileUtils.getBaseName(fileResource.getFilename()), filePath));
+ FileUtils.getBaseName(String.valueOf(fileResource.getFileName())), filePath));
}
}
} catch (RuntimeException | IOException e) {
diff --git a/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4TestEngine.java b/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4TestEngine.java
index 4a9042d664..674190fff5 100644
--- a/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4TestEngine.java
+++ b/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4TestEngine.java
@@ -29,13 +29,12 @@
import org.citrusframework.main.TestRunConfiguration;
import org.citrusframework.main.scan.ClassPathTestScanner;
import org.citrusframework.main.scan.JarFileTestScanner;
+import org.citrusframework.util.StringUtils;
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.notification.RunListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -58,11 +57,11 @@ public JUnit4TestEngine(TestRunConfiguration configuration) {
@Override
public void run() {
- if (!CollectionUtils.isEmpty(getConfiguration().getTestClasses())) {
+ if (getConfiguration().getTestClasses() != null && !getConfiguration().getTestClasses().isEmpty()) {
run(getConfiguration().getTestClasses());
} else {
List packagesToRun = getConfiguration().getPackages();
- if (CollectionUtils.isEmpty(packagesToRun) && CollectionUtils.isEmpty(getConfiguration().getTestClasses())) {
+ if (packagesToRun.isEmpty() && getConfiguration().getTestClasses().isEmpty()) {
packagesToRun = Collections.singletonList("");
logger.info("Running all tests in project");
}
diff --git a/runtime/citrus-junit/src/main/java/org/citrusframework/junit/spring/CitrusSpringJUnit4Runner.java b/runtime/citrus-junit/src/main/java/org/citrusframework/junit/spring/CitrusSpringJUnit4Runner.java
index 857871ea97..1083ab601c 100644
--- a/runtime/citrus-junit/src/main/java/org/citrusframework/junit/spring/CitrusSpringJUnit4Runner.java
+++ b/runtime/citrus-junit/src/main/java/org/citrusframework/junit/spring/CitrusSpringJUnit4Runner.java
@@ -25,14 +25,13 @@
import org.citrusframework.common.TestLoader;
import org.citrusframework.junit.CitrusFrameworkMethod;
import org.citrusframework.junit.JUnit4Helper;
-import org.citrusframework.junit.TestSuiteExecutionListener;
+import org.citrusframework.util.StringUtils;
import org.junit.Test;
import org.junit.internal.runners.statements.InvokeMethod;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.springframework.util.StringUtils;
/**
* JUnit runner reads Citrus test annotation for XML test cases and prepares test execution within proper Citrus
diff --git a/runtime/citrus-junit/src/main/java/org/citrusframework/junit/TestSuiteExecutionListener.java b/runtime/citrus-junit/src/main/java/org/citrusframework/junit/spring/TestSuiteExecutionListener.java
similarity index 66%
rename from runtime/citrus-junit/src/main/java/org/citrusframework/junit/TestSuiteExecutionListener.java
rename to runtime/citrus-junit/src/main/java/org/citrusframework/junit/spring/TestSuiteExecutionListener.java
index 5c5793d7e0..223c332ae0 100644
--- a/runtime/citrus-junit/src/main/java/org/citrusframework/junit/TestSuiteExecutionListener.java
+++ b/runtime/citrus-junit/src/main/java/org/citrusframework/junit/spring/TestSuiteExecutionListener.java
@@ -1,23 +1,27 @@
/*
- * Copyright 2006-2010 the original author or authors.
+ * Copyright 2023 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
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * 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.
+ * 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.junit;
+package org.citrusframework.junit.spring;
import org.citrusframework.Citrus;
import org.citrusframework.CitrusSpringContextProvider;
+import org.citrusframework.junit.TestSuiteState;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.support.AbstractTestExecutionListener;
diff --git a/runtime/citrus-junit5/src/main/java/org/citrusframework/junit/jupiter/CitrusExtensionHelper.java b/runtime/citrus-junit5/src/main/java/org/citrusframework/junit/jupiter/CitrusExtensionHelper.java
index 0f58b95de2..8520362507 100644
--- a/runtime/citrus-junit5/src/main/java/org/citrusframework/junit/jupiter/CitrusExtensionHelper.java
+++ b/runtime/citrus-junit5/src/main/java/org/citrusframework/junit/jupiter/CitrusExtensionHelper.java
@@ -37,14 +37,14 @@
import org.citrusframework.common.TestSourceAware;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.ObjectHelper;
+import org.citrusframework.util.StringUtils;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolutionException;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.ResourceLoader;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -97,7 +97,7 @@ public static TestCaseRunner createTestRunner(String testName, ExtensionContext
* @return the {@code TestCaseRunner} (never {@code null})
*/
public static TestCaseRunner getTestRunner(ExtensionContext extensionContext) {
- Assert.notNull(extensionContext, "ExtensionContext must not be null");
+ ObjectHelper.assertNotNull(extensionContext, "ExtensionContext must not be null");
return extensionContext.getRoot().getStore(CitrusExtension.NAMESPACE).getOrComputeIfAbsent(getBaseKey(extensionContext) + TestCaseRunner.class.getSimpleName(), key -> {
String testName = extensionContext.getRequiredTestClass().getSimpleName() + "." + extensionContext.getRequiredTestMethod().getName();
@@ -119,7 +119,7 @@ public static TestCaseRunner getTestRunner(ExtensionContext extensionContext) {
* @return the {@code TestLoader} (never {@code null})
*/
public static TestLoader getTestLoader(ExtensionContext extensionContext) {
- Assert.notNull(extensionContext, "ExtensionContext must not be null");
+ ObjectHelper.assertNotNull(extensionContext, "ExtensionContext must not be null");
return extensionContext.getRoot().getStore(CitrusExtension.NAMESPACE).getOrComputeIfAbsent(getBaseKey(extensionContext) + TestLoader.class.getSimpleName(),
key -> createTestLoader(extensionContext), TestLoader.class);
@@ -131,7 +131,7 @@ public static TestLoader getTestLoader(ExtensionContext extensionContext) {
* @return the {@code TestCase} (never {@code null})
*/
public static TestCase getTestCase(ExtensionContext extensionContext) {
- Assert.notNull(extensionContext, "ExtensionContext must not be null");
+ ObjectHelper.assertNotNull(extensionContext, "ExtensionContext must not be null");
return extensionContext.getRoot().getStore(CitrusExtension.NAMESPACE).getOrComputeIfAbsent(getBaseKey(extensionContext) + TestCase.class.getSimpleName(), key -> {
if (CitrusExtensionHelper.isTestSourceMethod(extensionContext.getRequiredTestMethod())) {
return getTestLoader(extensionContext).getTestCase();
@@ -192,7 +192,7 @@ public static TestLoader createTestLoader(ExtensionContext extensionContext) {
* @return the {@code TestContext} (never {@code null})
*/
public static TestContext getTestContext(ExtensionContext extensionContext) {
- Assert.notNull(extensionContext, "ExtensionContext must not be null");
+ ObjectHelper.assertNotNull(extensionContext, "ExtensionContext must not be null");
return extensionContext.getRoot().getStore(CitrusExtension.NAMESPACE).getOrComputeIfAbsent(getBaseKey(extensionContext) + TestContext.class.getSimpleName(),
key -> getCitrus(extensionContext).getCitrusContext().createTestContext(), TestContext.class);
}
@@ -212,7 +212,7 @@ public static String getBaseKey(ExtensionContext extensionContext) {
* @return the {@code Citrus} (never {@code null})
*/
public static Citrus getCitrus(ExtensionContext extensionContext) {
- Assert.notNull(extensionContext, "ExtensionContext must not be null");
+ ObjectHelper.assertNotNull(extensionContext, "ExtensionContext must not be null");
Citrus citrus = extensionContext.getRoot().getStore(CitrusExtension.NAMESPACE).get(Citrus.class.getName(), Citrus.class);
if (citrus == null) {
@@ -229,7 +229,7 @@ public static Citrus getCitrus(ExtensionContext extensionContext) {
* @return the {@code Citrus} (never {@code null})
*/
public static void setCitrus(Citrus citrus, ExtensionContext extensionContext) {
- Assert.notNull(extensionContext, "ExtensionContext must not be null");
+ ObjectHelper.assertNotNull(extensionContext, "ExtensionContext must not be null");
extensionContext.getRoot().getStore(CitrusExtension.NAMESPACE).put(Citrus.class.getName(), citrus);
}
@@ -254,7 +254,7 @@ public static Object resolveParameter(ParameterContext parameterContext, Extensi
* @return
*/
public static boolean requiresCitrus(ExtensionContext extensionContext) {
- Assert.notNull(extensionContext, "ExtensionContext must not be null");
+ ObjectHelper.assertNotNull(extensionContext, "ExtensionContext must not be null");
Citrus citrus = extensionContext.getRoot().getStore(CitrusExtension.NAMESPACE).get(Citrus.class.getName(), Citrus.class);
return citrus == null;
}
@@ -290,14 +290,14 @@ private static void configure(TestLoader testLoader, ExtensionContext extensionC
source = sources[0];
Resource file = FileUtils.getFileResource(source);
- testName = FileUtils.getBaseName(file.getFilename());
+ testName = FileUtils.getBaseName(FileUtils.getFileName(file.getLocation()));
packageName = source;
- if (packageName.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX)) {
- packageName = source.substring(ResourceLoader.CLASSPATH_URL_PREFIX.length());
+ if (packageName.startsWith(Resources.CLASSPATH_RESOURCE_PREFIX)) {
+ packageName = source.substring(Resources.CLASSPATH_RESOURCE_PREFIX.length());
}
- if (StringUtils.hasLength(packageName) && packageName.contains("/")) {
+ if (StringUtils.hasText(packageName) && packageName.contains("/")) {
packageName = packageName.substring(0, packageName.lastIndexOf("/"));
}
diff --git a/runtime/citrus-junit5/src/main/java/org/citrusframework/junit/jupiter/CitrusTestFactorySupport.java b/runtime/citrus-junit5/src/main/java/org/citrusframework/junit/jupiter/CitrusTestFactorySupport.java
index 055c81c34c..9bb6fa8408 100644
--- a/runtime/citrus-junit5/src/main/java/org/citrusframework/junit/jupiter/CitrusTestFactorySupport.java
+++ b/runtime/citrus-junit5/src/main/java/org/citrusframework/junit/jupiter/CitrusTestFactorySupport.java
@@ -21,8 +21,10 @@
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Stream;
@@ -31,10 +33,9 @@
import org.citrusframework.annotations.CitrusAnnotations;
import org.citrusframework.common.TestLoader;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.ClasspathResourceResolver;
import org.citrusframework.util.FileUtils;
import org.junit.jupiter.api.DynamicTest;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
/**
* @author Christoph Deppisch
@@ -76,9 +77,9 @@ public Stream packageScan(String ... packagesToScan) {
for (String packageScan : packagesToScan) {
try {
for (String fileNamePattern : CitrusSettings.getTestFileNamePattern(type)) {
- Resource[] fileResources = new PathMatchingResourcePatternResolver().getResources(packageScan.replace('.', File.separatorChar) + fileNamePattern);
- for (Resource fileResource : fileResources) {
- String filePath = fileResource.getFile().getParentFile().getCanonicalPath();
+ Set fileResources = new ClasspathResourceResolver().getResources(packageScan.replace('.', File.separatorChar), fileNamePattern);
+ for (Path fileResource : fileResources) {
+ String filePath = fileResource.getParent().toFile().getCanonicalPath();
if (packageScan.startsWith("file:")) {
filePath = "file:" + filePath;
@@ -86,7 +87,7 @@ public Stream packageScan(String ... packagesToScan) {
filePath = filePath.substring(filePath.indexOf(packageScan.replace('.', File.separatorChar)));
- String testName = FileUtils.getBaseName(fileResource.getFilename());
+ String testName = FileUtils.getBaseName(String.valueOf(fileResource.getFileName()));
TestLoader testLoader = createTestLoader(testName, filePath);
tests.add(DynamicTest.dynamicTest(testName, () -> handler.accept(testLoader)));
diff --git a/runtime/citrus-main/src/main/java/org/citrusframework/main/CitrusAppOptions.java b/runtime/citrus-main/src/main/java/org/citrusframework/main/CitrusAppOptions.java
index ce64fbaa96..4d06cc6cd1 100644
--- a/runtime/citrus-main/src/main/java/org/citrusframework/main/CitrusAppOptions.java
+++ b/runtime/citrus-main/src/main/java/org/citrusframework/main/CitrusAppOptions.java
@@ -21,14 +21,13 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-import java.util.Optional;
import java.util.stream.Collectors;
import org.citrusframework.TestClass;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -110,10 +109,16 @@ protected void doProcess(T configuration, String arg, String value, LinkedList remainingArgs) {
if (StringUtils.hasText(value)) {
- configuration.getDefaultProperties().putAll(StringUtils.commaDelimitedListToSet(value)
- .stream()
- .map(keyValue -> Optional.ofNullable(StringUtils.split(keyValue, "=")).orElse(new String[] {keyValue, ""}))
- .collect(Collectors.toMap(keyValue -> keyValue[0], keyValue -> keyValue[1])));
+ configuration.getDefaultProperties().putAll(Arrays.stream(value.split(","))
+ .map(keyValue -> keyValue.split("="))
+ .filter(keyValue -> StringUtils.hasText(keyValue[0]))
+ .map(keyValue -> {
+ if (keyValue.length < 2) {
+ return new String[]{keyValue[0], ""};
+ }
+ return keyValue;
+ })
+ .collect(Collectors.toMap(keyValue -> keyValue[0], keyValue -> keyValue[1])));
} else {
throw new CitrusRuntimeException("Missing parameter value for -D/--properties option");
}
diff --git a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGCitrusMethodInterceptor.java b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGCitrusMethodInterceptor.java
index 50295ef3a8..c1b5eddc35 100644
--- a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGCitrusMethodInterceptor.java
+++ b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGCitrusMethodInterceptor.java
@@ -18,17 +18,18 @@
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import org.citrusframework.CitrusSettings;
import org.citrusframework.annotations.CitrusTestSource;
import org.citrusframework.annotations.CitrusXmlTest;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.ClasspathResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.testng.IMethodInstance;
import org.testng.IMethodInterceptor;
import org.testng.ITestContext;
@@ -71,8 +72,8 @@ public List intercept(List methods, ITestConte
for (String packageName : packagesToScan) {
try {
for (String fileNamePattern : CitrusSettings.getTestFileNamePattern(citrusTestAnnotation.type())) {
- Resource[] fileResources = new PathMatchingResourcePatternResolver().getResources(packageName.replace('.', File.separatorChar) + fileNamePattern);
- for (int i = 0; i < fileResources.length; i++) {
+ Set fileResources = new ClasspathResourceResolver().getResources(packageName.replace('.', File.separatorChar), fileNamePattern);
+ for (int i = 0; i < fileResources.size(); i++) {
if (i == 0 && !baseMethodAdded) {
baseMethodAdded = true;
interceptedMethods.add(method);
diff --git a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGEngine.java b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGEngine.java
index e2dc058349..86010ebfa6 100644
--- a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGEngine.java
+++ b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGEngine.java
@@ -29,10 +29,9 @@
import org.citrusframework.main.TestRunConfiguration;
import org.citrusframework.main.scan.ClassPathTestScanner;
import org.citrusframework.main.scan.JarFileTestScanner;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
import org.testng.ITestNGListener;
import org.testng.TestNG;
import org.testng.annotations.Test;
@@ -70,7 +69,7 @@ public void run() {
XmlSuite suite = new XmlSuite();
testng.setXmlSuites(Collections.singletonList(suite));
- if (!CollectionUtils.isEmpty(getConfiguration().getTestClasses())) {
+ if (getConfiguration().getTestClasses() != null && !getConfiguration().getTestClasses().isEmpty()) {
for (TestClass testClass : getConfiguration().getTestClasses()) {
logger.info(String.format("Running test %s",
Optional.ofNullable(testClass.getMethod()).map(method -> testClass.getName() + "#" + method)
@@ -100,7 +99,7 @@ public void run() {
}
} else {
List packagesToRun = getConfiguration().getPackages();
- if (CollectionUtils.isEmpty(packagesToRun)) {
+ if (packagesToRun == null || packagesToRun.isEmpty()) {
packagesToRun = Collections.singletonList("");
logger.info("Running all tests in project");
}
diff --git a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGHelper.java b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGHelper.java
index 9644938ccf..42b4e1726d 100644
--- a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGHelper.java
+++ b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGHelper.java
@@ -22,6 +22,7 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -38,14 +39,14 @@
import org.citrusframework.common.TestSourceAware;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.ClasspathResourceResolver;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.ReflectionHelper;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.ResourceLoader;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.util.ReflectionUtils;
-import org.springframework.util.StringUtils;
import org.testng.IHookCallBack;
import org.testng.ITestResult;
@@ -79,7 +80,7 @@ public static void invokeTestMethod(Object target, ITestResult testResult, Metho
TestLoader testLoader, TestContext context, int invocationCount) {
Object[] params = TestNGParameterHelper.resolveParameter(target, testResult, method, context, invocationCount);
testLoader.configureTestCase(t -> TestNGParameterHelper.injectTestParameters(method, t, params));
- testLoader.doWithTestCase(t -> ReflectionUtils.invokeMethod(method, target, params));
+ testLoader.doWithTestCase(t -> ReflectionHelper.invokeMethod(method, target, params));
testLoader.load();
}
@@ -169,15 +170,15 @@ private static List extends TestLoader> createMethodTestLoaders(Method method,
Resource file = FileUtils.getFileResource(source);
String sourceFilePackageName = "";
- if (source.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX)) {
- sourceFilePackageName = source.substring(ResourceLoader.CLASSPATH_URL_PREFIX.length());
+ if (source.startsWith(Resources.CLASSPATH_RESOURCE_PREFIX)) {
+ sourceFilePackageName = source.substring(Resources.CLASSPATH_RESOURCE_PREFIX.length());
}
- if (StringUtils.hasLength(sourceFilePackageName) && sourceFilePackageName.contains("/")) {
+ if (StringUtils.hasText(sourceFilePackageName) && sourceFilePackageName.contains("/")) {
sourceFilePackageName = sourceFilePackageName.substring(0, sourceFilePackageName.lastIndexOf("/"));
}
- TestLoader testLoader = provider.createTestLoader(FileUtils.getBaseName(file.getFilename()),
+ TestLoader testLoader = provider.createTestLoader(FileUtils.getBaseName(FileUtils.getFileName(file.getLocation())),
sourceFilePackageName.replace("/","."), type);
if (testLoader instanceof TestSourceAware) {
@@ -191,9 +192,9 @@ private static List extends TestLoader> createMethodTestLoaders(Method method,
for (String packageScan : packagesToScan) {
try {
for (String fileNamePattern : testFileNamePattern) {
- Resource[] fileResources = new PathMatchingResourcePatternResolver().getResources(packageScan.replace('.', File.separatorChar) + fileNamePattern);
- for (Resource fileResource : fileResources) {
- String filePath = fileResource.getFile().getParentFile().getCanonicalPath();
+ Set fileResources = new ClasspathResourceResolver().getResources(packageScan.replace('.', File.separatorChar), fileNamePattern);
+ for (Path fileResource : fileResources) {
+ String filePath = fileResource.getParent().toFile().getCanonicalPath();
if (packageScan.startsWith("file:")) {
filePath = "file:" + filePath;
@@ -201,7 +202,8 @@ private static List extends TestLoader> createMethodTestLoaders(Method method,
filePath = filePath.substring(filePath.indexOf(packageScan.replace('.', File.separatorChar)));
- methodTestLoaders.add(provider.createTestLoader(FileUtils.getBaseName(fileResource.getFilename()), filePath, type));
+ methodTestLoaders.add(provider.createTestLoader(
+ FileUtils.getBaseName(String.valueOf(fileResource.getFileName())), filePath, type));
}
}
} catch (RuntimeException | IOException e) {
diff --git a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGParameterHelper.java b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGParameterHelper.java
index 787c21e951..12b6b7d114 100644
--- a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGParameterHelper.java
+++ b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGParameterHelper.java
@@ -33,8 +33,8 @@
import org.citrusframework.annotations.CitrusResource;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.springframework.util.ReflectionUtils;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.ReflectionHelper;
+import org.citrusframework.util.StringUtils;
import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.annotations.DataProvider;
@@ -68,7 +68,11 @@ public static Object[] resolveParameter(Object target, ITestResult testResult, f
if (method.getAnnotation(Test.class) != null &&
StringUtils.hasText(method.getAnnotation(Test.class).dataProvider())) {
final Method[] dataProvider = new Method[1];
- ReflectionUtils.doWithMethods(method.getDeclaringClass(), current -> {
+ ReflectionHelper.doWithMethods(method.getDeclaringClass(), current -> {
+ if (current.getAnnotation(DataProvider.class) == null) {
+ return;
+ }
+
if (StringUtils.hasText(current.getAnnotation(DataProvider.class).name()) &&
current.getAnnotation(DataProvider.class).name().equals(method.getAnnotation(Test.class).dataProvider())) {
dataProvider[0] = current;
@@ -76,13 +80,13 @@ public static Object[] resolveParameter(Object target, ITestResult testResult, f
dataProvider[0] = current;
}
- }, toFilter -> toFilter.getAnnotation(DataProvider.class) != null);
+ });
if (dataProvider[0] == null) {
throw new CitrusRuntimeException("Unable to find data provider: " + method.getAnnotation(Test.class).dataProvider());
}
- Object[][] parameters = (Object[][]) ReflectionUtils.invokeMethod(dataProvider[0], target,
+ Object[][] parameters = (Object[][]) ReflectionHelper.invokeMethod(dataProvider[0], target,
resolveParameter(target, testResult, dataProvider[0], context, -1));
if (parameters != null) {
dataProviderParams = parameters[invocationCount % parameters.length];
diff --git a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/spring/TestNGCitrusSpringMethodInterceptor.java b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/spring/TestNGCitrusSpringMethodInterceptor.java
index eae5c25a84..15ff342aec 100644
--- a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/spring/TestNGCitrusSpringMethodInterceptor.java
+++ b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/spring/TestNGCitrusSpringMethodInterceptor.java
@@ -18,17 +18,18 @@
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import org.citrusframework.CitrusSettings;
import org.citrusframework.annotations.CitrusTestSource;
import org.citrusframework.annotations.CitrusXmlTest;
import org.citrusframework.common.TestLoader;
+import org.citrusframework.spi.ClasspathResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.testng.IMethodInstance;
import org.testng.IMethodInterceptor;
import org.testng.ITestContext;
@@ -71,8 +72,8 @@ public List intercept(List methods, ITestConte
for (String packageName : packagesToScan) {
try {
for (String fileNamePattern : CitrusSettings.getTestFileNamePattern(citrusTestAnnotation.type())) {
- Resource[] fileResources = new PathMatchingResourcePatternResolver().getResources(packageName.replace('.', File.separatorChar) + fileNamePattern);
- for (int i = 0; i < fileResources.length; i++) {
+ Set fileResources = new ClasspathResourceResolver().getResources(packageName.replace('.', File.separatorChar), fileNamePattern);
+ for (int i = 0; i < fileResources.size(); i++) {
if (i == 0 && !baseMethodAdded) {
baseMethodAdded = true;
interceptedMethods.add(method);
@@ -102,8 +103,8 @@ public List intercept(List methods, ITestConte
for (String packageName : packagesToScan) {
try {
for (String fileNamePattern : CitrusSettings.getTestFileNamePattern(TestLoader.SPRING)) {
- Resource[] fileResources = new PathMatchingResourcePatternResolver().getResources(packageName.replace('.', File.separatorChar) + fileNamePattern);
- for (int i = 0; i < fileResources.length; i++) {
+ Set fileResources = new ClasspathResourceResolver().getResources(packageName.replace('.', File.separatorChar), fileNamePattern);
+ for (int i = 0; i < fileResources.size(); i++) {
if (i == 0 && !baseMethodAdded) {
baseMethodAdded = true;
interceptedMethods.add(method);
diff --git a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/spring/TestNGCitrusSpringSupport.java b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/spring/TestNGCitrusSpringSupport.java
index 50e62f08f1..f1a866c088 100644
--- a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/spring/TestNGCitrusSpringSupport.java
+++ b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/spring/TestNGCitrusSpringSupport.java
@@ -47,9 +47,9 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.testng.TestNGHelper;
+import org.citrusframework.util.ObjectHelper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
-import org.springframework.util.Assert;
import org.testng.IHookCallBack;
import org.testng.ITestContext;
import org.testng.ITestResult;
@@ -222,7 +222,7 @@ public final void beforeSuite(ITestContext testContext) {
} catch (Exception e) {
throw new CitrusRuntimeException("Failed to initialize Spring test context", e);
}
- Assert.notNull(applicationContext, "Missing proper application context in before suite initialization");
+ ObjectHelper.assertNotNull(applicationContext, "Missing proper application context in before suite initialization");
citrus = Citrus.newInstance(new CitrusSpringContextProvider(applicationContext));
CitrusAnnotations.injectCitrusFramework(this, citrus);
diff --git a/runtime/citrus-testng/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageTestActionBuilderTest.java b/runtime/citrus-testng/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageTestActionBuilderTest.java
index fadf0b27d4..3f6c55aa1b 100644
--- a/runtime/citrus-testng/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageTestActionBuilderTest.java
+++ b/runtime/citrus-testng/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageTestActionBuilderTest.java
@@ -39,6 +39,7 @@
import org.citrusframework.messaging.SelectiveConsumer;
import org.citrusframework.report.TestActionListeners;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.spi.Resource;
import org.citrusframework.validation.AbstractValidationProcessor;
import org.citrusframework.validation.builder.DefaultMessageBuilder;
import org.citrusframework.validation.builder.StaticMessageBuilder;
@@ -47,7 +48,6 @@
import org.citrusframework.validation.xml.XmlMessageValidationContext;
import org.citrusframework.variable.MessageHeaderVariableExtractor;
import org.mockito.Mockito;
-import org.springframework.core.io.Resource;
import org.testng.Assert;
import org.testng.annotations.Test;
diff --git a/runtime/citrus-testng/src/test/java/org/citrusframework/actions/dsl/SendMessageTestActionBuilderTest.java b/runtime/citrus-testng/src/test/java/org/citrusframework/actions/dsl/SendMessageTestActionBuilderTest.java
index 0e94da5212..75d0c56144 100644
--- a/runtime/citrus-testng/src/test/java/org/citrusframework/actions/dsl/SendMessageTestActionBuilderTest.java
+++ b/runtime/citrus-testng/src/test/java/org/citrusframework/actions/dsl/SendMessageTestActionBuilderTest.java
@@ -36,12 +36,11 @@
import org.citrusframework.messaging.Producer;
import org.citrusframework.report.TestActionListeners;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.spi.Resource;
import org.citrusframework.validation.builder.DefaultMessageBuilder;
import org.citrusframework.validation.builder.StaticMessageBuilder;
import org.citrusframework.variable.MessageHeaderVariableExtractor;
-import org.citrusframework.xml.Marshaller;
import org.mockito.Mockito;
-import org.springframework.core.io.Resource;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -63,8 +62,6 @@ public class SendMessageTestActionBuilderTest extends UnitTestSupport {
private final Producer messageProducer = Mockito.mock(Producer.class);
private final Resource resource = Mockito.mock(Resource.class);
- private final Marshaller marshaller = Mockito.mock(Marshaller.class);
-
@Test
public void testSendBuilderWithMessageInstance() {
reset(messageEndpoint, messageProducer);
diff --git a/runtime/citrus-testng/src/test/java/org/citrusframework/actions/dsl/TransformTestActionBuilderTest.java b/runtime/citrus-testng/src/test/java/org/citrusframework/actions/dsl/TransformTestActionBuilderTest.java
index 8383b60ae2..9d30487079 100644
--- a/runtime/citrus-testng/src/test/java/org/citrusframework/actions/dsl/TransformTestActionBuilderTest.java
+++ b/runtime/citrus-testng/src/test/java/org/citrusframework/actions/dsl/TransformTestActionBuilderTest.java
@@ -22,7 +22,7 @@
import org.citrusframework.TestCase;
import org.citrusframework.UnitTestSupport;
import org.citrusframework.actions.TransformAction;
-import org.springframework.core.io.ClassPathResource;
+import org.citrusframework.spi.Resources;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -70,8 +70,8 @@ public void testTransformBuilderWithData() {
@Test
public void testTransformBuilderWithResource() throws IOException {
DefaultTestCaseRunner builder = new DefaultTestCaseRunner(context);
- builder.$(transform().source(new ClassPathResource("org/citrusframework/actions/dsl/transform-source.xml"))
- .xslt(new ClassPathResource("org/citrusframework/actions/dsl/transform.xslt"))
+ builder.$(transform().source(Resources.newClasspathResource("org/citrusframework/actions/dsl/transform-source.xml"))
+ .xslt(Resources.newClasspathResource("org/citrusframework/actions/dsl/transform.xslt"))
.result("result"));
Assert.assertNotNull(context.getVariable("result"));
diff --git a/runtime/citrus-testng/src/test/java/org/citrusframework/integration/actions/TransformActionJavaIT.java b/runtime/citrus-testng/src/test/java/org/citrusframework/integration/actions/TransformActionJavaIT.java
index 0dd363a22d..ce911e3fb6 100644
--- a/runtime/citrus-testng/src/test/java/org/citrusframework/integration/actions/TransformActionJavaIT.java
+++ b/runtime/citrus-testng/src/test/java/org/citrusframework/integration/actions/TransformActionJavaIT.java
@@ -17,8 +17,8 @@
package org.citrusframework.integration.actions;
import org.citrusframework.annotations.CitrusTest;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
-import org.springframework.core.io.ClassPathResource;
import org.testng.annotations.Test;
import static org.citrusframework.actions.EchoAction.Builder.echo;
@@ -51,8 +51,8 @@ public void transformAction() {
run(echo("${result}"));
run(transform()
- .source(new ClassPathResource("org/citrusframework/integration/actions/transform-source.xml"))
- .xslt(new ClassPathResource("org/citrusframework/integration/actions/transform.xslt"))
+ .source(Resources.newClasspathResource("org/citrusframework/integration/actions/transform-source.xml"))
+ .xslt(Resources.newClasspathResource("org/citrusframework/integration/actions/transform.xslt"))
.result("result"));
diff --git a/runtime/citrus-testng/src/test/java/org/citrusframework/integration/container/WaitJavaIT.java b/runtime/citrus-testng/src/test/java/org/citrusframework/integration/container/WaitJavaIT.java
index 208ecf5706..c70379115b 100644
--- a/runtime/citrus-testng/src/test/java/org/citrusframework/integration/container/WaitJavaIT.java
+++ b/runtime/citrus-testng/src/test/java/org/citrusframework/integration/container/WaitJavaIT.java
@@ -25,10 +25,10 @@
import org.citrusframework.annotations.CitrusTest;
import org.citrusframework.integration.common.FileHelper;
import org.citrusframework.message.MessageType;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
import org.citrusframework.util.SocketUtils;
import com.sun.net.httpserver.HttpServer;
-import org.springframework.core.io.ClassPathResource;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -96,7 +96,7 @@ public void waitMessage() {
public void waitFile() throws IOException {
run(waitFor()
.file()
- .resource(new ClassPathResource("citrus.properties").getFile()));
+ .resource(Resources.newClasspathResource("citrus.properties").getFile()));
}
@CitrusTest
diff --git a/runtime/citrus-xml/src/main/java/org/citrusframework/xml/XmlTemplateLoader.java b/runtime/citrus-xml/src/main/java/org/citrusframework/xml/XmlTemplateLoader.java
index 6e9085419d..c6a94f95c1 100644
--- a/runtime/citrus-xml/src/main/java/org/citrusframework/xml/XmlTemplateLoader.java
+++ b/runtime/citrus-xml/src/main/java/org/citrusframework/xml/XmlTemplateLoader.java
@@ -28,9 +28,9 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
import org.citrusframework.xml.container.Template;
-import org.springframework.core.io.Resource;
/**
* @author Christoph Deppisch
diff --git a/runtime/citrus-xml/src/main/java/org/citrusframework/xml/XmlTestLoader.java b/runtime/citrus-xml/src/main/java/org/citrusframework/xml/XmlTestLoader.java
index 6cae3f1b5c..bd32c4e096 100644
--- a/runtime/citrus-xml/src/main/java/org/citrusframework/xml/XmlTestLoader.java
+++ b/runtime/citrus-xml/src/main/java/org/citrusframework/xml/XmlTestLoader.java
@@ -19,21 +19,21 @@
package org.citrusframework.xml;
-import jakarta.xml.bind.JAXBContext;
-import jakarta.xml.bind.JAXBException;
import java.io.File;
import java.io.IOException;
import java.util.regex.Pattern;
+import jakarta.xml.bind.JAXBContext;
+import jakarta.xml.bind.JAXBException;
import org.citrusframework.DefaultTestCaseRunner;
import org.citrusframework.common.DefaultTestLoader;
import org.citrusframework.common.TestSourceAware;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.Resource;
-import org.springframework.util.ResourceUtils;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* Loads test case as Spring bean from XML application context file. Loader holds application context file
@@ -119,7 +119,7 @@ public String getSource() {
if (StringUtils.hasText(source)) {
return source;
} else {
- return ResourceUtils.CLASSPATH_URL_PREFIX + packageName.replace('.', File.separatorChar) +
+ return Resources.CLASSPATH_RESOURCE_PREFIX + packageName.replace('.', File.separatorChar) +
File.separator + testName + FileUtils.FILE_EXTENSION_XML;
}
}
diff --git a/runtime/citrus-xml/src/main/java/org/citrusframework/xml/actions/MessageSupport.java b/runtime/citrus-xml/src/main/java/org/citrusframework/xml/actions/MessageSupport.java
index bd5e2cb1f2..7e998b0b72 100644
--- a/runtime/citrus-xml/src/main/java/org/citrusframework/xml/actions/MessageSupport.java
+++ b/runtime/citrus-xml/src/main/java/org/citrusframework/xml/actions/MessageSupport.java
@@ -31,10 +31,10 @@
import org.citrusframework.message.ScriptPayloadBuilder;
import org.citrusframework.message.builder.MessageBuilderSupport;
import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.interceptor.BinaryMessageProcessor;
import org.citrusframework.validation.interceptor.GzipMessageProcessor;
import org.citrusframework.xml.util.PayloadElementParser;
-import org.springframework.util.StringUtils;
import static org.citrusframework.dsl.MessageSupport.MessageBodySupport.fromBody;
import static org.citrusframework.dsl.MessageSupport.MessageHeaderSupport.fromHeaders;
diff --git a/runtime/citrus-xml/src/main/java/org/citrusframework/xml/actions/Receive.java b/runtime/citrus-xml/src/main/java/org/citrusframework/xml/actions/Receive.java
index e941e7d80c..8eb64486e2 100644
--- a/runtime/citrus-xml/src/main/java/org/citrusframework/xml/actions/Receive.java
+++ b/runtime/citrus-xml/src/main/java/org/citrusframework/xml/actions/Receive.java
@@ -38,12 +38,12 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.json.JsonMessageValidationContext;
import org.citrusframework.validation.json.JsonPathMessageValidationContext;
import org.citrusframework.validation.script.ScriptValidationContext;
import org.citrusframework.validation.xml.XmlMessageValidationContext;
import org.citrusframework.xml.actions.script.ScriptDefinitionType;
-import org.springframework.util.StringUtils;
@XmlRootElement(name = "receive")
public class Receive implements TestActionBuilder, ReferenceResolverAware {
diff --git a/runtime/citrus-xml/src/main/java/org/citrusframework/xml/container/WaitFor.java b/runtime/citrus-xml/src/main/java/org/citrusframework/xml/container/WaitFor.java
index 3674dbfd7b..3b2e2b5820 100644
--- a/runtime/citrus-xml/src/main/java/org/citrusframework/xml/container/WaitFor.java
+++ b/runtime/citrus-xml/src/main/java/org/citrusframework/xml/container/WaitFor.java
@@ -25,22 +25,22 @@
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlType;
-
import org.citrusframework.TestActionBuilder;
import org.citrusframework.condition.ActionCondition;
+import org.citrusframework.condition.Condition;
import org.citrusframework.condition.FileCondition;
import org.citrusframework.condition.HttpCondition;
import org.citrusframework.condition.MessageCondition;
import org.citrusframework.container.Wait;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.xml.TestActions;
-import org.springframework.util.StringUtils;
@XmlRootElement(name = "wait-for")
public class WaitFor implements TestActionBuilder, ReferenceResolverAware {
- private final Wait.Builder builder = new Wait.Builder();
+ private final Wait.Builder builder = new Wait.Builder<>();
private TestActionBuilder> action;
private ReferenceResolver referenceResolver;
diff --git a/runtime/citrus-xml/src/test/java/org/citrusframework/xml/actions/TransformTest.java b/runtime/citrus-xml/src/test/java/org/citrusframework/xml/actions/TransformTest.java
index 0a30789a37..8cd07e8ef1 100644
--- a/runtime/citrus-xml/src/test/java/org/citrusframework/xml/actions/TransformTest.java
+++ b/runtime/citrus-xml/src/test/java/org/citrusframework/xml/actions/TransformTest.java
@@ -22,8 +22,8 @@
import org.citrusframework.TestCase;
import org.citrusframework.TestCaseMetaInfo;
import org.citrusframework.actions.TransformAction;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.xml.XmlTestLoader;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
diff --git a/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/YamlTemplateLoader.java b/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/YamlTemplateLoader.java
index 8270b403ae..40620efc39 100644
--- a/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/YamlTemplateLoader.java
+++ b/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/YamlTemplateLoader.java
@@ -25,9 +25,9 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.spi.Resource;
import org.citrusframework.util.FileUtils;
import org.citrusframework.yaml.container.Template;
-import org.springframework.core.io.Resource;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
diff --git a/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/YamlTestLoader.java b/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/YamlTestLoader.java
index d0f5974fcf..4741221981 100644
--- a/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/YamlTestLoader.java
+++ b/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/YamlTestLoader.java
@@ -28,11 +28,11 @@
import org.citrusframework.common.DefaultTestLoader;
import org.citrusframework.common.TestSourceAware;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.yaml.actions.YamlTestActionBuilder;
-import org.springframework.core.io.Resource;
-import org.springframework.util.ResourceUtils;
-import org.springframework.util.StringUtils;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
@@ -142,7 +142,7 @@ public String getSource() {
if (StringUtils.hasText(source)) {
return source;
} else {
- return ResourceUtils.CLASSPATH_URL_PREFIX + packageName.replace('.', File.separatorChar) +
+ return Resources.CLASSPATH_RESOURCE_PREFIX + packageName.replace('.', File.separatorChar) +
File.separator + testName + ".yaml";
}
}
diff --git a/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/actions/MessageSupport.java b/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/actions/MessageSupport.java
index 63a72868cd..f950fc6ab9 100644
--- a/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/actions/MessageSupport.java
+++ b/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/actions/MessageSupport.java
@@ -31,9 +31,9 @@
import org.citrusframework.message.ScriptPayloadBuilder;
import org.citrusframework.message.builder.MessageBuilderSupport;
import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.interceptor.BinaryMessageProcessor;
import org.citrusframework.validation.interceptor.GzipMessageProcessor;
-import org.springframework.util.StringUtils;
import static org.citrusframework.dsl.MessageSupport.MessageBodySupport.fromBody;
import static org.citrusframework.dsl.MessageSupport.MessageHeaderSupport.fromHeaders;
diff --git a/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/actions/Receive.java b/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/actions/Receive.java
index df42226172..46b722d533 100644
--- a/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/actions/Receive.java
+++ b/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/actions/Receive.java
@@ -32,12 +32,12 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.json.JsonMessageValidationContext;
import org.citrusframework.validation.json.JsonPathMessageValidationContext;
import org.citrusframework.validation.script.ScriptValidationContext;
import org.citrusframework.validation.xml.XmlMessageValidationContext;
import org.citrusframework.yaml.actions.script.ScriptDefinitionType;
-import org.springframework.util.StringUtils;
public class Receive implements TestActionBuilder, ReferenceResolverAware {
diff --git a/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/container/WaitFor.java b/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/container/WaitFor.java
index 4cba06a640..5179e4953b 100644
--- a/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/container/WaitFor.java
+++ b/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/container/WaitFor.java
@@ -21,21 +21,22 @@
import org.citrusframework.TestActionBuilder;
import org.citrusframework.condition.ActionCondition;
+import org.citrusframework.condition.Condition;
import org.citrusframework.condition.FileCondition;
import org.citrusframework.condition.HttpCondition;
import org.citrusframework.condition.MessageCondition;
import org.citrusframework.container.Wait;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.yaml.TestActions;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
*/
public class WaitFor implements TestActionBuilder, ReferenceResolverAware {
- private final Wait.Builder builder = new Wait.Builder();
+ private final Wait.Builder builder = new Wait.Builder<>();
private TestActionBuilder> action;
private ReferenceResolver referenceResolver;
diff --git a/runtime/citrus-yaml/src/test/java/org/citrusframework/yaml/actions/TransformTest.java b/runtime/citrus-yaml/src/test/java/org/citrusframework/yaml/actions/TransformTest.java
index 4a9abca479..458403a6da 100644
--- a/runtime/citrus-yaml/src/test/java/org/citrusframework/yaml/actions/TransformTest.java
+++ b/runtime/citrus-yaml/src/test/java/org/citrusframework/yaml/actions/TransformTest.java
@@ -22,8 +22,8 @@
import org.citrusframework.TestCase;
import org.citrusframework.TestCaseMetaInfo;
import org.citrusframework.actions.TransformAction;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.yaml.YamlTestLoader;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
diff --git a/tools/docs-generator/src/main/java/org/citrusframework/docs/AbstractTestDocsGenerator.java b/tools/docs-generator/src/main/java/org/citrusframework/docs/AbstractTestDocsGenerator.java
index 8656fcf67c..d718713b81 100644
--- a/tools/docs-generator/src/main/java/org/citrusframework/docs/AbstractTestDocsGenerator.java
+++ b/tools/docs-generator/src/main/java/org/citrusframework/docs/AbstractTestDocsGenerator.java
@@ -16,15 +16,6 @@
package org.citrusframework.docs;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamSource;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
@@ -36,14 +27,23 @@
import java.nio.file.Paths;
import java.util.List;
import java.util.Properties;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamSource;
import org.citrusframework.CitrusSettings;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
import org.citrusframework.util.PropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
import org.xml.sax.SAXException;
public abstract class AbstractTestDocsGenerator implements TestDocsGenerator {
@@ -192,7 +192,7 @@ DocumentBuilder getDocumentBuilder() {
*/
Transformer getTransformer(final String fileName, final String mediaType, final String method) {
try {
- final Source source = new StreamSource(new ClassPathResource(fileName, getClass()).getInputStream());
+ final Source source = new StreamSource(Resources.create(fileName, getClass()).getInputStream());
final TransformerFactory factory = TransformerFactory.newInstance();
final Transformer t = factory.newTransformer(source);
@@ -201,7 +201,7 @@ Transformer getTransformer(final String fileName, final String mediaType, final
t.setOutputProperty(OutputKeys.METHOD, method);
return t;
- } catch (final TransformerException | IOException e) {
+ } catch (final TransformerException e) {
throw new CitrusRuntimeException(e);
}
}
diff --git a/tools/docs-generator/src/main/java/org/citrusframework/docs/ExcelTestDocsGenerator.java b/tools/docs-generator/src/main/java/org/citrusframework/docs/ExcelTestDocsGenerator.java
index 138ecc5b44..1b05c336ba 100644
--- a/tools/docs-generator/src/main/java/org/citrusframework/docs/ExcelTestDocsGenerator.java
+++ b/tools/docs-generator/src/main/java/org/citrusframework/docs/ExcelTestDocsGenerator.java
@@ -30,10 +30,10 @@
import javax.xml.transform.stream.StreamSource;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.xml.StringSource;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
-import org.springframework.util.StringUtils;
import org.xml.sax.SAXException;
/**
@@ -48,7 +48,7 @@ public class ExcelTestDocsGenerator extends AbstractTestDocsGenerator {
private String pageTitle = "Citrus Test Documentation";
private String company = "Unknown";
private String author = "Citrus Testframework";
- private Resource headers = new ClassPathResource("testdoc-header.xml", ExcelTestDocsGenerator.class);
+ private final Resource headers = Resources.create("testdoc-header.xml", ExcelTestDocsGenerator.class);
private String customHeaders = "";
/**
diff --git a/tools/docs-generator/src/test/java/org/citrusframework/docs/AbstractTestDocsGeneratorTest.java b/tools/docs-generator/src/test/java/org/citrusframework/docs/AbstractTestDocsGeneratorTest.java
index 598701d76d..cfe4cf6c7e 100644
--- a/tools/docs-generator/src/test/java/org/citrusframework/docs/AbstractTestDocsGeneratorTest.java
+++ b/tools/docs-generator/src/test/java/org/citrusframework/docs/AbstractTestDocsGeneratorTest.java
@@ -1,22 +1,22 @@
package org.citrusframework.docs;
-import org.citrusframework.generate.UnitFramework;
-import org.citrusframework.generate.xml.XmlTestGenerator;
-import org.testng.annotations.Test;
-import org.xml.sax.SAXException;
-
-import javax.xml.transform.TransformerException;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Properties;
+import javax.xml.transform.TransformerException;
+
+import org.citrusframework.generate.UnitFramework;
+import org.citrusframework.generate.xml.XmlTestGenerator;
+import org.testng.annotations.Test;
+import org.xml.sax.SAXException;
import static org.testng.Assert.assertEquals;
public class AbstractTestDocsGeneratorTest {
- private AbstractTestDocsGenerator abstractTestDocsGenerator = new AbstractTestDocsGenerator("", "") {
+ private final AbstractTestDocsGenerator abstractTestDocsGenerator = new AbstractTestDocsGenerator("", "") {
@Override
public void doBody(final OutputStream buffered) throws TransformerException, IOException, SAXException {
@@ -38,7 +38,7 @@ protected Properties getTestDocProperties() {
public void testGetTestFiles() throws IOException {
//GIVEN
- new XmlTestGenerator()
+ new XmlTestGenerator<>()
.withAuthor("Christoph")
.withDescription("This is a sample test")
.withName("SampleIT")
diff --git a/tools/docs-generator/src/test/java/org/citrusframework/docs/ExcelTestDocsGeneratorTest.java b/tools/docs-generator/src/test/java/org/citrusframework/docs/ExcelTestDocsGeneratorTest.java
index 2bcac2bffe..c6f9b8ae0a 100644
--- a/tools/docs-generator/src/test/java/org/citrusframework/docs/ExcelTestDocsGeneratorTest.java
+++ b/tools/docs-generator/src/test/java/org/citrusframework/docs/ExcelTestDocsGeneratorTest.java
@@ -25,8 +25,8 @@
import org.citrusframework.generate.TestGenerator;
import org.citrusframework.generate.UnitFramework;
import org.citrusframework.generate.xml.XmlTestGenerator;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.FileSystemResource;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -56,7 +56,7 @@ public void testExcelDocGeneration() throws IOException {
generator.generateDoc();
- String docContent = FileUtils.readToString(new FileSystemResource(ExcelTestDocsGenerator.getOutputDirectory() + File.separator + generator.getOutputFile()));
+ String docContent = FileUtils.readToString(Resources.newFileSystemResource(ExcelTestDocsGenerator.getOutputDirectory() + File.separator + generator.getOutputFile()));
Assert.assertTrue(docContent.contains("Citrus Testframework "));
Assert.assertTrue(docContent.contains("Citrus Test Documentation "));
@@ -88,7 +88,7 @@ public void testCustomizedExcelDocGeneration() throws IOException {
generator.generateDoc();
- String docContent = FileUtils.readToString(new FileSystemResource(ExcelTestDocsGenerator.getOutputDirectory() + File.separator + generator.getOutputFile()));
+ String docContent = FileUtils.readToString(Resources.newFileSystemResource(ExcelTestDocsGenerator.getOutputDirectory() + File.separator + generator.getOutputFile()));
Assert.assertTrue(docContent.contains("TestFactory "));
Assert.assertTrue(docContent.contains("TestCompany "));
diff --git a/tools/docs-generator/src/test/java/org/citrusframework/docs/HtmlTestDocsGeneratorTest.java b/tools/docs-generator/src/test/java/org/citrusframework/docs/HtmlTestDocsGeneratorTest.java
index 9a6f7b6858..5891a31c92 100644
--- a/tools/docs-generator/src/test/java/org/citrusframework/docs/HtmlTestDocsGeneratorTest.java
+++ b/tools/docs-generator/src/test/java/org/citrusframework/docs/HtmlTestDocsGeneratorTest.java
@@ -16,17 +16,18 @@
package org.citrusframework.docs;
+import java.io.File;
+import java.io.IOException;
+
+import org.citrusframework.generate.TestGenerator;
import org.citrusframework.generate.UnitFramework;
import org.citrusframework.generate.xml.XmlTestGenerator;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.FileSystemResource;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import java.io.File;
-import java.io.IOException;
-
/**
* @author Christoph Deppisch
*/
@@ -34,7 +35,7 @@ public class HtmlTestDocsGeneratorTest {
@BeforeClass
public void createSampleIT() {
- XmlTestGenerator generator = (XmlTestGenerator) new XmlTestGenerator()
+ TestGenerator> generator = new XmlTestGenerator<>()
.withAuthor("Christoph")
.withDescription("This is a sample test")
.withName("SampleIT")
@@ -43,15 +44,15 @@ public void createSampleIT() {
generator.create();
}
-
+
@Test
public void testHtmlDocGeneration() throws IOException {
HtmlTestDocsGenerator generator = HtmlTestDocsGenerator.build();
generator.generateDoc();
-
- String docContent = FileUtils.readToString(new FileSystemResource(HtmlTestDocsGenerator.getOutputDirectory() + File.separator + generator.getOutputFile()));
-
+
+ String docContent = FileUtils.readToString(Resources.newFileSystemResource(HtmlTestDocsGenerator.getOutputDirectory() + File.separator + generator.getOutputFile()));
+
Assert.assertTrue(docContent.contains("Citrus Test Documentation "));
Assert.assertTrue(docContent.contains(" "));
Assert.assertTrue(docContent.contains("Citrus Test Documentation "));
@@ -67,7 +68,7 @@ public void testHtmlDocGeneration() throws IOException {
File.separator + "sample" +
File.separator + "SampleIT.xml\">SampleIT.xml"));
}
-
+
@Test
public void testCustomizedHtmlDocGeneration() throws IOException {
HtmlTestDocsGenerator generator = HtmlTestDocsGenerator.build()
@@ -77,9 +78,9 @@ public void testCustomizedHtmlDocGeneration() throws IOException {
.useSrcDirectory("src" + File.separator + "test" + File.separator);
generator.generateDoc();
-
- String docContent = FileUtils.readToString(new FileSystemResource(HtmlTestDocsGenerator.getOutputDirectory() + File.separator + generator.getOutputFile()));
-
+
+ String docContent = FileUtils.readToString(Resources.newFileSystemResource(HtmlTestDocsGenerator.getOutputDirectory() + File.separator + generator.getOutputFile()));
+
Assert.assertTrue(docContent.contains("CustomPageTitle "));
Assert.assertTrue(docContent.contains(" "));
Assert.assertTrue(docContent.contains("CustomPageTitle "));
@@ -94,6 +95,6 @@ public void testCustomizedHtmlDocGeneration() throws IOException {
File.separator + "citrusframework" +
File.separator + "sample" +
File.separator + "SampleIT.xml\">SampleIT.xml"));
-
+
}
}
diff --git a/tools/docs-generator/src/test/java/org/citrusframework/docs/SvgTestDocsGeneratorTest.java b/tools/docs-generator/src/test/java/org/citrusframework/docs/SvgTestDocsGeneratorTest.java
index a9baf58323..24929187cb 100644
--- a/tools/docs-generator/src/test/java/org/citrusframework/docs/SvgTestDocsGeneratorTest.java
+++ b/tools/docs-generator/src/test/java/org/citrusframework/docs/SvgTestDocsGeneratorTest.java
@@ -16,16 +16,17 @@
package org.citrusframework.docs;
+import java.io.IOException;
+
+import org.citrusframework.generate.TestGenerator;
import org.citrusframework.generate.UnitFramework;
import org.citrusframework.generate.xml.XmlTestGenerator;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.FileSystemResource;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import java.io.IOException;
-
/**
* @author Christoph Deppisch
*/
@@ -33,7 +34,7 @@ public class SvgTestDocsGeneratorTest {
@BeforeClass
public void createSampleIT() {
- XmlTestGenerator generator = (XmlTestGenerator) new XmlTestGenerator()
+ TestGenerator> generator = new XmlTestGenerator<>()
.withAuthor("Christoph")
.withDescription("This is a sample test")
.withName("SampleIT")
@@ -42,15 +43,15 @@ public void createSampleIT() {
generator.create();
}
-
+
@Test
public void testSvgDocGeneration() throws IOException {
SvgTestDocsGenerator generator = SvgTestDocsGenerator.build();
-
+
generator.generateDoc();
-
- String docContent = FileUtils.readToString(new FileSystemResource(HtmlTestDocsGenerator.getOutputDirectory() + "/SampleIT.svg"));
-
+
+ String docContent = FileUtils.readToString(Resources.newFileSystemResource(HtmlTestDocsGenerator.getOutputDirectory() + "/SampleIT.svg"));
+
Assert.assertTrue(docContent.contains("SampleIT "));
Assert.assertTrue(docContent.contains("This is a sample test"));
Assert.assertTrue(docContent.contains("TestCase: SampleIT"));
diff --git a/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/CreateTestMojo.java b/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/CreateTestMojo.java
index dbcdcc59a8..247466f1d4 100644
--- a/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/CreateTestMojo.java
+++ b/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/CreateTestMojo.java
@@ -20,6 +20,11 @@
import java.util.Optional;
import java.util.stream.Collectors;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
import org.citrusframework.generate.SwaggerTestGenerator;
import org.citrusframework.generate.TestGenerator;
import org.citrusframework.generate.UnitFramework;
@@ -33,14 +38,9 @@
import org.citrusframework.generate.xml.WsdlXmlTestGenerator;
import org.citrusframework.generate.xml.XmlTestGenerator;
import org.citrusframework.generate.xml.XsdXmlTestGenerator;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Component;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
+import org.citrusframework.util.StringUtils;
import org.codehaus.plexus.components.interactivity.Prompter;
import org.codehaus.plexus.components.interactivity.PrompterException;
-import org.springframework.util.StringUtils;
/**
* Creates new Citrus test cases with empty XML test file and executable Java class.
diff --git a/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/GenerateTestMojo.java b/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/GenerateTestMojo.java
index 7fc98960ce..b422f49ae9 100644
--- a/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/GenerateTestMojo.java
+++ b/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/GenerateTestMojo.java
@@ -16,16 +16,27 @@
package org.citrusframework.mvn.plugin;
-import org.citrusframework.generate.*;
-import org.citrusframework.generate.javadsl.*;
-import org.citrusframework.generate.xml.*;
-import org.citrusframework.mvn.plugin.config.tests.TestConfiguration;
+import java.util.Optional;
+
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.*;
-import org.springframework.util.StringUtils;
-
-import java.util.Optional;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.citrusframework.generate.SwaggerTestGenerator;
+import org.citrusframework.generate.TestGenerator;
+import org.citrusframework.generate.WsdlTestGenerator;
+import org.citrusframework.generate.XsdTestGenerator;
+import org.citrusframework.generate.javadsl.JavaDslTestGenerator;
+import org.citrusframework.generate.javadsl.SwaggerJavaTestGenerator;
+import org.citrusframework.generate.javadsl.WsdlJavaTestGenerator;
+import org.citrusframework.generate.javadsl.XsdJavaTestGenerator;
+import org.citrusframework.generate.xml.SwaggerXmlTestGenerator;
+import org.citrusframework.generate.xml.WsdlXmlTestGenerator;
+import org.citrusframework.generate.xml.XmlTestGenerator;
+import org.citrusframework.generate.xml.XsdXmlTestGenerator;
+import org.citrusframework.mvn.plugin.config.tests.TestConfiguration;
+import org.citrusframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -122,7 +133,7 @@ public void doExecute() throws MojoExecutionException, MojoFailureException {
generator.withInboundMappingFile(test.getXsd().getMappings().getInboundFile());
generator.withOutboundMappingFile(test.getXsd().getMappings().getOutboundFile());
}
-
+
generator.withEndpoint(test.getEndpoint());
generator.withNameSuffix(test.getSuffix());
diff --git a/tools/restdocs/src/main/java/org/citrusframework/restdocs/config/xml/RestDocClientInterceptorParser.java b/tools/restdocs/src/main/java/org/citrusframework/restdocs/config/xml/RestDocClientInterceptorParser.java
index fe48dd5d96..6a4d07f595 100644
--- a/tools/restdocs/src/main/java/org/citrusframework/restdocs/config/xml/RestDocClientInterceptorParser.java
+++ b/tools/restdocs/src/main/java/org/citrusframework/restdocs/config/xml/RestDocClientInterceptorParser.java
@@ -16,14 +16,18 @@
package org.citrusframework.restdocs.config.xml;
-import org.citrusframework.restdocs.http.*;
-import org.citrusframework.restdocs.soap.*;
+import org.citrusframework.restdocs.http.RestDocClientInterceptor;
+import org.citrusframework.restdocs.http.RestDocRequestConverter;
+import org.citrusframework.restdocs.http.RestDocResponseConverter;
+import org.citrusframework.restdocs.soap.RestDocSoapClientInterceptor;
+import org.citrusframework.restdocs.soap.RestDocSoapRequestConverter;
+import org.citrusframework.restdocs.soap.RestDocSoapResponseConverter;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.restdocs.generate.RestDocumentationGenerator;
-import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
diff --git a/tools/restdocs/src/main/java/org/citrusframework/restdocs/config/xml/RestDocConfigurerParser.java b/tools/restdocs/src/main/java/org/citrusframework/restdocs/config/xml/RestDocConfigurerParser.java
index 17b9b2423a..84cd8d0302 100644
--- a/tools/restdocs/src/main/java/org/citrusframework/restdocs/config/xml/RestDocConfigurerParser.java
+++ b/tools/restdocs/src/main/java/org/citrusframework/restdocs/config/xml/RestDocConfigurerParser.java
@@ -18,12 +18,12 @@
import org.citrusframework.restdocs.http.CitrusRestDocConfigurer;
import org.citrusframework.restdocs.soap.CitrusRestDocSoapConfigurer;
+import org.citrusframework.util.StringUtils;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.restdocs.ManualRestDocumentation;
-import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/AbstractTemplateBasedTestGenerator.java b/tools/test-generator/src/main/java/org/citrusframework/generate/AbstractTemplateBasedTestGenerator.java
index b2fb88be1a..4dc13cdcd6 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/AbstractTemplateBasedTestGenerator.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/AbstractTemplateBasedTestGenerator.java
@@ -16,17 +16,20 @@
package org.citrusframework.generate;
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Properties;
+
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
import org.citrusframework.util.PropertyUtils;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-
-import java.io.*;
-import java.util.Properties;
/**
* Generator creating a new test case from a template.
- *
+ *
* @author Christoph Deppisch
* @since 2.7.4
*/
@@ -64,13 +67,13 @@ protected Properties getTemplateProperties() {
/**
* Read the given template file and replace all test case properties.
- *
+ *
* @param properties the dynamic test case properties.
* @return the final rest file content.
*/
private String createContent(Properties properties) {
StringBuilder contentBuilder = new StringBuilder();
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(new PathMatchingResourcePatternResolver().getResource(getTemplateFilePath()).getInputStream()))) {
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(Resources.newClasspathResource(getTemplateFilePath()).getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
contentBuilder.append(PropertyUtils.replacePropertiesInString(line, properties));
@@ -81,7 +84,7 @@ private String createContent(Properties properties) {
} catch (IOException e) {
throw new CitrusRuntimeException("Failed to create test case, error while accessing test case template file", e);
}
-
+
return contentBuilder.toString();
}
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/dictionary/InboundXmlDataDictionary.java b/tools/test-generator/src/main/java/org/citrusframework/generate/dictionary/InboundXmlDataDictionary.java
index 25013d9f71..918b1ee3b1 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/dictionary/InboundXmlDataDictionary.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/dictionary/InboundXmlDataDictionary.java
@@ -16,13 +16,13 @@
package org.citrusframework.generate.dictionary;
-import javax.xml.xpath.XPathConstants;
import java.util.Map;
+import javax.xml.xpath.XPathConstants;
import org.citrusframework.context.TestContext;
import org.citrusframework.variable.dictionary.xml.XpathMappingDataDictionary;
+import org.citrusframework.xml.namespace.DefaultNamespaceContext;
import org.citrusframework.xml.xpath.XPathUtils;
-import org.springframework.util.xml.SimpleNamespaceContext;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -69,8 +69,8 @@ private T translateIfPresent(Node node, T value, TestContext context) {
for (Map.Entry expressionEntry : mappings.entrySet()) {
String expression = expressionEntry.getKey();
- SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
- namespaceContext.setBindings(context.getNamespaceContextBuilder().getNamespaceMappings());
+ DefaultNamespaceContext namespaceContext = new DefaultNamespaceContext();
+ namespaceContext.addNamespaces(context.getNamespaceContextBuilder().getNamespaceMappings());
NodeList findings = (NodeList) XPathUtils.evaluateExpression(node.getOwnerDocument(), expression, namespaceContext, XPathConstants.NODESET);
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/SwaggerJavaTestGenerator.java b/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/SwaggerJavaTestGenerator.java
index eeec70ae83..0ed6672956 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/SwaggerJavaTestGenerator.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/SwaggerJavaTestGenerator.java
@@ -22,12 +22,6 @@
import java.util.Optional;
import java.util.stream.Collectors;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.generate.SwaggerTestGenerator;
-import org.citrusframework.http.actions.HttpActionBuilder;
-import org.citrusframework.http.message.HttpMessage;
-import org.citrusframework.util.FileUtils;
-import org.citrusframework.variable.dictionary.json.JsonPathMappingDataDictionary;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.TypeSpec;
import io.swagger.models.ArrayModel;
@@ -56,12 +50,17 @@
import io.swagger.models.properties.RefProperty;
import io.swagger.models.properties.StringProperty;
import io.swagger.parser.SwaggerParser;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.generate.SwaggerTestGenerator;
+import org.citrusframework.http.actions.HttpActionBuilder;
+import org.citrusframework.http.message.HttpMessage;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
+import org.citrusframework.variable.dictionary.json.JsonPathMappingDataDictionary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.http.HttpStatus;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
/**
* Test generator creates one to many test cases based on operations defined in a XML schema XSD.
@@ -81,8 +80,8 @@ public class SwaggerJavaTestGenerator extends MessagingJavaTestGenerator path : swagger.getPaths().entrySet()) {
@@ -271,7 +270,7 @@ private String createRandomValueExpression(Property property, Map
payload.append("citrus:currentDate()");
} else if (property instanceof DateTimeProperty) {
payload.append("citrus:currentDate('yyyy-MM-dd'T'hh:mm:ss')");
- } else if (!CollectionUtils.isEmpty(((StringProperty) property).getEnum())) {
+ } else if (((StringProperty)property).getEnum() != null && !((StringProperty) property).getEnum().isEmpty()) {
payload.append("citrus:randomEnumValue(").append(((StringProperty) property).getEnum().stream().map(value -> "'" + value + "'").collect(Collectors.joining(","))).append(")");
} else if (Optional.ofNullable(property.getFormat()).orElse("").equalsIgnoreCase("uuid")) {
payload.append("citrus:randomUUID()");
@@ -411,7 +410,7 @@ private String createValidationExpression(Property property, Map
if (StringUtils.hasText(((StringProperty) property).getPattern())) {
payload.append("@matches(").append(((StringProperty) property).getPattern()).append(")@");
- } else if (!CollectionUtils.isEmpty(((StringProperty) property).getEnum())) {
+ } else if (((StringProperty)property).getEnum() != null && !((StringProperty) property).getEnum().isEmpty()) {
payload.append("@matches(").append(((StringProperty) property).getEnum().stream().collect(Collectors.joining("|"))).append(")@");
} else {
payload.append("@notEmpty()@");
@@ -501,7 +500,7 @@ private String createValidationExpression(AbstractSerializableParameter paramete
return "\"@matchesDatePattern('yyyy-MM-dd'T'hh:mm:ss')@\"";
} else if (StringUtils.hasText(parameter.getPattern())) {
return "\"@matches(" + parameter.getPattern() + ")@\"";
- } else if (!CollectionUtils.isEmpty(parameter.getEnum())) {
+ } else if (parameter.getEnum() != null && !parameter.getEnum().isEmpty()) {
return "\"@matches(" + (parameter.getEnum().stream().collect(Collectors.joining("|"))) + ")@\"";
} else {
return "@notEmpty()@";
@@ -529,7 +528,7 @@ private String createRandomValueExpression(AbstractSerializableParameter paramet
return "\"citrus:currentDate('yyyy-MM-dd'T'hh:mm:ss')\"";
} else if (StringUtils.hasText(parameter.getPattern())) {
return "\"citrus:randomValue(" + parameter.getPattern() + ")\"";
- } else if (!CollectionUtils.isEmpty(parameter.getEnum())) {
+ } else if (parameter.getEnum() != null && !parameter.getEnum().isEmpty()) {
return "\"citrus:randomEnumValue(" + (parameter.getEnum().stream().collect(Collectors.joining(","))) + ")\"";
} else if (Optional.ofNullable(parameter.getFormat()).orElse("").equalsIgnoreCase("uuid")){
return "citrus:randomUUID()";
@@ -619,7 +618,7 @@ public SwaggerJavaTestGenerator withOutboundMappings(Map mapping
* @return
*/
public SwaggerJavaTestGenerator withInboundMappingFile(String mappingFile) {
- this.inboundDataDictionary.setMappingFile(new PathMatchingResourcePatternResolver().getResource(mappingFile));
+ this.inboundDataDictionary.setMappingFile(Resources.create(mappingFile));
this.inboundDataDictionary.initialize();
return this;
}
@@ -630,7 +629,7 @@ public SwaggerJavaTestGenerator withInboundMappingFile(String mappingFile) {
* @return
*/
public SwaggerJavaTestGenerator withOutboundMappingFile(String mappingFile) {
- this.outboundDataDictionary.setMappingFile(new PathMatchingResourcePatternResolver().getResource(mappingFile));
+ this.outboundDataDictionary.setMappingFile(Resources.create(mappingFile));
this.outboundDataDictionary.initialize();
return this;
}
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/WsdlJavaTestGenerator.java b/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/WsdlJavaTestGenerator.java
index d4d90b552f..ee1a418297 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/WsdlJavaTestGenerator.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/WsdlJavaTestGenerator.java
@@ -16,34 +16,34 @@
package org.citrusframework.generate.javadsl;
-import java.io.File;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.regex.Pattern;
+import org.apache.xmlbeans.SchemaType;
+import org.apache.xmlbeans.SchemaTypeSystem;
+import org.apache.xmlbeans.XmlBeans;
+import org.apache.xmlbeans.XmlError;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.generate.WsdlTestGenerator;
import org.citrusframework.generate.dictionary.InboundXmlDataDictionary;
import org.citrusframework.generate.dictionary.OutboundXmlDataDictionary;
import org.citrusframework.message.Message;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.util.XMLUtils;
import org.citrusframework.ws.message.SoapMessage;
import org.citrusframework.xml.XmlConfigurer;
-import org.apache.xmlbeans.SchemaType;
-import org.apache.xmlbeans.SchemaTypeSystem;
-import org.apache.xmlbeans.XmlBeans;
-import org.apache.xmlbeans.XmlError;
-import org.apache.xmlbeans.XmlException;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlOptions;
-import org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.util.StringUtils;
/**
* Test generator creates one to many test cases based on operations defined in a XML schema XSD.
@@ -55,14 +55,16 @@ public class WsdlJavaTestGenerator extends MessagingJavaTestGenerator", cursor));
- int noNs = StringUtils.countOccurrencesOf(nsWsdlOrig, "xmlns:");
+ int noNs = (int) COUNT_NS.matcher(nsWsdlOrig).results().count();
String[] namespacesWsdl = new String[noNs];
cursor = 0;
for (int i=0; i mappings)
* @return
*/
public WsdlJavaTestGenerator withInboundMappingFile(String mappingFile) {
- this.inboundDataDictionary.setMappingFile(new PathMatchingResourcePatternResolver().getResource(mappingFile));
+ this.inboundDataDictionary.setMappingFile(Resources.create(mappingFile));
this.inboundDataDictionary.initialize();
return this;
}
@@ -430,7 +422,7 @@ public WsdlJavaTestGenerator withInboundMappingFile(String mappingFile) {
* @return
*/
public WsdlJavaTestGenerator withOutboundMappingFile(String mappingFile) {
- this.outboundDataDictionary.setMappingFile(new PathMatchingResourcePatternResolver().getResource(mappingFile));
+ this.outboundDataDictionary.setMappingFile(Resources.create(mappingFile));
this.outboundDataDictionary.initialize();
return this;
}
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/XsdJavaTestGenerator.java b/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/XsdJavaTestGenerator.java
index ba5c75f5de..54a5a69a0d 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/XsdJavaTestGenerator.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/XsdJavaTestGenerator.java
@@ -16,11 +16,15 @@
package org.citrusframework.generate.javadsl;
-import java.io.File;
-import java.io.IOException;
import java.util.Collections;
import java.util.Map;
+import org.apache.xmlbeans.SchemaType;
+import org.apache.xmlbeans.SchemaTypeSystem;
+import org.apache.xmlbeans.XmlBeans;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.generate.XsdTestGenerator;
@@ -28,16 +32,11 @@
import org.citrusframework.generate.dictionary.OutboundXmlDataDictionary;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.util.XMLUtils;
import org.citrusframework.xml.XmlConfigurer;
-import org.apache.xmlbeans.SchemaType;
-import org.apache.xmlbeans.SchemaTypeSystem;
-import org.apache.xmlbeans.XmlBeans;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlOptions;
-import org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.util.StringUtils;
/**
* Test generator creates one to many test cases based on operations defined in a XML schema XSD.
@@ -53,8 +52,8 @@ public class XsdJavaTestGenerator extends MessagingJavaTestGenerator mappings) {
* @return
*/
public XsdJavaTestGenerator withInboundMappingFile(String mappingFile) {
- this.inboundDataDictionary.setMappingFile(new PathMatchingResourcePatternResolver().getResource(mappingFile));
+ this.inboundDataDictionary.setMappingFile(Resources.create(mappingFile));
this.inboundDataDictionary.initialize();
return this;
}
@@ -267,7 +257,7 @@ public XsdJavaTestGenerator withInboundMappingFile(String mappingFile) {
* @return
*/
public XsdJavaTestGenerator withOutboundMappingFile(String mappingFile) {
- this.outboundDataDictionary.setMappingFile(new PathMatchingResourcePatternResolver().getResource(mappingFile));
+ this.outboundDataDictionary.setMappingFile(Resources.create(mappingFile));
this.outboundDataDictionary.initialize();
return this;
}
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/MessageCodeProvider.java b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/MessageCodeProvider.java
index 5e6581d81b..b750104ad9 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/MessageCodeProvider.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/MessageCodeProvider.java
@@ -18,11 +18,10 @@
import java.util.Optional;
+import com.squareup.javapoet.CodeBlock;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageHeaders;
-import com.squareup.javapoet.CodeBlock;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
public class MessageCodeProvider {
@@ -33,14 +32,13 @@ public void provideHeaderAndPayload(final CodeBlock.Builder code, final Message
}
private void provideMessage(final CodeBlock.Builder code, final Message message) {
- if (StringUtils.hasText(message.getPayload(String.class))
- || !CollectionUtils.isEmpty(message.getHeaders())) {
+ if (StringUtils.hasText(message.getPayload(String.class)) || !message.getHeaders().isEmpty()) {
code.add(".message()\n", message.getPayload(String.class));
}
}
private void provideHeader(final CodeBlock.Builder code, final Message message) {
- if (!CollectionUtils.isEmpty(message.getHeaders())) {
+ if (!message.getHeaders().isEmpty()) {
message.getHeaders().entrySet().stream()
.filter(entry -> !entry.getKey().startsWith(MessageHeaders.PREFIX))
.forEach(entry -> code.add(
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/ReceiveActionProvider.java b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/ReceiveActionProvider.java
index 7f9f4e6428..edbbc10296 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/ReceiveActionProvider.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/ReceiveActionProvider.java
@@ -16,12 +16,11 @@
package org.citrusframework.generate.provider;
+import java.util.Optional;
+
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageHeaders;
import org.citrusframework.model.testcase.core.ReceiveModel;
-import org.springframework.util.CollectionUtils;
-
-import java.util.Optional;
/**
* @author Christoph Deppisch
@@ -39,7 +38,7 @@ public ReceiveModel getAction(String endpoint, Message message) {
receiveMessage.setData(message.getPayload(String.class));
receive.setMessage(receiveMessage);
- if (!CollectionUtils.isEmpty(message.getHeaders())) {
+ if (message.getHeaders() != null && !message.getHeaders().isEmpty()) {
ReceiveModel.Header header = new ReceiveModel.Header();
message.getHeaders().entrySet().stream()
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/SendActionProvider.java b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/SendActionProvider.java
index 95bc03528b..278a8d4318 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/SendActionProvider.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/SendActionProvider.java
@@ -16,12 +16,11 @@
package org.citrusframework.generate.provider;
+import java.util.Optional;
+
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageHeaders;
import org.citrusframework.model.testcase.core.SendModel;
-import org.springframework.util.CollectionUtils;
-
-import java.util.Optional;
/**
* @author Christoph Deppisch
@@ -39,7 +38,7 @@ public SendModel getAction(String endpoint, Message message) {
sendMessage.setData(message.getPayload(String.class));
send.setMessage(sendMessage);
- if (!CollectionUtils.isEmpty(message.getHeaders())) {
+ if (message.getHeaders() != null && !message.getHeaders().isEmpty()) {
SendModel.Header header = new SendModel.Header();
message.getHeaders().entrySet().stream()
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/http/HttpCodeProvider.java b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/http/HttpCodeProvider.java
index b05768ede5..a777893338 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/http/HttpCodeProvider.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/http/HttpCodeProvider.java
@@ -19,12 +19,11 @@
import java.util.Optional;
import java.util.stream.Stream;
+import com.squareup.javapoet.CodeBlock;
import org.citrusframework.generate.provider.MessageCodeProvider;
import org.citrusframework.http.message.HttpMessage;
-import com.squareup.javapoet.CodeBlock;
+import org.citrusframework.util.StringUtils;
import org.springframework.http.HttpStatus;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMethod;
class HttpCodeProvider {
@@ -67,7 +66,7 @@ private void providePath(final CodeBlock.Builder code, final HttpMessage message
}
private void provideQueryParameter(final CodeBlock.Builder code, final HttpMessage message) {
- if (!CollectionUtils.isEmpty(message.getQueryParams())) {
+ if (message.getQueryParams() != null && !message.getQueryParams().isEmpty()) {
message.getQueryParams()
.forEach((key, values) ->
values.forEach(value ->
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/http/ReceiveHttpRequestActionProvider.java b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/http/ReceiveHttpRequestActionProvider.java
index b38c148cd2..0fd7a525fd 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/http/ReceiveHttpRequestActionProvider.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/http/ReceiveHttpRequestActionProvider.java
@@ -16,19 +16,18 @@
package org.citrusframework.generate.provider.http;
+import java.util.Optional;
+import java.util.stream.Stream;
+
import org.citrusframework.generate.provider.MessageActionProvider;
import org.citrusframework.http.message.HttpMessage;
import org.citrusframework.message.MessageHeaders;
import org.citrusframework.model.testcase.http.ParamType;
import org.citrusframework.model.testcase.http.ReceiveRequestModel;
import org.citrusframework.model.testcase.http.ServerRequestType;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMethod;
-import java.util.Optional;
-import java.util.stream.Stream;
-
/**
* @author Christoph Deppisch
* @since 2.7.4
@@ -64,7 +63,7 @@ public ReceiveRequestModel getAction(String endpoint, HttpMessage message) {
requestType.setHeaders(requestHeaders);
- if (!CollectionUtils.isEmpty(message.getQueryParams())) {
+ if (message.getQueryParams() != null && !message.getQueryParams().isEmpty()) {
message.getQueryParams()
.forEach((key, values) ->
values.forEach(value -> {
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/http/SendHttpRequestActionProvider.java b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/http/SendHttpRequestActionProvider.java
index 9ac09a781a..fa8defbd90 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/http/SendHttpRequestActionProvider.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/http/SendHttpRequestActionProvider.java
@@ -16,6 +16,9 @@
package org.citrusframework.generate.provider.http;
+import java.util.Optional;
+import java.util.stream.Stream;
+
import org.citrusframework.generate.provider.MessageActionProvider;
import org.citrusframework.http.message.HttpMessage;
import org.citrusframework.message.MessageHeaders;
@@ -23,13 +26,9 @@
import org.citrusframework.model.testcase.http.ParamType;
import org.citrusframework.model.testcase.http.RequestHeadersType;
import org.citrusframework.model.testcase.http.SendRequestModel;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMethod;
-import java.util.Optional;
-import java.util.stream.Stream;
-
/**
* @author Christoph Deppisch
* @since 2.7.4
@@ -64,7 +63,7 @@ public SendRequestModel getAction(String endpoint, HttpMessage message) {
requestType.setHeaders(requestHeaders);
- if (!CollectionUtils.isEmpty(message.getQueryParams())) {
+ if (message.getQueryParams() != null && !message.getQueryParams().isEmpty()) {
message.getQueryParams()
.forEach((key, values) ->
values.forEach(value -> {
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/ReceiveSoapRequestActionProvider.java b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/ReceiveSoapRequestActionProvider.java
index e76b131a2c..54aea491b6 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/ReceiveSoapRequestActionProvider.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/ReceiveSoapRequestActionProvider.java
@@ -16,13 +16,12 @@
package org.citrusframework.generate.provider.soap;
+import java.util.Optional;
+
import org.citrusframework.generate.provider.MessageActionProvider;
import org.citrusframework.message.MessageHeaders;
import org.citrusframework.model.testcase.ws.ReceiveModel;
import org.citrusframework.ws.message.SoapMessage;
-import org.springframework.util.CollectionUtils;
-
-import java.util.Optional;
/**
* @author Christoph Deppisch
@@ -42,7 +41,7 @@ public ReceiveModel getAction(String endpoint, SoapMessage message) {
receiveMessage.setData(message.getPayload(String.class));
request.setMessage(receiveMessage);
- if (!CollectionUtils.isEmpty(message.getHeaders())) {
+ if (message.getHeaders() != null && !message.getHeaders().isEmpty()) {
org.citrusframework.model.testcase.core.ReceiveModel.Header header = new org.citrusframework.model.testcase.core.ReceiveModel.Header();
message.getHeaders().entrySet().stream()
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/ReceiveSoapResponseActionProvider.java b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/ReceiveSoapResponseActionProvider.java
index 3cfa7720b9..f4fee677e3 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/ReceiveSoapResponseActionProvider.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/ReceiveSoapResponseActionProvider.java
@@ -16,13 +16,12 @@
package org.citrusframework.generate.provider.soap;
+import java.util.Optional;
+
import org.citrusframework.generate.provider.MessageActionProvider;
import org.citrusframework.message.MessageHeaders;
import org.citrusframework.model.testcase.ws.ReceiveModel;
import org.citrusframework.ws.message.SoapMessage;
-import org.springframework.util.CollectionUtils;
-
-import java.util.Optional;
/**
* @author Christoph Deppisch
@@ -40,7 +39,7 @@ public ReceiveModel getAction(String endpoint, SoapMessage message) {
receiveMessage.setData(message.getPayload(String.class));
response.setMessage(receiveMessage);
- if (!CollectionUtils.isEmpty(message.getHeaders())) {
+ if (message.getHeaders() != null && !message.getHeaders().isEmpty()) {
org.citrusframework.model.testcase.core.ReceiveModel.Header header = new org.citrusframework.model.testcase.core.ReceiveModel.Header();
message.getHeaders().entrySet().stream()
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/SendSoapRequestActionProvider.java b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/SendSoapRequestActionProvider.java
index 8d64d82394..c4f260ebf9 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/SendSoapRequestActionProvider.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/SendSoapRequestActionProvider.java
@@ -16,13 +16,12 @@
package org.citrusframework.generate.provider.soap;
+import java.util.Optional;
+
import org.citrusframework.generate.provider.MessageActionProvider;
import org.citrusframework.message.MessageHeaders;
import org.citrusframework.model.testcase.ws.SendModel;
import org.citrusframework.ws.message.SoapMessage;
-import org.springframework.util.CollectionUtils;
-
-import java.util.Optional;
/**
* @author Christoph Deppisch
@@ -44,7 +43,7 @@ public SendModel getAction(String endpoint, SoapMessage message) {
request.setContentType("application/xml");
- if (!CollectionUtils.isEmpty(message.getHeaders())) {
+ if (message.getHeaders() != null && !message.getHeaders().isEmpty()) {
org.citrusframework.model.testcase.core.SendModel.Header header = new org.citrusframework.model.testcase.core.SendModel.Header();
message.getHeaders().entrySet().stream()
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/SendSoapResponseActionProvider.java b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/SendSoapResponseActionProvider.java
index 73a99bd09e..202f5d4cd3 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/SendSoapResponseActionProvider.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/provider/soap/SendSoapResponseActionProvider.java
@@ -16,13 +16,12 @@
package org.citrusframework.generate.provider.soap;
+import java.util.Optional;
+
import org.citrusframework.generate.provider.MessageActionProvider;
import org.citrusframework.message.MessageHeaders;
import org.citrusframework.model.testcase.ws.SendModel;
import org.citrusframework.ws.message.SoapMessage;
-import org.springframework.util.CollectionUtils;
-
-import java.util.Optional;
/**
* @author Christoph Deppisch
@@ -40,7 +39,7 @@ public SendModel getAction(String endpoint, SoapMessage message) {
sendMessage.setData(message.getPayload(String.class));
response.setMessage(sendMessage);
- if (!CollectionUtils.isEmpty(message.getHeaders())) {
+ if (message.getHeaders() != null && !message.getHeaders().isEmpty()) {
org.citrusframework.model.testcase.core.SendModel.Header header = new org.citrusframework.model.testcase.core.SendModel.Header();
message.getHeaders().entrySet().stream()
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/xml/SwaggerXmlTestGenerator.java b/tools/test-generator/src/main/java/org/citrusframework/generate/xml/SwaggerXmlTestGenerator.java
index 6e4535ff36..2d05d937c0 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/xml/SwaggerXmlTestGenerator.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/xml/SwaggerXmlTestGenerator.java
@@ -22,12 +22,6 @@
import java.util.Optional;
import java.util.stream.Collectors;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.generate.SwaggerTestGenerator;
-import org.citrusframework.http.message.HttpMessage;
-import org.citrusframework.model.testcase.http.ObjectFactory;
-import org.citrusframework.util.FileUtils;
-import org.citrusframework.variable.dictionary.json.JsonPathMappingDataDictionary;
import io.swagger.models.ArrayModel;
import io.swagger.models.HttpMethod;
import io.swagger.models.Model;
@@ -54,14 +48,18 @@
import io.swagger.models.properties.RefProperty;
import io.swagger.models.properties.StringProperty;
import io.swagger.parser.SwaggerParser;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.generate.SwaggerTestGenerator;
+import org.citrusframework.http.message.HttpMessage;
+import org.citrusframework.model.testcase.http.ObjectFactory;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
+import org.citrusframework.variable.dictionary.json.JsonPathMappingDataDictionary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.http.HttpStatus;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
/**
* Test generator creates one to many test cases based on operations defined in a XML schema XSD.
@@ -88,13 +86,13 @@ public class SwaggerXmlTestGenerator extends MessagingXmlTestGenerator path : swagger.getPaths().entrySet()) {
@@ -183,7 +181,7 @@ protected List getMarshallerContextPaths() {
@Override
protected List getMarshallerSchemas() {
List schemas = super.getMarshallerSchemas();
- schemas.add(new ClassPathResource("org/citrusframework/schema/citrus-http-testcase.xsd"));
+ schemas.add(Resources.newClasspathResource("org/citrusframework/schema/citrus-http-testcase.xsd"));
return schemas;
}
@@ -279,7 +277,7 @@ private String createRandomValueExpression(Property property, Map
payload.append("citrus:currentDate()");
} else if (property instanceof DateTimeProperty) {
payload.append("citrus:currentDate('yyyy-MM-dd'T'hh:mm:ss')");
- } else if (!CollectionUtils.isEmpty(((StringProperty) property).getEnum())) {
+ } else if (((StringProperty)((StringProperty) property).getEnum()) != null && !((StringProperty) property).getEnum().isEmpty()) {
payload.append("citrus:randomEnumValue(").append(((StringProperty) property).getEnum().stream().map(value -> "'" + value + "'").collect(Collectors.joining(","))).append(")");
} else if (Optional.ofNullable(property.getFormat()).orElse("").equalsIgnoreCase("uuid")) {
payload.append("citrus:randomUUID()");
@@ -419,7 +417,7 @@ private String createValidationExpression(Property property, Map
if (StringUtils.hasText(((StringProperty) property).getPattern())) {
payload.append("@matches(").append(((StringProperty) property).getPattern()).append(")@");
- } else if (!CollectionUtils.isEmpty(((StringProperty) property).getEnum())) {
+ } else if (((StringProperty) property).getEnum() != null && !((StringProperty) property).getEnum().isEmpty()) {
payload.append("@matches(").append(((StringProperty) property).getEnum().stream().collect(Collectors.joining("|"))).append(")@");
} else {
payload.append("@notEmpty()@");
@@ -509,7 +507,7 @@ private String createValidationExpression(AbstractSerializableParameter paramete
return "\"@matchesDatePattern('yyyy-MM-dd'T'hh:mm:ss')@\"";
} else if (StringUtils.hasText(parameter.getPattern())) {
return "\"@matches(" + parameter.getPattern() + ")@\"";
- } else if (!CollectionUtils.isEmpty(parameter.getEnum())) {
+ } else if (parameter.getEnum() != null && !parameter.getEnum().isEmpty()) {
return "\"@matches(" + (parameter.getEnum().stream().collect(Collectors.joining("|"))) + ")@\"";
} else {
return "@notEmpty()@";
@@ -537,7 +535,7 @@ private String createRandomValueExpression(AbstractSerializableParameter paramet
return "\"citrus:currentDate('yyyy-MM-dd'T'hh:mm:ss')\"";
} else if (StringUtils.hasText(parameter.getPattern())) {
return "\"citrus:randomValue(" + parameter.getPattern() + ")\"";
- } else if (!CollectionUtils.isEmpty(parameter.getEnum())) {
+ } else if (parameter.getEnum() != null && !parameter.getEnum().isEmpty()) {
return "\"citrus:randomEnumValue(" + (parameter.getEnum().stream().collect(Collectors.joining(","))) + ")\"";
} else if (Optional.ofNullable(parameter.getFormat()).orElse("").equalsIgnoreCase("uuid")){
return "citrus:randomUUID()";
@@ -627,7 +625,7 @@ public SwaggerXmlTestGenerator withOutboundMappings(Map mappings
* @return
*/
public SwaggerXmlTestGenerator withInboundMappingFile(String mappingFile) {
- this.inboundDataDictionary.setMappingFile(new PathMatchingResourcePatternResolver().getResource(mappingFile));
+ this.inboundDataDictionary.setMappingFile(Resources.create(mappingFile));
this.inboundDataDictionary.initialize();
return this;
}
@@ -638,7 +636,7 @@ public SwaggerXmlTestGenerator withInboundMappingFile(String mappingFile) {
* @return
*/
public SwaggerXmlTestGenerator withOutboundMappingFile(String mappingFile) {
- this.outboundDataDictionary.setMappingFile(new PathMatchingResourcePatternResolver().getResource(mappingFile));
+ this.outboundDataDictionary.setMappingFile(Resources.create(mappingFile));
this.outboundDataDictionary.initialize();
return this;
}
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/xml/TestActionMarshaller.java b/tools/test-generator/src/main/java/org/citrusframework/generate/xml/TestActionMarshaller.java
index 421b96aace..8849ecbc5a 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/xml/TestActionMarshaller.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/xml/TestActionMarshaller.java
@@ -16,14 +16,14 @@
package org.citrusframework.generate.xml;
-import jakarta.xml.bind.JAXBException;
import javax.xml.transform.Result;
+import jakarta.xml.bind.JAXBException;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resource;
import org.citrusframework.xml.Jaxb2Marshaller;
import org.citrusframework.xml.Marshaller;
import org.citrusframework.xml.namespace.CitrusNamespacePrefixMapper;
-import org.springframework.core.io.Resource;
/**
* @author Christoph Deppisch
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/xml/WsdlXmlTestGenerator.java b/tools/test-generator/src/main/java/org/citrusframework/generate/xml/WsdlXmlTestGenerator.java
index 016bfc873a..6a37b51ffe 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/xml/WsdlXmlTestGenerator.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/xml/WsdlXmlTestGenerator.java
@@ -17,12 +17,20 @@
package org.citrusframework.generate.xml;
import java.io.File;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.regex.Pattern;
+import org.apache.xmlbeans.SchemaType;
+import org.apache.xmlbeans.SchemaTypeSystem;
+import org.apache.xmlbeans.XmlBeans;
+import org.apache.xmlbeans.XmlError;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.generate.WsdlTestGenerator;
@@ -30,23 +38,14 @@
import org.citrusframework.generate.dictionary.OutboundXmlDataDictionary;
import org.citrusframework.message.Message;
import org.citrusframework.model.testcase.ws.ObjectFactory;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.util.XMLUtils;
import org.citrusframework.ws.message.SoapMessage;
import org.citrusframework.xml.XmlConfigurer;
-import org.apache.xmlbeans.SchemaType;
-import org.apache.xmlbeans.SchemaTypeSystem;
-import org.apache.xmlbeans.XmlBeans;
-import org.apache.xmlbeans.XmlError;
-import org.apache.xmlbeans.XmlException;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlOptions;
-import org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.util.StringUtils;
/**
* Test generator creates one to many test cases based on operations defined in a XML schema XSD.
@@ -58,14 +57,15 @@ public class WsdlXmlTestGenerator extends MessagingXmlTestGenerator getMarshallerContextPaths() {
@Override
protected List getMarshallerSchemas() {
List schemas = super.getMarshallerSchemas();
- schemas.add(new ClassPathResource("org/citrusframework/schema/citrus-http-testcase.xsd"));
- schemas.add(new ClassPathResource("org/citrusframework/schema/citrus-ws-testcase.xsd"));
+ schemas.add(Resources.newClasspathResource("org/citrusframework/schema/citrus-http-testcase.xsd"));
+ schemas.add(Resources.newClasspathResource("org/citrusframework/schema/citrus-ws-testcase.xsd"));
return schemas;
}
@@ -186,8 +186,8 @@ protected Message generateOutboundMessage(Message message) {
private XmlObject compileWsdl(String wsdl) {
File wsdlFile;
try {
- wsdlFile = new PathMatchingResourcePatternResolver().getResource(wsdl).getFile();
- } catch (IOException e) {
+ wsdlFile = Resources.create(wsdl).getFile();
+ } catch (Exception e) {
wsdlFile = new File(wsdl);
}
@@ -340,7 +340,7 @@ private String extractSchemaNamespacePrefix(XmlObject wsdl) {
private String[] extractNamespacesOnWsdlLevel(XmlObject wsdl) {
int cursor = wsdl.xmlText().indexOf(":") + ":definitions ".length();
String nsWsdlOrig = wsdl.xmlText().substring(cursor, wsdl.xmlText().indexOf(">", cursor));
- int noNs = StringUtils.countOccurrencesOf(nsWsdlOrig, "xmlns:");
+ int noNs = (int) COUNT_NS.matcher(nsWsdlOrig).results().count();
String[] namespacesWsdl = new String[noNs];
cursor = 0;
for (int i=0; i mappings) {
* @return
*/
public WsdlXmlTestGenerator withInboundMappingFile(String mappingFile) {
- this.inboundDataDictionary.setMappingFile(new PathMatchingResourcePatternResolver().getResource(mappingFile));
+ this.inboundDataDictionary.setMappingFile(Resources.create(mappingFile));
this.inboundDataDictionary.initialize();
return this;
}
@@ -448,7 +448,7 @@ public WsdlXmlTestGenerator withInboundMappingFile(String mappingFile) {
* @return
*/
public WsdlXmlTestGenerator withOutboundMappingFile(String mappingFile) {
- this.outboundDataDictionary.setMappingFile(new PathMatchingResourcePatternResolver().getResource(mappingFile));
+ this.outboundDataDictionary.setMappingFile(Resources.create(mappingFile));
this.outboundDataDictionary.initialize();
return this;
}
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/xml/XmlTestGenerator.java b/tools/test-generator/src/main/java/org/citrusframework/generate/xml/XmlTestGenerator.java
index de0d8df748..63dcd8aeb5 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/xml/XmlTestGenerator.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/xml/XmlTestGenerator.java
@@ -22,7 +22,6 @@
import java.util.Properties;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
-
import javax.xml.namespace.QName;
import jakarta.xml.bind.JAXBElement;
@@ -31,10 +30,10 @@
import org.citrusframework.generate.javadsl.JavaTestGenerator;
import org.citrusframework.model.testcase.core.EchoActionType;
import org.citrusframework.model.testcase.core.ObjectFactory;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
import org.citrusframework.xml.StringResult;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
/**
* @author Christoph Deppisch
@@ -78,7 +77,7 @@ protected List getMarshallerContextPaths() {
*/
protected List getMarshallerSchemas() {
List schemas = new ArrayList<>();
- schemas.add(new ClassPathResource("org/citrusframework/schema/citrus-testcase.xsd"));
+ schemas.add(Resources.create("org/citrusframework/schema/citrus-testcase.xsd"));
return schemas;
}
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/xml/XmlTestMarshaller.java b/tools/test-generator/src/main/java/org/citrusframework/generate/xml/XmlTestMarshaller.java
index f6cc4af491..2ee4adbf20 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/xml/XmlTestMarshaller.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/xml/XmlTestMarshaller.java
@@ -16,28 +16,26 @@
package org.citrusframework.generate.xml;
+import java.util.List;
import javax.xml.XMLConstants;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.sax.SAXSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
-import java.io.IOException;
-import java.util.List;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.xml.namespace.CitrusNamespacePrefixMapper;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;
import jakarta.xml.bind.Unmarshaller;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.exceptions.ValidationException;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.xml.namespace.CitrusNamespacePrefixMapper;
import org.glassfish.jaxb.runtime.marshaller.NamespacePrefixMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
@@ -59,7 +57,7 @@ public class XmlTestMarshaller {
private NamespacePrefixMapper namespacePrefixMapper = new CitrusNamespacePrefixMapper();
public XmlTestMarshaller() {
- this.schema = loadSchema(new ClassPathResource("org/citrusframework/schema/citrus-testcase.xsd"));
+ this.schema = loadSchema(Resources.newClasspathResource("org/citrusframework/schema/citrus-testcase.xsd"));
}
public void marshal(Object graph, Result result) {
@@ -120,27 +118,29 @@ private JAXBContext getOrCreateContext() throws JAXBException {
private Schema loadSchema(Resource resource) {
if (logger.isDebugEnabled()) {
- logger.debug(String.format("Using marshaller validation schema '%s'", resource.getFilename()));
+ logger.debug(String.format("Using marshaller validation schema '%s'", resource.getLocation()));
}
try {
XMLReader xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
- Assert.isTrue(resource != null && resource.exists(), () -> "Resource does not exist: " + resource);
+ if (resource == null || !resource.exists()) {
+ throw new ValidationException("Resource does not exist: " + resource);
+ }
InputSource inputSource = new InputSource(resource.getInputStream());
inputSource.setSystemId(resource.getURI().toString());
Source schemaSource = new SAXSource(xmlReader, inputSource);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
return schemaFactory.newSchema(schemaSource);
- } catch (IOException | SAXException e) {
+ } catch (SAXException e) {
throw new CitrusRuntimeException("Failed to load schema for marshaller", e);
}
}
public void setContextPaths(List contextPaths) {
- this.contextPath = StringUtils.arrayToDelimitedString(contextPaths.toArray(new String[0]), ":");
+ this.contextPath = String.join(":", contextPaths.toArray(new String[0]));
}
public NamespacePrefixMapper getNamespacePrefixMapper() {
diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/xml/XsdXmlTestGenerator.java b/tools/test-generator/src/main/java/org/citrusframework/generate/xml/XsdXmlTestGenerator.java
index 23f58fac44..7acb20537f 100644
--- a/tools/test-generator/src/main/java/org/citrusframework/generate/xml/XsdXmlTestGenerator.java
+++ b/tools/test-generator/src/main/java/org/citrusframework/generate/xml/XsdXmlTestGenerator.java
@@ -16,11 +16,15 @@
package org.citrusframework.generate.xml;
-import java.io.File;
-import java.io.IOException;
import java.util.Collections;
import java.util.Map;
+import org.apache.xmlbeans.SchemaType;
+import org.apache.xmlbeans.SchemaTypeSystem;
+import org.apache.xmlbeans.XmlBeans;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.generate.XsdTestGenerator;
@@ -28,16 +32,11 @@
import org.citrusframework.generate.dictionary.OutboundXmlDataDictionary;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.util.XMLUtils;
import org.citrusframework.xml.XmlConfigurer;
-import org.apache.xmlbeans.SchemaType;
-import org.apache.xmlbeans.SchemaTypeSystem;
-import org.apache.xmlbeans.XmlBeans;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlOptions;
-import org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.util.StringUtils;
/**
* Test generator creates one to many test cases based on operations defined in a XML schema XSD.
@@ -53,8 +52,8 @@ public class XsdXmlTestGenerator extends MessagingXmlTestGenerator mappings) {
* @return
*/
public XsdXmlTestGenerator withInboundMappingFile(String mappingFile) {
- this.inboundDataDictionary.setMappingFile(new PathMatchingResourcePatternResolver().getResource(mappingFile));
+ this.inboundDataDictionary.setMappingFile(Resources.create(mappingFile));
this.inboundDataDictionary.initialize();
return this;
}
@@ -267,7 +257,7 @@ public XsdXmlTestGenerator withInboundMappingFile(String mappingFile) {
* @return
*/
public XsdXmlTestGenerator withOutboundMappingFile(String mappingFile) {
- this.outboundDataDictionary.setMappingFile(new PathMatchingResourcePatternResolver().getResource(mappingFile));
+ this.outboundDataDictionary.setMappingFile(Resources.create(mappingFile));
this.outboundDataDictionary.initialize();
return this;
}
diff --git a/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/JavaDslTestGeneratorTest.java b/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/JavaDslTestGeneratorTest.java
index aa85d1918a..9915836415 100644
--- a/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/JavaDslTestGeneratorTest.java
+++ b/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/JavaDslTestGeneratorTest.java
@@ -8,14 +8,13 @@
import org.citrusframework.generate.UnitFramework;
import org.citrusframework.util.FileUtils;
import org.citrusframework.utils.CleanupUtils;
-import org.springframework.core.io.FileSystemResource;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
public class JavaDslTestGeneratorTest {
- private final JavaDslTestGenerator generatorUnderTest = new JavaDslTestGenerator();
+ private final JavaDslTestGenerator> generatorUnderTest = new JavaDslTestGenerator<>();
private final File testFile = new File(CitrusSettings.DEFAULT_TEST_SRC_DIRECTORY + "/java/org/citrusframework/FooTest.java");
private final CleanupUtils cleanupUtils = new CleanupUtils();
@@ -98,7 +97,7 @@ public void create_should_fail_when_test_name_starts_with_lowercase_letter(){
private String loadTestFile() throws IOException {
Assert.assertTrue(testFile.exists());
- return FileUtils.readToString(new FileSystemResource(testFile));
+ return FileUtils.readToString(testFile);
}
private void assertContains(String haystack, String needle){
diff --git a/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/MessagingJavaTestGeneratorTest.java b/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/MessagingJavaTestGeneratorTest.java
index a6b2a85377..5498c11e5a 100644
--- a/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/MessagingJavaTestGeneratorTest.java
+++ b/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/MessagingJavaTestGeneratorTest.java
@@ -23,7 +23,6 @@
import org.citrusframework.generate.UnitFramework;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.FileSystemResource;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -34,7 +33,7 @@ public class MessagingJavaTestGeneratorTest {
@Test
public void testCreateTest() throws IOException {
- MessagingJavaTestGenerator generator = new MessagingJavaTestGenerator();
+ MessagingJavaTestGenerator> generator = new MessagingJavaTestGenerator<>();
generator.withAuthor("Christoph")
.withDescription("This is a sample test")
@@ -50,7 +49,7 @@ public void testCreateTest() throws IOException {
File javaFile = new File(CitrusSettings.DEFAULT_TEST_SRC_DIRECTORY + "java/org/citrusframework/SampleReqResIT.java");
Assert.assertTrue(javaFile.exists());
- String javaContent = FileUtils.readToString(new FileSystemResource(javaFile));
+ String javaContent = FileUtils.readToString(javaFile);
Assert.assertTrue(javaContent.contains("@author Christoph"));
Assert.assertTrue(javaContent.contains("public class SampleReqResIT"));
Assert.assertTrue(javaContent.contains("* This is a sample test"));
diff --git a/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/SwaggerJavaTestGeneratorTest.java b/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/SwaggerJavaTestGeneratorTest.java
index e785a6def9..f84209ec40 100644
--- a/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/SwaggerJavaTestGeneratorTest.java
+++ b/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/SwaggerJavaTestGeneratorTest.java
@@ -23,7 +23,6 @@
import org.citrusframework.generate.TestGenerator;
import org.citrusframework.generate.UnitFramework;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.FileSystemResource;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -78,7 +77,7 @@ private void verifyTest(String name) throws IOException {
name + FileUtils.FILE_EXTENSION_JAVA);
Assert.assertTrue(javaFile.exists());
- String javaContent = FileUtils.readToString(new FileSystemResource(javaFile));
+ String javaContent = FileUtils.readToString(javaFile);
Assert.assertTrue(javaContent.contains("@author Christoph"));
Assert.assertTrue(javaContent.contains("public class " + name));
Assert.assertTrue(javaContent.contains("* This is a sample test"));
diff --git a/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/WsdlJavaTestGeneratorTest.java b/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/WsdlJavaTestGeneratorTest.java
index 677f2defca..1e55b7378b 100644
--- a/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/WsdlJavaTestGeneratorTest.java
+++ b/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/WsdlJavaTestGeneratorTest.java
@@ -24,7 +24,6 @@
import org.citrusframework.generate.UnitFramework;
import org.citrusframework.util.FileUtils;
import org.citrusframework.utils.CleanupUtils;
-import org.springframework.core.io.FileSystemResource;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -35,7 +34,7 @@
*/
public class WsdlJavaTestGeneratorTest {
- private String testDir = CitrusSettings.DEFAULT_TEST_SRC_DIRECTORY + "java/org/citrusframework/";
+ private final String testDir = CitrusSettings.DEFAULT_TEST_SRC_DIRECTORY + "java/org/citrusframework/";
private final CleanupUtils cleanupUtils = new CleanupUtils();
@@ -66,7 +65,7 @@ private void verifyTest(String name, String requestName, String responseName) th
File javaFile = new File(testDir + name + FileUtils.FILE_EXTENSION_JAVA);
Assert.assertTrue(javaFile.exists());
- String javaContent = FileUtils.readToString(new FileSystemResource(javaFile));
+ String javaContent = FileUtils.readToString(javaFile);
Assert.assertTrue(javaContent.contains("@author Christoph"));
Assert.assertTrue(javaContent.contains("public class " + name));
Assert.assertTrue(javaContent.contains("* This is a sample test"));
diff --git a/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/XsdJavaTestGeneratorTest.java b/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/XsdJavaTestGeneratorTest.java
index 28952faea6..811289bfee 100644
--- a/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/XsdJavaTestGeneratorTest.java
+++ b/tools/test-generator/src/test/java/org/citrusframework/generate/javadsl/XsdJavaTestGeneratorTest.java
@@ -23,7 +23,6 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.generate.UnitFramework;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.FileSystemResource;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -52,7 +51,7 @@ public void testCreateTest(String requestName, String responseName, String gener
File javaFile = new File(CitrusSettings.DEFAULT_TEST_SRC_DIRECTORY + "java/org/citrusframework/HelloIT.java");
Assert.assertTrue(javaFile.exists());
- String javaContent = FileUtils.readToString(new FileSystemResource(javaFile));
+ String javaContent = FileUtils.readToString(javaFile);
Assert.assertTrue(javaContent.contains("@author Christoph"));
Assert.assertTrue(javaContent.contains("public class HelloIT"));
Assert.assertTrue(javaContent.contains("* This is a sample test"));
@@ -91,7 +90,7 @@ public void testCreateTestWithoutResponse() throws IOException {
File javaFile = new File(CitrusSettings.DEFAULT_TEST_SRC_DIRECTORY + "java/org/citrusframework/HelloIT.java");
Assert.assertTrue(javaFile.exists());
- String javaContent = FileUtils.readToString(new FileSystemResource(javaFile));
+ String javaContent = FileUtils.readToString(javaFile);
Assert.assertTrue(javaContent.contains("@author Christoph"));
Assert.assertTrue(javaContent.contains("public class HelloIT"));
Assert.assertTrue(javaContent.contains("* This is a sample test"));
diff --git a/tools/test-generator/src/test/java/org/citrusframework/generate/xml/MessagingXmlTestGeneratorTest.java b/tools/test-generator/src/test/java/org/citrusframework/generate/xml/MessagingXmlTestGeneratorTest.java
index 5947142074..4aa06e705a 100644
--- a/tools/test-generator/src/test/java/org/citrusframework/generate/xml/MessagingXmlTestGeneratorTest.java
+++ b/tools/test-generator/src/test/java/org/citrusframework/generate/xml/MessagingXmlTestGeneratorTest.java
@@ -23,7 +23,6 @@
import org.citrusframework.generate.UnitFramework;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.FileSystemResource;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -34,7 +33,7 @@ public class MessagingXmlTestGeneratorTest {
@Test
public void testCreateTest() throws IOException {
- MessagingXmlTestGenerator generator = new MessagingXmlTestGenerator();
+ MessagingXmlTestGenerator> generator = new MessagingXmlTestGenerator<>();
generator.withAuthor("Christoph")
.withDescription("This is a sample test")
@@ -53,14 +52,14 @@ public void testCreateTest() throws IOException {
File xmlFile = new File(CitrusSettings.DEFAULT_TEST_SRC_DIRECTORY + "resources/org/citrusframework/SampleReqResIT.xml");
Assert.assertTrue(xmlFile.exists());
- String javaContent = FileUtils.readToString(new FileSystemResource(javaFile));
+ String javaContent = FileUtils.readToString(javaFile);
Assert.assertTrue(javaContent.contains("@author Christoph"));
Assert.assertTrue(javaContent.contains("public class SampleReqResIT"));
Assert.assertTrue(javaContent.contains("* This is a sample test"));
Assert.assertTrue(javaContent.contains("package org.citrusframework;"));
Assert.assertTrue(javaContent.contains("extends TestNGCitrusSupport"));
- String xmlContent = FileUtils.readToString(new FileSystemResource(xmlFile));
+ String xmlContent = FileUtils.readToString(xmlFile);
Assert.assertTrue(xmlContent.contains("Christoph "));
Assert.assertTrue(xmlContent.contains("This is a sample test "));
Assert.assertTrue(xmlContent.contains(""));
diff --git a/tools/test-generator/src/test/java/org/citrusframework/generate/xml/SwaggerXmlTestGeneratorTest.java b/tools/test-generator/src/test/java/org/citrusframework/generate/xml/SwaggerXmlTestGeneratorTest.java
index a925693354..6904a7db87 100644
--- a/tools/test-generator/src/test/java/org/citrusframework/generate/xml/SwaggerXmlTestGeneratorTest.java
+++ b/tools/test-generator/src/test/java/org/citrusframework/generate/xml/SwaggerXmlTestGeneratorTest.java
@@ -23,7 +23,6 @@
import org.citrusframework.generate.TestGenerator;
import org.citrusframework.generate.UnitFramework;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.FileSystemResource;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -82,14 +81,14 @@ private void verifyTest(String name) throws IOException {
name + FileUtils.FILE_EXTENSION_XML);
Assert.assertTrue(xmlFile.exists());
- String javaContent = FileUtils.readToString(new FileSystemResource(javaFile));
+ String javaContent = FileUtils.readToString(javaFile);
Assert.assertTrue(javaContent.contains("@author Christoph"));
Assert.assertTrue(javaContent.contains("public class " + name));
Assert.assertTrue(javaContent.contains("* This is a sample test"));
Assert.assertTrue(javaContent.contains("package org.citrusframework;"));
Assert.assertTrue(javaContent.contains("extends TestNGCitrusSupport"));
- String xmlContent = FileUtils.readToString(new FileSystemResource(xmlFile));
+ String xmlContent = FileUtils.readToString(xmlFile);
Assert.assertTrue(xmlContent.contains("Christoph "));
Assert.assertTrue(xmlContent.contains("This is a sample test "));
Assert.assertTrue(xmlContent.contains(""));
diff --git a/tools/test-generator/src/test/java/org/citrusframework/generate/xml/WsdlXmlTestGeneratorTest.java b/tools/test-generator/src/test/java/org/citrusframework/generate/xml/WsdlXmlTestGeneratorTest.java
index c19d19ea33..dafa58bcbe 100644
--- a/tools/test-generator/src/test/java/org/citrusframework/generate/xml/WsdlXmlTestGeneratorTest.java
+++ b/tools/test-generator/src/test/java/org/citrusframework/generate/xml/WsdlXmlTestGeneratorTest.java
@@ -22,7 +22,6 @@
import org.citrusframework.CitrusSettings;
import org.citrusframework.generate.UnitFramework;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.FileSystemResource;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -59,14 +58,14 @@ private void verifyTest(String name, String requestName, String responseName) th
name + FileUtils.FILE_EXTENSION_XML);
Assert.assertTrue(xmlFile.exists());
- String javaContent = FileUtils.readToString(new FileSystemResource(javaFile));
+ String javaContent = FileUtils.readToString(javaFile);
Assert.assertTrue(javaContent.contains("@author Christoph"));
Assert.assertTrue(javaContent.contains("public class " + name));
Assert.assertTrue(javaContent.contains("* This is a sample test"));
Assert.assertTrue(javaContent.contains("package org.citrusframework;"));
Assert.assertTrue(javaContent.contains("extends TestNGCitrusSupport"));
- String xmlContent = FileUtils.readToString(new FileSystemResource(xmlFile));
+ String xmlContent = FileUtils.readToString(xmlFile);
Assert.assertTrue(xmlContent.contains("Christoph "));
Assert.assertTrue(xmlContent.contains("This is a sample test "));
Assert.assertTrue(xmlContent.contains(""));
diff --git a/tools/test-generator/src/test/java/org/citrusframework/generate/xml/XmlTestGeneratorTest.java b/tools/test-generator/src/test/java/org/citrusframework/generate/xml/XmlTestGeneratorTest.java
index dbf28d2bf0..8698ef5a70 100644
--- a/tools/test-generator/src/test/java/org/citrusframework/generate/xml/XmlTestGeneratorTest.java
+++ b/tools/test-generator/src/test/java/org/citrusframework/generate/xml/XmlTestGeneratorTest.java
@@ -21,10 +21,10 @@
import org.citrusframework.CitrusSettings;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.generate.TestGenerator;
import org.citrusframework.generate.TestGeneratorMain;
import org.citrusframework.generate.UnitFramework;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.FileSystemResource;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -35,7 +35,7 @@ public class XmlTestGeneratorTest {
@Test
public void testCreateTestNGTest() throws IOException {
- XmlTestGenerator generator = (XmlTestGenerator) new XmlTestGenerator()
+ TestGenerator> generator = new XmlTestGenerator<>()
.withAuthor("Christoph")
.withDescription("This is a sample test")
.withName("SampleIT")
@@ -50,14 +50,14 @@ public void testCreateTestNGTest() throws IOException {
File xmlFile = new File(CitrusSettings.DEFAULT_TEST_SRC_DIRECTORY + "resources/org/citrusframework/SampleIT.xml");
Assert.assertTrue(xmlFile.exists());
- String javaContent = FileUtils.readToString(new FileSystemResource(javaFile));
+ String javaContent = FileUtils.readToString(javaFile);
Assert.assertTrue(javaContent.contains("@author Christoph"));
Assert.assertTrue(javaContent.contains("public class SampleIT"));
Assert.assertTrue(javaContent.contains("* This is a sample test"));
Assert.assertTrue(javaContent.contains("package org.citrusframework;"));
Assert.assertTrue(javaContent.contains("extends TestNGCitrusSupport"));
- String xmlContent = FileUtils.readToString(new FileSystemResource(xmlFile));
+ String xmlContent = FileUtils.readToString(xmlFile);
Assert.assertTrue(xmlContent.contains("Christoph "));
Assert.assertTrue(xmlContent.contains("This is a sample test "));
Assert.assertTrue(xmlContent.contains(""));
@@ -65,7 +65,7 @@ public void testCreateTestNGTest() throws IOException {
@Test
public void testCreateJUnitTest() throws IOException {
- XmlTestGenerator generator = (XmlTestGenerator) new XmlTestGenerator()
+ TestGenerator> generator = new XmlTestGenerator<>()
.withAuthor("Christoph")
.withDescription("This is a sample test")
.withName("SampleIT")
@@ -80,14 +80,14 @@ public void testCreateJUnitTest() throws IOException {
File xmlFile = new File(CitrusSettings.DEFAULT_TEST_SRC_DIRECTORY + "resources/org/citrusframework/SampleIT.xml");
Assert.assertTrue(xmlFile.exists());
- String javaContent = FileUtils.readToString(new FileSystemResource(javaFile));
+ String javaContent = FileUtils.readToString(javaFile);
Assert.assertTrue(javaContent.contains("@author Christoph"));
Assert.assertTrue(javaContent.contains("public class SampleIT"));
Assert.assertTrue(javaContent.contains("* This is a sample test"));
Assert.assertTrue(javaContent.contains("package org.citrusframework;"));
Assert.assertTrue(javaContent.contains("extends JUnit4CitrusSupport"));
- String xmlContent = FileUtils.readToString(new FileSystemResource(xmlFile));
+ String xmlContent = FileUtils.readToString(xmlFile);
Assert.assertTrue(xmlContent.contains("Christoph "));
Assert.assertTrue(xmlContent.contains("This is a sample test "));
Assert.assertTrue(xmlContent.contains(""));
@@ -95,7 +95,7 @@ public void testCreateJUnitTest() throws IOException {
@Test
public void testInvalidName() throws IOException {
- XmlTestGenerator generator = (XmlTestGenerator) new XmlTestGenerator()
+ TestGenerator> generator = new XmlTestGenerator<>()
.withAuthor("Christoph")
.withDescription("This is a sample test")
.withName("sampletest")
@@ -120,14 +120,14 @@ public void testDefaultValues() throws IOException {
File xmlFile = new File(CitrusSettings.DEFAULT_TEST_SRC_DIRECTORY + "resources/org/citrusframework/SampleIT.xml");
Assert.assertTrue(xmlFile.exists());
- String javaContent = FileUtils.readToString(new FileSystemResource(javaFile));
+ String javaContent = FileUtils.readToString(javaFile);
Assert.assertTrue(javaContent.contains("@author Unknown"));
Assert.assertTrue(javaContent.contains("public class SampleIT"));
Assert.assertTrue(javaContent.contains("* TODO: Description"));
Assert.assertTrue(javaContent.contains("package org.citrusframework;"));
Assert.assertTrue(javaContent.contains("extends TestNGCitrusSupport"));
- String xmlContent = FileUtils.readToString(new FileSystemResource(xmlFile));
+ String xmlContent = FileUtils.readToString(xmlFile);
Assert.assertTrue(xmlContent.contains("Unknown "));
Assert.assertTrue(xmlContent.contains("TODO: Description "));
Assert.assertTrue(xmlContent.contains(""));
diff --git a/tools/test-generator/src/test/java/org/citrusframework/generate/xml/XsdXmlTestGeneratorTest.java b/tools/test-generator/src/test/java/org/citrusframework/generate/xml/XsdXmlTestGeneratorTest.java
index 6d03b888ae..12f0acc507 100644
--- a/tools/test-generator/src/test/java/org/citrusframework/generate/xml/XsdXmlTestGeneratorTest.java
+++ b/tools/test-generator/src/test/java/org/citrusframework/generate/xml/XsdXmlTestGeneratorTest.java
@@ -23,7 +23,6 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.generate.UnitFramework;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.FileSystemResource;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -55,14 +54,14 @@ public void testCreateTest(String requestName, String responseName, String gener
File xmlFile = new File(CitrusSettings.DEFAULT_TEST_SRC_DIRECTORY + "resources/org/citrusframework/HelloIT.xml");
Assert.assertTrue(xmlFile.exists());
- String javaContent = FileUtils.readToString(new FileSystemResource(javaFile));
+ String javaContent = FileUtils.readToString(javaFile);
Assert.assertTrue(javaContent.contains("@author Christoph"));
Assert.assertTrue(javaContent.contains("public class HelloIT"));
Assert.assertTrue(javaContent.contains("* This is a sample test"));
Assert.assertTrue(javaContent.contains("package org.citrusframework;"));
Assert.assertTrue(javaContent.contains("extends TestNGCitrusSupport"));
- String xmlContent = FileUtils.readToString(new FileSystemResource(xmlFile));
+ String xmlContent = FileUtils.readToString(xmlFile);
Assert.assertTrue(xmlContent.contains("Christoph "));
Assert.assertTrue(xmlContent.contains("This is a sample test "));
Assert.assertTrue(xmlContent.contains(""));
@@ -104,14 +103,14 @@ public void testCreateTestWithoutResponse() throws IOException {
File xmlFile = new File(CitrusSettings.DEFAULT_TEST_SRC_DIRECTORY + "resources/org/citrusframework/HelloIT.xml");
Assert.assertTrue(xmlFile.exists());
- String javaContent = FileUtils.readToString(new FileSystemResource(javaFile));
+ String javaContent = FileUtils.readToString(javaFile);
Assert.assertTrue(javaContent.contains("@author Christoph"));
Assert.assertTrue(javaContent.contains("public class HelloIT"));
Assert.assertTrue(javaContent.contains("* This is a sample test"));
Assert.assertTrue(javaContent.contains("package org.citrusframework;"));
Assert.assertTrue(javaContent.contains("extends TestNGCitrusSupport"));
- String xmlContent = FileUtils.readToString(new FileSystemResource(xmlFile));
+ String xmlContent = FileUtils.readToString(xmlFile);
Assert.assertTrue(xmlContent.contains("Christoph "));
Assert.assertTrue(xmlContent.contains("This is a sample test "));
Assert.assertTrue(xmlContent.contains(""));
diff --git a/utils/citrus-test-support/pom.xml b/utils/citrus-test-support/pom.xml
index 78f494281d..b331da62e7 100644
--- a/utils/citrus-test-support/pom.xml
+++ b/utils/citrus-test-support/pom.xml
@@ -47,6 +47,10 @@
+
+ org.springframework
+ spring-core
+
org.springframework
spring-context
diff --git a/utils/citrus-test-support/src/main/java/org/citrusframework/testng/AbstractTestNGUnitTest.java b/utils/citrus-test-support/src/main/java/org/citrusframework/testng/AbstractTestNGUnitTest.java
index 8baaaab216..9589b65270 100644
--- a/utils/citrus-test-support/src/main/java/org/citrusframework/testng/AbstractTestNGUnitTest.java
+++ b/utils/citrus-test-support/src/main/java/org/citrusframework/testng/AbstractTestNGUnitTest.java
@@ -18,9 +18,9 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.context.TestContextFactory;
+import org.citrusframework.util.ObjectHelper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
-import org.springframework.util.Assert;
import org.testng.ITestContext;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
@@ -48,7 +48,7 @@ public abstract class AbstractTestNGUnitTest extends AbstractTestNGSpringContext
@BeforeSuite(alwaysRun = true)
public void beforeSuite(ITestContext testContext) throws Exception {
springTestContextPrepareTestInstance();
- Assert.notNull(applicationContext, "Missing proper application context in before suite initialization");
+ ObjectHelper.assertNotNull(applicationContext, "Missing proper application context in before suite initialization");
}
/**
diff --git a/validation/citrus-validation-groovy/src/main/java/org/citrusframework/validation/script/GroovyJsonMessageValidator.java b/validation/citrus-validation-groovy/src/main/java/org/citrusframework/validation/script/GroovyJsonMessageValidator.java
index b5b452fb29..0d2ac322fd 100644
--- a/validation/citrus-validation-groovy/src/main/java/org/citrusframework/validation/script/GroovyJsonMessageValidator.java
+++ b/validation/citrus-validation-groovy/src/main/java/org/citrusframework/validation/script/GroovyJsonMessageValidator.java
@@ -18,8 +18,8 @@
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageType;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.MessageUtils;
-import org.springframework.core.io.ClassPathResource;
/**
* Extended groovy message validator providing specific Json slurper support.
@@ -34,7 +34,7 @@ public class GroovyJsonMessageValidator extends GroovyScriptMessageValidator {
* Default constructor using default script template.
*/
public GroovyJsonMessageValidator() {
- super(new ClassPathResource("org/citrusframework/validation/json-validation-template.groovy"));
+ super(Resources.newClasspathResource("org/citrusframework/validation/json-validation-template.groovy"));
}
@Override
diff --git a/validation/citrus-validation-groovy/src/main/java/org/citrusframework/validation/script/GroovyScriptMessageValidator.java b/validation/citrus-validation-groovy/src/main/java/org/citrusframework/validation/script/GroovyScriptMessageValidator.java
index ad0f18b781..0e05772edd 100644
--- a/validation/citrus-validation-groovy/src/main/java/org/citrusframework/validation/script/GroovyScriptMessageValidator.java
+++ b/validation/citrus-validation-groovy/src/main/java/org/citrusframework/validation/script/GroovyScriptMessageValidator.java
@@ -20,22 +20,22 @@
import java.security.PrivilegedAction;
import java.util.List;
+import groovy.lang.GroovyClassLoader;
+import groovy.lang.GroovyObject;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.ValidationException;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageType;
import org.citrusframework.script.ScriptTypes;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.AbstractMessageValidator;
import org.citrusframework.validation.context.ValidationContext;
-import groovy.lang.GroovyClassLoader;
-import groovy.lang.GroovyObject;
import org.codehaus.groovy.control.CompilationFailedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
-import org.springframework.util.StringUtils;
/**
* Groovy script message validator passing the message to a validation script.
@@ -58,14 +58,14 @@ public class GroovyScriptMessageValidator extends AbstractMessageValidator${project.version}
+
+
+ org.springframework
+ spring-core
+ provided
+
+
org.hamcrest
hamcrest
diff --git a/validation/citrus-validation-hamcrest/src/main/java/org/citrusframework/validation/HamcrestHeaderValidator.java b/validation/citrus-validation-hamcrest/src/main/java/org/citrusframework/validation/HamcrestHeaderValidator.java
index 26d1c8f17f..e8be99e2d7 100644
--- a/validation/citrus-validation-hamcrest/src/main/java/org/citrusframework/validation/HamcrestHeaderValidator.java
+++ b/validation/citrus-validation-hamcrest/src/main/java/org/citrusframework/validation/HamcrestHeaderValidator.java
@@ -23,7 +23,6 @@
import org.hamcrest.core.IsEqual;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
/**
* @author Christoph Deppisch
@@ -36,23 +35,21 @@ public class HamcrestHeaderValidator implements HeaderValidator {
@Override
public void validateHeader(String headerName, Object receivedValue, Object controlValue, TestContext context, HeaderValidationContext validationContext) {
- try {
- if (controlValue instanceof Matcher) {
- Assert.isTrue(((Matcher>) controlValue).matches(receivedValue),
- ValidationUtils.buildValueMismatchErrorMessage(
- "Values not matching for header '" + headerName + "'", controlValue, receivedValue));
- } else {
- IsEqual equalMatcher = new IsEqual<>(controlValue);
- Assert.isTrue(equalMatcher.matches(receivedValue),
- ValidationUtils.buildValueMismatchErrorMessage(
- "Values not equal for header '" + headerName + "'", controlValue, receivedValue));
+ if (controlValue instanceof Matcher) {
+ if (!((Matcher>) controlValue).matches(receivedValue)) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage(
+ "Header validation failed: Values not matching for header '" + headerName + "'", controlValue, receivedValue));
+ }
+ } else {
+ IsEqual equalMatcher = new IsEqual<>(controlValue);
+ if (!equalMatcher.matches(receivedValue)) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage(
+ "Header validation failed: Values not equal for header '" + headerName + "'", controlValue, receivedValue));
}
- } catch (IllegalArgumentException e) {
- throw new ValidationException("Validation failed:", e);
}
if (logger.isDebugEnabled()) {
- logger.debug("Validating header element: " + headerName + "='" + controlValue + "': OK.");
+ logger.debug("Header validation: " + headerName + "='" + controlValue + "': OK.");
}
}
diff --git a/validation/citrus-validation-hamcrest/src/main/java/org/citrusframework/validation/matcher/hamcrest/HamcrestValidationMatcher.java b/validation/citrus-validation-hamcrest/src/main/java/org/citrusframework/validation/matcher/hamcrest/HamcrestValidationMatcher.java
index 6031446730..ce0b1b85a9 100644
--- a/validation/citrus-validation-hamcrest/src/main/java/org/citrusframework/validation/matcher/hamcrest/HamcrestValidationMatcher.java
+++ b/validation/citrus-validation-hamcrest/src/main/java/org/citrusframework/validation/matcher/hamcrest/HamcrestValidationMatcher.java
@@ -35,15 +35,14 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.ValidationException;
+import org.citrusframework.util.ReflectionHelper;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.matcher.ControlExpressionParser;
import org.citrusframework.validation.matcher.DefaultControlExpressionParser;
import org.citrusframework.validation.matcher.ValidationMatcher;
import org.citrusframework.variable.VariableUtils;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
-import org.springframework.util.Assert;
-import org.springframework.util.ReflectionUtils;
-import org.springframework.util.StringUtils;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -135,7 +134,7 @@ private Matcher> getMatcher(String matcherName, String[] matcherParameter, Tes
}
if (noArgumentMatchers.contains(matcherName)) {
- Method matcherMethod = ReflectionUtils.findMethod(Matchers.class, matcherName);
+ Method matcherMethod = ReflectionHelper.findMethod(Matchers.class, matcherName);
if (matcherMethod != null) {
return (Matcher>) matcherMethod.invoke(null);
@@ -143,17 +142,19 @@ private Matcher> getMatcher(String matcherName, String[] matcherParameter, Tes
}
if (noArgumentCollectionMatchers.contains(matcherName)) {
- Method matcherMethod = ReflectionUtils.findMethod(Matchers.class, matcherName);
+ Method matcherMethod = ReflectionHelper.findMethod(Matchers.class, matcherName);
if (matcherMethod != null) {
return (Matcher>) matcherMethod.invoke(null);
}
}
- Assert.isTrue(matcherParameter.length > 0, "Missing matcher parameter");
+ if (matcherParameter.length == 0) {
+ throw new CitrusRuntimeException("Missing matcher parameter");
+ }
if (containerMatchers.contains(matcherName)) {
- Method matcherMethod = ReflectionUtils.findMethod(Matchers.class, matcherName, Matcher.class);
+ Method matcherMethod = ReflectionHelper.findMethod(Matchers.class, matcherName, Matcher.class);
if (matcherMethod != null) {
String matcherExpression = matcherParameter[0];
@@ -172,7 +173,7 @@ private Matcher> getMatcher(String matcherName, String[] matcherParameter, Tes
}
if (iterableMatchers.contains(matcherName)) {
- Method matcherMethod = ReflectionUtils.findMethod(Matchers.class, matcherName, Iterable.class);
+ Method matcherMethod = ReflectionHelper.findMethod(Matchers.class, matcherName, Iterable.class);
if (matcherMethod != null) {
List> nestedMatchers = new ArrayList<>();
@@ -195,10 +196,10 @@ private Matcher> getMatcher(String matcherName, String[] matcherParameter, Tes
unescapeQuotes(matcherParameter);
- Method matcherMethod = ReflectionUtils.findMethod(Matchers.class, matcherName, String.class);
+ Method matcherMethod = ReflectionHelper.findMethod(Matchers.class, matcherName, String.class);
if (matcherMethod == null) {
- matcherMethod = ReflectionUtils.findMethod(Matchers.class, matcherName, Object.class);
+ matcherMethod = ReflectionHelper.findMethod(Matchers.class, matcherName, Object.class);
}
if (matcherMethod != null) {
@@ -207,7 +208,7 @@ private Matcher> getMatcher(String matcherName, String[] matcherParameter, Tes
}
if (numericMatchers.contains(matcherName)) {
- Method matcherMethod = ReflectionUtils.findMethod(Matchers.class, matcherName, double.class, double.class);
+ Method matcherMethod = ReflectionHelper.findMethod(Matchers.class, matcherName, double.class, double.class);
if (matcherMethod != null) {
return (Matcher>) matcherMethod.invoke(
@@ -215,7 +216,7 @@ private Matcher> getMatcher(String matcherName, String[] matcherParameter, Tes
Double.valueOf(matcherParameter[0]), matcherParameter.length > 1 ? Double.parseDouble(matcherParameter[1]) : 0.0D);
}
- matcherMethod = ReflectionUtils.findMethod(Matchers.class, matcherName, Comparable.class);
+ matcherMethod = ReflectionHelper.findMethod(Matchers.class, matcherName, Comparable.class);
if (matcherMethod != null) {
return (Matcher>) matcherMethod.invoke(null, matcherParameter[0]);
@@ -226,19 +227,19 @@ private Matcher> getMatcher(String matcherName, String[] matcherParameter, Tes
unescapeQuotes(matcherParameter);
- Method matcherMethod = ReflectionUtils.findMethod(Matchers.class, matcherName, int.class);
+ Method matcherMethod = ReflectionHelper.findMethod(Matchers.class, matcherName, int.class);
if (matcherMethod != null) {
return (Matcher>) matcherMethod.invoke(null, Integer.valueOf(matcherParameter[0]));
}
- matcherMethod = ReflectionUtils.findMethod(Matchers.class, matcherName, Object.class);
+ matcherMethod = ReflectionHelper.findMethod(Matchers.class, matcherName, Object.class);
if (matcherMethod != null) {
return (Matcher>) matcherMethod.invoke(null, matcherParameter[0]);
}
- matcherMethod = ReflectionUtils.findMethod(Matchers.class, matcherName, Object[].class);
+ matcherMethod = ReflectionHelper.findMethod(Matchers.class, matcherName, Object[].class);
if (matcherMethod != null) {
return (Matcher>) matcherMethod.invoke(null, new Object[] { matcherParameter });
@@ -249,13 +250,13 @@ private Matcher> getMatcher(String matcherName, String[] matcherParameter, Tes
unescapeQuotes(matcherParameter);
- Method matcherMethod = ReflectionUtils.findMethod(Matchers.class, matcherName, Object.class);
+ Method matcherMethod = ReflectionHelper.findMethod(Matchers.class, matcherName, Object.class);
if (matcherMethod != null) {
return (Matcher>) matcherMethod.invoke(null, matcherParameter[0]);
}
- matcherMethod = ReflectionUtils.findMethod(Matchers.class, matcherName, Object.class, Object.class);
+ matcherMethod = ReflectionHelper.findMethod(Matchers.class, matcherName, Object.class, Object.class);
if (matcherMethod != null) {
return (Matcher>) matcherMethod.invoke(null, matcherParameter[0], matcherParameter[1]);
@@ -266,18 +267,18 @@ private Matcher> getMatcher(String matcherName, String[] matcherParameter, Tes
unescapeQuotes(matcherParameter);
- Method matcherMethod = ReflectionUtils.findMethod(Matchers.class, matcherName, Object[].class);
+ Method matcherMethod = ReflectionHelper.findMethod(Matchers.class, matcherName, Object[].class);
if (matcherMethod != null) {
return (Matcher>) matcherMethod.invoke(null, new Object[] { matcherParameter });
}
- matcherMethod = ReflectionUtils.findMethod(Matchers.class, matcherName, Collection.class);
+ matcherMethod = ReflectionHelper.findMethod(Matchers.class, matcherName, Collection.class);
if (matcherMethod != null) {
return (Matcher>) matcherMethod.invoke(
null,
- new Object[] { getCollection(StringUtils.arrayToCommaDelimitedString(matcherParameter)) });
+ new Object[] { getCollection(String.join(",", matcherParameter)) });
}
}
} catch (InvocationTargetException | IllegalAccessException e) {
@@ -328,15 +329,19 @@ private Optional lookupMatcherProvider(String matcherNa
* @return
*/
private List getCollection(String value) {
- String arrayString = value;
+ if (value.equals("[]")) {
+ return Collections.emptyList();
+ }
+ String arrayString = value;
if (arrayString.startsWith("[") && arrayString.endsWith("]")) {
arrayString = arrayString.substring(1, arrayString.length()-1);
}
- return Arrays.stream(StringUtils.commaDelimitedListToStringArray(arrayString))
+ return Arrays.stream(arrayString.split(","))
.map(String::trim)
.map(VariableUtils::cutOffDoubleQuotes)
+ .filter(StringUtils::hasText)
.collect(Collectors.toList());
}
diff --git a/validation/citrus-validation-hamcrest/src/test/java/org/citrusframework/integration/TextEqualsMessageValidator.java b/validation/citrus-validation-hamcrest/src/test/java/org/citrusframework/integration/TextEqualsMessageValidator.java
index 1bcfe3759d..063b73bb89 100644
--- a/validation/citrus-validation-hamcrest/src/test/java/org/citrusframework/integration/TextEqualsMessageValidator.java
+++ b/validation/citrus-validation-hamcrest/src/test/java/org/citrusframework/integration/TextEqualsMessageValidator.java
@@ -1,11 +1,11 @@
package org.citrusframework.integration;
import org.citrusframework.context.TestContext;
+import org.citrusframework.exceptions.ValidationException;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageType;
import org.citrusframework.validation.DefaultMessageValidator;
import org.citrusframework.validation.context.ValidationContext;
-import org.springframework.util.Assert;
/**
* Basic message validator performs String equals on received message payloads. We add this validator in order to have a
@@ -16,8 +16,9 @@ public class TextEqualsMessageValidator extends DefaultMessageValidator {
@Override
public void validateMessage(Message receivedMessage, Message controlMessage, TestContext context, ValidationContext validationContext) {
- Assert.isTrue(receivedMessage.getPayload(String.class).equals(controlMessage.getPayload(String.class)), "Validation failed - " +
- "expected message contents not equal!");
+ if (!receivedMessage.getPayload(String.class).equals(controlMessage.getPayload(String.class))) {
+ throw new ValidationException("Validation failed - expected message contents not equal!");
+ }
}
@Override
diff --git a/validation/citrus-validation-json/pom.xml b/validation/citrus-validation-json/pom.xml
index 336c7cecf3..1e4c07abe4 100644
--- a/validation/citrus-validation-json/pom.xml
+++ b/validation/citrus-validation-json/pom.xml
@@ -25,6 +25,11 @@
provided
+
+ org.springframework
+ spring-core
+
+
com.fasterxml.jackson.core
jackson-core
diff --git a/validation/citrus-validation-json/src/main/java/org/citrusframework/functions/core/JsonPathFunction.java b/validation/citrus-validation-json/src/main/java/org/citrusframework/functions/core/JsonPathFunction.java
index 513be603ed..3fe7e81e03 100644
--- a/validation/citrus-validation-json/src/main/java/org/citrusframework/functions/core/JsonPathFunction.java
+++ b/validation/citrus-validation-json/src/main/java/org/citrusframework/functions/core/JsonPathFunction.java
@@ -22,7 +22,6 @@
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
import org.citrusframework.json.JsonPathUtils;
-import org.springframework.util.CollectionUtils;
/**
* @author Christoph Deppisch
@@ -32,7 +31,7 @@ public class JsonPathFunction implements Function {
@Override
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
diff --git a/validation/citrus-validation-json/src/main/java/org/citrusframework/json/JsonPathUtils.java b/validation/citrus-validation-json/src/main/java/org/citrusframework/json/JsonPathUtils.java
index 82baed5aef..fa9be55348 100644
--- a/validation/citrus-validation-json/src/main/java/org/citrusframework/json/JsonPathUtils.java
+++ b/validation/citrus-validation-json/src/main/java/org/citrusframework/json/JsonPathUtils.java
@@ -18,8 +18,6 @@
import java.util.Optional;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.validation.json.JsonPathFunctions;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
import com.jayway.jsonpath.ReadContext;
@@ -27,7 +25,9 @@
import net.minidev.json.JSONObject;
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;
-import org.springframework.util.StringUtils;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.util.StringUtils;
+import org.citrusframework.validation.json.JsonPathFunctions;
/**
* @author Christoph Deppisch
diff --git a/validation/citrus-validation-json/src/main/java/org/citrusframework/json/JsonSchemaRepository.java b/validation/citrus-validation-json/src/main/java/org/citrusframework/json/JsonSchemaRepository.java
index 38731c00a2..0c7d9aef77 100644
--- a/validation/citrus-validation-json/src/main/java/org/citrusframework/json/JsonSchemaRepository.java
+++ b/validation/citrus-validation-json/src/main/java/org/citrusframework/json/JsonSchemaRepository.java
@@ -16,18 +16,23 @@
package org.citrusframework.json;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
import org.citrusframework.common.InitializingPhase;
import org.citrusframework.common.Named;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.json.schema.SimpleJsonSchema;
+import org.citrusframework.spi.ClasspathResourceResolver;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
/**
* Schema repository holding a set of json schema resources known in the test scope.
@@ -55,13 +60,19 @@ public void setName(String name) {
@Override
public void initialize() {
try {
- PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
-
+ ClasspathResourceResolver resourceResolver = new ClasspathResourceResolver();
for (String location : locations) {
- Resource[] findings = resourcePatternResolver.getResources(location);
+ Set findings;
+ if (StringUtils.hasText(FileUtils.getFileExtension(location))) {
+ String fileNamePattern = FileUtils.getFileName(location).replace(".", "\\.").replace("*", ".*");
+ String basePath = FileUtils.getBasePath(location);
+ findings = resourceResolver.getResources(basePath, fileNamePattern);
+ } else {
+ findings = resourceResolver.getResources(location);
+ }
- for (Resource resource : findings) {
- addSchemas(resource);
+ for (Path resource : findings) {
+ addSchemas(Resources.newClasspathResource(resource.toString()));
}
}
} catch (IOException e) {
@@ -70,15 +81,15 @@ public void initialize() {
}
private void addSchemas(Resource resource) {
- if (resource.getFilename().endsWith(".json")) {
+ if (resource.getLocation().endsWith(".json")) {
if (logger.isDebugEnabled()) {
- logger.debug("Loading json schema resource " + resource.getFilename());
+ logger.debug("Loading json schema resource " + resource.getLocation());
}
SimpleJsonSchema simpleJsonSchema = new SimpleJsonSchema(resource);
simpleJsonSchema.initialize();
schemas.add(simpleJsonSchema);
} else {
- logger.warn("Skipped resource other than json schema for repository (" + resource.getFilename() + ")");
+ logger.warn("Skipped resource other than json schema for repository (" + resource.getLocation() + ")");
}
}
diff --git a/validation/citrus-validation-json/src/main/java/org/citrusframework/json/schema/SimpleJsonSchema.java b/validation/citrus-validation-json/src/main/java/org/citrusframework/json/schema/SimpleJsonSchema.java
index cf102ae996..6ab8d87017 100644
--- a/validation/citrus-validation-json/src/main/java/org/citrusframework/json/schema/SimpleJsonSchema.java
+++ b/validation/citrus-validation-json/src/main/java/org/citrusframework/json/schema/SimpleJsonSchema.java
@@ -16,16 +16,16 @@
package org.citrusframework.json.schema;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Objects;
+
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SpecVersion;
import org.citrusframework.common.InitializingPhase;
import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.springframework.core.io.Resource;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Objects;
+import org.citrusframework.spi.Resource;
/**
* Adapter between the resource reference from the bean configuration and the usable {@link SimpleJsonSchema} for
@@ -34,7 +34,7 @@
public class SimpleJsonSchema implements InitializingPhase {
/** Default json schema factory */
- private JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4);
+ private final JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4);
/** The Resource of the json schema passed from the bean config */
private Resource json;
diff --git a/validation/citrus-validation-json/src/main/java/org/citrusframework/message/selector/JsonPathPayloadMessageSelector.java b/validation/citrus-validation-json/src/main/java/org/citrusframework/message/selector/JsonPathPayloadMessageSelector.java
index 58055de381..e50182fc1f 100644
--- a/validation/citrus-validation-json/src/main/java/org/citrusframework/message/selector/JsonPathPayloadMessageSelector.java
+++ b/validation/citrus-validation-json/src/main/java/org/citrusframework/message/selector/JsonPathPayloadMessageSelector.java
@@ -20,7 +20,7 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.json.JsonPathUtils;
import org.citrusframework.message.Message;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
/**
* Message selector accepts JSON messages in case JsonPath expression evaluation result matches
diff --git a/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/JsonMappingValidationProcessor.java b/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/JsonMappingValidationProcessor.java
index 933eb8309a..e6930c4bed 100644
--- a/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/JsonMappingValidationProcessor.java
+++ b/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/JsonMappingValidationProcessor.java
@@ -19,18 +19,18 @@
import java.io.IOException;
import java.util.Map;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageProcessor;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.util.ObjectHelper;
import org.citrusframework.validation.AbstractValidationProcessor;
import org.citrusframework.validation.GenericValidationProcessor;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
/**
* @author Christoph Deppisch
@@ -73,7 +73,7 @@ public void validate(Message message, TestContext context) {
private T readJson(Message message) {
if (mapper == null) {
- Assert.notNull(referenceResolver, "Json mapping validation callback requires object mapper instance " +
+ ObjectHelper.assertNotNull(referenceResolver, "Json mapping validation callback requires object mapper instance " +
"or proper reference resolver with nested bean definition of type marshaller");
mapper = referenceResolver.resolve(ObjectMapper.class);
diff --git a/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/JsonPathMessageProcessor.java b/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/JsonPathMessageProcessor.java
index 152564f8a7..ebb2910f44 100644
--- a/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/JsonPathMessageProcessor.java
+++ b/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/JsonPathMessageProcessor.java
@@ -19,6 +19,11 @@
import java.util.LinkedHashMap;
import java.util.Map;
+import com.jayway.jsonpath.DocumentContext;
+import com.jayway.jsonpath.JsonPath;
+import com.jayway.jsonpath.PathNotFoundException;
+import net.minidev.json.parser.JSONParser;
+import net.minidev.json.parser.ParseException;
import org.citrusframework.builder.WithExpressions;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
@@ -27,15 +32,9 @@
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageProcessor;
import org.citrusframework.message.MessageType;
-import com.jayway.jsonpath.DocumentContext;
-import com.jayway.jsonpath.JsonPath;
-import com.jayway.jsonpath.PathNotFoundException;
-import net.minidev.json.parser.JSONParser;
-import net.minidev.json.parser.ParseException;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.NumberUtils;
-import org.springframework.util.StringUtils;
/**
* @author Christoph Deppisch
@@ -95,7 +94,7 @@ public void processMessage(Message message, TestContext context) {
value = false;
} else {
try {
- value = NumberUtils.parseNumber(valueExpression, Integer.class);
+ value = Integer.valueOf(valueExpression);
} catch (IllegalArgumentException e) {
value = valueExpression;
}
diff --git a/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/JsonPathMessageValidator.java b/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/JsonPathMessageValidator.java
index 33b712864f..797f3dce47 100644
--- a/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/JsonPathMessageValidator.java
+++ b/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/JsonPathMessageValidator.java
@@ -21,22 +21,21 @@
import java.util.Map;
import java.util.stream.Collectors;
+import com.jayway.jsonpath.JsonPath;
+import com.jayway.jsonpath.ReadContext;
+import net.minidev.json.parser.JSONParser;
+import net.minidev.json.parser.ParseException;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.ValidationException;
import org.citrusframework.json.JsonPathUtils;
import org.citrusframework.message.Message;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.AbstractMessageValidator;
import org.citrusframework.validation.ValidationUtils;
import org.citrusframework.validation.context.ValidationContext;
-import com.jayway.jsonpath.JsonPath;
-import com.jayway.jsonpath.ReadContext;
-import net.minidev.json.parser.JSONParser;
-import net.minidev.json.parser.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
/**
* Message validator evaluates set of JSONPath expressions on message payload and checks that values are as expected.
@@ -49,7 +48,9 @@ public class JsonPathMessageValidator extends AbstractMessageValidator findSchemaRepositories(TestContext context) {
@SuppressWarnings("rawtypes")
public void validateJson(String elementName, JSONObject receivedJson, JSONObject controlJson, JsonMessageValidationContext validationContext, TestContext context, ReadContext readContext) {
if (strict) {
- Assert.isTrue(controlJson.size() == receivedJson.size(),
- ValidationUtils.buildValueMismatchErrorMessage("Number of JSON entries not equal for element: '" + elementName + "'", controlJson.size(), receivedJson.size()));
+ if (controlJson.size() != receivedJson.size()) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Number of JSON entries not equal for element: '" + elementName + "'", controlJson.size(), receivedJson.size()));
+ }
}
for (Map.Entry controlJsonEntry : controlJson.entrySet()) {
String controlKey = controlJsonEntry.getKey();
- Assert.isTrue(receivedJson.containsKey(controlKey),
- "Missing JSON entry: + '" + controlKey + "'");
+ if (!receivedJson.containsKey(controlKey)) {
+ throw new ValidationException("Missing JSON entry: + '" + controlKey + "'");
+ }
Object controlValue = controlJsonEntry.getValue();
Object receivedValue = receivedJson.get(controlKey);
@@ -161,25 +164,28 @@ public void validateJson(String elementName, JSONObject receivedJson, JSONObject
}
if (controlValue == null) {
- Assert.isTrue(receivedValue == null,
- ValidationUtils.buildValueMismatchErrorMessage("Values not equal for entry: '" + controlKey + "'",
+ if (receivedValue != null) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Values not equal for entry: '" + controlKey + "'",
null, receivedValue));
+ }
} else if (receivedValue != null) {
if (ValidationMatcherUtils.isValidationMatcherExpression(controlValue.toString())) {
ValidationMatcherUtils.resolveValidationMatcher(controlKey,
receivedValue.toString(),
controlValue.toString(), context);
} else if (controlValue instanceof JSONObject) {
- Assert.isTrue(receivedValue instanceof JSONObject,
- ValidationUtils.buildValueMismatchErrorMessage("Type mismatch for JSON entry '" + controlKey + "'",
+ if (!(receivedValue instanceof JSONObject)) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Type mismatch for JSON entry '" + controlKey + "'",
JSONObject.class.getSimpleName(), receivedValue.getClass().getSimpleName()));
+ }
validateJson(controlKey, (JSONObject) receivedValue,
(JSONObject) controlValue, validationContext, context, readContext);
} else if (controlValue instanceof JSONArray) {
- Assert.isTrue(receivedValue instanceof JSONArray,
- ValidationUtils.buildValueMismatchErrorMessage("Type mismatch for JSON entry '" + controlKey + "'",
+ if (!(receivedValue instanceof JSONArray)) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Type mismatch for JSON entry '" + controlKey + "'",
JSONArray.class.getSimpleName(), receivedValue.getClass().getSimpleName()));
+ }
JSONArray jsonArrayControl = (JSONArray) controlValue;
JSONArray jsonArrayReceived = (JSONArray) receivedValue;
@@ -189,37 +195,40 @@ public void validateJson(String elementName, JSONObject receivedJson, JSONObject
}
if (strict) {
- Assert.isTrue(jsonArrayControl.size() == jsonArrayReceived.size(),
- ValidationUtils.buildValueMismatchErrorMessage("JSONArray size mismatch for JSON entry '" + controlKey + "'",
+ if (jsonArrayControl.size() != jsonArrayReceived.size()) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("JSONArray size mismatch for JSON entry '" + controlKey + "'",
jsonArrayControl.size(), jsonArrayReceived.size()));
+ }
}
for (int i = 0; i < jsonArrayControl.size(); i++) {
if (jsonArrayControl.get(i).getClass().isAssignableFrom(JSONObject.class)) {
- Assert.isTrue(jsonArrayReceived.get(i).getClass().isAssignableFrom(JSONObject.class),
- ValidationUtils.buildValueMismatchErrorMessage("Value types not equal for entry: '" + jsonArrayControl.get(i) + "'",
+ if (!jsonArrayReceived.get(i).getClass().isAssignableFrom(JSONObject.class)) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Value types not equal for entry: '" + jsonArrayControl.get(i) + "'",
JSONObject.class.getName(), jsonArrayReceived.get(i).getClass().getName()));
+ }
validateJson(controlKey, (JSONObject) jsonArrayReceived.get(i),
(JSONObject) jsonArrayControl.get(i), validationContext, context, readContext);
} else {
- Assert.isTrue(jsonArrayControl.get(i).equals(jsonArrayReceived.get(i)),
- ValidationUtils.buildValueMismatchErrorMessage("Values not equal for entry: '" + jsonArrayControl.get(i) + "'",
+ if (!jsonArrayControl.get(i).equals(jsonArrayReceived.get(i))) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Values not equal for entry: '" + jsonArrayControl.get(i) + "'",
jsonArrayControl.get(i), jsonArrayReceived.get(i)));
+ }
}
}
} else {
- Assert.isTrue(controlValue.equals(receivedValue),
- ValidationUtils.buildValueMismatchErrorMessage("Values not equal for entry: '" + controlKey + "'",
+ if (!controlValue.equals(receivedValue)) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Values not equal for entry: '" + controlKey + "'",
controlValue, receivedValue));
+ }
}
} else if (ValidationMatcherUtils.isValidationMatcherExpression(controlValue.toString())) {
ValidationMatcherUtils.resolveValidationMatcher(controlKey,
null,
controlValue.toString(), context);
- } else {
- Assert.isTrue(!StringUtils.hasText(controlValue.toString()),
- ValidationUtils.buildValueMismatchErrorMessage(
- "Values not equal for entry '" + controlKey + "'", controlValue.toString(), null));
+ } else if (StringUtils.hasText(controlValue.toString())) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage(
+ "Values not equal for entry '" + controlKey + "'", controlValue.toString(), null));
}
if (logger.isDebugEnabled()) {
diff --git a/validation/citrus-validation-json/src/main/java/org/citrusframework/variable/dictionary/json/JsonMappingDataDictionary.java b/validation/citrus-validation-json/src/main/java/org/citrusframework/variable/dictionary/json/JsonMappingDataDictionary.java
index d11a860d4c..305175a1f0 100644
--- a/validation/citrus-validation-json/src/main/java/org/citrusframework/variable/dictionary/json/JsonMappingDataDictionary.java
+++ b/validation/citrus-validation-json/src/main/java/org/citrusframework/variable/dictionary/json/JsonMappingDataDictionary.java
@@ -19,16 +19,16 @@
import java.util.Iterator;
import java.util.Map;
-import org.citrusframework.context.TestContext;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.citrusframework.message.Message;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;
+import org.citrusframework.context.TestContext;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.message.Message;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
/**
* Simple json data dictionary implementation holds a set of mappings where keys are json path expressions to match
diff --git a/validation/citrus-validation-json/src/main/java/org/citrusframework/variable/dictionary/json/JsonPathMappingDataDictionary.java b/validation/citrus-validation-json/src/main/java/org/citrusframework/variable/dictionary/json/JsonPathMappingDataDictionary.java
index bc7529594b..a966372901 100644
--- a/validation/citrus-validation-json/src/main/java/org/citrusframework/variable/dictionary/json/JsonPathMappingDataDictionary.java
+++ b/validation/citrus-validation-json/src/main/java/org/citrusframework/variable/dictionary/json/JsonPathMappingDataDictionary.java
@@ -21,10 +21,10 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.message.Message;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.json.JsonPathMessageProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
/**
* Json data dictionary implementation maps elements via JsonPath expressions. When element is identified by some expression
diff --git a/validation/citrus-validation-json/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageActionBuilderTest.java b/validation/citrus-validation-json/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageActionBuilderTest.java
index 3d17be312e..8605ccea17 100644
--- a/validation/citrus-validation-json/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageActionBuilderTest.java
+++ b/validation/citrus-validation-json/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageActionBuilderTest.java
@@ -16,6 +16,12 @@
package org.citrusframework.actions.dsl;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
import com.fasterxml.jackson.databind.ObjectMapper;
import com.networknt.schema.JsonSchema;
import org.citrusframework.DefaultTestCaseRunner;
@@ -37,6 +43,7 @@
import org.citrusframework.messaging.Consumer;
import org.citrusframework.report.TestActionListeners;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.spi.Resource;
import org.citrusframework.validation.DelegatingPayloadVariableExtractor;
import org.citrusframework.validation.builder.DefaultMessageBuilder;
import org.citrusframework.validation.builder.StaticMessageBuilder;
@@ -47,16 +54,9 @@
import org.citrusframework.validation.xml.XmlMessageValidationContext;
import org.hamcrest.core.AnyOf;
import org.mockito.Mockito;
-import org.springframework.core.io.Resource;
import org.testng.Assert;
import org.testng.annotations.Test;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
import static org.citrusframework.actions.ReceiveMessageAction.Builder.receive;
import static org.citrusframework.dsl.JsonPathSupport.jsonPath;
import static org.citrusframework.dsl.JsonSupport.json;
@@ -65,11 +65,7 @@
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.nullValue;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.anyLong;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
/**
* @author Christoph Deppisch
diff --git a/validation/citrus-validation-json/src/test/java/org/citrusframework/actions/dsl/SendMessageActionBuilderTest.java b/validation/citrus-validation-json/src/test/java/org/citrusframework/actions/dsl/SendMessageActionBuilderTest.java
index ff04d80949..2c31a8e0fb 100644
--- a/validation/citrus-validation-json/src/test/java/org/citrusframework/actions/dsl/SendMessageActionBuilderTest.java
+++ b/validation/citrus-validation-json/src/test/java/org/citrusframework/actions/dsl/SendMessageActionBuilderTest.java
@@ -42,7 +42,6 @@
import org.citrusframework.variable.dictionary.DataDictionary;
import org.citrusframework.variable.dictionary.json.JsonMappingDataDictionary;
import org.mockito.Mockito;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -217,7 +216,7 @@ public void testJsonPathSupport() {
when(messageEndpoint.getActor()).thenReturn(null);
doAnswer(invocation -> {
Message message = (Message) invocation.getArguments()[0];
- Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)), "{\"TestRequest\":{\"Message\":\"HelloWorld!\"}}");
+ Assert.assertEquals(message.getPayload(String.class).replaceAll("\\s", ""), "{\"TestRequest\":{\"Message\":\"HelloWorld!\"}}");
return null;
}).when(messageProducer).send(any(Message.class), any(TestContext.class));
@@ -253,7 +252,7 @@ public void testSendBuilderWithDictionary() {
when(messageEndpoint.getActor()).thenReturn(null);
doAnswer(invocation -> {
Message message = (Message) invocation.getArguments()[0];
- Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)), "{\"TestRequest\":{\"Message\":\"HelloWorld!\"}}");
+ Assert.assertEquals(message.getPayload(String.class).replaceAll("\\s", ""), "{\"TestRequest\":{\"Message\":\"HelloWorld!\"}}");
return null;
}).when(messageProducer).send(any(Message.class), any(TestContext.class));
@@ -285,7 +284,7 @@ public void testSendBuilderWithDictionaryName() {
when(messageEndpoint.getActor()).thenReturn(null);
doAnswer(invocation -> {
Message message = (Message) invocation.getArguments()[0];
- Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)), "{\"TestRequest\":{\"Message\":\"HelloWorld!\"}}");
+ Assert.assertEquals(message.getPayload(String.class).replaceAll("\\s", ""), "{\"TestRequest\":{\"Message\":\"HelloWorld!\"}}");
return null;
}).when(messageProducer).send(any(Message.class), any(TestContext.class));
diff --git a/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/ReceiveMessageActionTest.java b/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/ReceiveMessageActionTest.java
index 05a4bfe1d8..280d4a293e 100644
--- a/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/ReceiveMessageActionTest.java
+++ b/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/ReceiveMessageActionTest.java
@@ -289,8 +289,7 @@ public void testReceiveEmptyMessagePayloadUnexpected() {
try {
receiveAction.execute(context);
} catch(CitrusRuntimeException e) {
- Assert.assertEquals(e.getMessage(), "Failed to validate JSON text:" + System.lineSeparator() +
- " Validation failed - expected message contents, but received empty message!");
+ Assert.assertEquals(e.getMessage(), "Validation failed - expected message contents, but received empty message!");
return;
}
diff --git a/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/SendMessageActionTest.java b/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/SendMessageActionTest.java
index b77dbbc843..63261cc72d 100644
--- a/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/SendMessageActionTest.java
+++ b/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/SendMessageActionTest.java
@@ -16,7 +16,6 @@
package org.citrusframework.validation.json;
-import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -27,34 +26,27 @@
import org.citrusframework.endpoint.Endpoint;
import org.citrusframework.endpoint.EndpointConfiguration;
import org.citrusframework.functions.DefaultFunctionLibrary;
-import org.citrusframework.json.JsonSchemaRepository;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageType;
import org.citrusframework.message.builder.DefaultPayloadBuilder;
import org.citrusframework.messaging.Producer;
import org.citrusframework.testng.AbstractTestNGUnitTest;
-import org.citrusframework.testng.UnitTestConfig;
-import org.citrusframework.util.FileUtils;
-import org.citrusframework.util.TestUtils;
import org.citrusframework.validation.DefaultMessageHeaderValidator;
-import org.citrusframework.validation.MessageValidator;
import org.citrusframework.validation.SchemaValidator;
import org.citrusframework.validation.builder.DefaultMessageBuilder;
import org.citrusframework.validation.context.HeaderValidationContext;
-import org.citrusframework.validation.json.schema.JsonSchemaValidation;
import org.citrusframework.validation.matcher.DefaultValidationMatcherLibrary;
import org.mockito.Mockito;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.Test;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.when;
/**
* @author Christoph Deppisch
diff --git a/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/schema/JsonSchemaValidationTest.java b/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/schema/JsonSchemaValidationTest.java
index 02338e7f73..b1488b359f 100644
--- a/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/schema/JsonSchemaValidationTest.java
+++ b/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/schema/JsonSchemaValidationTest.java
@@ -16,30 +16,27 @@
package org.citrusframework.validation.json.schema;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
import org.citrusframework.json.JsonSchemaRepository;
import org.citrusframework.json.schema.SimpleJsonSchema;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.citrusframework.validation.SchemaValidator;
import org.citrusframework.validation.context.SchemaValidationContext;
import org.citrusframework.validation.json.JsonMessageValidationContext;
import org.citrusframework.validation.json.report.GraciousProcessingReport;
-import org.junit.jupiter.api.BeforeEach;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
-import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -58,7 +55,7 @@ public class JsonSchemaValidationTest {
@Mock
private JsonSchemaFilter jsonSchemaFilterMock;
-
+
private JsonSchemaValidation fixture;
@BeforeMethod
@@ -72,7 +69,7 @@ public void testValidJsonMessageSuccessfullyValidated() {
// Setup json schema repositories
JsonSchemaRepository jsonSchemaRepository = new JsonSchemaRepository();
jsonSchemaRepository.setName("schemaRepository1");
- Resource schemaResource = new ClassPathResource("org/citrusframework/validation/ProductsSchema.json");
+ Resource schemaResource = Resources.newClasspathResource("org/citrusframework/validation/ProductsSchema.json");
SimpleJsonSchema schema = new SimpleJsonSchema(schemaResource);
schema.initialize();
jsonSchemaRepository.getSchemas().add(schema);
@@ -115,7 +112,7 @@ public void testInvalidJsonMessageValidationIsNotSuccessful() {
// Setup json schema repositories
JsonSchemaRepository jsonSchemaRepository = new JsonSchemaRepository();
jsonSchemaRepository.setName("schemaRepository1");
- Resource schemaResource = new ClassPathResource("org/citrusframework/validation/ProductsSchema.json");
+ Resource schemaResource = Resources.newClasspathResource("org/citrusframework/validation/ProductsSchema.json");
SimpleJsonSchema schema = new SimpleJsonSchema(schemaResource);
schema.initialize();
jsonSchemaRepository.getSchemas().add(schema);
@@ -156,12 +153,12 @@ public void testValidationIsSuccessfulIfOneSchemaMatches() {
JsonSchemaRepository jsonSchemaRepository = new JsonSchemaRepository();
jsonSchemaRepository.setName("schemaRepository1");
- Resource schemaResource = new ClassPathResource("org/citrusframework/validation/BookSchema.json");
+ Resource schemaResource = Resources.newClasspathResource("org/citrusframework/validation/BookSchema.json");
SimpleJsonSchema schema = new SimpleJsonSchema(schemaResource);
schema.initialize();
jsonSchemaRepository.getSchemas().add(schema);
- schemaResource = new ClassPathResource("org/citrusframework/validation/ProductsSchema.json");
+ schemaResource = Resources.newClasspathResource("org/citrusframework/validation/ProductsSchema.json");
schema = new SimpleJsonSchema(schemaResource);
schema.initialize();
jsonSchemaRepository.getSchemas().add(schema);
@@ -205,7 +202,7 @@ public void testValidationIsSuccessfulIfOneSchemaMatchesWithRepositoryMerge() {
JsonSchemaRepository jsonSchemaRepository = new JsonSchemaRepository();
jsonSchemaRepository.setName("schemaRepository1");
- Resource schemaResource = new ClassPathResource("org/citrusframework/validation/BookSchema.json");
+ Resource schemaResource = Resources.newClasspathResource("org/citrusframework/validation/BookSchema.json");
SimpleJsonSchema invalidSchema = new SimpleJsonSchema(schemaResource);
invalidSchema.initialize();
jsonSchemaRepository.getSchemas().add(invalidSchema);
@@ -215,7 +212,7 @@ public void testValidationIsSuccessfulIfOneSchemaMatchesWithRepositoryMerge() {
jsonSchemaRepository = new JsonSchemaRepository();
jsonSchemaRepository.setName("schemaRepository2");
- schemaResource = new ClassPathResource("org/citrusframework/validation/ProductsSchema.json");
+ schemaResource = Resources.newClasspathResource("org/citrusframework/validation/ProductsSchema.json");
SimpleJsonSchema validSchema = new SimpleJsonSchema(schemaResource);
validSchema.initialize();
jsonSchemaRepository.getSchemas().add(validSchema);
diff --git a/validation/citrus-validation-json/src/test/java/org/citrusframework/variable/dictionary/json/JsonMappingDataDictionaryTest.java b/validation/citrus-validation-json/src/test/java/org/citrusframework/variable/dictionary/json/JsonMappingDataDictionaryTest.java
index fce051f22d..0cd7204131 100644
--- a/validation/citrus-validation-json/src/test/java/org/citrusframework/variable/dictionary/json/JsonMappingDataDictionaryTest.java
+++ b/validation/citrus-validation-json/src/test/java/org/citrusframework/variable/dictionary/json/JsonMappingDataDictionaryTest.java
@@ -23,8 +23,8 @@
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageType;
+import org.citrusframework.spi.Resources;
import org.citrusframework.variable.dictionary.DataDictionary;
-import org.springframework.core.io.ClassPathResource;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -132,7 +132,7 @@ public void testTranslateFromMappingFile() throws Exception {
Message message = new DefaultMessage("{\"TestMessage\":{\"Text\":\"Hello World!\",\"OtherText\":\"No changes\"}}");
JsonMappingDataDictionary dictionary = new JsonMappingDataDictionary();
- dictionary.setMappingFile(new ClassPathResource("jsonmapping.properties", DataDictionary.class));
+ dictionary.setMappingFile(Resources.create("jsonmapping.properties", DataDictionary.class));
dictionary.initialize();
dictionary.processMessage(message, context);
diff --git a/validation/citrus-validation-json/src/test/java/org/citrusframework/variable/dictionary/json/JsonPathMappingDataDictionaryTest.java b/validation/citrus-validation-json/src/test/java/org/citrusframework/variable/dictionary/json/JsonPathMappingDataDictionaryTest.java
index c88f54c3f3..91d02181a5 100644
--- a/validation/citrus-validation-json/src/test/java/org/citrusframework/variable/dictionary/json/JsonPathMappingDataDictionaryTest.java
+++ b/validation/citrus-validation-json/src/test/java/org/citrusframework/variable/dictionary/json/JsonPathMappingDataDictionaryTest.java
@@ -22,8 +22,8 @@
import org.citrusframework.UnitTestSupport;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
+import org.citrusframework.spi.Resources;
import org.citrusframework.variable.dictionary.DataDictionary;
-import org.springframework.core.io.ClassPathResource;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -119,7 +119,7 @@ public void testTranslateFromMappingFile() throws Exception {
Message message = new DefaultMessage("{\"TestMessage\":{\"Text\":\"Hello World!\",\"OtherText\":\"No changes\"}}");
JsonPathMappingDataDictionary dictionary = new JsonPathMappingDataDictionary();
- dictionary.setMappingFile(new ClassPathResource("jsonmapping.properties", DataDictionary.class));
+ dictionary.setMappingFile(Resources.create("jsonmapping.properties", DataDictionary.class));
dictionary.initialize();
dictionary.processMessage(message, context);
diff --git a/validation/citrus-validation-json/src/test/resources/org/citrusframework/context/citrus-unit-context.xml b/validation/citrus-validation-json/src/test/resources/org/citrusframework/context/citrus-unit-context.xml
index 11c6253099..46148829bc 100644
--- a/validation/citrus-validation-json/src/test/resources/org/citrusframework/context/citrus-unit-context.xml
+++ b/validation/citrus-validation-json/src/test/resources/org/citrusframework/context/citrus-unit-context.xml
@@ -16,4 +16,15 @@
org.citrusframework.json.schema.SimpleJsonSchema
+
+
+
+
+
+
+
+
+
+
diff --git a/validation/citrus-validation-text/src/main/java/org/citrusframework/validation/text/GzipBinaryBase64MessageValidator.java b/validation/citrus-validation-text/src/main/java/org/citrusframework/validation/text/GzipBinaryBase64MessageValidator.java
index 11de4dc433..014d0857da 100644
--- a/validation/citrus-validation-text/src/main/java/org/citrusframework/validation/text/GzipBinaryBase64MessageValidator.java
+++ b/validation/citrus-validation-text/src/main/java/org/citrusframework/validation/text/GzipBinaryBase64MessageValidator.java
@@ -27,7 +27,6 @@
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageType;
import org.citrusframework.validation.context.ValidationContext;
-import org.springframework.util.StreamUtils;
/**
* Message validator automatically converts received binary data message payload to base64 String. Assumes control
@@ -43,7 +42,8 @@ public void validateMessage(Message receivedMessage, Message controlMessage,
if (receivedMessage.getPayload() instanceof byte[]) {
try (GZIPInputStream gzipInputStream = new GZIPInputStream(receivedMessage.getPayload(InputStream.class));
ByteArrayOutputStream unzipped = new ByteArrayOutputStream()) {
- StreamUtils.copy(gzipInputStream, unzipped);
+ unzipped.write(gzipInputStream.readAllBytes());
+ unzipped.flush();
receivedMessage.setPayload(unzipped.toByteArray());
} catch (IOException e) {
throw new CitrusRuntimeException("Failed to validate gzipped message", e);
diff --git a/validation/citrus-validation-text/src/main/java/org/citrusframework/validation/text/PlainTextMessageValidator.java b/validation/citrus-validation-text/src/main/java/org/citrusframework/validation/text/PlainTextMessageValidator.java
index 419498a68e..cc6ed6f2a2 100644
--- a/validation/citrus-validation-text/src/main/java/org/citrusframework/validation/text/PlainTextMessageValidator.java
+++ b/validation/citrus-validation-text/src/main/java/org/citrusframework/validation/text/PlainTextMessageValidator.java
@@ -24,11 +24,10 @@
import org.citrusframework.exceptions.ValidationException;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageType;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.validation.DefaultMessageValidator;
import org.citrusframework.validation.context.ValidationContext;
import org.citrusframework.validation.matcher.ValidationMatcherUtils;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
/**
* Plain text validator using simple String comparison.
@@ -164,13 +163,13 @@ private void validateText(String receivedMessagePayload, String controlMessagePa
if (!StringUtils.hasText(controlMessagePayload)) {
logger.debug("Skip message payload validation as no control message was defined");
return;
- } else {
- Assert.isTrue(StringUtils.hasText(receivedMessagePayload), "Validation failed - " +
+ } else if (!StringUtils.hasText(receivedMessagePayload)) {
+ throw new ValidationException("Validation failed - " +
"expected message contents, but received empty message!");
}
if (!receivedMessagePayload.equals(controlMessagePayload)) {
- if (StringUtils.trimAllWhitespace(receivedMessagePayload).equals(StringUtils.trimAllWhitespace(controlMessagePayload))) {
+ if (receivedMessagePayload.replaceAll("\\s", "").equals(controlMessagePayload.replaceAll("\\s", ""))) {
throw new ValidationException("Text values not equal (only whitespaces!), expected '" + controlMessagePayload + "' " +
"but was '" + receivedMessagePayload + "'");
} else {
diff --git a/validation/citrus-validation-text/src/test/java/org/citrusframework/validation/text/GzipBinaryBase64MessageValidatorTest.java b/validation/citrus-validation-text/src/test/java/org/citrusframework/validation/text/GzipBinaryBase64MessageValidatorTest.java
index bc35b27a4a..c3725aabae 100644
--- a/validation/citrus-validation-text/src/test/java/org/citrusframework/validation/text/GzipBinaryBase64MessageValidatorTest.java
+++ b/validation/citrus-validation-text/src/test/java/org/citrusframework/validation/text/GzipBinaryBase64MessageValidatorTest.java
@@ -31,7 +31,6 @@
import org.citrusframework.validation.context.ValidationContext;
import org.citrusframework.validation.script.ScriptValidationContext;
import org.apache.commons.codec.binary.Base64;
-import org.springframework.util.StreamUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -40,8 +39,8 @@
*/
public class GzipBinaryBase64MessageValidatorTest extends AbstractTestNGUnitTest {
- private GzipBinaryBase64MessageValidator validator = new GzipBinaryBase64MessageValidator();
- private ValidationContext validationContext = new DefaultValidationContext();
+ private final GzipBinaryBase64MessageValidator validator = new GzipBinaryBase64MessageValidator();
+ private final ValidationContext validationContext = new DefaultValidationContext();
@Test
public void testGzipBinaryBase64Validation() throws IOException {
@@ -85,8 +84,8 @@ public void testGzipBinaryBase64ValidationError() throws IOException {
private byte[] getZippedContent(String payload) throws IOException {
try (ByteArrayOutputStream zipped = new ByteArrayOutputStream();
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(zipped)) {
- StreamUtils.copy(payload.getBytes(), gzipOutputStream);
-
+ gzipOutputStream.write(payload.getBytes());
+ gzipOutputStream.flush();
gzipOutputStream.close();
return zipped.toByteArray();
}
diff --git a/validation/citrus-validation-xml/pom.xml b/validation/citrus-validation-xml/pom.xml
index fca774cfbc..0e7e787e6d 100644
--- a/validation/citrus-validation-xml/pom.xml
+++ b/validation/citrus-validation-xml/pom.xml
@@ -25,6 +25,10 @@
provided
+
+ org.springframework
+ spring-core
+
org.springframework.ws
spring-xml
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/functions/core/CreateCDataSectionFunction.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/functions/core/CreateCDataSectionFunction.java
index 5900a464a3..f80547524d 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/functions/core/CreateCDataSectionFunction.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/functions/core/CreateCDataSectionFunction.java
@@ -21,7 +21,6 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
-import org.springframework.util.CollectionUtils;
/**
* Adds XML CDATA section tags to parameter value. This is extremely useful when having
@@ -39,7 +38,7 @@ public class CreateCDataSectionFunction implements Function {
@Override
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList) || parameterList.size() != 1) {
+ if (parameterList == null || parameterList.size() != 1) {
throw new InvalidFunctionUsageException("Invalid function parameter usage - missing parameter value!");
}
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/functions/core/EscapeXmlFunction.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/functions/core/EscapeXmlFunction.java
index bc79328b10..e9e9e814e3 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/functions/core/EscapeXmlFunction.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/functions/core/EscapeXmlFunction.java
@@ -22,7 +22,6 @@
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
import org.apache.commons.lang.StringEscapeUtils;
-import org.springframework.util.CollectionUtils;
/**
* Escapes XML fragment with escaped characters for '<', '>'.
@@ -33,7 +32,7 @@ public class EscapeXmlFunction implements Function {
@Override
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList) || parameterList.size() != 1) {
+ if (parameterList == null || parameterList.size() != 1) {
throw new InvalidFunctionUsageException("Invalid function parameter usage! Expected single parameter but found: " + parameterList.size());
}
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/functions/core/XpathFunction.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/functions/core/XpathFunction.java
index d7c92eef0d..5b0633af37 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/functions/core/XpathFunction.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/functions/core/XpathFunction.java
@@ -22,9 +22,8 @@
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
import org.citrusframework.util.XMLUtils;
+import org.citrusframework.xml.namespace.DefaultNamespaceContext;
import org.citrusframework.xml.xpath.XPathUtils;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.xml.SimpleNamespaceContext;
/**
* @author Christoph Deppisch
@@ -34,7 +33,7 @@ public class XpathFunction implements Function {
@Override
public String execute(List parameterList, TestContext context) {
- if (CollectionUtils.isEmpty(parameterList)) {
+ if (parameterList == null || parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty");
}
@@ -45,8 +44,8 @@ public String execute(List parameterList, TestContext context) {
String xmlSource = parameterList.get(0);
String xpathExpression = parameterList.get(1);
- SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
- namespaceContext.setBindings(context.getNamespaceContextBuilder().getNamespaceMappings());
+ DefaultNamespaceContext namespaceContext = new DefaultNamespaceContext();
+ namespaceContext.addNamespaces(context.getNamespaceContextBuilder().getNamespaceMappings());
return XPathUtils.evaluateAsString(XMLUtils.parseMessagePayload(context.replaceDynamicContentInString(xmlSource)),
context.replaceDynamicContentInString(xpathExpression), namespaceContext);
}
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/message/selector/RootQNameMessageSelector.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/message/selector/RootQNameMessageSelector.java
index 4225c47905..36c6976c66 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/message/selector/RootQNameMessageSelector.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/message/selector/RootQNameMessageSelector.java
@@ -20,11 +20,10 @@
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.util.XMLUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
import org.springframework.xml.namespace.QNameUtils;
import org.w3c.dom.Document;
import org.w3c.dom.ls.LSException;
@@ -37,7 +36,7 @@
public class RootQNameMessageSelector extends AbstractMessageSelector {
/** Target message XML root QName to look for */
- private QName rootQName;
+ private final QName rootQName;
/** Special selector element name identifying this message selector implementation */
public static final String SELECTOR_ID = "root-qname";
@@ -51,9 +50,10 @@ public class RootQNameMessageSelector extends AbstractMessageSelector {
public RootQNameMessageSelector(String name, String value, TestContext context) {
super(name, value, context);
- Assert.isTrue(selectKey.equals(SELECTOR_ID),
- String.format("Invalid usage of root QName message selector - " +
+ if (!selectKey.equals(SELECTOR_ID)) {
+ throw new CitrusRuntimeException(String.format("Invalid usage of root QName message selector - " +
"usage restricted to key '%s' but was '%s'", SELECTOR_ID, selectKey));
+ }
if (QNameUtils.validateQName(value)) {
this.rootQName = QNameUtils.parseQNameString(value);
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/util/XMLUtils.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/util/XMLUtils.java
index 2c2c4f9e2b..2d3e7d94d3 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/util/XMLUtils.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/util/XMLUtils.java
@@ -16,7 +16,6 @@
package org.citrusframework.util;
-import javax.xml.XMLConstants;
import java.io.ByteArrayInputStream;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
@@ -25,11 +24,11 @@
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
+import javax.xml.XMLConstants;
import org.citrusframework.CitrusSettings;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.xml.XmlConfigurer;
-import org.springframework.util.StringUtils;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xhtml/XhtmlMessageConverter.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xhtml/XhtmlMessageConverter.java
index 1982b535f7..1b3e15bd83 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xhtml/XhtmlMessageConverter.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xhtml/XhtmlMessageConverter.java
@@ -16,13 +16,11 @@
package org.citrusframework.validation.xhtml;
-import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import org.citrusframework.common.InitializingPhase;
-import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.springframework.core.io.Resource;
+import org.citrusframework.spi.Resource;
import org.w3c.tidy.Tidy;
/**
@@ -67,21 +65,17 @@ public String convert(String messagePayload) {
@Override
public void initialize() {
- try {
- if (tidyInstance == null) {
- tidyInstance = new Tidy();
- tidyInstance.setXHTML(true);
- tidyInstance.setShowWarnings(false);
- tidyInstance.setQuiet(true);
- tidyInstance.setEscapeCdata(true);
- tidyInstance.setTidyMark(false);
-
- if (tidyConfiguration != null) {
- tidyInstance.setConfigurationFromFile(tidyConfiguration.getFile().getAbsolutePath());
- }
+ if (tidyInstance == null) {
+ tidyInstance = new Tidy();
+ tidyInstance.setXHTML(true);
+ tidyInstance.setShowWarnings(false);
+ tidyInstance.setQuiet(true);
+ tidyInstance.setEscapeCdata(true);
+ tidyInstance.setTidyMark(false);
+
+ if (tidyConfiguration != null) {
+ tidyInstance.setConfigurationFromFile(tidyConfiguration.getFile().getAbsolutePath());
}
- } catch (IOException e) {
- throw new CitrusRuntimeException("Failed to initialize XHTML tidy instance");
}
}
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/DomXmlMessageValidator.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/DomXmlMessageValidator.java
index 0cf545863c..d0b5d5fbed 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/DomXmlMessageValidator.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/DomXmlMessageValidator.java
@@ -31,6 +31,7 @@
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageType;
import org.citrusframework.util.MessageUtils;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.util.XMLUtils;
import org.citrusframework.validation.AbstractMessageValidator;
import org.citrusframework.validation.ValidationUtils;
@@ -39,9 +40,6 @@
import org.citrusframework.xml.namespace.NamespaceContextBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
@@ -66,7 +64,7 @@ public class DomXmlMessageValidator extends AbstractMessageValidator receivedMessage.getHeaderData().size()) {
+ throw new ValidationException("Failed to validate header data XML fragments - found " +
receivedMessage.getHeaderData().size() + " header fragments, expected " + controlMessage.getHeaderData().size());
+ }
for (int i = 0; i < controlMessage.getHeaderData().size(); i++) {
validateXmlHeaderFragment(receivedMessage.getHeaderData().get(i),
@@ -96,9 +95,6 @@ public void validateMessage(Message receivedMessage, Message controlMessage,
logger.info("XML message validation successful: All values OK");
} catch (ClassCastException | DOMException | LSException e) {
throw new CitrusRuntimeException(e);
- } catch (IllegalArgumentException e) {
- logger.error("Failed to validate:\n" + XMLUtils.prettyPrint(receivedMessage.getPayload(String.class)));
- throw new ValidationException("Validation failed:", e);
} catch (ValidationException ex) {
logger.error("Failed to validate:\n" + XMLUtils.prettyPrint(receivedMessage.getPayload(String.class)));
throw ex;
@@ -114,7 +110,9 @@ public void validateMessage(Message receivedMessage, Message controlMessage,
* @param receivedMessage
*/
protected void validateNamespaces(Map expectedNamespaces, Message receivedMessage) {
- if (CollectionUtils.isEmpty(expectedNamespaces)) { return; }
+ if (expectedNamespaces == null || expectedNamespaces.isEmpty()) {
+ return;
+ }
if (receivedMessage.getPayload() == null || !StringUtils.hasText(receivedMessage.getPayload(String.class))) {
throw new ValidationException("Unable to validate message namespaces - receive message payload was empty");
@@ -162,8 +160,9 @@ private void doElementNameValidation(Node received, Node source) {
logger.debug("Validating element: " + received.getLocalName() + " (" + received.getNamespaceURI() + ")");
}
- Assert.isTrue(received.getLocalName().equals(source.getLocalName()),
- ValidationUtils.buildValueMismatchErrorMessage("Element names not equal", source.getLocalName(), received.getLocalName()));
+ if (!received.getLocalName().equals(source.getLocalName())) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Element names not equal", source.getLocalName(), received.getLocalName()));
+ }
}
private void doElementNamespaceValidation(Node received, Node source) {
@@ -173,16 +172,17 @@ private void doElementNamespaceValidation(Node received, Node source) {
}
if (received.getNamespaceURI() != null) {
- Assert.isTrue(source.getNamespaceURI() != null,
- ValidationUtils.buildValueMismatchErrorMessage("Element namespace not equal for element '" +
+ if (source.getNamespaceURI() == null) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Element namespace not equal for element '" +
received.getLocalName() + "'", null, received.getNamespaceURI()));
+ }
- Assert.isTrue(received.getNamespaceURI().equals(source.getNamespaceURI()),
- ValidationUtils.buildValueMismatchErrorMessage("Element namespace not equal for element '" +
- received.getLocalName() + "'", source.getNamespaceURI(), received.getNamespaceURI()));
- } else {
- Assert.isTrue(source.getNamespaceURI() == null,
- ValidationUtils.buildValueMismatchErrorMessage("Element namespace not equal for element '" +
+ if (!received.getNamespaceURI().equals(source.getNamespaceURI())) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Element namespace not equal for element '" +
+ received.getLocalName() + "'", source.getNamespaceURI(), received.getNamespaceURI()));
+ }
+ } else if (source.getNamespaceURI() != null) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Element namespace not equal for element '" +
received.getLocalName() + "'", source.getNamespaceURI(), null));
}
}
@@ -210,8 +210,9 @@ protected void validateMessageContent(Message receivedMessage, Message controlMe
String controlMessagePayload = controlMessage.getPayload(String.class);
if (receivedMessage.getPayload() == null || !StringUtils.hasText(receivedMessage.getPayload(String.class))) {
- Assert.isTrue(!StringUtils.hasText(controlMessagePayload),
- "Unable to validate message payload - received message payload was empty, control message payload is not");
+ if (StringUtils.hasText(controlMessagePayload)) {
+ throw new ValidationException("Unable to validate message payload - received message payload was empty, control message payload is not");
+ }
return;
} else if (!StringUtils.hasText(controlMessagePayload)) {
logger.debug("Skip message payload validation as no control message payload was defined");
@@ -300,7 +301,9 @@ private void doDocumentTypeDefinition(Node received, Node source,
XmlMessageValidationContext validationContext,
NamespaceContext namespaceContext, TestContext context) {
- Assert.isTrue(source instanceof DocumentType, "Missing document type definition in expected xml fragment");
+ if (!(source instanceof DocumentType)) {
+ throw new ValidationException("Missing document type definition in expected xml fragment");
+ }
DocumentType receivedDTD = (DocumentType) received;
DocumentType sourceDTD = (DocumentType) source;
@@ -311,35 +314,37 @@ private void doDocumentTypeDefinition(Node received, Node source,
}
if (!StringUtils.hasText(sourceDTD.getPublicId())) {
- Assert.isNull(receivedDTD.getPublicId(),
- ValidationUtils.buildValueMismatchErrorMessage("Document type public id not equal",
- sourceDTD.getPublicId(), receivedDTD.getPublicId()));
+ if (receivedDTD.getPublicId() != null) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Document type public id not equal",
+ sourceDTD.getPublicId(), receivedDTD.getPublicId()));
+ }
} else if (sourceDTD.getPublicId().trim().equals(CitrusSettings.IGNORE_PLACEHOLDER)) {
if (logger.isDebugEnabled()) {
logger.debug("Document type public id: '" + receivedDTD.getPublicId() +
"' is ignored by placeholder '" + CitrusSettings.IGNORE_PLACEHOLDER + "'");
}
} else {
- Assert.isTrue(StringUtils.hasText(receivedDTD.getPublicId()) &&
- receivedDTD.getPublicId().equals(sourceDTD.getPublicId()),
- ValidationUtils.buildValueMismatchErrorMessage("Document type public id not equal",
- sourceDTD.getPublicId(), receivedDTD.getPublicId()));
+ if (!StringUtils.hasText(receivedDTD.getPublicId()) || !receivedDTD.getPublicId().equals(sourceDTD.getPublicId())) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Document type public id not equal",
+ sourceDTD.getPublicId(), receivedDTD.getPublicId()));
+ }
}
if (!StringUtils.hasText(sourceDTD.getSystemId())) {
- Assert.isNull(receivedDTD.getSystemId(),
- ValidationUtils.buildValueMismatchErrorMessage("Document type system id not equal",
- sourceDTD.getSystemId(), receivedDTD.getSystemId()));
+ if (receivedDTD.getSystemId() != null) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Document type system id not equal",
+ sourceDTD.getSystemId(), receivedDTD.getSystemId()));
+ }
} else if (sourceDTD.getSystemId().trim().equals(CitrusSettings.IGNORE_PLACEHOLDER)) {
if (logger.isDebugEnabled()) {
logger.debug("Document type system id: '" + receivedDTD.getSystemId() +
"' is ignored by placeholder '" + CitrusSettings.IGNORE_PLACEHOLDER + "'");
}
} else {
- Assert.isTrue(StringUtils.hasText(receivedDTD.getSystemId()) &&
- receivedDTD.getSystemId().equals(sourceDTD.getSystemId()),
- ValidationUtils.buildValueMismatchErrorMessage("Document type system id not equal",
- sourceDTD.getSystemId(), receivedDTD.getSystemId()));
+ if (!StringUtils.hasText(receivedDTD.getSystemId()) || !receivedDTD.getSystemId().equals(sourceDTD.getSystemId())) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Document type system id not equal",
+ sourceDTD.getSystemId(), receivedDTD.getSystemId()));
+ }
}
validateXmlTree(received.getNextSibling(),
@@ -372,9 +377,10 @@ private void doElement(Node received, Node source,
NamedNodeMap receivedAttr = received.getAttributes();
NamedNodeMap sourceAttr = source.getAttributes();
- Assert.isTrue(countAttributes(receivedAttr) == countAttributes(sourceAttr),
- ValidationUtils.buildValueMismatchErrorMessage("Number of attributes not equal for element '"
+ if (countAttributes(receivedAttr) != countAttributes(sourceAttr)) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Number of attributes not equal for element '"
+ received.getLocalName() + "'", countAttributes(sourceAttr), countAttributes(receivedAttr)));
+ }
for (int i = 0; i < receivedAttr.getLength(); i++) {
doAttribute(received, receivedAttr.item(i), source, validationContext, namespaceContext, context);
@@ -395,9 +401,10 @@ private void doElement(Node received, Node source,
List receivedChildElements = DomUtils.getChildElements((Element) received);
List sourceChildElements = DomUtils.getChildElements((Element) source);
- Assert.isTrue(receivedChildElements.size() == sourceChildElements.size(),
- ValidationUtils.buildValueMismatchErrorMessage("Number of child elements not equal for element '"
+ if (receivedChildElements.size() != sourceChildElements.size()) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Number of child elements not equal for element '"
+ received.getLocalName() + "'", sourceChildElements.size(), receivedChildElements.size()));
+ }
for (int i = 0; i < receivedChildElements.size(); i++) {
this.validateXmlTree(receivedChildElements.get(i), sourceChildElements.get(i),
@@ -424,19 +431,9 @@ private void doText(Element received, Element source) {
String receivedText = DomUtils.getTextValue(received);
String sourceText = DomUtils.getTextValue(source);
- if (receivedText != null) {
- Assert.isTrue(sourceText != null,
- ValidationUtils.buildValueMismatchErrorMessage("Node value not equal for element '"
- + received.getLocalName() + "'", null, receivedText.trim()));
-
- Assert.isTrue(receivedText.trim().equals(sourceText.trim()),
- ValidationUtils.buildValueMismatchErrorMessage("Node value not equal for element '"
- + received.getLocalName() + "'", sourceText.trim(),
- receivedText.trim()));
- } else {
- Assert.isTrue(sourceText == null,
- ValidationUtils.buildValueMismatchErrorMessage("Node value not equal for element '"
- + received.getLocalName() + "'", sourceText.trim(), null));
+ if (!receivedText.trim().equals(sourceText.trim())) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Node value not equal for element '"
+ + received.getLocalName() + "'", sourceText.trim(), receivedText.trim()));
}
if (logger.isDebugEnabled()) {
@@ -465,10 +462,11 @@ private void doAttribute(Node receivedElement, Node receivedAttribute, Node sour
NamedNodeMap sourceAttributes = sourceElement.getAttributes();
Node sourceAttribute = sourceAttributes.getNamedItemNS(receivedAttribute.getNamespaceURI(), receivedAttributeName);
- Assert.isTrue(sourceAttribute != null,
- "Attribute validation failed for element '"
+ if (sourceAttribute == null) {
+ throw new ValidationException("Attribute validation failed for element '"
+ receivedElement.getLocalName() + "', unknown attribute "
+ receivedAttributeName + " (" + receivedAttribute.getNamespaceURI() + ")");
+ }
if (XmlValidationUtils.isAttributeIgnored(receivedElement, receivedAttribute, sourceAttribute, validationContext.getIgnoreExpressions(), namespaceContext)) {
return;
@@ -484,9 +482,10 @@ private void doAttribute(Node receivedElement, Node receivedAttribute, Node sour
} else if (receivedValue.contains(":") && sourceValue.contains(":")) {
doNamespaceQualifiedAttributeValidation(receivedElement, receivedAttribute, sourceElement, sourceAttribute);
} else {
- Assert.isTrue(receivedValue.equals(sourceValue),
- ValidationUtils.buildValueMismatchErrorMessage("Values not equal for attribute '"
+ if (!receivedValue.equals(sourceValue)) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Values not equal for attribute '"
+ receivedAttributeName + "'", sourceValue, receivedValue));
+ }
}
if (logger.isDebugEnabled()) {
@@ -519,9 +518,10 @@ private void doNamespaceQualifiedAttributeValidation(Node receivedElement, Node
sourceNamespaces.putAll(XMLUtils.lookupNamespaces(sourceElement));
if (sourceNamespaces.containsKey(sourcePrefix)) {
- Assert.isTrue(sourceNamespaces.get(sourcePrefix).equals(receivedNamespaces.get(receivedPrefix)),
- ValidationUtils.buildValueMismatchErrorMessage("Values not equal for attribute value namespace '"
+ if (!sourceNamespaces.get(sourcePrefix).equals(receivedNamespaces.get(receivedPrefix))) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Values not equal for attribute value namespace '"
+ receivedValue + "'", sourceNamespaces.get(sourcePrefix), receivedNamespaces.get(receivedPrefix)));
+ }
// remove namespace prefixes as they must not form equality
receivedValue = receivedValue.substring((receivedPrefix + ":").length());
@@ -533,9 +533,10 @@ private void doNamespaceQualifiedAttributeValidation(Node receivedElement, Node
}
}
- Assert.isTrue(receivedValue.equals(sourceValue),
- ValidationUtils.buildValueMismatchErrorMessage("Values not equal for attribute '"
+ if (!receivedValue.equals(sourceValue)) {
+ throw new ValidationException(ValidationUtils.buildValueMismatchErrorMessage("Values not equal for attribute '"
+ receivedAttribute.getLocalName() + "'", sourceValue, receivedValue));
+ }
}
/**
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XmlMarshallingValidationProcessor.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XmlMarshallingValidationProcessor.java
index 4d5556401f..e04ead1b0a 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XmlMarshallingValidationProcessor.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XmlMarshallingValidationProcessor.java
@@ -16,11 +16,11 @@
package org.citrusframework.validation.xml;
+import java.io.File;
+import java.util.Map;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
-import java.io.File;
-import java.util.Map;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
@@ -28,11 +28,11 @@
import org.citrusframework.message.MessageProcessor;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;
+import org.citrusframework.util.ObjectHelper;
import org.citrusframework.validation.AbstractValidationProcessor;
import org.citrusframework.validation.GenericValidationProcessor;
import org.citrusframework.xml.StringSource;
import org.citrusframework.xml.Unmarshaller;
-import org.springframework.util.Assert;
import org.w3c.dom.Document;
/**
@@ -68,8 +68,8 @@ public void validate(Message message, TestContext context) {
@SuppressWarnings("unchecked")
private T unmarshalMessage(Message message) {
if (unmarshaller == null) {
- Assert.notNull(referenceResolver, "Marshalling validation callback requires marshaller instance " +
- "or proper reference resolver with nested bean definition of type marshaller");
+ ObjectHelper.assertNotNull(referenceResolver, "Marshalling validation callback requires marshaller instance " +
+ "or proper reference resolver with nested bean definition of type marshaller");
unmarshaller = referenceResolver.resolve(Unmarshaller.class);
}
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XmlValidationUtils.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XmlValidationUtils.java
index 2e2819b332..0f0f88d884 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XmlValidationUtils.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XmlValidationUtils.java
@@ -16,16 +16,15 @@
package org.citrusframework.validation.xml;
-import javax.xml.namespace.NamespaceContext;
import java.util.Set;
+import javax.xml.namespace.NamespaceContext;
import org.citrusframework.CitrusSettings;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.util.XMLUtils;
import org.citrusframework.xml.xpath.XPathUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -80,7 +79,7 @@ public static boolean isElementIgnored(Node source, Node received, Set i
* @return
*/
public static boolean isElementIgnored(final Node received, Set ignoreExpressions, NamespaceContext namespaceContext) {
- if (CollectionUtils.isEmpty(ignoreExpressions)) {
+ if (ignoreExpressions == null || ignoreExpressions.isEmpty()) {
return false;
}
@@ -168,7 +167,7 @@ public static boolean isAttributeIgnored(Node receivedElement, Node receivedAttr
*/
private static boolean isAttributeIgnored(Node receivedElement, Node receivedAttribute,
Set ignoreMessageElements, NamespaceContext namespaceContext) {
- if (CollectionUtils.isEmpty(ignoreMessageElements)) {
+ if (ignoreMessageElements == null || ignoreMessageElements.isEmpty()) {
return false;
}
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XpathMessageProcessor.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XpathMessageProcessor.java
index c6c9b3525f..36a5f37606 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XpathMessageProcessor.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XpathMessageProcessor.java
@@ -29,11 +29,11 @@
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageProcessor;
import org.citrusframework.message.MessageType;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.util.XMLUtils;
import org.citrusframework.xml.xpath.XPathUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XpathMessageValidator.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XpathMessageValidator.java
index 4b6d3480e8..556c95d480 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XpathMessageValidator.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/validation/xml/XpathMessageValidator.java
@@ -27,6 +27,7 @@
import org.citrusframework.exceptions.UnknownElementException;
import org.citrusframework.exceptions.ValidationException;
import org.citrusframework.message.Message;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.util.XMLUtils;
import org.citrusframework.validation.AbstractMessageValidator;
import org.citrusframework.validation.ValidationUtils;
@@ -36,8 +37,6 @@
import org.citrusframework.xml.xpath.XPathUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -56,7 +55,9 @@ public class XpathMessageValidator extends AbstractMessageValidator {
/** Logger */
@@ -51,7 +51,6 @@ public class XmlSchemaValidation implements SchemaValidator namespaces = XMLUtils.lookupNamespaces(node.getOwnerDocument());
// add default namespace mappings
namespaces.putAll(getNamespaceContextBuilder(context).getNamespaceMappings());
- simpleNamespaceContext.setBindings(namespaces);
+ simpleNamespaceContext.addNamespaces(namespaces);
return simpleNamespaceContext;
}
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/LSResolverImpl.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/LSResolverImpl.java
index fad7ad7710..e0cc3521fb 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/LSResolverImpl.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/LSResolverImpl.java
@@ -16,22 +16,21 @@
package org.citrusframework.xml;
-import java.io.IOException;
-
-import org.springframework.core.io.ClassPathResource;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSResourceResolver;
/**
* Very basic LSResolver implementation for resolving dtd resources by their systemId.
- *
+ *
* @author Christoph Deppisch
*/
public class LSResolverImpl implements LSResourceResolver {
/** DOM implementation */
private DOMImplementationLS domImpl;
-
+
/**
* Constructor
* @param domImpl
@@ -39,19 +38,19 @@ public class LSResolverImpl implements LSResourceResolver {
public LSResolverImpl(DOMImplementationLS domImpl) {
this.domImpl = domImpl;
}
-
+
/**
* @see org.w3c.dom.ls.LSResourceResolver#resolveResource(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
public LSInput resolveResource(String type, String namespaceURI,
String publicId, String systemId, String baseURI) {
LSInput input = domImpl.createLSInput();
- try {
- input.setByteStream(new ClassPathResource(systemId).getInputStream());
- } catch (IOException e) {
+ Resource resource = Resources.newClasspathResource(systemId);
+ if (resource.getInputStream() == null || !resource.exists()) {
return null;
}
-
+
+ input.setByteStream(resource.getInputStream());
return input;
}
}
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/XpathSegmentVariableExtractor.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/XpathSegmentVariableExtractor.java
index e8cb1e968f..c6480f8906 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/XpathSegmentVariableExtractor.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/XpathSegmentVariableExtractor.java
@@ -1,5 +1,9 @@
package org.citrusframework.xml;
+import java.util.Collections;
+import java.util.UUID;
+import javax.xml.namespace.NamespaceContext;
+
import org.citrusframework.XmlValidationHelper;
import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
@@ -8,18 +12,12 @@
import org.citrusframework.util.XMLUtils;
import org.citrusframework.variable.SegmentVariableExtractorRegistry;
import org.citrusframework.variable.VariableExpressionSegmentMatcher;
-import org.citrusframework.xml.namespace.NamespaceContextBuilder;
import org.citrusframework.xml.xpath.XPathExpressionResult;
import org.citrusframework.xml.xpath.XPathUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.xml.SimpleNamespaceContext;
import org.w3c.dom.Document;
-import javax.xml.namespace.NamespaceContext;
-import java.util.Collections;
-import java.util.UUID;
-
/**
* @author Thorsten Schlathoelter
*/
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/XsdSchemaRepository.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/XsdSchemaRepository.java
index 495a761fc7..483132c448 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/XsdSchemaRepository.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/XsdSchemaRepository.java
@@ -17,20 +17,26 @@
package org.citrusframework.xml;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
import org.citrusframework.common.InitializingPhase;
import org.citrusframework.common.Named;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.ClasspathResourceResolver;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.xml.schema.TargetNamespaceSchemaMappingStrategy;
import org.citrusframework.xml.schema.WsdlXsdSchema;
import org.citrusframework.xml.schema.XsdSchemaMappingStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.core.io.ByteArrayResource;
import org.springframework.xml.xsd.SimpleXsdSchema;
import org.springframework.xml.xsd.XsdSchema;
import org.w3c.dom.Document;
@@ -43,7 +49,7 @@
*/
@SuppressWarnings("unused")
public class XsdSchemaRepository implements Named, InitializingPhase {
- /** This repositories name in the Spring application context */
+ /** The name of the repository */
private String name = "schemaRepository";
/** List of schema resources */
@@ -71,13 +77,19 @@ public boolean canValidate(Document doc) {
@Override
public void initialize() {
try {
- PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
-
+ ClasspathResourceResolver resourceResolver = new ClasspathResourceResolver();
for (String location : locations) {
- Resource[] findings = resourcePatternResolver.getResources(location);
+ Set findings;
+ if (StringUtils.hasText(FileUtils.getFileExtension(location))) {
+ String fileNamePattern = FileUtils.getFileName(location).replace(".", "\\.").replace("*", ".*");
+ String basePath = FileUtils.getBasePath(location);
+ findings = resourceResolver.getResources(basePath, fileNamePattern);
+ } else {
+ findings = resourceResolver.getResources(location);
+ }
- for (Resource resource : findings) {
- addSchemas(resource);
+ for (Path resource : findings) {
+ addSchemas(Resources.newClasspathResource(resource.toString()));
}
}
@@ -98,25 +110,25 @@ public void initialize() {
* @param schemaName The name of the schema within the citrus schema package
*/
protected void addCitrusSchema(String schemaName) throws IOException, SAXException, ParserConfigurationException {
- Resource resource = new PathMatchingResourcePatternResolver().getResource("classpath:org/citrusframework/schema/" + schemaName + ".xsd");
+ Resource resource = Resources.newClasspathResource("classpath:org/citrusframework/schema/" + schemaName + ".xsd");
if (resource.exists()) {
addXsdSchema(resource);
}
}
private void addSchemas(Resource resource) {
- if (resource.getFilename().endsWith(".xsd")) {
+ if (resource.getLocation().endsWith(".xsd")) {
addXsdSchema(resource);
- } else if (resource.getFilename().endsWith(".wsdl")) {
+ } else if (resource.getLocation().endsWith(".wsdl")) {
addWsdlSchema(resource);
} else {
- logger.warn("Skipped resource other than XSD schema for repository (" + resource.getFilename() + ")");
+ logger.warn("Skipped resource other than XSD schema for repository (" + resource.getLocation() + ")");
}
}
private void addWsdlSchema(Resource resource) {
if (logger.isDebugEnabled()) {
- logger.debug("Loading WSDL schema resource " + resource.getFilename());
+ logger.debug("Loading WSDL schema resource " + resource.getLocation());
}
WsdlXsdSchema wsdl = new WsdlXsdSchema(resource);
@@ -126,10 +138,10 @@ private void addWsdlSchema(Resource resource) {
private void addXsdSchema(Resource resource) {
if (logger.isDebugEnabled()) {
- logger.debug("Loading XSD schema resource " + resource.getFilename());
+ logger.debug("Loading XSD schema resource " + resource.getLocation());
}
- SimpleXsdSchema schema = new SimpleXsdSchema(resource);
+ SimpleXsdSchema schema = new SimpleXsdSchema(new ByteArrayResource(FileUtils.copyToByteArray(resource)));
try {
schema.afterPropertiesSet();
} catch (ParserConfigurationException | IOException | SAXException e) {
@@ -177,7 +189,7 @@ public void setName(String name) {
/**
* Gets the name.
- * @return the name the name to get.
+ * @return the name to get.
*/
public String getName() {
return name;
@@ -185,7 +197,7 @@ public String getName() {
/**
* Gets the locations.
- * @return the locations the locations to get.
+ * @return the locations to get.
*/
public List getLocations() {
return locations;
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/AbstractSchemaCollection.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/AbstractSchemaCollection.java
index 08c0c321ac..d3ac9d6e82 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/AbstractSchemaCollection.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/AbstractSchemaCollection.java
@@ -16,6 +16,12 @@
package org.citrusframework.xml.schema;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
import javax.wsdl.WSDLException;
import javax.wsdl.extensions.schema.Schema;
import javax.wsdl.extensions.schema.SchemaImport;
@@ -28,19 +34,15 @@
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Vector;
import org.citrusframework.common.InitializingPhase;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.FileUtils;
import org.springframework.core.io.ByteArrayResource;
+import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
-import org.springframework.util.Assert;
import org.springframework.xml.validation.XmlValidator;
import org.springframework.xml.validation.XmlValidatorFactory;
import org.springframework.xml.xsd.SimpleXsdSchema;
@@ -65,12 +67,26 @@ public abstract class AbstractSchemaCollection extends SimpleXsdSchema implement
@Override
public XmlValidator createValidator() {
try {
- return XmlValidatorFactory.createValidator(schemaResources.toArray(new Resource[schemaResources.size()]), W3C_XML_SCHEMA_NS_URI);
+ return XmlValidatorFactory.createValidator(schemaResources
+ .stream()
+ .map(AbstractSchemaCollection::toSpringResource)
+ .toList()
+ .toArray(new org.springframework.core.io.Resource[]{}), W3C_XML_SCHEMA_NS_URI);
} catch (IOException e) {
throw new CitrusRuntimeException("Failed to create validator from multi resource schema files", e);
}
}
+ public static org.springframework.core.io.Resource toSpringResource(Resource resource) {
+ if (resource instanceof Resources.ClasspathResource) {
+ return new ClassPathResource(resource.getLocation());
+ } else if (resource instanceof Resources.FileSystemResource) {
+ return new FileSystemResource(resource.getLocation());
+ }
+
+ return new ByteArrayResource(FileUtils.copyToByteArray(resource));
+ }
+
/**
* Recursively add all imported schemas as schema resource.
* This is necessary when schema import are located in jar files. If they are not added immediately the reference to them is lost.
@@ -91,7 +107,7 @@ protected void addImportedSchemas(Schema schema) throws WSDLException, IOExcepti
Result result = new StreamResult(bos);
TransformerFactory.newInstance().newTransformer().transform(source, result);
- Resource schemaResource = new ByteArrayResource(bos.toByteArray());
+ Resource schemaResource = Resources.create(bos.toByteArray());
addImportedSchemas(referencedSchema);
schemaResources.add(schemaResource);
@@ -115,20 +131,22 @@ protected void addIncludedSchemas(Schema schema) throws WSDLException, IOExcepti
schemaLocation = schema.getDocumentBaseURI().substring(0, schema.getDocumentBaseURI().lastIndexOf('/') + 1) + schemaReference.getSchemaLocationURI();
}
- schemaResources.add(new FileSystemResource(schemaLocation));
+ schemaResources.add(Resources.create(schemaLocation));
}
}
@Override
public void initialize() {
Resource targetXsd = loadSchemaResources();
-
if (targetXsd == null) {
throw new CitrusRuntimeException("Failed to find target schema xsd file resource");
}
- Assert.isTrue(!schemaResources.isEmpty(), "At least one schema xsd file resource is required");
- setXsd(targetXsd);
+ if (schemaResources.isEmpty()) {
+ throw new CitrusRuntimeException("At least one schema xsd file resource is required");
+ }
+
+ setXsd(new ByteArrayResource(FileUtils.copyToByteArray(targetXsd)));
try {
super.afterPropertiesSet();
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/RootQNameSchemaMappingStrategy.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/RootQNameSchemaMappingStrategy.java
index 67961da9c7..07c47e65d9 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/RootQNameSchemaMappingStrategy.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/RootQNameSchemaMappingStrategy.java
@@ -16,12 +16,12 @@
package org.citrusframework.xml.schema;
-import javax.xml.namespace.QName;
import java.util.List;
import java.util.Map;
+import javax.xml.namespace.QName;
import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
import org.springframework.xml.xsd.XsdSchema;
/**
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/TargetNamespaceSchemaMappingStrategy.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/TargetNamespaceSchemaMappingStrategy.java
index da023b4cc6..ed8952d85a 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/TargetNamespaceSchemaMappingStrategy.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/TargetNamespaceSchemaMappingStrategy.java
@@ -18,14 +18,14 @@
import java.util.List;
-import org.springframework.util.StringUtils;
+import org.citrusframework.util.StringUtils;
import org.springframework.xml.xsd.XsdSchema;
/**
* Mapping strategy checks on target namespaces in schemas to find matching schema
* instance.
- *
+ *
* @author Christoph Deppisch
*/
public class TargetNamespaceSchemaMappingStrategy extends AbstractSchemaMappingStrategy {
@@ -33,12 +33,12 @@ public class TargetNamespaceSchemaMappingStrategy extends AbstractSchemaMappingS
@Override
public XsdSchema getSchema(List schemas, String namespace, String elementName) {
for (XsdSchema schema : schemas) {
- if (StringUtils.hasText(schema.getTargetNamespace()) &&
+ if (StringUtils.hasText(schema.getTargetNamespace()) &&
schema.getTargetNamespace().equals(namespace)) {
return schema;
}
}
-
+
return null;
}
}
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/WsdlXsdSchema.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/WsdlXsdSchema.java
index 5db6b8456d..2016efb21d 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/WsdlXsdSchema.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/WsdlXsdSchema.java
@@ -16,6 +16,13 @@
package org.citrusframework.xml.schema;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Vector;
import javax.wsdl.Definition;
import javax.wsdl.Import;
import javax.wsdl.Types;
@@ -29,27 +36,16 @@
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.net.URI;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Vector;
+import com.ibm.wsdl.extensions.schema.SchemaImpl;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.ObjectHelper;
+import org.citrusframework.util.StringUtils;
import org.citrusframework.xml.schema.locator.JarWSDLLocator;
-import com.ibm.wsdl.extensions.schema.SchemaImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.BeanCreationException;
-import org.springframework.core.io.ByteArrayResource;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.UrlResource;
-import org.springframework.util.Assert;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
import org.xml.sax.InputSource;
/**
@@ -86,13 +82,15 @@ public WsdlXsdSchema(Resource wsdl) {
@Override
public Resource loadSchemaResources() {
- Assert.notNull(wsdl, "wsdl file resource is required");
- Assert.isTrue(wsdl.exists(), "wsdl file resource '" + wsdl + " does not exist");
+ ObjectHelper.assertNotNull(wsdl, "wsdl file resource is required");
+ if (!wsdl.exists()) {
+ throw new CitrusRuntimeException("wsdl file resource '" + wsdl + " does not exist");
+ }
try {
return loadSchemas(getWsdlDefinition(wsdl));
} catch (Exception e) {
- throw new BeanCreationException("Failed to load schema types from WSDL file", e);
+ throw new CitrusRuntimeException("Failed to load schema types from WSDL file", e);
}
}
@@ -124,7 +122,7 @@ private Resource loadSchemas(Definition definition) throws WSDLException, IOExce
Result result = new StreamResult(bos);
TransformerFactory.newInstance().newTransformer().transform(source, result);
- Resource schemaResource = new ByteArrayResource(bos.toByteArray());
+ Resource schemaResource = Resources.create(bos.toByteArray());
importedSchemas.add(getTargetNamespace(schema));
schemaResources.add(schemaResource);
@@ -151,11 +149,7 @@ private Resource loadSchemas(Definition definition) throws WSDLException, IOExce
schemaLocation = definition.getDocumentBaseURI().substring(0, definition.getDocumentBaseURI().lastIndexOf('/') + 1) + wsdlImport.getLocationURI();
}
- if (schemaLocation.startsWith("jar:")) {
- loadSchemas(getWsdlDefinition(new UrlResource(schemaLocation)));
- } else {
- loadSchemas(getWsdlDefinition(new FileSystemResource(schemaLocation)));
- }
+ loadSchemas(getWsdlDefinition(Resources.create(schemaLocation)));
}
}
@@ -163,7 +157,7 @@ private Resource loadSchemas(Definition definition) throws WSDLException, IOExce
// Obviously no schema resource in WSDL did match the targetNamespace, just use the first schema resource found as main schema
if (firstSchemaInWSDL != null) {
targetXsd = firstSchemaInWSDL;
- } else if (!CollectionUtils.isEmpty(schemaResources)) {
+ } else if (!schemaResources.isEmpty()) {
targetXsd = schemaResources.get(0);
}
}
@@ -211,8 +205,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 wsdl schema instance", e);
}
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/XsdSchemaCollection.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/XsdSchemaCollection.java
index df2d83e16f..32b3ec8363 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/XsdSchemaCollection.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/XsdSchemaCollection.java
@@ -16,12 +16,17 @@
package org.citrusframework.xml.schema;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import org.citrusframework.exceptions.CitrusRuntimeException;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.citrusframework.spi.ClasspathResourceResolver;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
+import org.citrusframework.util.FileUtils;
+import org.citrusframework.util.StringUtils;
/**
* Schema combines multiple file resources usually with exactly the same target namespace to
@@ -38,14 +43,21 @@ public class XsdSchemaCollection extends AbstractSchemaCollection {
* Loads all schema resource files from schema locations.
*/
protected Resource loadSchemaResources() {
- PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
+ ClasspathResourceResolver resourceResolver = new ClasspathResourceResolver();
for (String location : schemas) {
try {
- Resource[] findings = resourcePatternResolver.getResources(location);
+ Set findings;
+ if (StringUtils.hasText(FileUtils.getFileExtension(location))) {
+ String fileNamePattern = FileUtils.getFileName(location).replace(".", "\\.").replace("*", ".*");
+ String basePath = FileUtils.getBasePath(location);
+ findings = resourceResolver.getResources(basePath, fileNamePattern);
+ } else {
+ findings = resourceResolver.getResources(location);
+ }
- for (Resource finding : findings) {
- if (finding.getFilename().endsWith(".xsd") || finding.getFilename().endsWith(".wsdl")) {
- schemaResources.add(finding);
+ for (Path finding : findings) {
+ if (finding.toString().endsWith(".xsd") || finding.toString().endsWith(".wsdl")) {
+ schemaResources.add(Resources.newClasspathResource(finding.toString()));
}
}
} catch (IOException e) {
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/locator/JarWSDLLocator.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/locator/JarWSDLLocator.java
index 6b159adf4e..8d187c7faa 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/locator/JarWSDLLocator.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/schema/locator/JarWSDLLocator.java
@@ -16,14 +16,13 @@
package org.citrusframework.xml.schema.locator;
-import javax.wsdl.xml.WSDLLocator;
-import java.io.IOException;
import java.net.URI;
+import javax.wsdl.xml.WSDLLocator;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.xml.sax.InputSource;
/**
@@ -34,7 +33,7 @@ public class JarWSDLLocator implements WSDLLocator {
/** Logger */
private static final Logger logger = LoggerFactory.getLogger(JarWSDLLocator.class);
- private Resource wsdl;
+ private final Resource wsdl;
private Resource importResource = null;
public JarWSDLLocator(Resource wsdl) {
@@ -43,11 +42,7 @@ public JarWSDLLocator(Resource wsdl) {
@Override
public InputSource getBaseInputSource() {
- try {
- return new InputSource(wsdl.getInputStream());
- } catch (IOException e) {
- return null;
- }
+ return new InputSource(wsdl.getInputStream());
}
@Override
@@ -60,22 +55,13 @@ public InputSource getImportInputSource(String parentLocation, String importLoca
resolvedImportLocation = parentLocation.substring(0, parentLocation.lastIndexOf('/') + 1) + importLocation;
}
- try {
- importResource = new PathMatchingResourcePatternResolver().getResource(resolvedImportLocation);
- return new InputSource(importResource.getInputStream());
- } catch (IOException e) {
- logger.warn(String.format("Failed to resolve imported WSDL schema path location '%s'", importLocation), e);
- return null;
- }
+ importResource = Resources.create(resolvedImportLocation);
+ return new InputSource(importResource.getInputStream());
}
@Override
public String getBaseURI() {
- try {
- return wsdl.getURI().toString();
- } catch (IOException e) {
- return null;
- }
+ return wsdl.getURI().toString();
}
@Override
@@ -84,12 +70,7 @@ public String getLatestImportURI() {
return null;
}
- try {
- return importResource.getURI().toString();
- } catch (IOException e) {
- logger.warn("Failed to resolve last imported WSDL schema resource", e);
- return null;
- }
+ return importResource.getURI().toString();
}
@Override
diff --git a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/xpath/XPathUtils.java b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/xpath/XPathUtils.java
index 411cf05f95..143a7a3c3e 100644
--- a/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/xpath/XPathUtils.java
+++ b/validation/citrus-validation-xml/src/main/java/org/citrusframework/xml/xpath/XPathUtils.java
@@ -16,6 +16,12 @@
package org.citrusframework.xml.xpath;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.xpath.XPath;
@@ -24,17 +30,11 @@
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathFactoryConfigurationException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
diff --git a/validation/citrus-validation-xml/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageActionBuilderTest.java b/validation/citrus-validation-xml/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageActionBuilderTest.java
index 6a13092029..b9f0644ce2 100644
--- a/validation/citrus-validation-xml/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageActionBuilderTest.java
+++ b/validation/citrus-validation-xml/src/test/java/org/citrusframework/actions/dsl/ReceiveMessageActionBuilderTest.java
@@ -42,6 +42,7 @@
import org.citrusframework.messaging.SelectiveConsumer;
import org.citrusframework.report.TestActionListeners;
import org.citrusframework.spi.ReferenceResolver;
+import org.citrusframework.spi.Resource;
import org.citrusframework.validation.AbstractValidationProcessor;
import org.citrusframework.validation.builder.DefaultMessageBuilder;
import org.citrusframework.validation.builder.StaticMessageBuilder;
@@ -59,7 +60,6 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.springframework.core.io.Resource;
import org.springframework.xml.validation.XmlValidator;
import org.springframework.xml.xsd.XsdSchema;
import org.testng.Assert;
diff --git a/validation/citrus-validation-xml/src/test/java/org/citrusframework/actions/dsl/SendMessageActionBuilderTest.java b/validation/citrus-validation-xml/src/test/java/org/citrusframework/actions/dsl/SendMessageActionBuilderTest.java
index 2df6ca1499..f1787b02af 100644
--- a/validation/citrus-validation-xml/src/test/java/org/citrusframework/actions/dsl/SendMessageActionBuilderTest.java
+++ b/validation/citrus-validation-xml/src/test/java/org/citrusframework/actions/dsl/SendMessageActionBuilderTest.java
@@ -40,7 +40,6 @@
import org.citrusframework.xml.Marshaller;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -228,7 +227,7 @@ public void testXpathSupport() {
when(messageEndpoint.getActor()).thenReturn(null);
doAnswer(invocation -> {
Message message = (Message) invocation.getArguments()[0];
- Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),
+ Assert.assertEquals(message.getPayload(String.class).replaceAll("\\s", ""),
"HelloWorld! ");
return null;
}).when(messageProducer).send(any(Message.class), any(TestContext.class));
diff --git a/validation/citrus-validation-xml/src/test/java/org/citrusframework/validation/xml/DomXmlMessageValidatorTest.java b/validation/citrus-validation-xml/src/test/java/org/citrusframework/validation/xml/DomXmlMessageValidatorTest.java
index 6043bc11a4..ca403b1eaf 100644
--- a/validation/citrus-validation-xml/src/test/java/org/citrusframework/validation/xml/DomXmlMessageValidatorTest.java
+++ b/validation/citrus-validation-xml/src/test/java/org/citrusframework/validation/xml/DomXmlMessageValidatorTest.java
@@ -16,7 +16,6 @@
package org.citrusframework.validation.xml;
-import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -24,6 +23,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.xml.parsers.ParserConfigurationException;
import org.citrusframework.UnitTestSupport;
import org.citrusframework.context.TestContextFactory;
@@ -32,7 +32,6 @@
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageType;
-import org.citrusframework.util.FileUtils;
import org.citrusframework.validation.SchemaValidator;
import org.citrusframework.validation.context.HeaderValidationContext;
import org.citrusframework.validation.context.SchemaValidationContext;
@@ -55,26 +54,26 @@
*/
public class DomXmlMessageValidatorTest extends UnitTestSupport {
- private DomXmlMessageValidator validator = new DomXmlMessageValidator();
+ private final DomXmlMessageValidator validator = new DomXmlMessageValidator();
- private XsdSchemaRepository schemaRepository = new XsdSchemaRepository();
- private XsdSchemaRepository testSchemaRepository1 = new XsdSchemaRepository();
- private XsdSchemaRepository testSchemaRepository2 = new XsdSchemaRepository();
+ private final XsdSchemaRepository schemaRepository = new XsdSchemaRepository();
+ private final XsdSchemaRepository testSchemaRepository1 = new XsdSchemaRepository();
+ private final XsdSchemaRepository testSchemaRepository2 = new XsdSchemaRepository();
- private SimpleXsdSchema testSchema = new SimpleXsdSchema();
- private SimpleXsdSchema testSchema1 = new SimpleXsdSchema();
- private SimpleXsdSchema testSchema2 = new SimpleXsdSchema();
- private SimpleXsdSchema testSchema3 = new SimpleXsdSchema();
+ private final SimpleXsdSchema testSchema = new SimpleXsdSchema();
+ private final SimpleXsdSchema testSchema1 = new SimpleXsdSchema();
+ private final SimpleXsdSchema testSchema2 = new SimpleXsdSchema();
+ private final SimpleXsdSchema testSchema3 = new SimpleXsdSchema();
@BeforeClass
public void setupMocks() throws Exception {
- testSchema.setXsd(FileUtils.getFileResource("org/citrusframework/validation/test.xsd"));
+ testSchema.setXsd(new ClassPathResource("org/citrusframework/validation/test.xsd"));
testSchema.afterPropertiesSet();
- testSchema1.setXsd(FileUtils.getFileResource("org/citrusframework/validation/test.xsd"));
+ testSchema1.setXsd(new ClassPathResource("org/citrusframework/validation/test.xsd"));
testSchema1.afterPropertiesSet();
- testSchema2.setXsd(FileUtils.getFileResource("org/citrusframework/validation/test.xsd"));
+ testSchema2.setXsd(new ClassPathResource("org/citrusframework/validation/test.xsd"));
testSchema2.afterPropertiesSet();
- testSchema3.setXsd(FileUtils.getFileResource("org/citrusframework/validation/test.xsd"));
+ testSchema3.setXsd(new ClassPathResource("org/citrusframework/validation/test.xsd"));
testSchema3.afterPropertiesSet();
schemaRepository.getSchemas().add(testSchema);
diff --git a/validation/citrus-validation-xml/src/test/java/org/citrusframework/validation/xml/ReceiveMessageActionTest.java b/validation/citrus-validation-xml/src/test/java/org/citrusframework/validation/xml/ReceiveMessageActionTest.java
index d0c9177898..763d7fa1e8 100644
--- a/validation/citrus-validation-xml/src/test/java/org/citrusframework/validation/xml/ReceiveMessageActionTest.java
+++ b/validation/citrus-validation-xml/src/test/java/org/citrusframework/validation/xml/ReceiveMessageActionTest.java
@@ -16,6 +16,9 @@
package org.citrusframework.validation.xml;
+import java.util.HashMap;
+import java.util.Map;
+
import org.citrusframework.DefaultTestCase;
import org.citrusframework.TestActor;
import org.citrusframework.TestCase;
@@ -44,9 +47,6 @@
import org.testng.Assert;
import org.testng.annotations.Test;
-import java.util.HashMap;
-import java.util.Map;
-
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyLong;
import static org.mockito.Mockito.reset;
@@ -1158,7 +1158,7 @@ public void testReceiveEmptyMessagePayloadUnexpected() {
try {
receiveAction.execute(context);
} catch(CitrusRuntimeException e) {
- Assert.assertEquals(e.getMessage(), "Validation failed: Unable to validate message payload - received message payload was empty, control message payload is not");
+ Assert.assertEquals(e.getMessage(), "Unable to validate message payload - received message payload was empty, control message payload is not");
return;
}
diff --git a/validation/citrus-validation-xml/src/test/java/org/citrusframework/validation/xml/XpathMessageProcessorTest.java b/validation/citrus-validation-xml/src/test/java/org/citrusframework/validation/xml/XpathMessageProcessorTest.java
index 676a64c6c6..96dfa13fe6 100644
--- a/validation/citrus-validation-xml/src/test/java/org/citrusframework/validation/xml/XpathMessageProcessorTest.java
+++ b/validation/citrus-validation-xml/src/test/java/org/citrusframework/validation/xml/XpathMessageProcessorTest.java
@@ -24,7 +24,6 @@
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
import org.citrusframework.testng.AbstractTestNGUnitTest;
-import org.springframework.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -33,9 +32,9 @@
*/
public class XpathMessageProcessorTest extends AbstractTestNGUnitTest {
- private Message message = new DefaultMessage("Hello World! ");
+ private final Message message = new DefaultMessage("Hello World! ");
- private Message messageNamespace = new DefaultMessage("" +
+ private final Message messageNamespace = new DefaultMessage("" +
"Hello World! " +
" ");
@@ -49,7 +48,7 @@ public void testConstructWithXPath() {
.build();
processor.processMessage(message, context);
- Assert.assertTrue(StringUtils.trimAllWhitespace(message.getPayload(String.class))
+ Assert.assertTrue(message.getPayload(String.class).replaceAll("\\s", "")
.endsWith("Hello! "));
}
@@ -67,7 +66,7 @@ public void testConstructWithXPathAndDefaultNamespace() {
.build();
processor.processMessage(message, context);
- Assert.assertTrue(StringUtils.trimAllWhitespace(message.getPayload(String.class))
+ Assert.assertTrue(message.getPayload(String.class).replaceAll("\\s", "")
.contains("Hello! "));
}
@@ -81,7 +80,7 @@ public void testConstructWithXPathAndNamespace() {
.build();
processor.processMessage(messageNamespace, context);
- Assert.assertTrue(StringUtils.trimAllWhitespace(messageNamespace.getPayload(String.class))
+ Assert.assertTrue(messageNamespace.getPayload(String.class).replaceAll("\\s", "")
.contains("Hello! "));
}
@@ -97,7 +96,7 @@ public void testConstructWithXPathAndGlobalNamespace() {
.build();
processor.processMessage(messageNamespace, context);
- Assert.assertTrue(StringUtils.trimAllWhitespace(messageNamespace.getPayload(String.class))
+ Assert.assertTrue(messageNamespace.getPayload(String.class).replaceAll("\\s", "")
.contains("Hello! "));
}
@@ -115,7 +114,7 @@ public void testConstructWithXPathAndNestedNamespace() {
.build();
processor.processMessage(message, context);
- Assert.assertTrue(StringUtils.trimAllWhitespace(message.getPayload(String.class))
+ Assert.assertTrue(message.getPayload(String.class).replaceAll("\\s", "")
.contains("Hello!"));
}
@@ -154,7 +153,7 @@ public void testConstructWithXPathAndInvalidGlobalNamespace() {
.build();
processor.processMessage(messageNamespace, context);
- Assert.assertTrue(StringUtils.trimAllWhitespace(messageNamespace.getPayload(String.class))
+ Assert.assertTrue(messageNamespace.getPayload(String.class).replaceAll("\\s", "")
.contains("Hello! "));
}
@@ -176,8 +175,7 @@ public void testAddTextToEmptyElement(){
processor.processMessage(message, context);
//THEN
- Assert.assertTrue(StringUtils
- .trimAllWhitespace(message.getPayload(String.class))
+ Assert.assertTrue(message.getPayload(String.class).replaceAll("\\s", "")
.contains("foobar "));
}
}
diff --git a/validation/citrus-validation-xml/src/test/java/org/citrusframework/variable/dictionary/xml/NodeMappingDataDictionaryTest.java b/validation/citrus-validation-xml/src/test/java/org/citrusframework/variable/dictionary/xml/NodeMappingDataDictionaryTest.java
index ac1bbe83f4..dd5e584c36 100644
--- a/validation/citrus-validation-xml/src/test/java/org/citrusframework/variable/dictionary/xml/NodeMappingDataDictionaryTest.java
+++ b/validation/citrus-validation-xml/src/test/java/org/citrusframework/variable/dictionary/xml/NodeMappingDataDictionaryTest.java
@@ -16,17 +16,17 @@
package org.citrusframework.variable.dictionary.xml;
+import java.util.HashMap;
+import java.util.Map;
+
import org.citrusframework.UnitTestSupport;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
+import org.citrusframework.spi.Resources;
import org.citrusframework.variable.dictionary.DataDictionary;
-import org.springframework.core.io.ClassPathResource;
import org.testng.Assert;
import org.testng.annotations.Test;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* @author Christoph Deppisch
* @since 1.4
@@ -157,7 +157,7 @@ public void testTranslateFromMappingFile() throws Exception {
context.setVariable("newText", "Hello!");
NodeMappingDataDictionary dictionary = new NodeMappingDataDictionary();
- dictionary.setMappingFile(new ClassPathResource("mapping.properties", DataDictionary.class));
+ dictionary.setMappingFile(Resources.create("mapping.properties", DataDictionary.class));
dictionary.initialize();
dictionary.processMessage(message, context);
diff --git a/validation/citrus-validation-xml/src/test/java/org/citrusframework/variable/dictionary/xml/XpathMappingDataDictionaryTest.java b/validation/citrus-validation-xml/src/test/java/org/citrusframework/variable/dictionary/xml/XpathMappingDataDictionaryTest.java
index db0db1c3d7..1e0dfe50a8 100644
--- a/validation/citrus-validation-xml/src/test/java/org/citrusframework/variable/dictionary/xml/XpathMappingDataDictionaryTest.java
+++ b/validation/citrus-validation-xml/src/test/java/org/citrusframework/variable/dictionary/xml/XpathMappingDataDictionaryTest.java
@@ -16,19 +16,19 @@
package org.citrusframework.variable.dictionary.xml;
+import java.util.HashMap;
+import java.util.Map;
+
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
import org.citrusframework.message.MessageType;
+import org.citrusframework.spi.Resources;
import org.citrusframework.testng.AbstractTestNGUnitTest;
import org.citrusframework.variable.dictionary.DataDictionary;
import org.citrusframework.xml.namespace.NamespaceContextBuilder;
-import org.springframework.core.io.ClassPathResource;
import org.testng.Assert;
import org.testng.annotations.Test;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* @author Christoph Deppisch
* @since 1.4
@@ -159,7 +159,7 @@ public void testTranslateFromMappingFile() throws Exception {
Message message = new DefaultMessage(payload);
XpathMappingDataDictionary dictionary = new XpathMappingDataDictionary();
- dictionary.setMappingFile(new ClassPathResource("xpathmapping.properties", DataDictionary.class));
+ dictionary.setMappingFile(Resources.create("xpathmapping.properties", DataDictionary.class));
dictionary.initialize();
dictionary.processMessage(message, context);
diff --git a/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/XsdSchemaRepositoryTest.java b/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/XsdSchemaRepositoryTest.java
index 0ed239986f..d046d3b65b 100644
--- a/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/XsdSchemaRepositoryTest.java
+++ b/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/XsdSchemaRepositoryTest.java
@@ -39,13 +39,14 @@ public void testResourceLocation() throws Exception {
Assert.assertEquals(schemaRepository.getSchemas().get(0).getClass(), SimpleXsdSchema.class);
}
- @Test(expectedExceptions = { IllegalArgumentException.class })
+ @Test
public void testUnknownLocation() throws Exception {
XsdSchemaRepository schemaRepository = new XsdSchemaRepository();
schemaRepository.getLocations().add("classpath:org/citrusframework/unknown/unknown.xsd");
schemaRepository.initialize();
+ Assert.assertEquals(schemaRepository.getSchemas().size(), 0);
}
@Test
@@ -67,7 +68,7 @@ public void testResourceLocationPattern() throws Exception {
public void testResourceLocationPatternNothingFound() throws Exception {
XsdSchemaRepository schemaRepository = new XsdSchemaRepository();
- schemaRepository.getLocations().add("classpath:org/citrusframework/*.xsd");
+ schemaRepository.getLocations().add("classpath:org/citrusframework/tests/*.xsd");
schemaRepository.initialize();
diff --git a/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/schema/WsdlXsdSchemaTest.java b/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/schema/WsdlXsdSchemaTest.java
index a7bf128443..a320425a68 100644
--- a/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/schema/WsdlXsdSchemaTest.java
+++ b/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/schema/WsdlXsdSchemaTest.java
@@ -21,9 +21,9 @@
import java.net.URLClassLoader;
import javax.xml.parsers.ParserConfigurationException;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.citrusframework.util.FileUtils;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.UrlResource;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;
@@ -35,7 +35,7 @@ public class WsdlXsdSchemaTest {
@Test
public void testWsdlSchema() throws ParserConfigurationException, IOException, SAXException {
- WsdlXsdSchema wsdl = new WsdlXsdSchema(new ClassPathResource("org/citrusframework/validation/SampleService.wsdl"));
+ WsdlXsdSchema wsdl = new WsdlXsdSchema(Resources.newClasspathResource("org/citrusframework/validation/SampleService.wsdl"));
wsdl.initialize();
wsdl.afterPropertiesSet();
Assert.assertEquals(wsdl.getSchemaResources().size(), 2);
@@ -45,7 +45,7 @@ public void testWsdlSchema() throws ParserConfigurationException, IOException, S
@Test
public void testWsdlSchemaImports() throws ParserConfigurationException, IOException, SAXException {
- WsdlXsdSchema wsdl = new WsdlXsdSchema(new ClassPathResource("org/citrusframework/validation/SampleServiceWithImports.wsdl"));
+ WsdlXsdSchema wsdl = new WsdlXsdSchema(Resources.newClasspathResource("org/citrusframework/validation/SampleServiceWithImports.wsdl"));
wsdl.initialize();
wsdl.afterPropertiesSet();
Assert.assertEquals(wsdl.getSchemaResources().size(), 2);
@@ -57,7 +57,7 @@ public void testWsdlSchemaImports() throws ParserConfigurationException, IOExcep
@Test
public void testWsdlSchemaImportsNamespaceDiff() throws ParserConfigurationException, IOException, SAXException {
- WsdlXsdSchema wsdl = new WsdlXsdSchema(new ClassPathResource("org/citrusframework/validation/SampleServiceWithImportsNamespaceDiff.wsdl"));
+ WsdlXsdSchema wsdl = new WsdlXsdSchema(Resources.newClasspathResource("org/citrusframework/validation/SampleServiceWithImportsNamespaceDiff.wsdl"));
wsdl.initialize();
wsdl.afterPropertiesSet();
Assert.assertEquals(wsdl.getSchemaResources().size(), 4);
@@ -69,7 +69,7 @@ public void testWsdlSchemaImportsNamespaceDiff() throws ParserConfigurationExcep
@Test
public void testWsdlSchemaWsdlImports() throws ParserConfigurationException, IOException, SAXException {
- WsdlXsdSchema wsdl = new WsdlXsdSchema(new ClassPathResource("org/citrusframework/validation/SampleServiceWithWsdlImports.wsdl"));
+ WsdlXsdSchema wsdl = new WsdlXsdSchema(Resources.newClasspathResource("org/citrusframework/validation/SampleServiceWithWsdlImports.wsdl"));
wsdl.initialize();
wsdl.afterPropertiesSet();
Assert.assertEquals(wsdl.getSchemaResources().size(), 3);
@@ -81,10 +81,10 @@ public void testWsdlSchemaWsdlImports() throws ParserConfigurationException, IOE
@Test
public void testWsdlSchemaWsdlImportsFromJar() throws ParserConfigurationException, IOException, SAXException {
- ClassPathResource classPathResource = new ClassPathResource("sample.jar", WsdlXsdSchemaTest.class);
+ Resource classPathResource = Resources.create("sample.jar", WsdlXsdSchemaTest.class);
URLClassLoader urlClassLoader = URLClassLoader.newInstance(new URL[]{classPathResource.getURL()});
URL url = urlClassLoader.getResource("SampleServiceWithWsdlImports.wsdl");
- WsdlXsdSchema wsdl = new WsdlXsdSchema(new UrlResource(url));
+ WsdlXsdSchema wsdl = new WsdlXsdSchema(Resources.create(url));
wsdl.initialize();
Assert.assertEquals(wsdl.getSchemaResources().size(), 3);
@@ -96,7 +96,7 @@ public void testWsdlSchemaWsdlImportsFromJar() throws ParserConfigurationExcepti
@Test
public void testWsdlSchemaWsdlImportsOnly() throws ParserConfigurationException, IOException, SAXException {
- WsdlXsdSchema wsdl = new WsdlXsdSchema(new ClassPathResource("org/citrusframework/validation/SampleServiceWithWsdlImportsOnly.wsdl"));
+ WsdlXsdSchema wsdl = new WsdlXsdSchema(Resources.newClasspathResource("org/citrusframework/validation/SampleServiceWithWsdlImportsOnly.wsdl"));
wsdl.initialize();
wsdl.afterPropertiesSet();
Assert.assertEquals(wsdl.getSchemaResources().size(), 2);
@@ -108,7 +108,7 @@ public void testWsdlSchemaWsdlImportsOnly() throws ParserConfigurationException,
@Test
public void testWsdlSchemaDuplicateImports() throws ParserConfigurationException, IOException, SAXException {
- WsdlXsdSchema wsdl = new WsdlXsdSchema(new ClassPathResource("org/citrusframework/validation/SampleServiceWithDuplicateImports.wsdl"));
+ WsdlXsdSchema wsdl = new WsdlXsdSchema(Resources.newClasspathResource("org/citrusframework/validation/SampleServiceWithDuplicateImports.wsdl"));
wsdl.initialize();
wsdl.afterPropertiesSet();
Assert.assertEquals(wsdl.getSchemaResources().size(), 3);
@@ -118,7 +118,7 @@ public void testWsdlSchemaDuplicateImports() throws ParserConfigurationException
@Test
public void testWsdlSchemaNoMatchingTargetNamespace() throws ParserConfigurationException, IOException, SAXException {
- WsdlXsdSchema wsdl = new WsdlXsdSchema(new ClassPathResource("org/citrusframework/validation/SampleServiceNoMatchingTargetNamespace.wsdl"));
+ WsdlXsdSchema wsdl = new WsdlXsdSchema(Resources.newClasspathResource("org/citrusframework/validation/SampleServiceNoMatchingTargetNamespace.wsdl"));
wsdl.initialize();
wsdl.afterPropertiesSet();
Assert.assertEquals(wsdl.getSchemaResources().size(), 2);
@@ -128,7 +128,7 @@ public void testWsdlSchemaNoMatchingTargetNamespace() throws ParserConfiguration
@Test
public void testWsdlSchemaWithIncludes() throws ParserConfigurationException, IOException, SAXException {
- WsdlXsdSchema wsdl = new WsdlXsdSchema(new ClassPathResource("org/citrusframework/validation/SampleServiceWithIncludes.wsdl"));
+ WsdlXsdSchema wsdl = new WsdlXsdSchema(Resources.newClasspathResource("org/citrusframework/validation/SampleServiceWithIncludes.wsdl"));
wsdl.initialize();
wsdl.afterPropertiesSet();
Assert.assertEquals(wsdl.getSchemaResources().size(), 3);
@@ -138,20 +138,20 @@ public void testWsdlSchemaWithIncludes() throws ParserConfigurationException, IO
@Test
public void testNamespaceInheritance() throws ParserConfigurationException, IOException, SAXException {
- WsdlXsdSchema wsdl = new WsdlXsdSchema(new ClassPathResource("org/citrusframework/xml/BookStore.wsdl"));
+ WsdlXsdSchema wsdl = new WsdlXsdSchema(Resources.newClasspathResource("org/citrusframework/xml/BookStore.wsdl"));
wsdl.initialize();
wsdl.afterPropertiesSet();
Assert.assertEquals(wsdl.getSchemaResources().size(), 2);
- String xsd = FileUtils.readToString(wsdl.getSchemaResources().get(0));
+ String xsd = FileUtils.readToString(wsdl.getSchemaResources().get(0).getInputStream());
Assert.assertTrue(xsd.contains("xmlns:tns=\"http://citrusframework.org/bookstore/\""));
Assert.assertTrue(xsd.contains("xmlns:audio=\"http://citrusframework.org/bookstore/audio\""));
Assert.assertTrue(xsd.contains("xmlns:book=\"http://citrusframework.org/book\""));
Assert.assertTrue(xsd.contains("xmlns:author=\"http://citrusframework.org/author\""));
Assert.assertTrue(xsd.contains("xmlns=\"http://citrusframework.org/bookstore/\""));
- xsd = FileUtils.readToString(wsdl.getSchemaResources().get(1));
+ xsd = FileUtils.readToString(wsdl.getSchemaResources().get(1).getInputStream());
Assert.assertTrue(xsd.contains("xmlns:tns=\"http://citrusframework.org/bookstore/\""));
Assert.assertTrue(xsd.contains("xmlns:audio=\"http://citrusframework.org/bookstore/audio\""));
Assert.assertTrue(xsd.contains("xmlns:book=\"http://citrusframework.org/book/wsdl\""));
diff --git a/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/schema/locator/JarWSDLLocatorTest.java b/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/schema/locator/JarWSDLLocatorTest.java
index 740ef39820..663c4c072c 100644
--- a/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/schema/locator/JarWSDLLocatorTest.java
+++ b/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/schema/locator/JarWSDLLocatorTest.java
@@ -16,27 +16,32 @@
package org.citrusframework.xml.schema.locator;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.spi.Resource;
+import org.citrusframework.spi.Resources;
import org.testng.Assert;
import org.testng.annotations.Test;
public class JarWSDLLocatorTest {
- private Resource wsdl = new ClassPathResource("org/citrusframework/validation/SampleService.wsdl");
+ private final Resource wsdl = Resources.newClasspathResource("org/citrusframework/validation/SampleService.wsdl");
@Test
- public void testGetImportInputSource() throws Exception {
+ public void testGetImportInputSource() {
JarWSDLLocator locator = new JarWSDLLocator(wsdl);
Assert.assertNotNull(locator.getBaseInputSource());
Assert.assertNotNull(locator.getBaseURI());
Assert.assertTrue(locator.getBaseURI().endsWith("org/citrusframework/validation/SampleService.wsdl"));
Assert.assertNull(locator.getLatestImportURI());
- Assert.assertNull(locator.getImportInputSource(locator.getBaseURI(), "invalid.xsd"));
- Assert.assertTrue(locator.getLatestImportURI().endsWith("org/citrusframework/validation/invalid.xsd"));
Assert.assertNotNull(locator.getImportInputSource(locator.getBaseURI(), "types.xsd"));
Assert.assertTrue(locator.getLatestImportURI().endsWith("org/citrusframework/validation/types.xsd"));
}
+ @Test(expectedExceptions = CitrusRuntimeException.class, expectedExceptionsMessageRegExp = ".* does not exists")
+ public void testGetInvalidImportInputSource() {
+ JarWSDLLocator locator = new JarWSDLLocator(wsdl);
+ locator.getImportInputSource(locator.getBaseURI(), "invalid.xsd");
+ }
+
}
diff --git a/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/xpath/XPathUtilsTest.java b/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/xpath/XPathUtilsTest.java
index 08b9dd4634..783ef6f275 100644
--- a/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/xpath/XPathUtilsTest.java
+++ b/validation/citrus-validation-xml/src/test/java/org/citrusframework/xml/xpath/XPathUtilsTest.java
@@ -16,14 +16,14 @@
package org.citrusframework.xml.xpath;
+import java.util.HashMap;
+import java.util.Map;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.xpath.XPathFactory;
-import java.util.HashMap;
-import java.util.Map;
import org.citrusframework.util.XMLUtils;
-import org.springframework.util.xml.SimpleNamespaceContext;
+import org.citrusframework.xml.namespace.DefaultNamespaceContext;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
@@ -82,7 +82,7 @@ public void testEvaluate() {
"23 " +
"");
- NamespaceContext namespaceContext = new SimpleNamespaceContext();
+ NamespaceContext namespaceContext = new DefaultNamespaceContext();
Assert.assertEquals(XPathUtils.evaluate(personNode, "/person/name", namespaceContext, XPathExpressionResult.STRING), "foo");
Assert.assertEquals(XPathUtils.evaluate(personNode, "/person/age", namespaceContext, XPathExpressionResult.NUMBER), 23.0D);
@@ -94,7 +94,7 @@ public void testEvaluate() {
Assert.assertFalse(XPathUtils.evaluateAsBoolean(personNode, "/person/unknown", namespaceContext));
Assert.assertEquals(XPathUtils.evaluateAsString(personNode, "/person/name", namespaceContext), "foo");
Assert.assertEquals(XPathUtils.evaluateAsObject(personNode, "/person/name", namespaceContext, new QName("http://www.w3.org/1999/XSL/Transform", "STRING")), "foo");
- Assert.assertEquals(XPathUtils.evaluateAsNumber(personNode, "/person/age", namespaceContext), new Double(23.0D));
+ Assert.assertEquals(XPathUtils.evaluateAsNumber(personNode, "/person/age", namespaceContext), Double.valueOf(23.0D));
Assert.assertEquals(XPathUtils.evaluateAsString(personNode, "/person/@status", namespaceContext), "single");
}
diff --git a/validation/citrus-validation-xml/src/test/resources/org/citrusframework/context/citrus-unit-context.xml b/validation/citrus-validation-xml/src/test/resources/org/citrusframework/context/citrus-unit-context.xml
index 08a0e93d91..8872572927 100644
--- a/validation/citrus-validation-xml/src/test/resources/org/citrusframework/context/citrus-unit-context.xml
+++ b/validation/citrus-validation-xml/src/test/resources/org/citrusframework/context/citrus-unit-context.xml
@@ -17,4 +17,15 @@
org.springframework.xml.xsd.XsdSchema
+
+
+
+
+
+
+
+
+
+