Update tests following code changes
See gh-22821
This commit is contained in:
@@ -39,7 +39,7 @@ class ContextTests {
|
||||
@Test
|
||||
void createWhenSourceIsNullThrowsException() {
|
||||
assertThatIllegalStateException().isThrownBy(() -> new Context(null, this.temp))
|
||||
.withMessage("Unable to find source JAR");
|
||||
.withMessage("Unable to find source archive");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -47,7 +47,15 @@ class ContextTests {
|
||||
File directory = new File(this.temp, "test");
|
||||
directory.mkdir();
|
||||
assertThatIllegalStateException().isThrownBy(() -> new Context(directory, this.temp))
|
||||
.withMessage("Unable to find source JAR");
|
||||
.withMessage("Unable to find source archive");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWhenSourceIsNotJarOrWarThrowsException() throws Exception {
|
||||
File zip = new File(this.temp, "test.zip");
|
||||
Files.createFile(zip.toPath());
|
||||
assertThatIllegalStateException().isThrownBy(() -> new Context(zip, this.temp))
|
||||
.withMessage("Unable to find source archive");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -20,9 +20,11 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@@ -33,6 +35,9 @@ import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
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.assertThatIllegalStateException;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -114,7 +119,7 @@ class ExtractCommandTests {
|
||||
.withMessageContaining("not compatible with layertools");
|
||||
}
|
||||
|
||||
private File createJarFile(String name) throws IOException {
|
||||
private File createJarFile(String name) throws Exception {
|
||||
File file = new File(this.temp, name);
|
||||
try (ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file))) {
|
||||
out.putNextEntry(new ZipEntry("a/"));
|
||||
@@ -131,10 +136,19 @@ class ExtractCommandTests {
|
||||
out.closeEntry();
|
||||
out.putNextEntry(new ZipEntry("d/"));
|
||||
out.closeEntry();
|
||||
out.putNextEntry(new JarEntry("META-INF/MANIFEST.MF"));
|
||||
out.write(getFile("test-manifest.MF").getBytes());
|
||||
out.closeEntry();
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
private String getFile(String fileName) throws Exception {
|
||||
ClassPathResource resource = new ClassPathResource(fileName, getClass());
|
||||
InputStreamReader reader = new InputStreamReader(resource.getInputStream());
|
||||
return FileCopyUtils.copyToString(reader);
|
||||
}
|
||||
|
||||
private static class TestLayers implements Layers {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.boot.jarmode.layertools;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -31,6 +31,9 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -70,9 +73,12 @@ class HelpCommandTests {
|
||||
assertThat(this.out).hasSameContentAsResource("help-extract-output.txt");
|
||||
}
|
||||
|
||||
private File createJarFile(String name) throws IOException {
|
||||
private File createJarFile(String name) throws Exception {
|
||||
File file = new File(this.temp, name);
|
||||
try (ZipOutputStream jarOutputStream = new ZipOutputStream(new FileOutputStream(file))) {
|
||||
jarOutputStream.putNextEntry(new JarEntry("META-INF/MANIFEST.MF"));
|
||||
jarOutputStream.write(getFile("test-manifest.MF").getBytes());
|
||||
jarOutputStream.closeEntry();
|
||||
JarEntry indexEntry = new JarEntry("BOOT-INF/layers.idx");
|
||||
jarOutputStream.putNextEntry(indexEntry);
|
||||
Writer writer = new OutputStreamWriter(jarOutputStream, StandardCharsets.UTF_8);
|
||||
@@ -88,4 +94,10 @@ class HelpCommandTests {
|
||||
return file;
|
||||
}
|
||||
|
||||
private String getFile(String fileName) throws Exception {
|
||||
ClassPathResource resource = new ClassPathResource(fileName, getClass());
|
||||
InputStreamReader reader = new InputStreamReader(resource.getInputStream());
|
||||
return FileCopyUtils.copyToString(reader);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -98,10 +98,10 @@ class IndexedLayersTests {
|
||||
}
|
||||
|
||||
private String getIndex() throws Exception {
|
||||
return getIndex("test-layers.idx");
|
||||
return getFile("test-layers.idx");
|
||||
}
|
||||
|
||||
private String getIndex(String fileName) throws Exception {
|
||||
private String getFile(String fileName) throws Exception {
|
||||
ClassPathResource resource = new ClassPathResource(fileName, getClass());
|
||||
InputStreamReader reader = new InputStreamReader(resource.getInputStream());
|
||||
return FileCopyUtils.copyToString(reader);
|
||||
@@ -123,10 +123,10 @@ class IndexedLayersTests {
|
||||
out.putNextEntry(new ZipEntry("WEB-INF/classes/Demo.class"));
|
||||
out.closeEntry();
|
||||
out.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
|
||||
out.write(getIndex("test-manifest.MF").getBytes());
|
||||
out.write(getFile("test-war-manifest.MF").getBytes());
|
||||
out.closeEntry();
|
||||
out.putNextEntry(new ZipEntry("WEB-INF/layers.idx"));
|
||||
out.write(getIndex("test-war-layers.idx").getBytes());
|
||||
out.write(getFile("test-war-layers.idx").getBytes());
|
||||
out.closeEntry();
|
||||
}
|
||||
return file;
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.boot.jarmode.layertools;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintStream;
|
||||
import java.io.Writer;
|
||||
@@ -31,6 +31,9 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -98,9 +101,12 @@ class LayerToolsJarModeTests {
|
||||
assertThat(this.out).hasSameContentAsResource("error-option-missing-value-output.txt");
|
||||
}
|
||||
|
||||
private File createJarFile(String name) throws IOException {
|
||||
private File createJarFile(String name) throws Exception {
|
||||
File file = new File(this.temp, name);
|
||||
try (ZipOutputStream jarOutputStream = new ZipOutputStream(new FileOutputStream(file))) {
|
||||
jarOutputStream.putNextEntry(new JarEntry("META-INF/MANIFEST.MF"));
|
||||
jarOutputStream.write(getFile("test-manifest.MF").getBytes());
|
||||
jarOutputStream.closeEntry();
|
||||
JarEntry indexEntry = new JarEntry("BOOT-INF/layers.idx");
|
||||
jarOutputStream.putNextEntry(indexEntry);
|
||||
Writer writer = new OutputStreamWriter(jarOutputStream, StandardCharsets.UTF_8);
|
||||
@@ -116,4 +122,10 @@ class LayerToolsJarModeTests {
|
||||
return file;
|
||||
}
|
||||
|
||||
private String getFile(String fileName) throws Exception {
|
||||
ClassPathResource resource = new ClassPathResource(fileName, getClass());
|
||||
InputStreamReader reader = new InputStreamReader(resource.getInputStream());
|
||||
return FileCopyUtils.copyToString(reader);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.boot.jarmode.layertools;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -33,6 +34,9 @@ import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
@@ -72,7 +76,7 @@ class ListCommandTests {
|
||||
assertThat(this.out).hasSameContentAsResource("list-output.txt");
|
||||
}
|
||||
|
||||
private File createJarFile(String name) throws IOException {
|
||||
private File createJarFile(String name) throws Exception {
|
||||
File file = new File(this.temp, name);
|
||||
try (ZipOutputStream jarOutputStream = new ZipOutputStream(new FileOutputStream(file))) {
|
||||
writeLayersIndex(jarOutputStream);
|
||||
@@ -91,6 +95,9 @@ class ListCommandTests {
|
||||
jarOutputStream.closeEntry();
|
||||
jarOutputStream.putNextEntry(new ZipEntry(entryPrefix + "d/"));
|
||||
jarOutputStream.closeEntry();
|
||||
jarOutputStream.putNextEntry(new JarEntry("META-INF/MANIFEST.MF"));
|
||||
jarOutputStream.write(getFile("test-manifest.MF").getBytes());
|
||||
jarOutputStream.closeEntry();
|
||||
}
|
||||
return file;
|
||||
}
|
||||
@@ -109,4 +116,10 @@ class ListCommandTests {
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
private String getFile(String fileName) throws Exception {
|
||||
ClassPathResource resource = new ClassPathResource(fileName, getClass());
|
||||
InputStreamReader reader = new InputStreamReader(resource.getInputStream());
|
||||
return FileCopyUtils.copyToString(reader);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
Manifest-Version: 1.0
|
||||
Created-By: Maven WAR Plugin 3.3.1
|
||||
Created-By: Maven JAR Plugin
|
||||
Build-Jdk-Spec: 11
|
||||
Implementation-Title: demo
|
||||
Implementation-Version: 0.0.1-SNAPSHOT
|
||||
Main-Class: org.springframework.boot.loader.WarLauncher
|
||||
Start-Class: com.example.DemoApplication
|
||||
Spring-Boot-Version: 2.5.0-SNAPSHOT
|
||||
Spring-Boot-Classes: WEB-INF/classes/
|
||||
Spring-Boot-Lib: WEB-INF/lib/
|
||||
Spring-Boot-Classpath-Index: WEB-INF/classpath.idx
|
||||
Spring-Boot-Layers-Index: WEB-INF/layers.idx
|
||||
Spring-Boot-Classes: BOOT-INF/classes/
|
||||
Spring-Boot-Lib: BOOT-INF/lib/
|
||||
Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx
|
||||
Spring-Boot-Layers-Index: BOOT-INF/layers.idx
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
Manifest-Version: 1.0
|
||||
Created-By: Maven WAR Plugin 3.3.1
|
||||
Build-Jdk-Spec: 11
|
||||
Implementation-Title: demo
|
||||
Implementation-Version: 0.0.1-SNAPSHOT
|
||||
Main-Class: org.springframework.boot.loader.WarLauncher
|
||||
Start-Class: com.example.DemoApplication
|
||||
Spring-Boot-Version: 2.5.0-SNAPSHOT
|
||||
Spring-Boot-Classes: WEB-INF/classes/
|
||||
Spring-Boot-Lib: WEB-INF/lib/
|
||||
Spring-Boot-Classpath-Index: WEB-INF/classpath.idx
|
||||
Spring-Boot-Layers-Index: WEB-INF/layers.idx
|
||||
Reference in New Issue
Block a user