Home / Class/ GraylogExtendedLogFormatPropertiesTests Class — spring-boot Architecture

GraylogExtendedLogFormatPropertiesTests Class — spring-boot Architecture

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

Entity Profile

Relationship Graph

Source Code

core/spring-boot/src/test/java/org/springframework/boot/logging/structured/GraylogExtendedLogFormatPropertiesTests.java lines 38–127

class GraylogExtendedLogFormatPropertiesTests {

	@Test
	void getBindsFromEnvironment() {
		MockEnvironment environment = new MockEnvironment();
		environment.setProperty("logging.structured.gelf.host", "spring");
		environment.setProperty("logging.structured.gelf.service.version", "1.2.3");
		GraylogExtendedLogFormatProperties properties = GraylogExtendedLogFormatProperties.get(environment);
		assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service("1.2.3")));
	}

	@Test
	void getBindsFromEnvironmentWhenHostIsPresentAndServiceIsMissing() {
		MockEnvironment environment = new MockEnvironment();
		environment.setProperty("logging.structured.gelf.host", "spring");
		GraylogExtendedLogFormatProperties properties = GraylogExtendedLogFormatProperties.get(environment);
		assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service(null)));
	}

	@Test
	void getBindsFromEnvironmentWhenHostIsPresentAndServiceIsMissingUsesApplicationVersion() {
		MockEnvironment environment = new MockEnvironment();
		environment.setProperty("logging.structured.gelf.host", "spring");
		environment.setProperty("spring.application.version", "1.2.3");
		GraylogExtendedLogFormatProperties properties = GraylogExtendedLogFormatProperties.get(environment);
		assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service("1.2.3")));
	}

	@Test
	void getBindsFromEnvironmentWhenVersionIsPresentAndHostIsMissingUsesApplicationName() {
		MockEnvironment environment = new MockEnvironment();
		environment.setProperty("spring.application.name", "spring");
		environment.setProperty("logging.structured.gelf.service.version", "1.2.3");
		GraylogExtendedLogFormatProperties properties = GraylogExtendedLogFormatProperties.get(environment);
		assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service("1.2.3")));
	}

	@Test
	void getWhenNoServiceNameUsesApplicationName() {
		MockEnvironment environment = new MockEnvironment();
		environment.setProperty("spring.application.name", "spring");
		GraylogExtendedLogFormatProperties properties = GraylogExtendedLogFormatProperties.get(environment);
		assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service(null)));
	}

	@Test
	void getWhenNoServiceVersionUsesApplicationVersion() {
		MockEnvironment environment = new MockEnvironment();
		environment.setProperty("spring.application.version", "1.2.3");
		GraylogExtendedLogFormatProperties properties = GraylogExtendedLogFormatProperties.get(environment);
		assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties(null, new Service("1.2.3")));
	}

	@Test
	void getWhenNoPropertiesToBind() {
		MockEnvironment environment = new MockEnvironment();
		GraylogExtendedLogFormatProperties properties = GraylogExtendedLogFormatProperties.get(environment);
		assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties(null, new Service(null)));
	}

	@Test
	void addToJsonMembersCreatesValidJson() {
		GraylogExtendedLogFormatProperties properties = new GraylogExtendedLogFormatProperties("spring",
				new Service("1.2.3"));
		JsonWriter<GraylogExtendedLogFormatProperties> writer = JsonWriter.of(properties::jsonMembers);
		assertThat(writer.writeToString(properties)).isEqualTo("{\"host\":\"spring\",\"_service_version\":\"1.2.3\"}");
	}

	@Test
	void shouldRegisterRuntimeHints() throws Exception {
		RuntimeHints hints = new RuntimeHints();
		new GraylogExtendedLogFormatPropertiesRuntimeHints().registerHints(hints, getClass().getClassLoader());
		assertThat(RuntimeHintsPredicates.reflection().onType(GraylogExtendedLogFormatProperties.class)).accepts(hints);
		assertThat(RuntimeHintsPredicates.reflection()
			.onConstructorInvocation(
					GraylogExtendedLogFormatProperties.class.getConstructor(String.class, Service.class)))
			.accepts(hints);
		assertThat(RuntimeHintsPredicates.reflection().onType(Service.class)).accepts(hints);
		assertThat(RuntimeHintsPredicates.reflection()
			.onConstructorInvocation(GraylogExtendedLogFormatProperties.Service.class.getConstructor(String.class)))
			.accepts(hints);
	}

	@Test
	void graylogExtendedLogFormatPropertiesRuntimeHintsIsRegistered() {
		assertThat(AotServices.factories().load(RuntimeHintsRegistrar.class))
			.anyMatch(GraylogExtendedLogFormatPropertiesRuntimeHints.class::isInstance);
	}

}

Domain

Analyze Your Own Codebase

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

Try Supermodel Free