Skip to content

Commit ca1e1f7

Browse files
fixing issue with the name returned when adding a file to a database wallet (#1378)
1 parent 5e33bfb commit ca1e1f7

File tree

2 files changed

+93
-19
lines changed

2 files changed

+93
-19
lines changed

core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4502,11 +4502,6 @@ protected String addDatabaseWallet(String walletName, String sourceLocation, boo
45024502
newName = addItemToZip(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName, sourceFile, false);
45034503
} else {
45044504
newName = addItemToZip(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName, sourceFile);
4505-
4506-
// When adding a file (e.g., zip file), the wallet name returned should always point
4507-
// to the wallet directory containing the file.
4508-
//
4509-
newName = getDatabaseWalletArchivePathFromAddedFile(ARCHIVE_DB_WALLETS_DIR, newName);
45104505
}
45114506

45124507
LOGGER.exiting(CLASS, METHOD, newName);
@@ -4931,20 +4926,6 @@ private String getDatabaseWalletNameFromArchivePath(String archivePath) {
49314926
return result;
49324927
}
49334928

4934-
private String getDatabaseWalletArchivePathFromAddedFile(String walletParentPath, String walletFileName) {
4935-
String result = null;
4936-
4937-
int fromIndex = walletParentPath.length();
4938-
if (!walletParentPath.endsWith(ZIP_SEP)) {
4939-
fromIndex++;
4940-
}
4941-
int endIndex = walletParentPath.indexOf(ZIP_SEP, fromIndex);
4942-
if (endIndex != -1) {
4943-
result = walletFileName.substring(0, endIndex);
4944-
}
4945-
return result;
4946-
}
4947-
49484929
private String getNameFromPath(String path, int startIndex) throws WLSDeployArchiveIOException {
49494930
final String METHOD = "getNameFromPath";
49504931
LOGGER.entering(CLASS, METHOD, path, startIndex);

core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperAddTest.java

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,30 @@ void testAddNewDatabaseWalletDir_ReturnsExceptedResult() throws Exception {
12851285
assertArchiveInExpectedState(LIST_DATABASE_WALLETS, EMPTY_ARRAY, DATABASE_WALLET_WALLET1_CONTENTS);
12861286
}
12871287

1288+
@Test
1289+
void testAddNewDatabaseWalletFile_ReturnsExpectedResult() throws Exception {
1290+
StringWriter outStringWriter = new StringWriter();
1291+
StringWriter errStringWriter = new StringWriter();
1292+
String[] args = new String[]{
1293+
"add",
1294+
"databaseWallet",
1295+
"-archive_file",
1296+
NEW_ARCHIVE_VALUE,
1297+
"-wallet_name",
1298+
"wallet1",
1299+
"-source",
1300+
getSourcePath(ArchiveEntryType.DB_WALLET, "wallet1/atpwallet.zip")
1301+
};
1302+
int actual = -1;
1303+
try (PrintWriter out = new PrintWriter(outStringWriter);
1304+
PrintWriter err = new PrintWriter(errStringWriter)) {
1305+
actual = ArchiveHelper.executeCommand(out, err, args);
1306+
}
1307+
1308+
assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK);
1309+
assertEquals("wlsdeploy/dbWallets/wallet1/atpwallet.zip", outStringWriter.toString().trim());
1310+
}
1311+
12881312
@Test
12891313
void testAddDatabaseWalletDirOverwrite_ReturnsExceptedResult() throws Exception {
12901314
StringWriter outStringWriter = new StringWriter();
@@ -1318,6 +1342,41 @@ void testAddDatabaseWalletDirOverwrite_ReturnsExceptedResult() throws Exception
13181342
assertArchiveInExpectedState(LIST_DATABASE_WALLETS, EMPTY_ARRAY, DATABASE_WALLET_WALLET1_CONTENTS);
13191343
}
13201344

1345+
@Test
1346+
void testAddNewDatabaseWalletFileOverwrite_ReturnsExpectedResult() throws Exception {
1347+
StringWriter outStringWriter = new StringWriter();
1348+
StringWriter errStringWriter = new StringWriter();
1349+
String[] args = new String[]{
1350+
"add",
1351+
"databaseWallet",
1352+
"-archive_file",
1353+
NEW_ARCHIVE_VALUE,
1354+
"-wallet_name",
1355+
"wallet1",
1356+
"-source",
1357+
getSourcePath(ArchiveEntryType.DB_WALLET, "wallet1/atpwallet.zip")
1358+
};
1359+
1360+
int actual = -1;
1361+
try (PrintWriter out = new PrintWriter(outStringWriter);
1362+
PrintWriter err = new PrintWriter(errStringWriter)) {
1363+
actual = ArchiveHelper.executeCommand(out, err, args);
1364+
}
1365+
1366+
assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK);
1367+
1368+
outStringWriter = new StringWriter();
1369+
errStringWriter = new StringWriter();
1370+
String[] overwriteArgs = getOverwriteArgs(args);
1371+
try (PrintWriter out = new PrintWriter(outStringWriter);
1372+
PrintWriter err = new PrintWriter(errStringWriter)) {
1373+
actual = ArchiveHelper.executeCommand(out, err, overwriteArgs);
1374+
}
1375+
1376+
assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK);
1377+
assertEquals("wlsdeploy/dbWallets/wallet1/atpwallet.zip", outStringWriter.toString().trim());
1378+
}
1379+
13211380
@Test
13221381
void testAddDatabaseWalletDirTwice_ReturnsExceptedResult() throws Exception {
13231382
StringWriter outStringWriter = new StringWriter();
@@ -1351,6 +1410,40 @@ void testAddDatabaseWalletDirTwice_ReturnsExceptedResult() throws Exception {
13511410
DATABASE_WALLET_WALLET1_DUP_CONTENTS);
13521411
}
13531412

1413+
@Test
1414+
void testAddDatabaseWalletFileTwice_ReturnsExceptedResult() throws Exception {
1415+
StringWriter outStringWriter = new StringWriter();
1416+
StringWriter errStringWriter = new StringWriter();
1417+
String[] args = new String[] {
1418+
"add",
1419+
"databaseWallet",
1420+
"-archive_file",
1421+
NEW_ARCHIVE_VALUE,
1422+
"-wallet_name",
1423+
"wallet1",
1424+
"-source",
1425+
getSourcePath(ArchiveEntryType.DB_WALLET, "wallet1/atpwallet.zip")
1426+
};
1427+
1428+
int actual = -1;
1429+
try (PrintWriter out = new PrintWriter(outStringWriter);
1430+
PrintWriter err = new PrintWriter(errStringWriter)) {
1431+
actual = ArchiveHelper.executeCommand(out, err, args);
1432+
}
1433+
1434+
assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK);
1435+
1436+
outStringWriter = new StringWriter();
1437+
errStringWriter = new StringWriter();
1438+
try (PrintWriter out = new PrintWriter(outStringWriter);
1439+
PrintWriter err = new PrintWriter(errStringWriter)) {
1440+
actual = ArchiveHelper.executeCommand(out, err, args);
1441+
}
1442+
1443+
assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK);
1444+
assertEquals("wlsdeploy/dbWallets/wallet1/atpwallet(1).zip", outStringWriter.toString().trim());
1445+
}
1446+
13541447
///////////////////////////////////////////////////////////////////////////////////////////////
13551448
// $DOMAIN_HOME/bin script //
13561449
///////////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)