Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import tools.jackson.core.JsonParser;
import tools.jackson.databind.DeserializationFeature;
import tools.jackson.databind.MapperFeature;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.SerializationFeature;
import tools.jackson.databind.json.JsonMapper;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.introspector.Property;
Expand Down
6 changes: 3 additions & 3 deletions connectors/citrus-docker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,20 @@
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<groupId>tools.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,27 @@

package org.citrusframework.docker.actions;

import java.util.Collections;
import java.util.Optional;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.citrusframework.AbstractTestActionBuilder;
import org.citrusframework.actions.AbstractTestAction;
import org.citrusframework.actions.docker.DockerActionBuilder;
import org.citrusframework.context.TestContext;
import org.citrusframework.docker.client.DockerClient;
import org.citrusframework.docker.command.*;
import org.citrusframework.docker.command.AbstractDockerCommandBuilder;
import org.citrusframework.docker.command.ContainerCreate;
import org.citrusframework.docker.command.ContainerInspect;
import org.citrusframework.docker.command.ContainerRemove;
import org.citrusframework.docker.command.ContainerStart;
import org.citrusframework.docker.command.ContainerStop;
import org.citrusframework.docker.command.ContainerWait;
import org.citrusframework.docker.command.DockerCommand;
import org.citrusframework.docker.command.ImageBuild;
import org.citrusframework.docker.command.ImageInspect;
import org.citrusframework.docker.command.ImagePull;
import org.citrusframework.docker.command.ImageRemove;
import org.citrusframework.docker.command.Info;
import org.citrusframework.docker.command.Ping;
import org.citrusframework.docker.command.StaticDockerCommandBuilder;
import org.citrusframework.docker.command.Version;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.ValidationException;
import org.citrusframework.message.DefaultMessage;
Expand All @@ -36,6 +46,10 @@
import org.citrusframework.validation.json.JsonMessageValidationContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.jackson.databind.ObjectMapper;

import java.util.Collections;
import java.util.Optional;

/**
* Executes docker command with given docker client implementation. Possible command result is stored within command object.
Expand Down Expand Up @@ -108,14 +122,10 @@ private void validateCommandResult(DockerCommand command, TestContext context) {
throw new ValidationException("Missing Docker command result");
}

try {
String commandResultJson = jsonMapper.writeValueAsString(command.getCommandResult());
JsonMessageValidationContext validationContext = new JsonMessageValidationContext();
getMessageValidator(context).validateMessage(new DefaultMessage(commandResultJson), new DefaultMessage(expectedCommandResult), context, Collections.singletonList(validationContext));
logger.debug("Docker command result validation successful - all values OK!");
} catch (JsonProcessingException e) {
throw new CitrusRuntimeException(e);
}
String commandResultJson = jsonMapper.writeValueAsString(command.getCommandResult());
JsonMessageValidationContext validationContext = new JsonMessageValidationContext();
getMessageValidator(context).validateMessage(new DefaultMessage(commandResultJson), new DefaultMessage(expectedCommandResult), context, Collections.singletonList(validationContext));
logger.debug("Docker command result validation successful - all values OK!");
}

if (command.getResultCallback() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.validation.MessageValidator;
import org.citrusframework.validation.context.ValidationContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectMapper;

public abstract class AbstractDockerCommandBuilder<R, T extends AbstractDockerCommand<R>, S extends AbstractDockerCommandBuilder<R, T, S>>
implements TestActionBuilder<DockerExecuteAction>, DockerActionBuilderBase<R, DockerExecuteAction, S> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.citrusframework.docker.command.DockerCommand;
import org.citrusframework.validation.MessageValidator;
import org.citrusframework.validation.context.ValidationContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import java.util.Map;
import java.util.Optional;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.core.JsonProcessingException;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.ObjectMapper;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.MessageType;
import org.springframework.http.HttpMethod;
Expand Down
8 changes: 4 additions & 4 deletions connectors/citrus-kubernetes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,23 @@
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<groupId>tools.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<groupId>tools.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,7 @@

package org.citrusframework.kubernetes;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import io.fabric8.kubernetes.api.model.ContainerStatus;
import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
import io.fabric8.kubernetes.api.model.GenericKubernetesResourceList;
Expand All @@ -47,21 +35,32 @@
import org.yaml.snakeyaml.nodes.NodeTuple;
import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.representer.Representer;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;

public final class KubernetesSupport {
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;

private static final ObjectMapper OBJECT_MAPPER;
import static tools.jackson.core.StreamReadFeature.AUTO_CLOSE_SOURCE;
import static tools.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
import static tools.jackson.databind.cfg.EnumFeature.READ_ENUMS_USING_TO_STRING;
import static tools.jackson.databind.cfg.EnumFeature.WRITE_ENUMS_USING_TO_STRING;

static {
OBJECT_MAPPER = JsonMapper.builder()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING)
.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)
.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE)
.enable(MapperFeature.BLOCK_UNSAFE_POLYMORPHIC_BASE_TYPES)
.build()
.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_EMPTY, JsonInclude.Include.NON_EMPTY));
}
public final class KubernetesSupport {

private static final ObjectMapper OBJECT_MAPPER = JsonMapper.builder()
.disable(FAIL_ON_UNKNOWN_PROPERTIES)
.enable(READ_ENUMS_USING_TO_STRING)
.enable(WRITE_ENUMS_USING_TO_STRING)
.disable(AUTO_CLOSE_SOURCE)
// .enable(MBLOCK_UNSAFE_POLYMORPHIC_BASE_TYPES)
.changeDefaultPropertyInclusion((handler) ->
handler.withValueInclusion(JsonInclude.Include.NON_EMPTY)
)
.build();

private KubernetesSupport() {
// prevent instantiation of utility class
Expand All @@ -70,6 +69,7 @@ private KubernetesSupport() {
/**
* Dump given domain model object as YAML.
* Uses Json conversion to generic map as intermediate step. This makes sure to properly write Json additional properties.
*
* @param model
* @return
*/
Expand All @@ -80,6 +80,7 @@ public static String dumpYaml(Object model) {
/**
* Retrieve current Kubernetes client if set in Citrus context as bean reference.
* Otherwise, create new default instance.
*
* @param citrus holding the potential bean reference to the client instance.
* @return
*/
Expand All @@ -94,6 +95,7 @@ public static KubernetesClient getKubernetesClient(Citrus citrus) {
/**
* Retrieve current Kubernetes client if set in test context as bean reference.
* Otherwise, create new default instance.
*
* @param context holding the potential client bean reference.
* @return
*/
Expand All @@ -108,6 +110,7 @@ public static KubernetesClient getKubernetesClient(TestContext context) {
/**
* Retrieve current namespace set as test variable.
* In case no suitable test variable is available use namespace loaded from Kubernetes settings via environment settings.
*
* @param context potentially holding the namespace variable.
* @return
*/
Expand All @@ -133,7 +136,7 @@ public static Yaml yaml() {
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) {
// if value of property is null, ignore it.
if (propertyValue == null || (propertyValue instanceof Collection && ((Collection<?>) propertyValue).isEmpty()) ||
(propertyValue instanceof Map && ((Map<?, ?>) propertyValue).isEmpty())) {
(propertyValue instanceof Map && ((Map<?, ?>) propertyValue).isEmpty())) {
return null;
} else {
return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
Expand Down Expand Up @@ -171,7 +174,7 @@ public static GenericKubernetesResourceList getResources(KubernetesClient k8sCli
}

public static <T> void createResource(KubernetesClient k8sClient, String namespace,
ResourceDefinitionContext context, T resource) {
ResourceDefinitionContext context, T resource) {
createResource(k8sClient, namespace, context, yaml().dumpAsMap(resource));
}

Expand Down Expand Up @@ -199,6 +202,7 @@ public static ResourceDefinitionContext crdContext(String resourceType, String g
/**
* Checks pod status with expected phase. If expected status is "Running" all
* containers in the pod must be in ready state, too.
*
* @param pod
* @param status
* @return
Expand All @@ -217,6 +221,7 @@ public static boolean verifyPodStatus(Pod pod, String status) {
* Try to get the cluster IP address of given service.
* Resolves service by its name in given namespace and retrieves the cluster IP setting from the service spec.
* Returns empty Optional in case of errors or no cluster IP setting.
*
* @param citrus
* @param serviceName
* @param namespace
Expand All @@ -237,6 +242,7 @@ public static Optional<String> getServiceClusterIp(Citrus citrus, String service

/**
* Create K8s conform name using lowercase RFC 1123 rules.
*
* @param name
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.Map;
import java.util.Optional;

import com.fasterxml.jackson.core.JsonProcessingException;
import io.fabric8.kubernetes.api.model.Endpoints;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.Namespace;
Expand Down Expand Up @@ -134,23 +133,19 @@ private void validateCommandResult(KubernetesCommand<?, ?> command, TestContext
throw new ValidationException("Missing Kubernetes command result");
}

try {
String commandResultJson = kubernetesClient.getEndpointConfiguration()
.getObjectMapper().writeValueAsString(result);
if (StringUtils.hasText(commandResult)) {
getMessageValidator(context).validateMessage(new DefaultMessage(commandResultJson), new DefaultMessage(commandResult), context, Collections.singletonList(new JsonMessageValidationContext()));
logger.debug("Kubernetes command result validation successful - all values OK!");
}
String commandResultJson = kubernetesClient.getEndpointConfiguration()
.getObjectMapper().writeValueAsString(result);
if (StringUtils.hasText(commandResult)) {
getMessageValidator(context).validateMessage(new DefaultMessage(commandResultJson), new DefaultMessage(commandResult), context, Collections.singletonList(new JsonMessageValidationContext()));
logger.debug("Kubernetes command result validation successful - all values OK!");
}

if (!commandResultExpressions.isEmpty()) {
JsonPathMessageValidationContext validationContext = new JsonPathMessageValidationContext.Builder()
.expressions(commandResultExpressions)
.build();
getPathValidator(context).validateMessage(new DefaultMessage(commandResultJson), new DefaultMessage(commandResult), context, Collections.singletonList(validationContext));
logger.debug("Kubernetes command result path validation successful - all values OK!");
}
} catch (JsonProcessingException e) {
throw new CitrusRuntimeException(e);
if (!commandResultExpressions.isEmpty()) {
JsonPathMessageValidationContext validationContext = new JsonPathMessageValidationContext.Builder()
.expressions(commandResultExpressions)
.build();
getPathValidator(context).validateMessage(new DefaultMessage(commandResultJson), new DefaultMessage(commandResult), context, Collections.singletonList(validationContext));
logger.debug("Kubernetes command result path validation successful - all values OK!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.citrusframework.kubernetes.client;

import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectMapper;
import io.fabric8.kubernetes.client.ConfigBuilder;
import org.citrusframework.endpoint.AbstractEndpointBuilder;
import org.citrusframework.kubernetes.message.KubernetesMessageConverter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.citrusframework.kubernetes.config.annotation;

import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectMapper;
import org.citrusframework.config.annotation.AnnotationConfigParser;
import org.citrusframework.kubernetes.client.KubernetesClient;
import org.citrusframework.kubernetes.client.KubernetesClientBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.citrusframework.kubernetes.message.KubernetesMessageConverter;
import org.citrusframework.message.DefaultMessageCorrelator;
import org.citrusframework.message.MessageCorrelator;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectMapper;
import io.fabric8.kubernetes.client.*;

/**
Expand Down
Loading
Loading