1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.net.ssl;
15
16 import static org.junit.Assert.assertNotNull;
17
18 import java.security.KeyStore;
19
20 import org.junit.Test;
21
22 import ch.qos.logback.core.net.ssl.KeyStoreFactoryBean;
23 import ch.qos.logback.core.net.ssl.SSL;
24
25
26
27
28
29
30 public class KeyStoreFactoryBeanTest {
31
32 private KeyStoreFactoryBean factoryBean = new KeyStoreFactoryBean();
33
34 @Test
35 public void testDefaults() throws Exception {
36 factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE);
37 assertNotNull(factoryBean.createKeyStore());
38 }
39
40 @Test
41 public void testExplicitProvider() throws Exception {
42 factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE);
43 KeyStore keyStore = factoryBean.createKeyStore();
44 factoryBean.setProvider(keyStore.getProvider().getName());
45 assertNotNull(factoryBean.createKeyStore());
46 }
47
48 @Test
49 public void testExplicitType() throws Exception {
50 factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE);
51 factoryBean.setType(SSL.DEFAULT_KEYSTORE_TYPE);
52 assertNotNull(factoryBean.createKeyStore());
53 }
54
55 @Test
56 public void testPKCS12Type() throws Exception {
57 factoryBean.setLocation(SSLTestConstants.KEYSTORE_PKCS12_RESOURCE);
58 factoryBean.setType(SSLTestConstants.PKCS12_TYPE);
59 assertNotNull(factoryBean.createKeyStore());
60 }
61
62 @Test
63 public void testExplicitPassphrase() throws Exception {
64 factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE);
65 factoryBean.setPassword(SSL.DEFAULT_KEYSTORE_PASSWORD);
66 assertNotNull(factoryBean.createKeyStore());
67 }
68
69 }