View Javadoc

1   /*
2    * $Id: HttpsFunctionalTestCase.java 22518 2011-07-22 07:00:22Z claude.mamo $
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.transport.http.functional;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  import static org.junit.Assert.assertTrue;
16  
17  import org.mule.api.MuleEventContext;
18  import org.mule.api.MuleMessage;
19  import org.mule.api.construct.FlowConstruct;
20  import org.mule.module.client.MuleClient;
21  import org.mule.tck.functional.EventCallback;
22  import org.mule.tck.functional.FunctionalTestComponent;
23  import org.mule.transport.http.HttpConstants;
24  import org.mule.transport.http.HttpsConnector;
25  
26  import java.util.Arrays;
27  import java.util.Collection;
28  import java.util.HashMap;
29  import java.util.Map;
30  import java.util.concurrent.atomic.AtomicBoolean;
31  
32  import org.junit.runners.Parameterized.Parameters;
33  
34  public class HttpsFunctionalTestCase extends HttpFunctionalTestCase
35  {
36  
37      public HttpsFunctionalTestCase(ConfigVariant variant, String configResources)
38      {
39          super(variant, configResources);
40      }
41  
42      @Parameters
43      public static Collection<Object[]> parameters()
44      {
45          return Arrays.asList(new Object[][]{
46              {ConfigVariant.SERVICE, "https-functional-test-service.xml"},
47              {ConfigVariant.FLOW, "https-functional-test-flow.xml"}
48          });
49      }     
50      
51      @Override
52      public void testSend() throws Exception
53      {               
54          FlowConstruct testSedaService = muleContext.getRegistry().lookupFlowConstruct("testComponent");
55          FunctionalTestComponent testComponent = (FunctionalTestComponent) getComponent(testSedaService);
56                 
57          assertNotNull(testComponent);
58  
59          final AtomicBoolean callbackMade = new AtomicBoolean(false);
60          EventCallback callback = new EventCallback()
61          {
62              public void eventReceived(final MuleEventContext context, final Object component) throws Exception
63              {
64                  MuleMessage msg = context.getMessage();
65                  assertTrue(callbackMade.compareAndSet(false, true));
66                  assertNotNull(msg.getOutboundProperty(HttpsConnector.LOCAL_CERTIFICATES));
67              }
68          };
69          testComponent.setEventCallback(callback);
70  
71          MuleClient client = new MuleClient(muleContext);
72          
73          Map<String, Object> props = new HashMap<String, Object>();
74          props.put(HttpConstants.HEADER_CONTENT_TYPE, "text/plain;charset=UTF-8");
75          MuleMessage result = client.send("clientEndpoint", TEST_MESSAGE, props);
76          
77          assertNotNull(result);
78          assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
79          assertTrue("Callback never fired", callbackMade.get());
80      }
81  }