Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deprecated code to recommended strategy #6078

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,25 @@
*/
package org.springframework.cloud.dataflow.common.test.docker.compose.configuration;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.HashMap;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.cloud.dataflow.common.test.docker.compose.configuration.AdditionalEnvironmentValidator;

public class AdditionalEnvironmentValidatorTests {
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;

@Rule
public ExpectedException exception = ExpectedException.none();
public class AdditionalEnvironmentValidatorTests {

@Test
public void throw_exception_when_additional_environment_variables_contain_docker_variables() {
public void throwExceptionWhenAdditionalEnvironmentVariablesContainDockerVariables() {
Map<String, String> variables = new HashMap<>();
variables.put("DOCKER_HOST", "tcp://some-host:2376");
variables.put("SOME_VARIABLE", "Some Value");
exception.expect(IllegalStateException.class);
exception.expectMessage("The following variables");
exception.expectMessage("DOCKER_HOST");
exception.expectMessage("cannot exist in your additional environment");
AdditionalEnvironmentValidator.validate(variables);

assertThatIllegalStateException().isThrownBy(() ->AdditionalEnvironmentValidator.validate(variables)).
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice improvement @cppwfs - thanks.

withMessageContaining("The following variables").
withMessageContaining("DOCKER_HOST").
withMessageContaining("cannot exist in your additional environment");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,17 @@
*/
package org.springframework.cloud.dataflow.common.test.docker.compose.configuration;

import static org.springframework.cloud.dataflow.common.test.docker.compose.configuration.EnvironmentVariables.DOCKER_CERT_PATH;
import static org.springframework.cloud.dataflow.common.test.docker.compose.configuration.EnvironmentVariables.DOCKER_HOST;
import static org.springframework.cloud.dataflow.common.test.docker.compose.configuration.EnvironmentVariables.DOCKER_TLS_VERIFY;

import java.util.HashMap;
import java.util.Map;
import org.junit.Rule;

import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.cloud.dataflow.common.test.docker.compose.configuration.DaemonEnvironmentValidator;

public class DaemonEnvironmentValidatorTests {
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.springframework.cloud.dataflow.common.test.docker.compose.configuration.EnvironmentVariables.DOCKER_CERT_PATH;
import static org.springframework.cloud.dataflow.common.test.docker.compose.configuration.EnvironmentVariables.DOCKER_HOST;
import static org.springframework.cloud.dataflow.common.test.docker.compose.configuration.EnvironmentVariables.DOCKER_TLS_VERIFY;

@Rule
public ExpectedException exception = ExpectedException.none();
public class DaemonEnvironmentValidatorTests {

@Test
public void validate_successfully_when_docker_environment_does_not_contain_docker_variables() {
Expand All @@ -47,13 +43,9 @@ public void throw_exception_when_docker_environment_contains_illegal_docker_vari
variables.put(DOCKER_TLS_VERIFY, "1");
variables.put(DOCKER_CERT_PATH, "/path/to/certs");

exception.expect(IllegalStateException.class);
exception.expectMessage("These variables were set:");
exception.expectMessage(DOCKER_HOST);
exception.expectMessage(DOCKER_CERT_PATH);
exception.expectMessage(DOCKER_TLS_VERIFY);
exception.expectMessage("They cannot be set when connecting to a local docker daemon");
DaemonEnvironmentValidator.instance().validateEnvironmentVariables(variables);
assertThatIllegalStateException().isThrownBy( () -> DaemonEnvironmentValidator.instance().validateEnvironmentVariables(variables)).
withMessageContaining(DOCKER_HOST).withMessageContaining(DOCKER_CERT_PATH).withMessageContaining(DOCKER_TLS_VERIFY).
withMessageContaining("They cannot be set when connecting to a local docker daemon");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,29 @@
import org.assertj.core.api.Condition;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class DockerComposeFilesTests {

@Rule
public final TemporaryFolder tempFolder = new TemporaryFolder();

@Rule
public final ExpectedException exception = ExpectedException.none();

@Test
public void throw_exception_when_compose_file_is_not_specified() {
exception.expect(IllegalStateException.class);
exception.expectMessage("A docker compose file must be specified.");
DockerComposeFiles.from();
assertThatIllegalStateException().isThrownBy(DockerComposeFiles::from).
withMessageContaining("A docker compose file must be specified.");
}

@Test
public void throw_exception_when_compose_file_does_not_exist() {
exception.expect(IllegalStateException.class);
exception.expectMessage("The following docker-compose files:");
exception.expectMessage("does-not-exist.yaml");
exception.expectMessage("do not exist.");
DockerComposeFiles.from("does-not-exist.yaml");
assertThatIllegalStateException().isThrownBy(() -> DockerComposeFiles.from("does-not-exist.yaml")).
withMessageContaining("The following docker-compose files:").withMessageContaining("does-not-exist.yaml").
withMessageContaining("do not exist.");
}

@Test
Expand Down Expand Up @@ -98,9 +93,8 @@ public void testFromClasspathExist() {

@Test
public void testFromClasspathDoesNotExist() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("Can't find resource classpath:does-not-exist.yaml");
DockerComposeFiles.from("classpath:does-not-exist.yaml");
assertThatIllegalArgumentException().isThrownBy(() -> DockerComposeFiles.from("classpath:does-not-exist.yaml")).
withMessageContaining("Can't find resource classpath:does-not-exist.yaml");
}

private static Condition<String> is(String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@

import java.util.List;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;

public class ProjectNameTests {

@Rule
public final ExpectedException exception = ExpectedException.none();

@Test
public void use_project_name_prefix_in_construct_compose_command() {
List<String> command = ProjectName.random().constructComposeFileCommand();
Expand Down Expand Up @@ -64,16 +60,14 @@ public void should_disallow_names_in_from_string_factory() {

@Test
public void reject_blanks_in_from_string() {
exception.expect(IllegalStateException.class);
exception.expectMessage("ProjectName must not be blank.");
ProjectName.fromString(" ");
assertThatIllegalStateException().isThrownBy(() -> ProjectName.fromString(" ")).
withMessageContaining("ProjectName must not be blank.");
}

@Test
public void match_validation_behavior_of_docker_compose_cli() {
exception.expect(IllegalStateException.class);
exception.expectMessage("ProjectName 'Crazy#Proj ect!Name' not allowed, please use lowercase letters and numbers only.");
ProjectName.fromString("Crazy#Proj ect!Name");
assertThatIllegalStateException().isThrownBy(() -> ProjectName.fromString("Crazy#Proj ect!Name")).
withMessageContaining("ProjectName 'Crazy#Proj ect!Name' not allowed, please use lowercase letters and numbers only.");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,27 @@
*/
package org.springframework.cloud.dataflow.common.test.docker.compose.configuration;

import static org.springframework.cloud.dataflow.common.test.docker.compose.configuration.EnvironmentVariables.DOCKER_CERT_PATH;
import static org.springframework.cloud.dataflow.common.test.docker.compose.configuration.EnvironmentVariables.DOCKER_HOST;
import static org.springframework.cloud.dataflow.common.test.docker.compose.configuration.EnvironmentVariables.DOCKER_TLS_VERIFY;

import java.util.HashMap;
import java.util.Map;
import org.junit.Rule;

import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.cloud.dataflow.common.test.docker.compose.configuration.RemoteEnvironmentValidator;

public class RemoteEnvironmentValidatorTests {
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.springframework.cloud.dataflow.common.test.docker.compose.configuration.EnvironmentVariables.DOCKER_CERT_PATH;
import static org.springframework.cloud.dataflow.common.test.docker.compose.configuration.EnvironmentVariables.DOCKER_HOST;
import static org.springframework.cloud.dataflow.common.test.docker.compose.configuration.EnvironmentVariables.DOCKER_TLS_VERIFY;

@Rule
public ExpectedException exception = ExpectedException.none();
public class RemoteEnvironmentValidatorTests {

@Test
public void throw_exception_if_docker_host_is_not_set() {
Map<String, String> variables = new HashMap<>();
variables.put("SOME_VARIABLE", "SOME_VALUE");

exception.expect(IllegalStateException.class);
exception.expectMessage("Missing required environment variables: ");
exception.expectMessage(DOCKER_HOST);
RemoteEnvironmentValidator.instance().validateEnvironmentVariables(variables);
assertThatIllegalStateException().isThrownBy(() -> RemoteEnvironmentValidator.instance().
validateEnvironmentVariables(variables)).
withMessageContaining("Missing required environment variables: ").
withMessageContaining(DOCKER_HOST);
}

@Test
Expand All @@ -48,10 +44,10 @@ public void throw_exception_if_docker_cert_path_is_missing_and_tls_is_on() {
variables.put(DOCKER_HOST, "tcp://192.168.99.100:2376");
variables.put(DOCKER_TLS_VERIFY, "1");

exception.expect(IllegalStateException.class);
exception.expectMessage("Missing required environment variables: ");
exception.expectMessage(DOCKER_CERT_PATH);
RemoteEnvironmentValidator.instance().validateEnvironmentVariables(variables);
assertThatIllegalStateException().isThrownBy(() -> RemoteEnvironmentValidator.instance().
validateEnvironmentVariables(variables)).
withMessageContaining("Missing required environment variables: ").
withMessageContaining(DOCKER_CERT_PATH);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,27 @@
*/
package org.springframework.cloud.dataflow.common.test.docker.compose.configuration;

import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.springframework.cloud.dataflow.common.test.docker.compose.configuration.EnvironmentVariables.TCP_PROTOCOL;

import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.cloud.dataflow.common.test.docker.compose.configuration.RemoteHostIpResolver;

public class RemoteHostIpResolverTests {

private static final String IP = "192.168.99.100";
private static final int PORT = 2376;

@Rule
public ExpectedException exception = ExpectedException.none();

@Test
public void result_in_error_blank_when_resolving_invalid_docker_host() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("DOCKER_HOST cannot be blank/null");
new RemoteHostIpResolver().resolveIp("");
assertThatIllegalArgumentException().isThrownBy(() ->new RemoteHostIpResolver().resolveIp("")).
withMessageContaining("DOCKER_HOST cannot be blank/null");
}

@Test
public void result_in_error_null_when_resolving_invalid_docker_host() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("DOCKER_HOST cannot be blank/null");
new RemoteHostIpResolver().resolveIp(null);
assertThatIllegalArgumentException().isThrownBy(() -> new RemoteHostIpResolver().resolveIp(null)).
withMessageContaining("DOCKER_HOST cannot be blank/null");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@

import java.io.IOException;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import org.springframework.cloud.dataflow.common.test.docker.compose.configuration.MockDockerEnvironment;
import org.springframework.cloud.dataflow.common.test.docker.compose.execution.Docker;
import org.springframework.cloud.dataflow.common.test.docker.compose.execution.DockerCompose;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
Expand All @@ -41,9 +39,6 @@ public class ContainerTests {

private static final String IP = "127.0.0.1";

@Rule
public ExpectedException exception = ExpectedException.none();

private final Docker docker = mock(Docker.class);
private final DockerCompose dockerCompose = mock(DockerCompose.class);
private final MockDockerEnvironment env = new MockDockerEnvironment(dockerCompose);
Expand Down Expand Up @@ -94,18 +89,16 @@ public void throw_illegal_argument_exception_when_a_port_for_an_unknown_external
throws Exception {
// Service must have ports otherwise we end up with an exception telling you the service is listening at all
env.availableService("service", IP, 5400, 5400);
exception.expect(IllegalArgumentException.class);
exception.expectMessage("No port mapped externally to '5432' for container 'service'");
container.portMappedExternallyTo(5432);
assertThatIllegalArgumentException().isThrownBy(() -> container.portMappedExternallyTo(5432)).
withMessageContaining("No port mapped externally to '5432' for container 'service'");
}

@Test
public void throw_illegal_argument_exception_when_a_port_for_an_unknown_internal_port_is_requested()
throws Exception {
env.availableService("service", IP, 5400, 5400);
exception.expect(IllegalArgumentException.class);
exception.expectMessage("No internal port '5432' for container 'service'");
container.port(5432);
assertThatIllegalArgumentException().isThrownBy(() -> container.port(5432)).
withMessageContaining("No internal port '5432' for container 'service'");
}

@Test
Expand Down
Loading
Loading