Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
82ac7eef
Commit
82ac7eef
authored
Jan 28, 2021
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update tests following code changes
See gh-22821
parent
9a32f678
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
88 additions
and
17 deletions
+88
-17
ContextTests.java
...springframework/boot/jarmode/layertools/ContextTests.java
+10
-2
ExtractCommandTests.java
...ramework/boot/jarmode/layertools/ExtractCommandTests.java
+15
-1
HelpCommandTests.java
...ngframework/boot/jarmode/layertools/HelpCommandTests.java
+14
-2
IndexedLayersTests.java
...framework/boot/jarmode/layertools/IndexedLayersTests.java
+4
-4
LayerToolsJarModeTests.java
...ework/boot/jarmode/layertools/LayerToolsJarModeTests.java
+14
-2
ListCommandTests.java
...ngframework/boot/jarmode/layertools/ListCommandTests.java
+14
-1
test-manifest.MF
.../springframework/boot/jarmode/layertools/test-manifest.MF
+5
-5
test-war-manifest.MF
...ingframework/boot/jarmode/layertools/test-war-manifest.MF
+12
-0
No files found.
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/test/java/org/springframework/boot/jarmode/layertools/ContextTests.java
View file @
82ac7eef
...
...
@@ -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
...
...
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/test/java/org/springframework/boot/jarmode/layertools/ExtractCommandTests.java
View file @
82ac7eef
...
...
@@ -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
IO
Exception
{
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
...
...
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/test/java/org/springframework/boot/jarmode/layertools/HelpCommandTests.java
View file @
82ac7eef
...
...
@@ -18,7 +18,7 @@ package org.springframework.boot.jarmode.layertools;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.I
OException
;
import
java.io.I
nputStreamReader
;
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
IO
Exception
{
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
);
}
}
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/test/java/org/springframework/boot/jarmode/layertools/IndexedLayersTests.java
View file @
82ac7eef
...
...
@@ -98,10 +98,10 @@ class IndexedLayersTests {
}
private
String
getIndex
()
throws
Exception
{
return
get
Index
(
"test-layers.idx"
);
return
get
File
(
"test-layers.idx"
);
}
private
String
get
Index
(
String
fileName
)
throws
Exception
{
private
String
get
File
(
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
(
get
Index
(
"test
-manifest.MF"
).
getBytes
());
out
.
write
(
get
File
(
"test-war
-manifest.MF"
).
getBytes
());
out
.
closeEntry
();
out
.
putNextEntry
(
new
ZipEntry
(
"WEB-INF/layers.idx"
));
out
.
write
(
get
Index
(
"test-war-layers.idx"
).
getBytes
());
out
.
write
(
get
File
(
"test-war-layers.idx"
).
getBytes
());
out
.
closeEntry
();
}
return
file
;
...
...
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/test/java/org/springframework/boot/jarmode/layertools/LayerToolsJarModeTests.java
View file @
82ac7eef
...
...
@@ -18,7 +18,7 @@ package org.springframework.boot.jarmode.layertools;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.I
OException
;
import
java.io.I
nputStreamReader
;
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
IO
Exception
{
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
);
}
}
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/test/java/org/springframework/boot/jarmode/layertools/ListCommandTests.java
View file @
82ac7eef
...
...
@@ -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
IO
Exception
{
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
);
}
}
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/test/resources/org/springframework/boot/jarmode/layertools/test-manifest.MF
View file @
82ac7eef
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
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/test/resources/org/springframework/boot/jarmode/layertools/test-war-manifest.MF
0 → 100644
View file @
82ac7eef
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment