View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.pgp;
8   
9   import org.mule.DefaultMuleEvent;
10  import org.mule.RequestContext;
11  import org.mule.api.MuleEvent;
12  import org.mule.tck.testmodels.fruit.Orange;
13  import org.mule.transformer.encryption.EncryptionTransformer;
14  import org.mule.transformer.simple.ByteArrayToObject;
15  
16  import java.io.InputStream;
17  
18  import org.apache.commons.io.IOUtils;
19  import org.junit.Test;
20  
21  import static org.junit.Assert.assertNotNull;
22  import static org.junit.Assert.assertTrue;
23  
24  public class KBEStrategyUsingEncryptionTransformerTestCase extends AbstractEncryptionStrategyTestCase
25  {
26      @Test
27      public void testEncrypt() throws Exception
28      {
29          String msg = "Test Message";
30          
31          MuleEvent event = (DefaultMuleEvent) getTestEvent(msg, getTestService("orange", Orange.class));
32          event = RequestContext.setEvent(event);
33          
34          EncryptionTransformer etrans = new EncryptionTransformer();
35          etrans.setStrategy(kbStrategy);
36          Object result = etrans.doTransform(msg.getBytes(), "UTF-8");
37          
38          assertNotNull(result);
39          InputStream inputStream = (InputStream) result;
40          String message = IOUtils.toString(inputStream);
41          String encrypted = (String) new ByteArrayToObject().doTransform(message.getBytes(), "UTF-8");
42          assertTrue(encrypted.startsWith("-----BEGIN PGP MESSAGE-----"));
43      }
44  }