1   /*
2    * $Id: HttpsFunctionalTestCase.java 12017 2008-06-12 09:04:04Z rossmason $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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 org.mule.api.MuleEventContext;
14  import org.mule.api.MuleMessage;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.functional.EventCallback;
17  import org.mule.tck.functional.FunctionalTestComponent;
18  import org.mule.tck.testmodels.mule.TestSedaService;
19  import org.mule.transport.http.HttpConstants;
20  import org.mule.transport.http.HttpsConnector;
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
26  
27  public class HttpsFunctionalTestCase extends HttpFunctionalTestCase
28  {
29      protected String getConfigResources()
30      {
31          return "https-functional-test.xml";
32      }
33  
34      public void testSend() throws Exception
35      {
36          final TestSedaService testSedaService = (TestSedaService) muleContext.getRegistry().lookupService("testComponent");
37          FunctionalTestComponent testComponent = (FunctionalTestComponent) getComponent(testSedaService);
38          assertNotNull(testComponent);
39  
40          final AtomicBoolean callbackMade = new AtomicBoolean(false);
41          EventCallback callback = new EventCallback()
42          {
43              public void eventReceived(final MuleEventContext context, final Object component) throws Exception
44              {
45                  MuleMessage msg = context.getMessage();
46                  assertTrue(callbackMade.compareAndSet(false, true));
47                  assertNotNull(msg.getProperty(HttpsConnector.LOCAL_CERTIFICATES));
48              }
49          };
50  
51          testComponent.setEventCallback(callback);
52  
53          MuleClient client = new MuleClient();
54          Map props = new HashMap();
55          props.put(HttpConstants.HEADER_CONTENT_TYPE, "text/plain;charset=UTF-8");
56          MuleMessage result = client.send("clientEndpoint", TEST_MESSAGE, props);
57          assertNotNull(result);
58          assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
59          assertTrue("Callback never fired", callbackMade.get());
60  
61      }
62  
63  }