1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }