1   /*
2    * Copyright 2008 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.soap.security.wss4j.support;
18  
19  import java.util.Properties;
20  
21  import junit.framework.TestCase;
22  import org.apache.ws.security.components.crypto.Merlin;
23  
24  import org.springframework.core.io.ClassPathResource;
25  import org.springframework.util.ClassUtils;
26  
27  public class CryptoFactoryBeanTest extends TestCase {
28  
29      private CryptoFactoryBean factoryBean;
30  
31      protected void setUp() throws Exception {
32          factoryBean = new CryptoFactoryBean();
33      }
34  
35      public void testSetConfiguration() throws Exception {
36          Properties configuration = new Properties();
37          configuration.setProperty("org.apache.ws.security.crypto.provider",
38                  "org.apache.ws.security.components.crypto.Merlin");
39          configuration.setProperty("org.apache.ws.security.crypto.merlin.keystore.type", "jceks");
40          configuration.setProperty("org.apache.ws.security.crypto.merlin.keystore.password", "123456");
41          configuration.setProperty("org.apache.ws.security.crypto.merlin.file", "private.jks");
42  
43          factoryBean.setConfiguration(configuration);
44          factoryBean.setBeanClassLoader(ClassUtils.getDefaultClassLoader());
45          factoryBean.afterPropertiesSet();
46  
47          Object result = factoryBean.getObject();
48          assertNotNull("No result", result);
49          assertTrue("Not a Merlin instance", result instanceof Merlin);
50      }
51  
52      public void testProperties() throws Exception {
53          factoryBean.setKeyStoreType("jceks");
54          factoryBean.setKeyStorePassword("123456");
55          factoryBean.setKeyStoreLocation(new ClassPathResource("private.jks"));
56          factoryBean.setBeanClassLoader(ClassUtils.getDefaultClassLoader());
57          factoryBean.afterPropertiesSet();
58          Object result = factoryBean.getObject();
59          assertNotNull("No result", result);
60          assertTrue("Not a Merlin instance", result instanceof Merlin);
61      }
62  }