View Javadoc

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