001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.core.net.ssl; 015 016import static org.junit.Assert.assertNotNull; 017 018import java.security.KeyStore; 019 020import org.junit.Test; 021 022import ch.qos.logback.core.net.ssl.KeyStoreFactoryBean; 023import ch.qos.logback.core.net.ssl.SSL; 024 025/** 026 * Unit tests for {@link KeyStoreFactoryBean}. 027 * 028 * @author Carl Harris 029 */ 030public class KeyStoreFactoryBeanTest { 031 032 private KeyStoreFactoryBean factoryBean = new KeyStoreFactoryBean(); 033 034 @Test 035 public void testDefaults() throws Exception { 036 factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE); 037 assertNotNull(factoryBean.createKeyStore()); 038 } 039 040 @Test 041 public void testExplicitProvider() throws Exception { 042 factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE); 043 KeyStore keyStore = factoryBean.createKeyStore(); 044 factoryBean.setProvider(keyStore.getProvider().getName()); 045 assertNotNull(factoryBean.createKeyStore()); 046 } 047 048 @Test 049 public void testExplicitType() throws Exception { 050 factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE); 051 factoryBean.setType(SSL.DEFAULT_KEYSTORE_TYPE); 052 assertNotNull(factoryBean.createKeyStore()); 053 } 054 055 @Test 056 public void testPKCS12Type() throws Exception { 057 factoryBean.setLocation(SSLTestConstants.KEYSTORE_PKCS12_RESOURCE); 058 factoryBean.setType(SSLTestConstants.PKCS12_TYPE); 059 assertNotNull(factoryBean.createKeyStore()); 060 } 061 062 @Test 063 public void testExplicitPassphrase() throws Exception { 064 factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE); 065 factoryBean.setPassword(SSL.DEFAULT_KEYSTORE_PASSWORD); 066 assertNotNull(factoryBean.createKeyStore()); 067 } 068 069}