Home / Class/ DockerEngineExceptionTests Class — spring-boot Architecture

DockerEngineExceptionTests Class — spring-boot Architecture

Architecture documentation for the DockerEngineExceptionTests class in DockerEngineExceptionTests.java from the spring-boot codebase.

Entity Profile

Source Code

buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/DockerEngineExceptionTests.java lines 35–140

class DockerEngineExceptionTests {

	private static final String HOST = "docker://localhost/";

	private static final URI URI;
	static {
		try {
			URI = new URI("example");
		}
		catch (URISyntaxException ex) {
			throw new IllegalStateException(ex);
		}
	}

	private static final Errors NO_ERRORS = new Errors(Collections.emptyList());

	private static final Errors ERRORS = new Errors(Collections.singletonList(new Errors.Error("code", "message")));

	private static final Message NO_MESSAGE = new Message(null);

	private static final Message MESSAGE = new Message("response message");

	@Test
	@SuppressWarnings("NullAway") // Test null check
	void createWhenHostIsNullThrowsException() {
		assertThatIllegalArgumentException()
			.isThrownBy(() -> new DockerEngineException(null, null, 404, null, NO_ERRORS, NO_MESSAGE, null))
			.withMessage("'host' must not be null");
	}

	@Test
	@SuppressWarnings("NullAway") // Test null check
	void createWhenUriIsNullThrowsException() {
		assertThatIllegalArgumentException()
			.isThrownBy(() -> new DockerEngineException(HOST, null, 404, null, NO_ERRORS, NO_MESSAGE, null))
			.withMessage("'uri' must not be null");
	}

	@Test
	void create() {
		DockerEngineException exception = new DockerEngineException(HOST, URI, 404, "missing", ERRORS, MESSAGE, null);
		assertThat(exception.getMessage()).isEqualTo(
				"Docker API call to 'docker://localhost/example' failed with status code 404 \"missing\" and message \"response message\" [code: message]");
		assertThat(exception.getStatusCode()).isEqualTo(404);
		assertThat(exception.getReasonPhrase()).isEqualTo("missing");
		assertThat(exception.getErrors()).isSameAs(ERRORS);
		assertThat(exception.getResponseMessage()).isSameAs(MESSAGE);
	}

	@Test
	void createWhenReasonPhraseIsNull() {
		DockerEngineException exception = new DockerEngineException(HOST, URI, 404, null, ERRORS, MESSAGE, null);
		assertThat(exception.getMessage()).isEqualTo(
				"Docker API call to 'docker://localhost/example' failed with status code 404 and message \"response message\" [code: message]");
		assertThat(exception.getStatusCode()).isEqualTo(404);
		assertThat(exception.getReasonPhrase()).isNull();
		assertThat(exception.getErrors()).isSameAs(ERRORS);
		assertThat(exception.getResponseMessage()).isSameAs(MESSAGE);
	}

	@Test
	void createWhenErrorsIsNull() {
		DockerEngineException exception = new DockerEngineException(HOST, URI, 404, "missing", null, MESSAGE, null);
		assertThat(exception.getMessage()).isEqualTo(
				"Docker API call to 'docker://localhost/example' failed with status code 404 \"missing\" and message \"response message\"");
		assertThat(exception.getErrors()).isNull();
	}

	@Test
	void createWhenErrorsIsEmpty() {
		DockerEngineException exception = new DockerEngineException(HOST, URI, 404, "missing", NO_ERRORS, MESSAGE,
				null);
		assertThat(exception.getMessage()).isEqualTo(
				"Docker API call to 'docker://localhost/example' failed with status code 404 \"missing\" and message \"response message\"");
		assertThat(exception.getStatusCode()).isEqualTo(404);
		assertThat(exception.getReasonPhrase()).isEqualTo("missing");
		assertThat(exception.getErrors()).isSameAs(NO_ERRORS);
	}

	@Test
	void createWhenMessageIsNull() {
		DockerEngineException exception = new DockerEngineException(HOST, URI, 404, "missing", ERRORS, null, null);
		assertThat(exception.getMessage()).isEqualTo(
				"Docker API call to 'docker://localhost/example' failed with status code 404 \"missing\" [code: message]");
		assertThat(exception.getResponseMessage()).isNull();
	}

	@Test
	void createWhenMessageIsEmpty() {
		DockerEngineException exception = new DockerEngineException(HOST, URI, 404, "missing", ERRORS, NO_MESSAGE,
				null);
		assertThat(exception.getMessage()).isEqualTo(
				"Docker API call to 'docker://localhost/example' failed with status code 404 \"missing\" [code: message]");
		assertThat(exception.getResponseMessage()).isSameAs(NO_MESSAGE);
	}

	@Test
	void createWhenProxyAuthFailureWithTextContent() {
		DockerEngineException exception = new DockerEngineException(HOST, URI, 407, "Proxy Authentication Required",
				null, null, "Badness".getBytes(StandardCharsets.UTF_8));
		assertThat(exception.getMessage())
			.isEqualTo("Docker API call to 'docker://localhost/example' failed with status code 407 "
					+ "\"Proxy Authentication Required\" and content \"Badness\"");
	}

}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free