View Javadoc

1   /*
2    * $Id: PgpNamespaceHandlerTestCase.java 22401 2011-07-13 09:10:18Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.pgp;
12  
13  import org.mule.api.EncryptionStrategy;
14  import org.mule.api.security.SecurityManager;
15  import org.mule.api.security.SecurityProvider;
16  import org.mule.tck.junit4.FunctionalTestCase;
17  
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertNotNull;
21  import static org.junit.Assert.assertTrue;
22  
23  public class PgpNamespaceHandlerTestCase extends FunctionalTestCase
24  {
25  
26      @Override
27      protected String getConfigResources()
28      {
29          return "pgp-namespace-config.xml";
30      }
31  
32      @Test
33      public void testPgpProvider()
34      {
35          knownProperties(getProvider("pgpSecurityProvider"));
36      }
37      
38      @Test
39      public void testKeyBasedEncryptionStrategy()
40      {
41          knownProperties(getEncryptionStrategy("keyBasedEncryptionStrategy"));
42      }
43  
44      protected SecurityProvider getProvider(String name)
45      {
46          SecurityManager securityManager = muleContext.getSecurityManager();
47          return securityManager.getProvider(name);
48      }
49  
50      protected void knownProperties(SecurityProvider provider)
51      {
52          assertNotNull(provider);
53          assertTrue(provider instanceof PGPSecurityProvider);
54          PGPSecurityProvider pgpProvider = (PGPSecurityProvider) provider;
55          assertNotNull(pgpProvider.getKeyManager());
56          assertTrue(pgpProvider.getKeyManager() instanceof PGPKeyRingImpl);
57      }
58      
59      protected EncryptionStrategy getEncryptionStrategy(String name)
60      {
61          SecurityManager securityManager = muleContext.getSecurityManager();
62          return securityManager.getEncryptionStrategy(name);
63      }
64      
65      protected void knownProperties(EncryptionStrategy encryptionStrategy)
66      {
67          assertNotNull(encryptionStrategy);
68          assertTrue(encryptionStrategy instanceof KeyBasedEncryptionStrategy);
69          KeyBasedEncryptionStrategy keyBased = (KeyBasedEncryptionStrategy) encryptionStrategy;
70          assertNotNull(keyBased.getKeyManager());
71          assertTrue(keyBased.getKeyManager() instanceof PGPKeyRingImpl);
72      }
73  
74  }