View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
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   * Unit tests for {@link KeyStoreFactoryBean}.
27   *
28   * @author Carl Harris
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  }