Skip to content

Commit

Permalink
chore(citrus-api): review and code cleanup
Browse files Browse the repository at this point in the history
pr: #1224

`citrus-api` module.
  • Loading branch information
bbortt committed Oct 24, 2024
1 parent 42ce36a commit 0f41890
Show file tree
Hide file tree
Showing 38 changed files with 188 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,7 +64,7 @@ static Map<String, TestActionBuilder<?>> lookup() {
Map<String, TestActionBuilder<?>> 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;
}
Expand All @@ -73,7 +73,7 @@ static Map<String, TestActionBuilder<?>> 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.
*
* <p>
* Given builder name is a combination of resource file name and type property separated by '.' character.
* @param builder
* @return
Expand All @@ -82,7 +82,7 @@ static Optional<TestActionBuilder<?>> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,7 +85,7 @@ static Map<String, TestLoader> lookup() {
Map<String, TestLoader> 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;
}
Expand All @@ -101,7 +101,7 @@ static Optional<TestLoader> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down Expand Up @@ -63,7 +63,7 @@ static Map<String, AnnotationConfigParser> 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;
Expand All @@ -73,7 +73,7 @@ static Map<String, AnnotationConfigParser> 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.
*
* <p>
* Given parser name is a combination of resource file name and type property separated by '.' character.
* @param parser
* @return
Expand All @@ -90,7 +90,7 @@ static Optional<AnnotationConfigParser> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(""));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -54,7 +54,7 @@ public interface TypeAliasResolver<S, A> {
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;
Expand All @@ -71,7 +71,7 @@ public interface TypeAliasResolver<S, A> {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
* <p>
* 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.
*
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -116,7 +116,7 @@ static Map<String, EndpointBuilder<?>> lookup() {
Map<String, EndpointBuilder<?>> 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;
}
Expand All @@ -125,7 +125,7 @@ static Map<String, EndpointBuilder<?>> 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.
*
* <p>
* Given builder name is a combination of resource file name and type property separated by '.' character.
* @param builder
* @return
Expand All @@ -142,7 +142,7 @@ static Optional<EndpointBuilder<?>> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,7 +75,7 @@ static Map<String, EndpointComponent> lookup() {
Map<String, EndpointComponent> 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;
}
Expand All @@ -92,7 +92,7 @@ static Optional<EndpointComponent> 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();
Expand Down
Loading

0 comments on commit 0f41890

Please sign in to comment.