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 java.security.KeyStore;
17  
18  import org.junit.jupiter.api.Test;
19  
20  import static org.junit.jupiter.api.Assertions.assertNotNull;
21  
22  /**
23   * Unit tests for {@link KeyStoreFactoryBean}.
24   *
25   * @author Carl Harris
26   */
27  public class KeyStoreFactoryBeanTest {
28  
29      private KeyStoreFactoryBean factoryBean = new KeyStoreFactoryBean();
30  
31      @Test
32      public void testDefaults() throws Exception {
33          factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE);
34          assertNotNull(factoryBean.createKeyStore());
35      }
36  
37      @Test
38      public void testExplicitProvider() throws Exception {
39          factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE);
40          KeyStore keyStore = factoryBean.createKeyStore();
41          factoryBean.setProvider(keyStore.getProvider().getName());
42          assertNotNull(factoryBean.createKeyStore());
43      }
44  
45      @Test
46      public void testExplicitType() throws Exception {
47          factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE);
48          factoryBean.setType(SSL.DEFAULT_KEYSTORE_TYPE);
49          assertNotNull(factoryBean.createKeyStore());
50      }
51  
52      @Test
53      public void testPKCS12Type() throws Exception {
54          factoryBean.setLocation(SSLTestConstants.KEYSTORE_PKCS12_RESOURCE);
55          factoryBean.setType(SSLTestConstants.PKCS12_TYPE);
56          assertNotNull(factoryBean.createKeyStore());
57      }
58  
59      @Test
60      public void testExplicitPassphrase() throws Exception {
61          factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE);
62          factoryBean.setPassword(SSL.DEFAULT_KEYSTORE_PASSWORD);
63          assertNotNull(factoryBean.createKeyStore());
64      }
65  
66  }