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.servlet.jetty;
8   
9   import org.mule.api.MuleEventContext;
10  import org.mule.api.MuleMessage;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.functional.EventCallback;
13  import org.mule.tck.functional.FunctionalTestComponent;
14  import org.mule.tck.testmodels.mule.TestSedaService;
15  import org.mule.transport.http.HttpConstants;
16  import org.mule.transport.http.functional.HttpFunctionalTestCase;
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 JettyHttpsFunctionalTestCase extends HttpFunctionalTestCase
28  {
29  
30      @Override
31      protected String getConfigResources()
32      {
33          return "jetty-https-functional-test.xml";
34      }
35  
36      @Override
37      public void testSend() throws Exception
38      {
39          final TestSedaService testSedaService = (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(MuleEventContext context, Object component) throws Exception
47              {
48                  assertTrue(callbackMade.compareAndSet(false, true));
49                  MuleMessage msg = context.getMessage();
50                  assertEquals(TEST_MESSAGE, msg.getPayloadAsString());
51              }
52          };
53  
54          testComponent.setEventCallback(callback);
55  
56          MuleClient client = new MuleClient(muleContext);
57          Map<String, String> props = new HashMap<String, String>();
58          props.put(HttpConstants.HEADER_CONTENT_TYPE, "text/plain;charset=UTF-8");
59          MuleMessage result = client.send("clientEndpoint", TEST_MESSAGE, props);
60          assertNotNull(result);
61          assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
62          assertTrue("Callback never fired", callbackMade.get());
63      }
64  }