From 0f41890c1d6637ff416ea849b4f379093e1b425e Mon Sep 17 00:00:00 2001 From: Timon Borter Date: Wed, 23 Oct 2024 20:47:10 +0200 Subject: [PATCH] chore(citrus-api): review and code cleanup pr: https://github.com/citrusframework/citrus/pull/1224 `citrus-api` module. --- .../citrusframework/TestActionBuilder.java | 12 +++--- .../CitrusEndpointAnnotations.java | 8 ++-- .../citrusframework/common/TestLoader.java | 12 +++--- .../annotation/AnnotationConfigParser.java | 16 ++++---- .../citrusframework/context/TestContext.java | 26 ++++++------- .../context/resolver/TypeAliasResolver.java | 12 +++--- .../endpoint/DefaultEndpointFactory.java | 16 ++++---- .../endpoint/EndpointBuilder.java | 18 ++++----- .../endpoint/EndpointComponent.java | 10 ++--- .../endpoint/EndpointFactory.java | 6 +-- .../citrusframework/functions/Function.java | 10 ++--- .../functions/FunctionRegistry.java | 8 ++-- .../functions/FunctionUtils.java | 2 +- .../org/citrusframework/main/TestEngine.java | 2 +- .../message/AbstractMessageProcessor.java | 2 +- .../message/ErrorHandlingStrategy.java | 2 +- .../message/MessageHeaderType.java | 6 +-- .../message/MessageHeaderUtils.java | 2 +- .../message/MessagePayloadUtils.java | 2 +- .../message/MessageProcessor.java | 6 +-- .../message/MessageSelector.java | 8 ++-- .../message/ScriptPayloadBuilder.java | 6 +-- .../citrusframework/spi/BindToRegistry.java | 2 +- .../util/ReflectionHelper.java | 8 ++-- .../citrusframework/util/TypeConverter.java | 20 +++++----- .../validation/HeaderValidator.java | 12 +++--- .../validation/MessageValidator.java | 12 +++--- .../validation/MessageValidatorRegistry.java | 38 +++++++++---------- .../validation/SchemaValidator.java | 6 +-- .../validation/ValueMatcher.java | 14 +++---- .../DefaultControlExpressionParser.java | 6 +-- .../validation/matcher/ValidationMatcher.java | 10 ++--- .../SegmentVariableExtractorRegistry.java | 20 +++++----- .../variable/VariableExtractor.java | 6 +-- .../variable/VariableUtils.java | 18 ++++----- .../variable/dictionary/DataDictionary.java | 4 +- .../namespace/NamespaceContextBuilder.java | 12 +++--- .../message/MessagePayloadUtilsTest.java | 5 +-- 38 files changed, 188 insertions(+), 197 deletions(-) diff --git a/core/citrus-api/src/main/java/org/citrusframework/TestActionBuilder.java b/core/citrus-api/src/main/java/org/citrusframework/TestActionBuilder.java index b6b7db67bf..601c3926e6 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/TestActionBuilder.java +++ b/core/citrus-api/src/main/java/org/citrusframework/TestActionBuilder.java @@ -16,14 +16,14 @@ package org.citrusframework; -import java.util.Map; -import java.util.Optional; - import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.spi.ResourcePathTypeResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Map; +import java.util.Optional; + /** * Test action builder. * @since 2.3 @@ -64,7 +64,7 @@ static Map> lookup() { Map> builders = TYPE_RESOLVER.resolveAll(); if (logger.isDebugEnabled()) { - builders.forEach((k, v) -> logger.debug(String.format("Found test action builder '%s' as %s", k, v.getClass()))); + builders.forEach((k, v) -> logger.debug("Found test action builder '{}' as {}", k, v.getClass())); } return builders; } @@ -73,7 +73,7 @@ static Map> lookup() { * Resolves test action builder from resource path lookup with given resource name. Scans classpath for test action builder meta information * with given name and returns instance of the builder. Returns optional instead of throwing exception when no test action builder * could be found. - * + *

* Given builder name is a combination of resource file name and type property separated by '.' character. * @param builder * @return @@ -82,7 +82,7 @@ static Optional> lookup(String builder) { try { return Optional.of(TYPE_RESOLVER.resolve(builder)); } catch (CitrusRuntimeException e) { - logger.warn(String.format("Failed to resolve test action builder from resource '%s/%s'", RESOURCE_PATH, builder)); + logger.warn("Failed to resolve test action builder from resource '{}/{}'", RESOURCE_PATH, builder); } return Optional.empty(); diff --git a/core/citrus-api/src/main/java/org/citrusframework/annotations/CitrusEndpointAnnotations.java b/core/citrus-api/src/main/java/org/citrusframework/annotations/CitrusEndpointAnnotations.java index c14fc50dde..3a56669423 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/annotations/CitrusEndpointAnnotations.java +++ b/core/citrus-api/src/main/java/org/citrusframework/annotations/CitrusEndpointAnnotations.java @@ -16,9 +16,6 @@ package org.citrusframework.annotations; -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; - import org.citrusframework.context.TestContext; import org.citrusframework.endpoint.Endpoint; import org.citrusframework.spi.BindToRegistry; @@ -28,6 +25,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; + /** * Dependency injection support for {@link CitrusEndpoint} endpoint annotations. * @@ -57,7 +57,7 @@ public static void injectEndpoints(final Object target, final TestContext contex return; } - logger.debug(String.format("Injecting Citrus endpoint on test class field '%s'", field.getName())); + logger.debug("Injecting Citrus endpoint on test class field '{}'", field.getName()); CitrusEndpoint endpointAnnotation = field.getAnnotation(CitrusEndpoint.class); for (Annotation annotation : field.getAnnotations()) { diff --git a/core/citrus-api/src/main/java/org/citrusframework/common/TestLoader.java b/core/citrus-api/src/main/java/org/citrusframework/common/TestLoader.java index 96899c096d..ba2ad4b38c 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/common/TestLoader.java +++ b/core/citrus-api/src/main/java/org/citrusframework/common/TestLoader.java @@ -16,16 +16,16 @@ package org.citrusframework.common; -import java.util.Map; -import java.util.Optional; -import java.util.function.Consumer; - import org.citrusframework.TestCase; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.spi.ResourcePathTypeResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Map; +import java.util.Optional; +import java.util.function.Consumer; + /** * Test loader interface. * @since 2.1 @@ -85,7 +85,7 @@ static Map lookup() { Map loader = TYPE_RESOLVER.resolveAll(); if (logger.isDebugEnabled()) { - loader.forEach((k, v) -> logger.debug(String.format("Found test loader '%s' as %s", k, v.getClass()))); + loader.forEach((k, v) -> logger.debug("Found test loader '{}' as {}", k, v.getClass())); } return loader; } @@ -101,7 +101,7 @@ static Optional lookup(String loader) { try { return Optional.of(TYPE_RESOLVER.resolve(loader)); } catch (CitrusRuntimeException e) { - logger.warn(String.format("Failed to resolve test loader from resource '%s/%s'", RESOURCE_PATH, loader)); + logger.warn("Failed to resolve test loader from resource '{}/{}'", RESOURCE_PATH, loader); } return Optional.empty(); diff --git a/core/citrus-api/src/main/java/org/citrusframework/config/annotation/AnnotationConfigParser.java b/core/citrus-api/src/main/java/org/citrusframework/config/annotation/AnnotationConfigParser.java index f497441f8b..1f3f612397 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/config/annotation/AnnotationConfigParser.java +++ b/core/citrus-api/src/main/java/org/citrusframework/config/annotation/AnnotationConfigParser.java @@ -16,11 +16,6 @@ package org.citrusframework.config.annotation; -import java.lang.annotation.Annotation; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - import org.citrusframework.endpoint.Endpoint; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.spi.ReferenceResolver; @@ -29,6 +24,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.lang.annotation.Annotation; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + /** * @since 2.5 */ @@ -63,7 +63,7 @@ static Map lookup() { parsers.putAll(TYPE_RESOLVER.resolveAll("", TypeResolver.TYPE_PROPERTY_WILDCARD)); if (logger.isDebugEnabled()) { - parsers.forEach((k, v) -> logger.debug(String.format("Found annotation config parser '%s' as %s", k, v.getClass()))); + parsers.forEach((k, v) -> logger.debug("Found annotation config parser '{}' as {}", k, v.getClass())); } } return parsers; @@ -73,7 +73,7 @@ static Map lookup() { * Resolves annotation config parser from resource path lookup with given resource name. Scans classpath for annotation config parser meta information * with given name and returns instance of the parser. Returns optional instead of throwing exception when no annotation config parser * could be found. - * + *

* Given parser name is a combination of resource file name and type property separated by '.' character. * @param parser * @return @@ -90,7 +90,7 @@ static Optional lookup(String parser) { return Optional.of(instance); } catch (CitrusRuntimeException e) { - logger.warn(String.format("Failed to resolve annotation config parser from resource '%s/%s'", RESOURCE_PATH, parser)); + logger.warn("Failed to resolve annotation config parser from resource '{}/{}'", RESOURCE_PATH, parser); } return Optional.empty(); diff --git a/core/citrus-api/src/main/java/org/citrusframework/context/TestContext.java b/core/citrus-api/src/main/java/org/citrusframework/context/TestContext.java index 0bf62b1b7d..5a872a0ed0 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/context/TestContext.java +++ b/core/citrus-api/src/main/java/org/citrusframework/context/TestContext.java @@ -16,17 +16,6 @@ package org.citrusframework.context; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; - import org.citrusframework.CitrusSettings; import org.citrusframework.TestAction; import org.citrusframework.TestActionBuilder; @@ -69,6 +58,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + /** * Class holding and managing test variables. The test context also provides utility methods * for replacing dynamic content(variables and functions) in message payloads and headers. @@ -255,7 +255,7 @@ public void setVariable(final String variableName, Object value) { } if (logger.isDebugEnabled()) { - logger.debug(String.format("Setting variable: %s with value: '%s'", VariableUtils.cutOffVariablesPrefix(variableName), value)); + logger.debug("Setting variable: {} with value: '{}'", VariableUtils.cutOffVariablesPrefix(variableName), value); } variables.put(VariableUtils.cutOffVariablesPrefix(variableName), value); @@ -849,7 +849,7 @@ private void logMessage(String operation, Message message, MessageDirection dire messageListeners.onInboundMessage(message, this); } } else if (logger.isDebugEnabled()) { - logger.debug(String.format("%s message:%n%s", operation, Optional.ofNullable(message).map(Message::toString).orElse(""))); + logger.debug("{} message:%n{}", operation, Optional.ofNullable(message).map(Message::toString).orElse("")); } } diff --git a/core/citrus-api/src/main/java/org/citrusframework/context/resolver/TypeAliasResolver.java b/core/citrus-api/src/main/java/org/citrusframework/context/resolver/TypeAliasResolver.java index 24ca0dc75d..2bec20ee41 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/context/resolver/TypeAliasResolver.java +++ b/core/citrus-api/src/main/java/org/citrusframework/context/resolver/TypeAliasResolver.java @@ -16,16 +16,16 @@ package org.citrusframework.context.resolver; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.spi.ResourcePathTypeResolver; import org.citrusframework.spi.TypeResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + /** * Type resolver able to adapt an alias type to a given source type. Used in {@link org.citrusframework.spi.ReferenceResolver} to * auto resolve types that can act as an alias interchangeably to a given type. @@ -54,7 +54,7 @@ public interface TypeAliasResolver { resolvers.putAll(TYPE_RESOLVER.resolveAll("", TypeResolver.DEFAULT_TYPE_PROPERTY, "name")); if (logger.isDebugEnabled()) { - resolvers.forEach((k, v) -> logger.debug(String.format("Found type alias resolver '%s' as %s", k, v.getClass()))); + resolvers.forEach((k, v) -> logger.debug("Found type alias resolver '{}' as {}", k, v.getClass())); } } return resolvers; @@ -71,7 +71,7 @@ public interface TypeAliasResolver { try { return Optional.of(TYPE_RESOLVER.resolve(resolver)); } catch (CitrusRuntimeException e) { - logger.warn(String.format("Failed to resolve type alias resolver from resource '%s/%s'", RESOURCE_PATH, resolver)); + logger.warn("Failed to resolve type alias resolver from resource '{}/{}'", RESOURCE_PATH, resolver); } return Optional.empty(); diff --git a/core/citrus-api/src/main/java/org/citrusframework/endpoint/DefaultEndpointFactory.java b/core/citrus-api/src/main/java/org/citrusframework/endpoint/DefaultEndpointFactory.java index daedca5ba0..d4b6a4b388 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/endpoint/DefaultEndpointFactory.java +++ b/core/citrus-api/src/main/java/org/citrusframework/endpoint/DefaultEndpointFactory.java @@ -16,12 +16,6 @@ package org.citrusframework.endpoint; -import java.lang.annotation.Annotation; -import java.util.Map; -import java.util.Optional; -import java.util.StringTokenizer; -import java.util.concurrent.ConcurrentHashMap; - import org.citrusframework.annotations.CitrusEndpoint; import org.citrusframework.annotations.CitrusEndpointConfig; import org.citrusframework.config.annotation.AnnotationConfigParser; @@ -31,11 +25,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.lang.annotation.Annotation; +import java.util.Map; +import java.util.Optional; +import java.util.StringTokenizer; +import java.util.concurrent.ConcurrentHashMap; + /** * Default endpoint factory implementation uses registered endpoint components in Spring application context to create endpoint * from given endpoint uri. If endpoint bean name is given factory directly creates from application context. If endpoint uri is given * factory tries to find proper endpoint component in application context and in default endpoint component configuration. - * + *

* Default endpoint components are listed in property file reference where key is the component name and value is the fully qualified class name * of the implementing endpoint component class. * @@ -133,7 +133,7 @@ public Endpoint create(String uri, TestContext context) { synchronized (endpointCache) { if (endpointCache.containsKey(cachedEndpointName)) { if (logger.isDebugEnabled()) { - logger.debug(String.format("Found cached endpoint for uri '%s'", cachedEndpointName)); + logger.debug("Found cached endpoint for uri '{}'", cachedEndpointName); } return endpointCache.get(cachedEndpointName); } else { diff --git a/core/citrus-api/src/main/java/org/citrusframework/endpoint/EndpointBuilder.java b/core/citrus-api/src/main/java/org/citrusframework/endpoint/EndpointBuilder.java index 18ce48691c..9b889f161f 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/endpoint/EndpointBuilder.java +++ b/core/citrus-api/src/main/java/org/citrusframework/endpoint/EndpointBuilder.java @@ -16,12 +16,6 @@ package org.citrusframework.endpoint; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.Properties; - import org.citrusframework.annotations.CitrusEndpoint; import org.citrusframework.annotations.CitrusEndpointProperty; import org.citrusframework.exceptions.CitrusRuntimeException; @@ -33,6 +27,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.Properties; + /** * Endpoint builder interface. All endpoint builder implementations do implement this interface * in order to build endpoints using a fluent Java API. @@ -116,7 +116,7 @@ static Map> lookup() { Map> builders = new HashMap<>(TYPE_RESOLVER.resolveAll("", TypeResolver.TYPE_PROPERTY_WILDCARD)); if (logger.isDebugEnabled()) { - builders.forEach((k, v) -> logger.debug(String.format("Found endpoint builder '%s' as %s", k, v.getClass()))); + builders.forEach((k, v) -> logger.debug("Found endpoint builder '{}' as {}", k, v.getClass())); } return builders; } @@ -125,7 +125,7 @@ static Map> lookup() { * Resolves endpoint builder from resource path lookup with given resource name. Scans classpath for endpoint builder meta information * with given name and returns instance of the builder. Returns optional instead of throwing exception when no endpoint builder * could be found. - * + *

* Given builder name is a combination of resource file name and type property separated by '.' character. * @param builder * @return @@ -142,7 +142,7 @@ static Optional> lookup(String builder) { return Optional.of(instance); } catch (CitrusRuntimeException e) { - logger.warn(String.format("Failed to resolve endpoint builder from resource '%s/%s'", RESOURCE_PATH, builder)); + logger.warn("Failed to resolve endpoint builder from resource '{}/{}'", RESOURCE_PATH, builder); } return Optional.empty(); diff --git a/core/citrus-api/src/main/java/org/citrusframework/endpoint/EndpointComponent.java b/core/citrus-api/src/main/java/org/citrusframework/endpoint/EndpointComponent.java index 7ea4e2c07a..1edb12b7e0 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/endpoint/EndpointComponent.java +++ b/core/citrus-api/src/main/java/org/citrusframework/endpoint/EndpointComponent.java @@ -16,15 +16,15 @@ package org.citrusframework.endpoint; -import java.util.Map; -import java.util.Optional; - import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.spi.ResourcePathTypeResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Map; +import java.util.Optional; + /** * Endpoint component registers with bean name in Spring application context and is then responsible to create proper endpoints dynamically from * endpoint uri values. Creates endpoint instance by parsing the dynamic endpoint uri with special properties and parameters. Creates proper endpoint @@ -75,7 +75,7 @@ static Map lookup() { Map components = TYPE_RESOLVER.resolveAll(); if (logger.isDebugEnabled()) { - components.forEach((k, v) -> logger.debug(String.format("Found endpoint component '%s' as %s", k, v.getClass()))); + components.forEach((k, v) -> logger.debug("Found endpoint component '{}' as {}", k, v.getClass())); } return components; } @@ -92,7 +92,7 @@ static Optional lookup(String component) { EndpointComponent instance = TYPE_RESOLVER.resolve(component); return Optional.of(instance); } catch (CitrusRuntimeException e) { - logger.warn(String.format("Failed to resolve endpoint component from resource '%s/%s'", RESOURCE_PATH, component)); + logger.warn("Failed to resolve endpoint component from resource '{}/{}'", RESOURCE_PATH, component); } return Optional.empty(); diff --git a/core/citrus-api/src/main/java/org/citrusframework/endpoint/EndpointFactory.java b/core/citrus-api/src/main/java/org/citrusframework/endpoint/EndpointFactory.java index 99f318f9c2..f003e05359 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/endpoint/EndpointFactory.java +++ b/core/citrus-api/src/main/java/org/citrusframework/endpoint/EndpointFactory.java @@ -16,15 +16,15 @@ package org.citrusframework.endpoint; -import java.lang.annotation.Annotation; - import org.citrusframework.annotations.CitrusEndpoint; import org.citrusframework.context.TestContext; +import java.lang.annotation.Annotation; + /** * Endpoint factory tries to get endpoint instance by parsing an endpoint uri. Uri can have parameters * that get passed to the endpoint configuration. - * + *

* If Spring application context is given searches for matching endpoint component bean and delegates to component for * endpoint creation. * diff --git a/core/citrus-api/src/main/java/org/citrusframework/functions/Function.java b/core/citrus-api/src/main/java/org/citrusframework/functions/Function.java index bba58d286c..d0c25caabd 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/functions/Function.java +++ b/core/citrus-api/src/main/java/org/citrusframework/functions/Function.java @@ -16,15 +16,15 @@ package org.citrusframework.functions; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import org.citrusframework.context.TestContext; import org.citrusframework.spi.ResourcePathTypeResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * General function interface. * @@ -49,7 +49,7 @@ static Map lookup() { functions.putAll(new ResourcePathTypeResolver().resolveAll(RESOURCE_PATH)); if (logger.isDebugEnabled()) { - functions.forEach((k, v) -> logger.debug(String.format("Found function '%s' as %s", k, v.getClass()))); + functions.forEach((k, v) -> logger.debug("Found function '{}' as {}", k, v.getClass())); } } diff --git a/core/citrus-api/src/main/java/org/citrusframework/functions/FunctionRegistry.java b/core/citrus-api/src/main/java/org/citrusframework/functions/FunctionRegistry.java index 923464c833..4cfbf452bd 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/functions/FunctionRegistry.java +++ b/core/citrus-api/src/main/java/org/citrusframework/functions/FunctionRegistry.java @@ -16,12 +16,12 @@ package org.citrusframework.functions; -import java.util.ArrayList; -import java.util.List; - import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.exceptions.NoSuchFunctionLibraryException; +import java.util.ArrayList; +import java.util.List; + /** * Function registry holding all available function libraries. * @@ -38,7 +38,7 @@ public class FunctionRegistry { * @return flag (true/false) */ public boolean isFunction(final String variableExpression) { - if (variableExpression == null || variableExpression.length() == 0) { + if (variableExpression == null || variableExpression.isEmpty()) { return false; } diff --git a/core/citrus-api/src/main/java/org/citrusframework/functions/FunctionUtils.java b/core/citrus-api/src/main/java/org/citrusframework/functions/FunctionUtils.java index 3b59c78980..fbfd138042 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/functions/FunctionUtils.java +++ b/core/citrus-api/src/main/java/org/citrusframework/functions/FunctionUtils.java @@ -98,7 +98,7 @@ public static String replaceFunctionsInString(final String stringValue, TestCont strBuffer.append(newString, startIndex, searchIndex); if (enableQuoting) { - strBuffer.append("'" + value + "'"); + strBuffer.append("'").append(value).append("'"); } else { strBuffer.append(value); } diff --git a/core/citrus-api/src/main/java/org/citrusframework/main/TestEngine.java b/core/citrus-api/src/main/java/org/citrusframework/main/TestEngine.java index 0a65db111b..5c4abb8370 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/main/TestEngine.java +++ b/core/citrus-api/src/main/java/org/citrusframework/main/TestEngine.java @@ -49,7 +49,7 @@ public interface TestEngine { static TestEngine lookup(TestRunConfiguration configuration) { try { TestEngine testEngine = TYPE_RESOLVER.resolve(configuration.getEngine(), configuration); - logger.debug(String.format("Using Citrus engine '%s' as %s", configuration.getEngine(), testEngine)); + logger.debug("Using Citrus engine '{}' as {}", configuration.getEngine(), testEngine); return testEngine; } catch (CitrusRuntimeException e) { throw new CitrusRuntimeException(String.format("Failed to resolve Citrus engine from resource '%s/%s'", RESOURCE_PATH, configuration.getEngine()), e); diff --git a/core/citrus-api/src/main/java/org/citrusframework/message/AbstractMessageProcessor.java b/core/citrus-api/src/main/java/org/citrusframework/message/AbstractMessageProcessor.java index 2370937d67..8f19623c0a 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/message/AbstractMessageProcessor.java +++ b/core/citrus-api/src/main/java/org/citrusframework/message/AbstractMessageProcessor.java @@ -38,7 +38,7 @@ public void process(Message message, TestContext context) { if (supportsMessageType(message.getType())) { processMessage(message, context); } else { - logger.debug(String.format("Message processor '%s' skipped for message type: %s", getName(), message.getType())); + logger.debug("Message processor '{}' skipped for message type: {}", getName(), message.getType()); } } diff --git a/core/citrus-api/src/main/java/org/citrusframework/message/ErrorHandlingStrategy.java b/core/citrus-api/src/main/java/org/citrusframework/message/ErrorHandlingStrategy.java index c87eef7f89..df2fc30842 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/message/ErrorHandlingStrategy.java +++ b/core/citrus-api/src/main/java/org/citrusframework/message/ErrorHandlingStrategy.java @@ -27,7 +27,7 @@ public enum ErrorHandlingStrategy { PROPAGATE("propagateError"); /** Name representation */ - private String name; + private final String name; /** * Default constructor using String name representation field. diff --git a/core/citrus-api/src/main/java/org/citrusframework/message/MessageHeaderType.java b/core/citrus-api/src/main/java/org/citrusframework/message/MessageHeaderType.java index db6f87ce80..33ecadd825 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/message/MessageHeaderType.java +++ b/core/citrus-api/src/main/java/org/citrusframework/message/MessageHeaderType.java @@ -38,15 +38,15 @@ public enum MessageHeaderType { public static final String TYPE_SUFFIX = "}:"; /** Properties */ - private String name; - private Class clazz; + private final String name; + private final Class clazz; /** * Default constructor using fields. * @param name * @param clazz */ - private MessageHeaderType(String name, Class clazz) { + MessageHeaderType(String name, Class clazz) { this.name = name; this.clazz = clazz; } diff --git a/core/citrus-api/src/main/java/org/citrusframework/message/MessageHeaderUtils.java b/core/citrus-api/src/main/java/org/citrusframework/message/MessageHeaderUtils.java index 46e4121d03..436cafc8d0 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/message/MessageHeaderUtils.java +++ b/core/citrus-api/src/main/java/org/citrusframework/message/MessageHeaderUtils.java @@ -35,7 +35,7 @@ private MessageHeaderUtils() { /** * Check if given header name belongs to Spring Integration internal headers. - * + *

* This is given if header name starts with internal header prefix or * matches one of Spring's internal header names. * diff --git a/core/citrus-api/src/main/java/org/citrusframework/message/MessagePayloadUtils.java b/core/citrus-api/src/main/java/org/citrusframework/message/MessagePayloadUtils.java index 4c2a8824c8..3d06776ff0 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/message/MessagePayloadUtils.java +++ b/core/citrus-api/src/main/java/org/citrusframework/message/MessagePayloadUtils.java @@ -105,7 +105,7 @@ public static String prettyPrintXml(String payload) { if (nextStartElementPos > i + 1) { String textBetweenElements = s.substring(i + 1, nextStartElementPos); - if (textBetweenElements.replaceAll("\\s", "").length() == 0) { + if (textBetweenElements.replaceAll("\\s", "").isEmpty()) { sb.append(System.lineSeparator()); } else { sb.append(textBetweenElements.trim()); diff --git a/core/citrus-api/src/main/java/org/citrusframework/message/MessageProcessor.java b/core/citrus-api/src/main/java/org/citrusframework/message/MessageProcessor.java index 5b84a59161..ec8e0edcc8 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/message/MessageProcessor.java +++ b/core/citrus-api/src/main/java/org/citrusframework/message/MessageProcessor.java @@ -16,8 +16,6 @@ package org.citrusframework.message; -import java.util.Optional; - import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.spi.ResourcePathTypeResolver; @@ -25,6 +23,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Optional; + /** * Processor performs operations on the given message. The processor is able to change message content such as payload and headers. */ @@ -52,7 +52,7 @@ static > Optional instance = TYPE_RESOLVER.resolve(processor); return Optional.of(instance); } catch (CitrusRuntimeException e) { - logger.warn(String.format("Failed to resolve message processor from resource '%s/%s'", RESOURCE_PATH, processor)); + logger.warn("Failed to resolve message processor from resource '{}/{}'", RESOURCE_PATH, processor); } return Optional.empty(); diff --git a/core/citrus-api/src/main/java/org/citrusframework/message/MessageSelector.java b/core/citrus-api/src/main/java/org/citrusframework/message/MessageSelector.java index 5a14220140..ed3ee99422 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/message/MessageSelector.java +++ b/core/citrus-api/src/main/java/org/citrusframework/message/MessageSelector.java @@ -16,15 +16,15 @@ package org.citrusframework.message; -import java.util.Map; - -import java.util.concurrent.ConcurrentHashMap; import org.citrusframework.context.TestContext; import org.citrusframework.spi.ResourcePathTypeResolver; import org.citrusframework.spi.TypeResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + @FunctionalInterface public interface MessageSelector { @@ -50,7 +50,7 @@ static Map lookup() { factories.putAll(TYPE_RESOLVER.resolveAll()); if (logger.isDebugEnabled()) { - factories.forEach((k, v) -> logger.debug(String.format("Found message selector '%s' as %s", k, v.getClass()))); + factories.forEach((k, v) -> logger.debug("Found message selector '{}' as {}", k, v.getClass())); } } diff --git a/core/citrus-api/src/main/java/org/citrusframework/message/ScriptPayloadBuilder.java b/core/citrus-api/src/main/java/org/citrusframework/message/ScriptPayloadBuilder.java index a5601fa874..8f877e6d5c 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/message/ScriptPayloadBuilder.java +++ b/core/citrus-api/src/main/java/org/citrusframework/message/ScriptPayloadBuilder.java @@ -16,14 +16,14 @@ package org.citrusframework.message; -import java.util.Optional; - import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.spi.ResourcePathTypeResolver; import org.citrusframework.spi.TypeResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Optional; + public interface ScriptPayloadBuilder extends MessagePayloadBuilder { /** Logger */ @@ -47,7 +47,7 @@ static Optional lookup(String type) { T instance = TYPE_RESOLVER.resolve(type); return Optional.of(instance); } catch (CitrusRuntimeException e) { - logger.warn(String.format("Failed to resolve script payload builder from resource '%s/%s'", RESOURCE_PATH, type)); + logger.warn("Failed to resolve script payload builder from resource '{}/{}'", RESOURCE_PATH, type); } return Optional.empty(); diff --git a/core/citrus-api/src/main/java/org/citrusframework/spi/BindToRegistry.java b/core/citrus-api/src/main/java/org/citrusframework/spi/BindToRegistry.java index 7e274637b2..8d5cb77f29 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/spi/BindToRegistry.java +++ b/core/citrus-api/src/main/java/org/citrusframework/spi/BindToRegistry.java @@ -24,7 +24,7 @@ /** * Used to bind an object to the Citrus context reference registry for dependency injection reasons. - * + *

* Object is bound with given name. In case no explicit name is given the registry will auto compute the name from given * Class name, method name or field name. * 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 index aaaed98d12..d0ca407b16 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/util/ReflectionHelper.java +++ b/core/citrus-api/src/main/java/org/citrusframework/util/ReflectionHelper.java @@ -16,16 +16,16 @@ package org.citrusframework.util; -import static java.lang.String.format; - import jakarta.annotation.Nonnull; +import org.citrusframework.exceptions.CitrusRuntimeException; + import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; -import org.citrusframework.exceptions.CitrusRuntimeException; +import static java.lang.String.format; /** * Helper for working with reflection on classes. @@ -282,7 +282,5 @@ public static void copyFields(@Nonnull Class clazz, @Nonnull Object source, @ currentClass = currentClass.getSuperclass(); } - } - } diff --git a/core/citrus-api/src/main/java/org/citrusframework/util/TypeConverter.java b/core/citrus-api/src/main/java/org/citrusframework/util/TypeConverter.java index 3e25a57157..4e9b0d5617 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/util/TypeConverter.java +++ b/core/citrus-api/src/main/java/org/citrusframework/util/TypeConverter.java @@ -16,14 +16,14 @@ package org.citrusframework.util; -import java.util.HashMap; -import java.util.Map; - import org.citrusframework.CitrusSettings; import org.citrusframework.spi.ResourcePathTypeResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.HashMap; +import java.util.Map; + public interface TypeConverter { /** Logger */ @@ -48,12 +48,12 @@ static Map lookup() { if (converters.isEmpty()) { converters.putAll(new ResourcePathTypeResolver().resolveAll(RESOURCE_PATH)); - if (converters.size() == 0) { + if (converters.isEmpty()) { converters.put(DEFAULT, DefaultTypeConverter.INSTANCE); } if (logger.isDebugEnabled()) { - converters.forEach((k, v) -> logger.debug(String.format("Found type converter '%s' as %s", k, v.getClass()))); + converters.forEach((k, v) -> logger.debug("Found type converter '{}' as {}", k, v.getClass())); } } @@ -64,7 +64,7 @@ static Map lookup() { * Lookup default type converter specified by resource path lookup and/or environment settings. In case only a single type converter is loaded * via resource path lookup this converter is used regardless of any environment settings. If there are multiple converter implementations * on the classpath the environment settings must specify the default. - * + *

* If no converter implementation is given via resource path lookup the default implementation is returned. * @return type converter to use by default. */ @@ -76,7 +76,7 @@ static TypeConverter lookupDefault() { * Lookup default type converter specified by resource path lookup and/or environment settings. In case only a single type converter is loaded * via resource path lookup this converter is used regardless of any environment settings. If there are multiple converter implementations * on the classpath the environment settings must specify the default. - * + *

* If no converter implementation is given via resource path lookup the default implementation is returned. * * @param defaultTypeConverter the fallback default converter @@ -89,20 +89,20 @@ static TypeConverter lookupDefault(TypeConverter defaultTypeConverter) { if (converters.size() == 1) { Map.Entry converterEntry = converters.entrySet().iterator().next(); if (logger.isDebugEnabled()) { - logger.debug(String.format("Using type converter '%s'", converterEntry.getKey())); + logger.debug("Using type converter '{}'", converterEntry.getKey()); } return converterEntry.getValue(); } else if (converters.containsKey(name)) { if (logger.isDebugEnabled()) { - logger.debug(String.format("Using type converter '%s'", name)); + logger.debug("Using type converter '{}'", name); } return converters.get(name); } if (!CitrusSettings.TYPE_CONVERTER_DEFAULT.equals(name)) { - logger.warn(String.format("Missing type converter for name '%s' - using default type converter", name)); + logger.warn("Missing type converter for name '{}' - using default type converter", name); } return defaultTypeConverter; diff --git a/core/citrus-api/src/main/java/org/citrusframework/validation/HeaderValidator.java b/core/citrus-api/src/main/java/org/citrusframework/validation/HeaderValidator.java index 1adf884c9c..e5eb3fccab 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/validation/HeaderValidator.java +++ b/core/citrus-api/src/main/java/org/citrusframework/validation/HeaderValidator.java @@ -16,10 +16,6 @@ package org.citrusframework.validation; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.spi.ResourcePathTypeResolver; @@ -28,6 +24,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + /** * @since 2.7.6 */ @@ -54,7 +54,7 @@ static Map lookup() { validators.putAll(TYPE_RESOLVER.resolveAll("", TypeResolver.DEFAULT_TYPE_PROPERTY, "name")); if (logger.isDebugEnabled()) { - validators.forEach((k, v) -> logger.debug(String.format("Found header validator '%s' as %s", k, v.getClass()))); + validators.forEach((k, v) -> logger.debug("Found header validator '{}' as {}", k, v.getClass())); } } return validators; @@ -72,7 +72,7 @@ static Optional lookup(String validator) { HeaderValidator instance = TYPE_RESOLVER.resolve(validator); return Optional.of(instance); } catch (CitrusRuntimeException e) { - logger.warn(String.format("Failed to resolve header validator from resource '%s/%s'", RESOURCE_PATH, validator)); + logger.warn("Failed to resolve header validator from resource '{}/{}'", RESOURCE_PATH, validator); } return Optional.empty(); diff --git a/core/citrus-api/src/main/java/org/citrusframework/validation/MessageValidator.java b/core/citrus-api/src/main/java/org/citrusframework/validation/MessageValidator.java index ca436bda24..2fab5c3c9f 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/validation/MessageValidator.java +++ b/core/citrus-api/src/main/java/org/citrusframework/validation/MessageValidator.java @@ -16,10 +16,6 @@ package org.citrusframework.validation; -import java.util.List; -import java.util.Map; -import java.util.Optional; - import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.exceptions.ValidationException; @@ -31,6 +27,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; +import java.util.Map; +import java.util.Optional; + /** * Message validator interface. Message validation need specific information like * control messages or validation scripts. These validation specific information is @@ -57,7 +57,7 @@ static Map> lookup() { Map> validators = TYPE_RESOLVER.resolveAll("", TypeResolver.DEFAULT_TYPE_PROPERTY, "name"); if (logger.isDebugEnabled()) { - validators.forEach((k, v) -> logger.debug(String.format("Found message validator '%s' as %s", k, v.getClass()))); + validators.forEach((k, v) -> logger.debug("Found message validator '{}' as {}", k, v.getClass())); } return validators; @@ -75,7 +75,7 @@ static Optional> lookup(String val MessageValidator instance = TYPE_RESOLVER.resolve(validator); return Optional.of(instance); } catch (CitrusRuntimeException e) { - logger.warn(String.format("Failed to resolve validator from resource '%s/%s'", RESOURCE_PATH, validator)); + logger.warn("Failed to resolve validator from resource '{}/{}'", RESOURCE_PATH, validator); } return Optional.empty(); diff --git a/core/citrus-api/src/main/java/org/citrusframework/validation/MessageValidatorRegistry.java b/core/citrus-api/src/main/java/org/citrusframework/validation/MessageValidatorRegistry.java index bbeecbcab6..d54c371799 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/validation/MessageValidatorRegistry.java +++ b/core/citrus-api/src/main/java/org/citrusframework/validation/MessageValidatorRegistry.java @@ -16,12 +16,6 @@ package org.citrusframework.validation; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.exceptions.NoSuchMessageValidatorException; import org.citrusframework.message.Message; @@ -33,10 +27,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static java.lang.String.format; + /** * Simple registry holding all available message validator implementations. Test context can ask this registry for * matching validator implementation according to the message type (e.g. xml, json, csv, plaintext). - * + *

* Registry tries to find a matching validator for the message. * */ @@ -105,18 +107,17 @@ public List> findMessageValidators } } - if (isEmptyOrDefault(matchingValidators) && - (message.getPayload(String.class) == null || message.getPayload(String.class).isBlank())) { + if (isEmptyOrDefault(matchingValidators) + && (message.getPayload(String.class) == null || message.getPayload(String.class).isBlank())) { matchingValidators.add(defaultEmptyMessageValidator); } if (isEmptyOrDefault(matchingValidators)) { if (mustFindValidator) { if (logger.isWarnEnabled()) { - logger.warn(String.format( - "Unable to find proper message validator. Message type is '%s' and message payload is '%s'", - messageType, message.getPayload(String.class))); + logger.warn("Unable to find proper message validator. Message type is '{}' and message payload is '{}'", messageType, message.getPayload(String.class)); } + throw new CitrusRuntimeException("Failed to find proper message validator for message"); } @@ -124,9 +125,7 @@ public List> findMessageValidators matchingValidators.add(defaultTextEqualsMessageValidator); } - if (logger.isDebugEnabled()) { - logger.debug(String.format("Found %s message validators for message", matchingValidators.size())); - } + logger.debug("Found {} message validators for message", matchingValidators.size()); return matchingValidators; } @@ -201,7 +200,7 @@ public MessageValidator getMessageValidator(String return this.messageValidators.get(name); } - throw new NoSuchMessageValidatorException(String.format("Unable to find message validator with name '%s'", name)); + throw new NoSuchMessageValidatorException(format("Unable to find message validator with name '%s'", name)); } /** @@ -211,7 +210,7 @@ public MessageValidator getMessageValidator(String */ public void addMessageValidator(String name, MessageValidator messageValidator) { if (this.messageValidators.containsKey(name) && logger.isDebugEnabled()) { - logger.debug(String.format("Overwriting message validator '%s' in registry", name)); + logger.debug("Overwriting message validator '{}' in registry", name); } this.messageValidators.put(name, messageValidator); @@ -224,7 +223,7 @@ public void addMessageValidator(String name, MessageValidator schemaValidator) { if (this.schemaValidators.containsKey(name) && logger.isDebugEnabled()) { - logger.debug(String.format("Overwriting message validator '%s' in registry", name)); + logger.debug("Overwriting message validator '{}' in registry", name); } this.schemaValidators.put(name, schemaValidator); @@ -234,8 +233,7 @@ public void addSchemaValidator(String name, SchemaValidator> messageValidators) { + public void setMessageValidators(Map> messageValidators) { this.messageValidators = messageValidators; } diff --git a/core/citrus-api/src/main/java/org/citrusframework/validation/SchemaValidator.java b/core/citrus-api/src/main/java/org/citrusframework/validation/SchemaValidator.java index 3d6a8d11d0..99549bee6a 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/validation/SchemaValidator.java +++ b/core/citrus-api/src/main/java/org/citrusframework/validation/SchemaValidator.java @@ -32,7 +32,7 @@ public interface SchemaValidator { /** Logger */ - Logger logger = LoggerFactory.getLogger(MessageValidator.class); + Logger logger = LoggerFactory.getLogger(SchemaValidator.class); /** Schema validator resource lookup path */ String RESOURCE_PATH = "META-INF/citrus/message/schemaValidator"; @@ -49,7 +49,7 @@ static Map> lookup() Map> validators = TYPE_RESOLVER.resolveAll("", TypeResolver.DEFAULT_TYPE_PROPERTY, "name"); if (logger.isDebugEnabled()) { - validators.forEach((k, v) -> logger.debug(String.format("Found message validator '%s' as %s", k, v.getClass()))); + validators.forEach((k, v) -> logger.debug("Found message validator '{}' as {}", k, v.getClass())); } return validators; @@ -67,7 +67,7 @@ static Optional> lookup(Strin SchemaValidator instance = TYPE_RESOLVER.resolve(validator); return Optional.of(instance); } catch (CitrusRuntimeException e) { - logger.warn(String.format("Failed to resolve validator from resource '%s/%s'", RESOURCE_PATH, validator)); + logger.warn("Failed to resolve validator from resource '{}/{}'", RESOURCE_PATH, validator); } return Optional.empty(); diff --git a/core/citrus-api/src/main/java/org/citrusframework/validation/ValueMatcher.java b/core/citrus-api/src/main/java/org/citrusframework/validation/ValueMatcher.java index c95c793394..a186fa0d81 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/validation/ValueMatcher.java +++ b/core/citrus-api/src/main/java/org/citrusframework/validation/ValueMatcher.java @@ -16,10 +16,6 @@ package org.citrusframework.validation; -import java.util.Map; -import java.util.Optional; - -import java.util.concurrent.ConcurrentHashMap; import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.spi.ResourcePathTypeResolver; @@ -27,10 +23,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; + public interface ValueMatcher { /** Logger */ - Logger logger = LoggerFactory.getLogger(MessageValidator.class); + Logger logger = LoggerFactory.getLogger(ValueMatcher.class); /** Message validator resource lookup path */ String RESOURCE_PATH = "META-INF/citrus/value/matcher"; @@ -50,7 +50,7 @@ static Map lookup() { validators.putAll(TYPE_RESOLVER.resolveAll()); if (logger.isDebugEnabled()) { - validators.forEach((k, v) -> logger.debug(String.format("Found validator '%s' as %s", k, v.getClass()))); + validators.forEach((k, v) -> logger.debug("Found validator '{}' as {}", k, v.getClass())); } } return validators; @@ -68,7 +68,7 @@ static Optional lookup(String validator) { ValueMatcher instance = TYPE_RESOLVER.resolve(validator); return Optional.of(instance); } catch (CitrusRuntimeException e) { - logger.warn(String.format("Failed to resolve value matcher from resource '%s/%s'", RESOURCE_PATH, validator)); + logger.warn("Failed to resolve value matcher from resource '{}/{}'", RESOURCE_PATH, validator); } return Optional.empty(); diff --git a/core/citrus-api/src/main/java/org/citrusframework/validation/matcher/DefaultControlExpressionParser.java b/core/citrus-api/src/main/java/org/citrusframework/validation/matcher/DefaultControlExpressionParser.java index a967eea9ae..6c99193476 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/validation/matcher/DefaultControlExpressionParser.java +++ b/core/citrus-api/src/main/java/org/citrusframework/validation/matcher/DefaultControlExpressionParser.java @@ -16,11 +16,11 @@ package org.citrusframework.validation.matcher; +import org.citrusframework.exceptions.CitrusRuntimeException; + import java.util.ArrayList; import java.util.List; -import org.citrusframework.exceptions.CitrusRuntimeException; - /** * Default implementation of control expression parser. * @since 2.5 @@ -34,7 +34,7 @@ public List extractControlValues(String controlExpression, Character del if (controlExpression != null && !controlExpression.isBlank()) { extractParameters(controlExpression, useDelimiter, extractedParameters, 0); - if (extractedParameters.size() == 0) { + if (extractedParameters.isEmpty()) { // if the controlExpression has text but no parameters were extracted, then assume that // the controlExpression itself is the only parameter extractedParameters.add(controlExpression); diff --git a/core/citrus-api/src/main/java/org/citrusframework/validation/matcher/ValidationMatcher.java b/core/citrus-api/src/main/java/org/citrusframework/validation/matcher/ValidationMatcher.java index 19dcaecd85..731f92d91e 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/validation/matcher/ValidationMatcher.java +++ b/core/citrus-api/src/main/java/org/citrusframework/validation/matcher/ValidationMatcher.java @@ -16,16 +16,16 @@ package org.citrusframework.validation.matcher; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.ValidationException; import org.citrusframework.spi.ResourcePathTypeResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * General validation matcher interface. * @@ -51,7 +51,7 @@ static Map lookup() { matcher.putAll(new ResourcePathTypeResolver().resolveAll(RESOURCE_PATH)); if (logger.isDebugEnabled()) { - matcher.forEach((k, v) -> logger.debug(String.format("Found validation matcher '%s' as %s", k, v.getClass()))); + matcher.forEach((k, v) -> logger.debug("Found validation matcher '{}' as {}", k, v.getClass())); } } return matcher; 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 0f4b6c22c8..3bb7742ce2 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 @@ -16,14 +16,6 @@ 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; @@ -32,6 +24,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +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; + /** * Simple registry holding all available segment variable extractor implementations. Test context can ask this registry for * the extractors managed by this registry in order to access variable content from the TestContext expressed by variable expressions. @@ -41,7 +41,7 @@ public class SegmentVariableExtractorRegistry { /** Logger */ - private static final Logger logger = LoggerFactory.getLogger(SegmentVariableExtractor.class); + private static final Logger logger = LoggerFactory.getLogger(SegmentVariableExtractorRegistry.class); /** Segment variable extractor resource lookup path */ private static final String RESOURCE_PATH = "META-INF/citrus/variable/extractor/segment"; @@ -60,7 +60,7 @@ static Collection lookup() { Map extractors = TYPE_RESOLVER.resolveAll(); return extractors.values(); } catch (CitrusRuntimeException e) { - logger.warn(String.format("Failed to resolve segment variable extractor from resource '%s'", RESOURCE_PATH)); + logger.warn("Failed to resolve segment variable extractor from resource '{}'", RESOURCE_PATH); } return Collections.emptyList(); diff --git a/core/citrus-api/src/main/java/org/citrusframework/variable/VariableExtractor.java b/core/citrus-api/src/main/java/org/citrusframework/variable/VariableExtractor.java index 67c3c50a68..ef3792bfff 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/variable/VariableExtractor.java +++ b/core/citrus-api/src/main/java/org/citrusframework/variable/VariableExtractor.java @@ -16,8 +16,6 @@ package org.citrusframework.variable; -import java.util.Optional; - import org.citrusframework.builder.WithExpressions; import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; @@ -28,6 +26,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Optional; + /** * Class extracting variables form messages. Implementing classes may read * message contents and save those to test variables. @@ -56,7 +56,7 @@ static > Optional instance = TYPE_RESOLVER.resolve(extractor); return Optional.of(instance); } catch (CitrusRuntimeException e) { - logger.warn(String.format("Failed to resolve variable extractor from resource '%s/%s'", RESOURCE_PATH, extractor)); + logger.warn("Failed to resolve variable extractor from resource '{}/{}'", RESOURCE_PATH, extractor); } return Optional.empty(); diff --git a/core/citrus-api/src/main/java/org/citrusframework/variable/VariableUtils.java b/core/citrus-api/src/main/java/org/citrusframework/variable/VariableUtils.java index 55a2cb329c..98fc6e8bb8 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/variable/VariableUtils.java +++ b/core/citrus-api/src/main/java/org/citrusframework/variable/VariableUtils.java @@ -16,15 +16,15 @@ package org.citrusframework.variable; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; - import org.citrusframework.CitrusSettings; import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.exceptions.NoSuchVariableException; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; + /** * Utility class manipulating test variables. * @@ -118,15 +118,11 @@ public static String cutOffVariablesEscaping(String variable) { * @return flag true/false */ public static boolean isVariableName(final String expression) { - if (expression == null || expression.length() == 0) { + if (expression == null || expression.isEmpty()) { return false; } - if (expression.startsWith(CitrusSettings.VARIABLE_PREFIX) && expression.endsWith(CitrusSettings.VARIABLE_SUFFIX)) { - return true; - } - - return false; + return expression.startsWith(CitrusSettings.VARIABLE_PREFIX) && expression.endsWith(CitrusSettings.VARIABLE_SUFFIX); } /** @@ -176,7 +172,7 @@ public static String replaceVariablesInString(final String str, TestContext cont final String value = context.getVariable(variableNameBuf.toString()); if (value == null) { - throw new NoSuchVariableException("Variable: " + variableNameBuf.toString() + " could not be found"); + throw new NoSuchVariableException("Variable: " + variableNameBuf + " could not be found"); } newStr.append(str, startIndex, searchIndex); diff --git a/core/citrus-api/src/main/java/org/citrusframework/variable/dictionary/DataDictionary.java b/core/citrus-api/src/main/java/org/citrusframework/variable/dictionary/DataDictionary.java index 29093b6e1a..a96f52f935 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/variable/dictionary/DataDictionary.java +++ b/core/citrus-api/src/main/java/org/citrusframework/variable/dictionary/DataDictionary.java @@ -26,7 +26,7 @@ * Data dictionary interface describes a mechanism to modify message content (payload) with global dictionary elements. * Dictionary translates element values to those defined in dictionary. Message construction process is aware of dictionaries * in Spring application context so user just has to add dictionary implementation to application context. - * + *

* Dictionary takes part in message construction for inbound and outbound messages in Citrus. * @since 1.4 */ @@ -59,6 +59,6 @@ public interface DataDictionary extends MessageProcessor, MessageDirectionAwa enum PathMappingStrategy { EXACT, ENDS_WITH, - STARTS_WITH; + STARTS_WITH } } diff --git a/core/citrus-api/src/main/java/org/citrusframework/xml/namespace/NamespaceContextBuilder.java b/core/citrus-api/src/main/java/org/citrusframework/xml/namespace/NamespaceContextBuilder.java index a4a7dae971..744023946a 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/xml/namespace/NamespaceContextBuilder.java +++ b/core/citrus-api/src/main/java/org/citrusframework/xml/namespace/NamespaceContextBuilder.java @@ -16,18 +16,18 @@ package org.citrusframework.xml.namespace; +import org.citrusframework.message.Message; + +import javax.xml.XMLConstants; +import javax.xml.namespace.NamespaceContext; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; -import javax.xml.XMLConstants; -import javax.xml.namespace.NamespaceContext; - -import org.citrusframework.message.Message; /** * Builds a namespace context for XPath expression evaluations. Builder supports default mappings * as well as dynamic mappings from received message. - * + *

* Namespace mappings are defined as key value pairs where key is definded as namespace prefix and value is the * actual namespace uri. * @@ -50,7 +50,7 @@ public NamespaceContext buildContext(Message receivedMessage, Map 0) { + if (!namespaceMappings.isEmpty()) { defaultNamespaceContext.addNamespaces(namespaceMappings); } diff --git a/core/citrus-api/src/test/java/org/citrusframework/message/MessagePayloadUtilsTest.java b/core/citrus-api/src/test/java/org/citrusframework/message/MessagePayloadUtilsTest.java index d89f582038..e6b33b73a9 100644 --- a/core/citrus-api/src/test/java/org/citrusframework/message/MessagePayloadUtilsTest.java +++ b/core/citrus-api/src/test/java/org/citrusframework/message/MessagePayloadUtilsTest.java @@ -16,12 +16,11 @@ package org.citrusframework.message; -import static org.testng.Assert.assertEquals; - -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; + public class MessagePayloadUtilsTest { @Test