View Javadoc

1   /*
2    * $Id: KBEStrategyUsingEncryptionTransformerTestCase.java 20310 2010-11-24 10:40:35Z esteban.robles $
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 java.io.InputStream;
14  
15  import org.apache.commons.io.IOUtils;
16  import org.mule.DefaultMuleEvent;
17  import org.mule.RequestContext;
18  import org.mule.api.MuleEvent;
19  import org.mule.tck.testmodels.fruit.Orange;
20  import org.mule.transformer.encryption.EncryptionTransformer;
21  import org.mule.transformer.simple.ByteArrayToObject;
22  
23  public class KBEStrategyUsingEncryptionTransformerTestCase extends AbstractEncryptionStrategyTestCase
24  {
25      public void testEncrypt() throws Exception
26      {
27          String msg = "Test Message";
28          
29          MuleEvent event = (DefaultMuleEvent) getTestEvent(msg, getTestService("orange", Orange.class));
30          event = RequestContext.setEvent(event);
31          
32          EncryptionTransformer etrans = new EncryptionTransformer();
33          etrans.setStrategy(kbStrategy);
34          Object result = etrans.doTransform(msg.getBytes(), "UTF-8");
35          
36          assertNotNull(result);
37          InputStream inputStream = (InputStream) result;
38          String message = IOUtils.toString(inputStream);
39          String encrypted = (String) new ByteArrayToObject().doTransform(message.getBytes(), "UTF-8");
40          assertTrue(encrypted.startsWith("-----BEGIN PGP MESSAGE-----"));
41      }
42  }