Skip to content

Commit 26839a5

Browse files
authored
BAEL-9268: Add integration test for determining JVM keystore location (#18955)
* BAEL-9268: Add integration test for determining JVM keystore location * fix to follows guidelines. * BAEL-9268: Replace System.out with Logger and remove imports * Corrections: imports and logger
1 parent 26c4176 commit 26839a5

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.baeldung.keystore;
2+
3+
import java.io.File;
4+
5+
import org.junit.jupiter.api.Test;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import static org.junit.jupiter.api.Assertions.*;
10+
11+
class KeystoreLocatorIntegrationTest {
12+
13+
private static final Logger logger = LoggerFactory.getLogger(KeystoreLocatorIntegrationTest.class);
14+
15+
@Test
16+
void givenJavaInstallation_whenUsingSystemProperties_thenKeystoreLocationFound() {
17+
String javaHome = System.getProperty("java.home");
18+
String separator = System.getProperty("file.separator");
19+
20+
String cacertsPath = javaHome + separator + "lib" + separator
21+
+ "security" + separator + "cacerts";
22+
23+
assertNotNull(javaHome);
24+
logger.info("Java Home: {}", javaHome);
25+
logger.info("Expected cacerts location: {}", cacertsPath);
26+
27+
File cacertsFile = new File(cacertsPath);
28+
if (cacertsFile.exists()) {
29+
logger.info("Cacerts file exists: YES");
30+
logger.info("Absolute path: {}", cacertsFile.getAbsolutePath());
31+
assertTrue(cacertsFile.exists());
32+
}
33+
34+
String customTrustStore = System.getProperty("javax.net.ssl.trustStore");
35+
if (customTrustStore != null) {
36+
logger.info("Custom trustStore is specified: {}", customTrustStore);
37+
} else {
38+
logger.info("No custom trustStore specified, using default");
39+
}
40+
41+
String userHome = System.getProperty("user.home");
42+
String userKeystore = userHome + separator + ".keystore";
43+
assertNotNull(userHome);
44+
logger.info("User keystore location: {}", userKeystore);
45+
}
46+
}

0 commit comments

Comments
 (0)