Skip to content

Commit b5a1969

Browse files
committed
Merge branch 'develop' of github.com:oracle/weblogic-deploy-tooling into develop
2 parents 6be8e90 + d0921a6 commit b5a1969

File tree

5 files changed

+180
-185
lines changed

5 files changed

+180
-185
lines changed

core/src/test/java/oracle/weblogic/deploy/util/FileUtilsTest.java

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
import java.io.ByteArrayOutputStream;
88
import java.io.File;
99
import java.io.FileOutputStream;
10-
import java.io.IOException;
1110
import java.nio.file.attribute.PosixFilePermission;
1211
import java.text.MessageFormat;
1312
import java.util.Set;
1413
import java.util.zip.ZipEntry;
1514
import java.util.zip.ZipOutputStream;
1615

17-
import org.junit.Assert;
18-
import org.junit.Before;
19-
import org.junit.Test;
16+
import org.junit.jupiter.api.BeforeAll;
17+
import org.junit.jupiter.api.Test;
18+
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertThrows;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2022

2123
public class FileUtilsTest {
2224
private static final String FILE_ERR_FORMAT = "Unexpected {0}: got {1}, expected {2}";
@@ -60,15 +62,15 @@ public class FileUtilsTest {
6062
private static final File UNIT_TEST_TARGET_DIR = new File(WLSDeployZipFileTest.UNIT_TEST_TARGET_DIR, "fileutils");
6163
private static final String WALLET_PATH = "wlsdeploy/wallet.zip";
6264

63-
@Before
64-
public void initialize() throws Exception {
65+
@BeforeAll
66+
static void initialize() throws Exception {
6567
if(!UNIT_TEST_TARGET_DIR.exists() && !UNIT_TEST_TARGET_DIR.mkdirs()) {
6668
throw new Exception("Unable to create unit test directory: " + UNIT_TEST_TARGET_DIR);
6769
}
6870
}
6971

7072
@Test
71-
public void testNormalFile_parseFileName() throws Exception {
73+
void testNormalFile_parseFileName() {
7274
File f = new File(FILE1);
7375
String[] nameComponents = FileUtils.parseFileName(f);
7476
assertMatch("filename", nameComponents[0], FILE1_EXPECTED_NAME);
@@ -111,22 +113,22 @@ public void testNormalFile_parseFileName() throws Exception {
111113
}
112114

113115
@Test
114-
public void testHashing() throws Exception {
116+
void testHashing() throws Exception {
115117
File archiveFile = FileUtils.getCanonicalFile(new File(ARCHIVE_FILE_NAME));
116118
WLSDeployArchive archive = new WLSDeployArchive(archiveFile.getAbsolutePath());
117119
String archiveHash = archive.getFileHash(APP_PATH);
118120

119121
File appFile = FileUtils.getCanonicalFile(new File(APP_FILE_NAME));
120122
String appHash = FileUtils.computeHash(appFile.getAbsolutePath());
121123

122-
Assert.assertEquals(appHash, archiveHash);
124+
assertEquals(appHash, archiveHash);
123125
}
124126

125127
@Test
126128
/* A wallet zip inside the archive must not contain an entry such as ../info.txt,
127129
since this creates a file overwrite security vulnerability (zip slip).
128130
*/
129-
public void testZipVulnerability() throws Exception {
131+
void testZipVulnerability() throws Exception {
130132
String extractPath = UNIT_TEST_TARGET_DIR.getPath();
131133

132134
// an entry with a simple name or path works fine
@@ -135,15 +137,12 @@ public void testZipVulnerability() throws Exception {
135137
FileUtils.extractZipFileContent(deployArchive, WALLET_PATH, extractPath);
136138

137139
// an entry with parent directory notation should throw an exception
138-
try {
139-
zipFile = buildWalletArchiveZip("../info.txt");
140-
deployArchive = new WLSDeployArchive(zipFile.getPath());
141-
FileUtils.extractZipFileContent(deployArchive, WALLET_PATH, extractPath);
142-
Assert.fail("Exception not thrown for zip entry outside extract directory");
143-
144-
} catch(IllegalArgumentException e) {
145-
// expected behavior
146-
}
140+
zipFile = buildWalletArchiveZip("../info.txt");
141+
final WLSDeployArchive deployArchive2 = new WLSDeployArchive(zipFile.getPath());
142+
assertThrows(IllegalArgumentException.class,
143+
() -> FileUtils.extractZipFileContent(deployArchive2, WALLET_PATH, extractPath),
144+
"Exception not thrown for zip entry outside extract directory");
145+
147146
}
148147

149148
/* Build an archive zip containing a wallet zip.
@@ -174,19 +173,18 @@ private File buildWalletArchiveZip(String contentName) throws Exception {
174173
}
175174

176175
private void assertMatch(String name, String got, String expected) {
177-
Assert.assertTrue(MessageFormat.format(FILE_ERR_FORMAT, name, got, expected),
178-
got.equals(expected));
176+
assertEquals(expected, got, MessageFormat.format(FILE_ERR_FORMAT, name, got, expected));
179177
}
180178

181179
@Test
182-
public void posixPermissions() throws IOException {
180+
void posixPermissions() {
183181
Set<PosixFilePermission> perms = FileUtils.getPermissions(0700);
184-
Assert.assertTrue(perms.contains(PosixFilePermission.OWNER_READ));
185-
Assert.assertTrue(perms.contains(PosixFilePermission.OWNER_WRITE));
186-
Assert.assertTrue(perms.contains(PosixFilePermission.OWNER_EXECUTE));
182+
assertTrue(perms.contains(PosixFilePermission.OWNER_READ));
183+
assertTrue(perms.contains(PosixFilePermission.OWNER_WRITE));
184+
assertTrue(perms.contains(PosixFilePermission.OWNER_EXECUTE));
187185

188186
Set<PosixFilePermission> perms2 = FileUtils.getPermissions(0006);
189-
Assert.assertTrue(perms2.contains(PosixFilePermission.OTHERS_READ));
190-
Assert.assertTrue(perms2.contains(PosixFilePermission.OTHERS_WRITE));
187+
assertTrue(perms2.contains(PosixFilePermission.OTHERS_READ));
188+
assertTrue(perms2.contains(PosixFilePermission.OTHERS_WRITE));
191189
}
192190
}

core/src/test/java/oracle/weblogic/deploy/util/PyOrderedDictTest.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,27 @@
44
*/
55
package oracle.weblogic.deploy.util;
66

7-
import org.python.core.PyList;
8-
import org.python.core.PyTuple;
9-
import org.python.core.PyString;
7+
import org.junit.jupiter.api.Test;
8+
import org.python.core.PyDictionary;
109
import org.python.core.PyInteger;
10+
import org.python.core.PyList;
1111
import org.python.core.PyObject;
12-
import org.python.core.PyDictionary;
13-
14-
import org.junit.jupiter.api.Test;
12+
import org.python.core.PyString;
13+
import org.python.core.PyTuple;
1514

1615
import static org.junit.jupiter.api.Assertions.assertEquals;
17-
import static org.junit.jupiter.api.Assertions.assertThrows;
1816
import static org.junit.jupiter.api.Assertions.assertTrue;
1917

2018
public class PyOrderedDictTest {
2119
@Test
22-
public void testIsInstance() throws Exception {
20+
void testIsInstance() {
2321
PyOrderedDict myOrderedDict = new PyOrderedDict();
2422
boolean result = (myOrderedDict instanceof PyDictionary);
2523
assertTrue(result, "isinstance(myOrderedDict, dict) returns true");
2624
}
2725

2826
@Test
29-
public void testSetItem() throws Exception {
27+
void testSetItem() {
3028
PyOrderedDict myOrderedDict = new PyOrderedDict();
3129

3230
myOrderedDict.__setitem__("nba_player", new PyString("Steph Curry"));
@@ -45,7 +43,7 @@ public void testSetItem() throws Exception {
4543
}
4644

4745
@Test
48-
public void testKeyOrdering() throws Exception {
46+
void testKeyOrdering() {
4947
PyOrderedDict myOrderedDict = new PyOrderedDict();
5048

5149
myOrderedDict.__setitem__("one", new PyInteger(1));
@@ -72,7 +70,7 @@ public void testKeyOrdering() throws Exception {
7270
}
7371

7472
@Test
75-
public void testIteritems() throws Exception {
73+
void testIteritems() {
7674
PyOrderedDict myOrderedDict = new PyOrderedDict();
7775

7876
myOrderedDict.__setitem__("one", new PyInteger(1));
@@ -90,7 +88,7 @@ public void testIteritems() throws Exception {
9088
}
9189

9290
@Test
93-
public void testOrderedDictAsValue() throws Exception {
91+
void testOrderedDictAsValue() {
9492
PyOrderedDict myOrderedDict = new PyOrderedDict();
9593
PyOrderedDict anotherOrderedDict = new PyOrderedDict();
9694
anotherOrderedDict.__setitem__("nested_key", new PyString("nested_value"));
@@ -100,7 +98,7 @@ public void testOrderedDictAsValue() throws Exception {
10098
}
10199

102100
@Test
103-
public void testCopyConstructor() throws Exception {
101+
void testCopyConstructor() {
104102
PyOrderedDict myOrderedDict = new PyOrderedDict();
105103

106104
myOrderedDict.__setitem__("foo", new PyString("bar"));
@@ -109,7 +107,7 @@ public void testCopyConstructor() throws Exception {
109107
}
110108

111109
@Test
112-
public void testUpdate() throws Exception {
110+
void testUpdate() {
113111
PyOrderedDict myOrderedDict = new PyOrderedDict();
114112
myOrderedDict.__setitem__("network_type", new PyString("ETHERNET"));
115113

core/src/test/java/oracle/weblogic/deploy/util/SwapFilesTest.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
import java.nio.file.Files;
99
import java.nio.file.Paths;
1010
import java.security.MessageDigest;
11-
1211
import javax.xml.bind.DatatypeConverter;
1312

14-
import org.junit.Assert;
15-
import org.junit.Before;
16-
import org.junit.Test;
13+
import org.junit.jupiter.api.BeforeEach;
14+
import org.junit.jupiter.api.Test;
15+
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertTrue;
1718

1819

1920
public class SwapFilesTest {
@@ -26,62 +27,62 @@ public class SwapFilesTest {
2627

2728
private WLSDeployArchive archive;
2829

29-
@Before
30-
public void init() throws Exception {
30+
@BeforeEach
31+
void init() {
3132
File folder = new File(UNIT_TEST_TARGET_DIR);
3233
File archiveFile = new File(folder, "swapFileTests.zip");
3334

3435
if ( !folder.exists() ) {
35-
Assert.assertTrue("Could not create directory " + folder.getPath(), folder.mkdirs());
36+
assertTrue(folder.mkdirs(), "Could not create directory " + folder.getPath());
3637
}
3738
archive = new WLSDeployArchive( archiveFile.getAbsolutePath() );
3839
}
3940

4041
@Test
41-
public void updateTwoThings() throws Exception {
42+
void updateTwoThings() throws Exception {
4243
File sourceModel = new File(SOURCE_MODEL_FILE);
4344
archive.addModel(sourceModel);
4445

4546
File unitTestDir = new File(UNIT_TEST_TARGET_DIR);
4647
archive.extractModel(unitTestDir);
4748
File targetModel = new File(TARGET_MODEL_FILE);
4849

49-
Assert.assertTrue("Target model file does not exist", targetModel.exists());
50+
assertTrue(targetModel.exists(), "Target model file does not exist");
5051
String sourceHash = getMD5Hash(sourceModel);
5152
String targetHash = getMD5Hash(targetModel);
52-
Assert.assertEquals("source and target models are different", sourceHash, targetHash);
53+
assertEquals(sourceHash, targetHash, "source and target models are different");
5354

5455
archive.removeAllBinaries();
5556
File sourceApp = new File(SOURCE_APP_FILE);
5657
archive.addApplication(sourceApp);
5758
archive.extractFileFromZip(TARGET_APP_ARCHIVE_LOCATION, unitTestDir);
5859
File targetApp = new File(TARGET_APP_FILE);
5960

60-
Assert.assertTrue("Target app file does not exist", targetApp.exists());
61+
assertTrue(targetApp.exists(), "Target app file does not exist");
6162
sourceHash = getMD5Hash(sourceApp);
6263
targetHash = getMD5Hash(targetApp);
63-
Assert.assertEquals("source and target apps are different", sourceHash, targetHash);
64+
assertEquals(sourceHash, targetHash, "source and target apps are different");
6465
archive.close();
6566
}
6667

6768
@Test
68-
public void updateModel() throws Exception {
69+
void updateModel() throws Exception {
6970
File sourceModel = new File(SOURCE_MODEL_FILE);
7071
archive.addModel(sourceModel);
7172

7273
File unitTestDir = new File(UNIT_TEST_TARGET_DIR);
7374
archive.extractModel(unitTestDir);
7475
File targetModel = new File(TARGET_MODEL_FILE);
7576

76-
Assert.assertTrue("Target model file does not exist", targetModel.exists());
77+
assertTrue(targetModel.exists(), "Target model file does not exist");
7778
String sourceHash = getMD5Hash(sourceModel);
7879
String targetHash = getMD5Hash(targetModel);
79-
Assert.assertEquals("source and target models are different", sourceHash, targetHash);
80+
assertEquals(sourceHash, targetHash, "source and target models are different");
8081
archive.close();
8182
}
8283

8384
@Test
84-
public void updateApp() throws Exception {
85+
void updateApp() throws Exception {
8586
File unitTestDir = new File(UNIT_TEST_TARGET_DIR);
8687

8788
archive.removeAllBinaries();
@@ -90,10 +91,10 @@ public void updateApp() throws Exception {
9091
archive.extractFileFromZip(TARGET_APP_ARCHIVE_LOCATION, unitTestDir);
9192
File targetApp = new File(TARGET_APP_FILE);
9293

93-
Assert.assertTrue("Target app file does not exist", targetApp.exists());
94+
assertTrue(targetApp.exists(), "Target app file does not exist");
9495
String sourceHash = getMD5Hash(sourceApp);
9596
String targetHash = getMD5Hash(targetApp);
96-
Assert.assertEquals("source and target apps are different", sourceHash, targetHash);
97+
assertEquals(sourceHash, targetHash, "source and target apps are different");
9798
archive.close();
9899
}
99100

0 commit comments

Comments
 (0)