+ * The default implementation creates a {@code URI} object from resource location.
+ */
+ default URI getURI() {
+ return URI.create(getLocation());
+ }
+
+ /**
+ * The {@link URL} for the resource or null if the URL can not be computed.
+ *
+ * The default implementation creates a {@code URI} object from resource location.
+ */
+ default URL getURL() throws MalformedURLException {
+ URI uri = getURI();
+ return uri != null ? uri.toURL() : null;
+ }
+
+ /**
+ * Returns an {@link InputStream} that reads from the underlying resource.
+ *
+ * Each invocation must return a new {@link InputStream} instance.
+ */
+ InputStream getInputStream();
+
+ /**
+ * Return the file associated with this resource.
+ * @return
+ */
+ File getFile();
+
+ /**
+ * Returns a {@link Reader} that reads from the underlying resource using UTF-8 as charset.
+ *
+ * Each invocation must return a new {@link Reader}.
+ *
+ * @see #getInputStream()
+ */
+ default Reader getReader() throws IOException {
+ return getReader(Charset.forName(CitrusSettings.CITRUS_FILE_ENCODING));
+ }
+
+ /**
+ * Returns a {@link Reader} that reads from the underlying resource using the given {@link Charset}
+ *
+ * Each invocation must return a new {@link Reader}.
+ *
+ * @see #getInputStream()
+ */
+ default Reader getReader(Charset charset) throws IOException {
+ return new InputStreamReader(getInputStream(), charset);
+ }
+}
diff --git a/core/citrus-api/src/main/java/org/citrusframework/spi/ResourcePathTypeResolver.java b/core/citrus-api/src/main/java/org/citrusframework/spi/ResourcePathTypeResolver.java
index c29ec8998d..856d9b341f 100644
--- a/core/citrus-api/src/main/java/org/citrusframework/spi/ResourcePathTypeResolver.java
+++ b/core/citrus-api/src/main/java/org/citrusframework/spi/ResourcePathTypeResolver.java
@@ -24,6 +24,7 @@
import java.util.zip.ZipInputStream;
import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -149,7 +150,7 @@ public Map resolveAll(String path, String property, String keyPro
private Stream resolveAllFromJar(String path) {
String rootAsString = ResourcePathTypeResolver.class.getProtectionDomain().getCodeSource().getLocation().toString();
- ClassLoader classLoader = Objects.requireNonNull(ResourcePathTypeResolver.class.getClassLoader());
+ ClassLoader classLoader = ObjectHelper.assertNotNull(ResourcePathTypeResolver.class.getClassLoader());
if (rootAsString.endsWith(".jar") && !rootAsString.matches(".*" + File.separator + "citrus-api-\\d+\\.\\d+\\.\\d+(-.*)?\\.jar")) {
return getZipEntries().stream()
.filter(entry -> entry.startsWith(path))
diff --git a/core/citrus-api/src/main/java/org/citrusframework/spi/Resources.java b/core/citrus-api/src/main/java/org/citrusframework/spi/Resources.java
new file mode 100644
index 0000000000..5c658bf3a2
--- /dev/null
+++ b/core/citrus-api/src/main/java/org/citrusframework/spi/Resources.java
@@ -0,0 +1,302 @@
+/*
+ * 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 java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.file.Paths;
+
+import org.citrusframework.exceptions.CitrusRuntimeException;
+import org.citrusframework.util.ReflectionHelper;
+
+/**
+ * Helps with resources of type classpath or file system.
+ */
+public class Resources {
+
+ public static final String CLASSPATH_RESOURCE_PREFIX = "classpath:";
+ public static final String FILESYSTEM_RESOURCE_PREFIX = "file:";
+
+ public static final String JAR_RESOURCE_PREFIX = "jar:";
+ public static final String HTTP_RESOURCE_PREFIX = "http:";
+
+ public static Resource create(String filePath) {
+ if (filePath.startsWith(CLASSPATH_RESOURCE_PREFIX)) {
+ return newClasspathResource(filePath);
+ } else if (filePath.startsWith(FILESYSTEM_RESOURCE_PREFIX)) {
+ return newFileSystemResource(filePath);
+ } else if (filePath.startsWith(HTTP_RESOURCE_PREFIX) || filePath.startsWith(JAR_RESOURCE_PREFIX)) {
+ try {
+ return create(new URL(filePath));
+ } catch (MalformedURLException e) {
+ throw new CitrusRuntimeException(e);
+ }
+ }
+
+ Resource file = newFileSystemResource(filePath);
+ if (file.exists()) {
+ return file;
+ }
+
+ return newClasspathResource(filePath);
+ }
+
+ public static Resource create(String filePath, Class> contextClass) {
+ return newClasspathResource(contextClass.getPackageName().replace(".", "/") + "/" + filePath);
+ }
+
+ public static Resource create(byte[] content) {
+ return new ByteArrayResource(content);
+ }
+
+ public static Resource create(File file) {
+ return new FileSystemResource(file);
+ }
+
+ public static Resource create(URL url) {
+ return new UrlResource(url);
+ }
+
+ public static Resource newClasspathResource(String filePath) {
+ return new ClasspathResource(filePath);
+ }
+
+ public static Resource newFileSystemResource(String filePath) {
+ return new FileSystemResource(filePath);
+ }
+
+ private static String getRawPath(String filePath) {
+ if (filePath.startsWith(CLASSPATH_RESOURCE_PREFIX)) {
+ return filePath.substring(CLASSPATH_RESOURCE_PREFIX.length());
+ }
+
+ if (filePath.startsWith(FILESYSTEM_RESOURCE_PREFIX)) {
+ return filePath.substring(FILESYSTEM_RESOURCE_PREFIX.length());
+ }
+
+ return filePath;
+ }
+
+ /**
+ * Resource loaded from classpath.
+ */
+ public static class ClasspathResource implements Resource {
+
+ private final String location;
+
+ public ClasspathResource(String location) {
+ String raw = getRawPath(location);
+
+ if (raw.startsWith("/")) {
+ this.location = raw.substring(1);
+ } else {
+ this.location = raw;
+ }
+ }
+
+ @Override
+ public String getLocation() {
+ return location;
+ }
+
+ @Override
+ public boolean exists() {
+ return this.getURI() != null;
+ }
+
+ @Override
+ public InputStream getInputStream() {
+ return ReflectionHelper.class.getClassLoader().getResourceAsStream(location);
+ }
+
+ @Override
+ public File getFile() {
+ if (!exists()) {
+ throw new CitrusRuntimeException(String.format("Failed to load classpath resource %s - does not exist", getLocation()));
+ }
+
+ return Paths.get(getURI()).toFile();
+ }
+
+ public URI getURI() {
+ URL url = ReflectionHelper.class.getClassLoader().getResource(location);
+ try {
+ return url != null ? url.toURI() : null;
+ } catch (URISyntaxException e) {
+ throw new CitrusRuntimeException("Failed to load classpath resource", e);
+ }
+ }
+ }
+
+ /**
+ * Resource with given byte array content.
+ */
+ public static class ByteArrayResource implements Resource {
+
+ private final byte[] content;
+
+ public ByteArrayResource(byte[] content) {
+ this.content = content;
+ }
+
+ @Override
+ public String getLocation() {
+ return "";
+ }
+
+ @Override
+ public boolean exists() {
+ return true;
+ }
+
+ @Override
+ public InputStream getInputStream() {
+ return new ByteArrayInputStream(content);
+ }
+
+ @Override
+ public File getFile() {
+ throw new UnsupportedOperationException("ByteArrayResource does not provide access to a file");
+ }
+ }
+
+ /**
+ * Resource on the file system.
+ */
+ public static class FileSystemResource implements Resource {
+
+ private final File file;
+
+ public FileSystemResource(String path) {
+ this.file = new File(getRawPath(path));
+ }
+
+ public FileSystemResource(File file) {
+ this.file = file;
+ }
+
+ @Override
+ public String getLocation() {
+ return file.getPath();
+ }
+
+ @Override
+ public boolean exists() {
+ return file.exists();
+ }
+
+ @Override
+ public InputStream getInputStream() {
+ if (!exists()) {
+ throw new CitrusRuntimeException(file + " does not exists");
+ }
+
+ if (file.isDirectory()) {
+ throw new UnsupportedOperationException(file + " is a directory");
+ }
+
+ try {
+ return new FileInputStream(file);
+ } catch (FileNotFoundException e) {
+ throw new CitrusRuntimeException(file + " does not exists", e);
+ }
+ }
+
+ @Override
+ public File getFile() {
+ return file;
+ }
+ }
+
+ public static class UrlResource implements Resource {
+
+ private final URL url;
+
+ public UrlResource(URL url) {
+ this.url = url;
+ }
+
+ @Override
+ public String getLocation() {
+ return url.toString();
+ }
+
+ @Override
+ public boolean exists() {
+ URLConnection connection = null;
+ try {
+ connection = url.openConnection();
+ if (connection instanceof HttpURLConnection) {
+ return ((HttpURLConnection) connection).getResponseCode() == HttpURLConnection.HTTP_OK;
+ }
+
+ return connection.getContentLengthLong() > 0;
+ } catch (IOException e) {
+ throw new CitrusRuntimeException(e);
+ } finally {
+ // close the http connection to avoid
+ // leaking gaps in case of an exception
+ if (connection instanceof HttpURLConnection) {
+ ((HttpURLConnection) connection).disconnect();
+ }
+ }
+ }
+
+ @Override
+ public InputStream getInputStream() {
+ URLConnection connection = null;
+ try {
+ connection = url.openConnection();
+ connection.setUseCaches(false);
+ return connection.getInputStream();
+ } catch (IOException e) {
+ throw new CitrusRuntimeException(e);
+ } finally {
+ // close the http connection to avoid
+ // leaking gaps in case of an exception
+ if (connection instanceof HttpURLConnection) {
+ ((HttpURLConnection) connection).disconnect();
+ }
+ }
+ }
+
+ @Override
+ public File getFile() {
+ if (!"file".equals(url.getProtocol())) {
+ throw new CitrusRuntimeException("Failed to resolve to absolute file path because it does not reside in the file system: " + url);
+ }
+ try {
+ return new File(url.toURI().getSchemeSpecificPart());
+ } catch (URISyntaxException ex) {
+ return new File(url.getFile());
+ }
+ }
+ }
+}
diff --git a/core/citrus-api/src/main/java/org/citrusframework/util/ObjectHelper.java b/core/citrus-api/src/main/java/org/citrusframework/util/ObjectHelper.java
new file mode 100644
index 0000000000..00ee8827c0
--- /dev/null
+++ b/core/citrus-api/src/main/java/org/citrusframework/util/ObjectHelper.java
@@ -0,0 +1,44 @@
+/*
+ * 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 org.citrusframework.exceptions.CitrusRuntimeException;
+
+/**
+ * Helper adds utility operations such as non-null assertion on objects.
+ */
+public class ObjectHelper {
+
+ private ObjectHelper() {
+ //prevent instantiation of utility class
+ }
+
+ public static T assertNotNull(T object) {
+ return assertNotNull(object, "Provided object must not be null");
+ }
+
+ public static 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.springframeworkspring-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.springframeworkspring-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.bindjakarta.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.springframeworkspring-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()), "