|
|
@ -16,10 +16,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.jarmode.layertools;
|
|
|
|
package org.springframework.boot.jarmode.layertools;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
|
|
|
import org.springframework.util.FileCopyUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|
|
|
import static org.mockito.BDDMockito.given;
|
|
|
|
import static org.mockito.BDDMockito.given;
|
|
|
@ -29,6 +33,7 @@ import static org.mockito.Mockito.mock;
|
|
|
|
* Tests for {@link IndexedLayers}.
|
|
|
|
* Tests for {@link IndexedLayers}.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Phillip Webb
|
|
|
|
* @author Phillip Webb
|
|
|
|
|
|
|
|
* @author Madhura Bhave
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class IndexedLayersTests {
|
|
|
|
class IndexedLayersTests {
|
|
|
|
|
|
|
|
|
|
|
@ -39,41 +44,35 @@ class IndexedLayersTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void createWhenIndexFileHasNoApplicationLayerAddSpringBootApplication() {
|
|
|
|
void createWhenIndexFileIsMalformedThrowsException() throws Exception {
|
|
|
|
IndexedLayers layers = new IndexedLayers("test");
|
|
|
|
assertThatIllegalStateException().isThrownBy(() -> new IndexedLayers("test"))
|
|
|
|
assertThat(layers).contains("springbootapplication");
|
|
|
|
.withMessage("Layer index file is malformed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void iteratorReturnsLayers() {
|
|
|
|
void iteratorReturnsLayers() throws Exception {
|
|
|
|
IndexedLayers layers = new IndexedLayers("test\napplication");
|
|
|
|
IndexedLayers layers = new IndexedLayers(getIndex());
|
|
|
|
assertThat(layers).containsExactly("test", "application");
|
|
|
|
assertThat(layers).containsExactly("test", "application");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void getLayerWhenMatchesLayerPatterReturnsLayer() {
|
|
|
|
void getLayerWhenMatchesNameReturnsLayer() throws Exception {
|
|
|
|
IndexedLayers layers = new IndexedLayers("test");
|
|
|
|
IndexedLayers layers = new IndexedLayers(getIndex());
|
|
|
|
assertThat(layers.getLayer(mockEntry("BOOT-INF/layers/test/lib/file.jar"))).isEqualTo("test");
|
|
|
|
assertThat(layers.getLayer(mockEntry("BOOT-INF/lib/a.jar"))).isEqualTo("test");
|
|
|
|
|
|
|
|
assertThat(layers.getLayer(mockEntry("BOOT-INF/classes/Demo.class"))).isEqualTo("application");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void getLayerWhenMatchesLayerPatterForMissingLayerThrowsException() {
|
|
|
|
void getLayerWhenMatchesNameForMissingLayerThrowsException() throws Exception {
|
|
|
|
IndexedLayers layers = new IndexedLayers("test");
|
|
|
|
IndexedLayers layers = new IndexedLayers(getIndex());
|
|
|
|
assertThatIllegalStateException()
|
|
|
|
assertThatIllegalStateException().isThrownBy(() -> layers.getLayer(mockEntry("file.jar")))
|
|
|
|
.isThrownBy(() -> layers.getLayer(mockEntry("BOOT-INF/layers/missing/lib/file.jar")))
|
|
|
|
.withMessage("No layer defined in index for file " + "'file.jar'");
|
|
|
|
.withMessage("Unexpected layer 'missing'");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
private String getIndex() throws Exception {
|
|
|
|
void getLayerWhenDoesNotMatchLayerPatternReturnsApplication() {
|
|
|
|
ClassPathResource resource = new ClassPathResource("test-layers.idx", getClass());
|
|
|
|
IndexedLayers layers = new IndexedLayers("test\napplication");
|
|
|
|
InputStreamReader reader = new InputStreamReader(resource.getInputStream());
|
|
|
|
assertThat(layers.getLayer(mockEntry("META-INF/MANIFEST.MF"))).isEqualTo("application");
|
|
|
|
return FileCopyUtils.copyToString(reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void getLayerWhenDoesNotMatchLayerPatternAndHasNoApplicationLayerReturnsSpringApplication() {
|
|
|
|
|
|
|
|
IndexedLayers layers = new IndexedLayers("test");
|
|
|
|
|
|
|
|
assertThat(layers.getLayer(mockEntry("META-INF/MANIFEST.MF"))).isEqualTo("springbootapplication");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ZipEntry mockEntry(String name) {
|
|
|
|
private ZipEntry mockEntry(String name) {
|
|
|
|