Skip to content

Commit

Permalink
Fixed #48 and fixed #28
Browse files Browse the repository at this point in the history
  • Loading branch information
dubinka committed Dec 27, 2017
1 parent e556920 commit 90da059
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import java.util.List;

/**
* Represents a command for docker container.
* Represents a command for docker tool.
*
* @author Yurii Dubinka (yurii.dubinka@gmail.com)
* @version $Id$
* @since 0.1.0
*/
public interface DockerContainerCommand {
public interface DockerCommand {

/**
* It may create a new container or reuse existing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
package org.dgroup.dockertest.docker;

/**
* Represents single docker container.
* Container will be removed after cmd execution.
* Represents single docker process.
* It might be creation of new container, pull command, etc.
*
* @author Yurii Dubinka (yurii.dubinka@gmail.com)
* @version $Id$
* @since 0.1.0
* @todo #48 Rename to DockerProcess as it's more clear description.
*/
public interface DockerContainer {
public interface DockerProcess {

/**
* Execute command inside of docker container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
package org.dgroup.dockertest.docker;

/**
* Represents an instance of docker container.
* Represents an instance of docker process on Unix-related systems.
*
* @author Yurii Dubinka (yurii.dubinka@gmail.com)
* @version $Id$
* @since 0.1.0
*/
public final class DefaultDockerContainer implements DockerContainer {
public final class DockerProcessOnUnix implements DockerProcess {

/**
* System process associated with docker container.
Expand All @@ -41,15 +41,15 @@ public final class DefaultDockerContainer implements DockerContainer {
* Ctor.
* @param cmd Docker container command.
*/
public DefaultDockerContainer(final DockerContainerCommand cmd) {
public DockerProcessOnUnix(final DockerCommand cmd) {
this(new SystemProcess(cmd.args()));
}

/**
* Ctor.
* @param process System process associated with docker container.
*/
public DefaultDockerContainer(final SystemProcess process) {
public DockerProcessOnUnix(final SystemProcess process) {
this.process = process;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* @since 0.1.0
*/
public final class StatelessDockerContainerCommand
implements DockerContainerCommand {
implements DockerCommand {

/**
* Docker container commands.
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/dgroup/dockertest/test/BasedOnYmlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
package org.dgroup.dockertest.test;

import org.dgroup.dockertest.cmd.Arg;
import org.dgroup.dockertest.docker.DefaultDockerContainer;
import org.dgroup.dockertest.docker.DockerContainer;
import org.dgroup.dockertest.docker.DockerProcess;
import org.dgroup.dockertest.docker.DockerProcessOnUnix;
import org.dgroup.dockertest.docker.StatelessDockerContainerCommand;
import org.dgroup.dockertest.yml.tag.YmlTagTest;

Expand All @@ -45,7 +45,7 @@ public final class BasedOnYmlTest implements Test {
/**
* Docker container where we need to execute the test.
*/
private final DockerContainer container;
private final DockerProcess container;

/**
* Ctor.
Expand All @@ -55,7 +55,7 @@ public final class BasedOnYmlTest implements Test {
public BasedOnYmlTest(final Arg image, final YmlTagTest test) {
this(
test,
new DefaultDockerContainer(
new DockerProcessOnUnix(
new StatelessDockerContainerCommand(
image.value(), test.dockerCmdAsArray()
)
Expand All @@ -69,7 +69,7 @@ public BasedOnYmlTest(final Arg image, final YmlTagTest test) {
* @param container Docker container where test be executed.
*/
public BasedOnYmlTest(final YmlTagTest test,
final DockerContainer container) {
final DockerProcess container) {
this.test = test;
this.container = container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,35 @@
*/
package org.dgroup.dockertest.docker;

import java.util.List;
import org.cactoos.list.Joined;
import org.cactoos.list.ListOf;
import org.dgroup.dockertest.RunOnlyOnUnix;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Represents Windows OS as docker container for unit testing.
* Unit tests for class {@link CmdOutputAsText} on Unix OS.
*
* @author Yurii Dubinka (yurii.dubinka@gmail.com)
* @version $Id$
* @since 0.1.0
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle MagicNumberCheck (500 lines)
*/
public final class WindowsOsAsDockerContainer implements DockerContainer {
@RunWith(RunOnlyOnUnix.class)
public final class CmdOutputAsTextOnUnixTest {

/**
* Commands for docker container.
*/
private final List<String> commands;

/**
* Ctor.
* @param commands Command for docker container.
*/
public WindowsOsAsDockerContainer(final List<String> commands) {
this.commands = new Joined<>(
new ListOf<>("cmd", "/c"),
commands
);
}

@Override
public CmdOutput run() {
return new CmdOutputAsText(
new SystemProcess(this.commands).execute()
@Test(timeout = 1000 * 3)
public void text() {
MatcherAssert.assertThat(
"Command `java -version` is `1.8`.",
new CmdOutputAsText(
new SystemProcess(
new ListOf<>("java", "-version")
).execute()
).asText(),
Matchers.containsString("1.8")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@
* @since 0.1.0
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle MagicNumberCheck (500 lines)
* @todo #20:50min Add the same test for Linux OS
*/
@RunWith(RunOnlyOnWindows.class)
public class CmdOutputAsTextOnWindowsTest {
public final class CmdOutputAsTextOnWindowsTest {

@Test(timeout = 1000 * 3)
public final void text() {
public void text() {
MatcherAssert.assertThat(
"Command `java -version` will have `1.8` version",
new CmdOutputAsText(
Expand Down

1 comment on commit 90da059

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 90da059 Dec 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 20-0f8fda7a disappeared from src/test/java/org/dgroup/dockertest/docker/CmdOutputAsTextOnWindowsTest.java, that's why I closed #28. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.