Skip to content
Merged
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 @@ -16,17 +16,27 @@

package org.citrusframework.docker.actions;

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

import tools.jackson.core.JacksonException;
import tools.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,11 @@
import org.citrusframework.validation.json.JsonMessageValidationContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.jackson.core.JacksonException;
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 All @@ -44,24 +59,33 @@
*/
public class DockerExecuteAction extends AbstractTestAction {

/** Docker client instance */
/**
* Docker client instance
*/
private final DockerClient dockerClient;

/** Docker command to execute */
/**
* Docker command to execute
*/
private final DockerCommand<?> command;

/** Expected command result for validation */
/**
* Expected command result for validation
*/
private final String expectedCommandResult;

/** JSON data binding */
/**
* JSON data binding
*/
private final ObjectMapper jsonMapper;

/** Validator used to validate expected json results */
/**
* Validator used to validate expected json results
*/
private final MessageValidator<? extends ValidationContext> jsonMessageValidator;

public static final String DEFAULT_JSON_MESSAGE_VALIDATOR = "defaultJsonMessageValidator";

/** Logger */
private static final Logger logger = LoggerFactory.getLogger(DockerExecuteAction.class);

/**
Expand All @@ -81,13 +105,13 @@ public DockerExecuteAction(Builder builder) {
public void doExecute(TestContext context) {
try {
if (logger.isDebugEnabled()) {
logger.debug(String.format("Executing Docker command '%s'", command.getName()));
logger.debug("Executing Docker command '{}'", command.getName());
}
command.execute(dockerClient, context);

validateCommandResult(command, context);

logger.info(String.format("Docker command execution successful: '%s'", command.getName()));
logger.info("Docker command execution successful: '{}'", command.getName());
} catch (CitrusRuntimeException e) {
throw e;
} catch (Exception e) {
Expand All @@ -97,8 +121,6 @@ public void doExecute(TestContext context) {

/**
* Validate command results.
* @param command
* @param context
*/
private void validateCommandResult(DockerCommand command, TestContext context) {
logger.debug("Starting Docker command result validation");
Expand All @@ -125,8 +147,6 @@ private void validateCommandResult(DockerCommand command, TestContext context) {

/**
* Find proper JSON message validator. Uses several strategies to lookup default JSON message validator.
* @param context
* @return
*/
private MessageValidator<? extends ValidationContext> getMessageValidator(TestContext context) {
if (jsonMessageValidator != null) {
Expand Down Expand Up @@ -155,23 +175,20 @@ private MessageValidator<? extends ValidationContext> getMessageValidator(TestCo

/**
* Gets the docker command to execute.
* @return
*/
public DockerCommand<?> getCommand() {
return command;
}

/**
* Gets the docker client.
* @return
*/
public DockerClient getDockerClient() {
return dockerClient;
}

/**
* Gets the expected command result data.
* @return
*/
public String getExpectedCommandResult() {
return expectedCommandResult;
Expand All @@ -191,7 +208,6 @@ public static class Builder extends AbstractTestActionBuilder<DockerExecuteActio

/**
* Fluent API action building entry method used in Java DSL.
* @return
*/
public static Builder docker() {
return new Builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package org.citrusframework.docker.client;

import java.util.Objects;

import org.citrusframework.context.TestContext;
import org.citrusframework.docker.command.DockerCommand;
import org.citrusframework.endpoint.AbstractEndpoint;
Expand All @@ -32,17 +30,20 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;

/**
* Docker client uses Java docker client implementation for executing docker commands.
*
* @since 2.4
*/
public class DockerClient extends AbstractEndpoint implements Producer, ReplyConsumer {

/** Logger */
private static final Logger logger = LoggerFactory.getLogger(DockerClient.class);

/** Store of reply messages */
/**
* Store of reply messages
*/
private CorrelationManager<DockerCommand> correlationManager;

/**
Expand All @@ -54,7 +55,6 @@ public DockerClient() {

/**
* Default constructor using endpoint configuration.
* @param endpointConfiguration
*/
public DockerClient(DockerEndpointConfiguration endpointConfiguration) {
super(endpointConfiguration);
Expand All @@ -74,13 +74,13 @@ public void send(Message message, TestContext context) {
correlationManager.saveCorrelationKey(correlationKeyName, correlationKey, context);

if (logger.isDebugEnabled()) {
logger.debug("Sending Docker request to: '" + getEndpointConfiguration().getDockerClientConfig().getDockerHost() + "'");
logger.debug("Sending Docker request to: '{}'", getEndpointConfiguration().getDockerClientConfig().getDockerHost());
}

DockerCommand command = message.getPayload(DockerCommand.class);
command.execute(this, context);

logger.info("Docker request was sent to endpoint: '" + getEndpointConfiguration().getDockerClientConfig().getDockerHost() + "'");
logger.info("Docker request was sent to endpoint: '{}'", getEndpointConfiguration().getDockerClientConfig().getDockerHost());

correlationManager.store(correlationKey, command);

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

package org.citrusframework.jbang;

import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
Expand All @@ -31,14 +36,8 @@
import java.util.Map;
import java.util.Optional;

import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CitrusJBang {

/** Logger */
private static final Logger logger = LoggerFactory.getLogger(CitrusJBang.class);

private final JBangSupport app;
Expand All @@ -55,7 +54,7 @@ public CitrusJBang(String app) {

String version = version();
if (logger.isDebugEnabled()) {
logger.debug("Citrus JBang version: " + version);
logger.debug("Citrus JBang version: {}", version);
}
}

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

package org.citrusframework.jbang;

import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.util.FileUtils;
import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -45,12 +51,6 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.util.FileUtils;
import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Support class prepares JBang executable and runs commands via spawned process using the JBang binary.
*/
Expand Down Expand Up @@ -279,12 +279,12 @@ private static void download() {
Path installPath = Paths.get(System.getProperty("user.home")).toAbsolutePath().resolve(".jbang").toAbsolutePath();

if (installPath.resolve(homePath).toFile().exists()) {
LOG.info("Using local JBang in " + installPath);
LOG.info("Using local JBang in {}", installPath);
installDir = installPath.resolve(homePath);
return;
}

LOG.info("Downloading JBang from " + JBangSettings.getJBangDownloadUrl() + " and installing in " + installPath);
LOG.info("Downloading JBang from {} and installing in {}", JBangSettings.getJBangDownloadUrl(), installPath);

try {
Files.createDirectories(installPath);
Expand Down Expand Up @@ -432,7 +432,7 @@ private static ProcessAndOutput execute(List<String> command, Path workingDir,
}

if (LOG.isDebugEnabled() && p.exitValue() != OK_EXIT_CODE) {
LOG.debug("Command failed: " + String.join(" ", command));
LOG.debug("Command failed: {}", String.join(" ", command));
LOG.debug(output);
}

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

package org.citrusframework.jbang;

import org.awaitility.core.ConditionTimeoutException;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
Expand All @@ -26,11 +31,6 @@
import java.util.List;
import java.util.stream.Collectors;

import org.awaitility.core.ConditionTimeoutException;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Process wrapper also holds the output that has been produced by the completed process.
*/
Expand Down Expand Up @@ -182,7 +182,7 @@ public List<Long> getDescendants() {
return process.descendants()
.peek(p -> {
if (LOG.isDebugEnabled()) {
LOG.info(String.format("Found descendant process (pid:%d) for process '%d'", p.pid(), getProcessId()));
LOG.info("Found descendant process (pid:{}) for process '{}'", p.pid(), getProcessId());
}
})
.map(ProcessHandle::pid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@

package org.citrusframework.jbang.engine;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.citrusframework.CitrusSettings;
import org.citrusframework.TestSource;
import org.citrusframework.exceptions.CitrusRuntimeException;
Expand All @@ -39,6 +28,17 @@
import org.citrusframework.util.FileUtils;
import org.citrusframework.util.StringUtils;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* Test engine implementation runs tests via Citrus JBang as a separate JVM process.
*/
Expand Down Expand Up @@ -90,10 +90,9 @@ private void runTestPackages(CitrusJBang citrus, TestRunConfiguration configurat

for (String packageName : packagesToRun) {
if (StringUtils.hasText(packageName)) {
logger.info(String.format("Running tests in directory %s", packageName));
logger.info("Running tests in directory {}", packageName);
} else {
logger.info(String.format("Running tests in current working directory %s",
Optional.ofNullable(workingDir).map(Path::toString).orElse(".")));
logger.info("Running tests in current working directory {}", Optional.ofNullable(workingDir).map(Path::toString).orElse("."));
}

citrus.run(packageName, Collections.emptyMap());
Expand All @@ -106,7 +105,7 @@ private void runTestSources(CitrusJBang citrus, TestRunConfiguration configurati
.toList();

for (TestSource directory : directories) {
logger.info(String.format("Running tests in directory %s", directory.getName()));
logger.info("Running tests in directory {}", directory.getName());
citrus.run(directory.getFilePath(), Collections.emptyMap());
}

Expand All @@ -116,7 +115,7 @@ private void runTestSources(CitrusJBang citrus, TestRunConfiguration configurati

for (TestSource source : sources) {
try {
logger.info(String.format("Running test source %s", source.getName()));
logger.info("Running test source {}", source.getName());

if (source.getSourceFile() instanceof Resources.ByteArrayResource) {
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
Expand Down
Loading
Loading