CustomLayersProviderTests Class — spring-boot Architecture
Architecture documentation for the CustomLayersProviderTests class in CustomLayersProviderTests.java from the spring-boot codebase.
Entity Profile
Source Code
build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/CustomLayersProviderTests.java lines 44–107
class CustomLayersProviderTests {
private CustomLayersProvider customLayersProvider;
@BeforeEach
void setup() {
this.customLayersProvider = new CustomLayersProvider();
}
@Test
void getLayerResolverWhenDocumentValid() throws Exception {
CustomLayers layers = this.customLayersProvider.getLayers(getDocument("layers.xml"));
assertThat(layers).extracting("name")
.containsExactly("my-deps", "my-dependencies-name", "snapshot-dependencies", "my-resources",
"configuration", "application");
Library snapshot = mockLibrary("test-SNAPSHOT.jar", "org.foo", "1.0.0-SNAPSHOT");
Library groupId = mockLibrary("my-library", "com.acme", null);
Library otherDependency = mockLibrary("other-library", "org.foo", null);
Library localSnapshotDependency = mockLibrary("local-library", "org.foo", "1.0-SNAPSHOT");
given(localSnapshotDependency.isLocal()).willReturn(true);
assertThat(layers.getLayer(snapshot)).hasToString("snapshot-dependencies");
assertThat(layers.getLayer(groupId)).hasToString("my-deps");
assertThat(layers.getLayer(otherDependency)).hasToString("my-dependencies-name");
assertThat(layers.getLayer(localSnapshotDependency)).hasToString("application");
assertThat(layers.getLayer("META-INF/resources/test.css")).hasToString("my-resources");
assertThat(layers.getLayer("application.yml")).hasToString("configuration");
assertThat(layers.getLayer("test")).hasToString("application");
}
private Library mockLibrary(String name, String groupId, @Nullable String version) {
Library library = mock(Library.class);
given(library.getName()).willReturn(name);
given(library.getCoordinates()).willReturn(LibraryCoordinates.of(groupId, null, version));
return library;
}
@Test
void getLayerResolverWhenDocumentContainsLibraryLayerWithNoFilters() throws Exception {
CustomLayers layers = this.customLayersProvider.getLayers(getDocument("dependencies-layer-no-filter.xml"));
Library library = mockLibrary("my-library", "com.acme", null);
assertThat(layers.getLayer(library)).hasToString("my-deps");
assertThatIllegalStateException().isThrownBy(() -> layers.getLayer("application.yml"))
.withMessageContaining("match any layer");
}
@Test
void getLayerResolverWhenDocumentContainsResourceLayerWithNoFilters() throws Exception {
CustomLayers layers = this.customLayersProvider.getLayers(getDocument("application-layer-no-filter.xml"));
Library library = mockLibrary("my-library", "com.acme", null);
assertThat(layers.getLayer("application.yml")).hasToString("my-layer");
assertThatIllegalStateException().isThrownBy(() -> layers.getLayer(library))
.withMessageContaining("match any layer");
}
private Document getDocument(String resourceName) throws Exception {
ClassPathResource resource = new ClassPathResource(resourceName);
InputSource inputSource = new InputSource(resource.getInputStream());
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder documentBuilder = factory.newDocumentBuilder();
return documentBuilder.parse(inputSource);
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free