1 20 package org.apache.mina.integration.spring.ssl; 21 22 import java.io.File ; 23 import java.io.FileOutputStream ; 24 import java.io.InputStream ; 25 import java.io.OutputStream ; 26 import java.security.KeyStore ; 27 28 import junit.framework.TestCase; 29 30 import org.springframework.core.io.ClassPathResource; 31 32 38 public class KeyStoreFactoryBeanTest extends TestCase { 39 public void testCreateInstanceFromResource() throws Exception { 40 KeyStoreFactoryBean factory = new KeyStoreFactoryBean(); 42 factory.setResource(new ClassPathResource("keystore.cert", getClass())); 43 factory.setPassword("boguspw"); 44 45 KeyStore ks = (KeyStore ) factory.createInstance(); 46 47 ks.getCertificate("bogus"); 48 ks.getKey("bogus", "boguspw".toCharArray()); 49 } 50 51 public void testCreateInstanceFromFile() throws Exception { 52 File file = File.createTempFile("keystoretest ", null); 54 file.deleteOnExit(); 55 InputStream in = getClass().getResourceAsStream("keystore.cert"); 56 OutputStream out = new FileOutputStream (file); 57 int b; 58 while ((b = in.read()) != -1) { 59 out.write(b); 60 } 61 in.close(); 62 out.close(); 63 64 KeyStoreFactoryBean factory = new KeyStoreFactoryBean(); 66 factory.setFile(file); 67 factory.setPassword("boguspw"); 68 69 KeyStore ks = (KeyStore ) factory.createInstance(); 70 71 ks.getCertificate("bogus"); 72 ks.getKey("bogus", "boguspw".toCharArray()); 73 } 74 75 } 76 | Popular Tags |