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.transport.http.functional;
8   
9   import org.mule.api.MuleEventContext;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.service.Service;
12  import org.mule.module.client.MuleClient;
13  import org.mule.tck.functional.EventCallback;
14  import org.mule.tck.functional.FunctionalTestComponent;
15  import org.mule.transport.http.HttpConstants;
16  import org.mule.transport.http.HttpsConnector;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertNotNull;
25  import static org.junit.Assert.assertTrue;
26  
27  public class HttpsFunctionalTestCase extends HttpFunctionalTestCase
28  {
29  
30      @Override
31      protected String getConfigResources()
32      {
33          return "https-functional-test.xml";
34      }
35  
36      @Override
37      public void testSend() throws Exception
38      {
39          Service testSedaService = muleContext.getRegistry().lookupService("testComponent");
40          FunctionalTestComponent testComponent = (FunctionalTestComponent) getComponent(testSedaService);
41          assertNotNull(testComponent);
42  
43          final AtomicBoolean callbackMade = new AtomicBoolean(false);
44          EventCallback callback = new EventCallback()
45          {
46              public void eventReceived(final MuleEventContext context, final Object component) throws Exception
47              {
48                  MuleMessage msg = context.getMessage();
49                  assertTrue(callbackMade.compareAndSet(false, true));
50                  assertNotNull(msg.getOutboundProperty(HttpsConnector.LOCAL_CERTIFICATES));
51              }
52          };
53          testComponent.setEventCallback(callback);
54  
55          MuleClient client = new MuleClient(muleContext);
56          
57          Map<String, Object> props = new HashMap<String, Object>();
58          props.put(HttpConstants.HEADER_CONTENT_TYPE, "text/plain;charset=UTF-8");
59          MuleMessage result = client.send("clientEndpoint", TEST_MESSAGE, props);
60          
61          assertNotNull(result);
62          assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
63          assertTrue("Callback never fired", callbackMade.get());
64      }
65  }