View Javadoc

1   /*
2    * $Id: JettyContinuationsTwoEndpointsSinglePortTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.servlet.jetty;
12  
13  import org.mule.api.MuleException;
14  import org.mule.api.MuleMessage;
15  import org.mule.api.transformer.DataType;
16  import org.mule.module.client.MuleClient;
17  import org.mule.tck.FunctionalTestCase;
18  import org.mule.util.SystemUtils;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  public class JettyContinuationsTwoEndpointsSinglePortTestCase extends FunctionalTestCase
24  {
25  
26      /**
27       * MULE-3992: this test hangs on JDK6
28       */
29      @Override
30      protected boolean isDisabledInThisEnvironment()
31      {
32          return SystemUtils.IS_JAVA_1_6;
33      }
34  
35      protected String getConfigResources()
36      {
37          return "jetty-continuations-two-endpoints-single-port.xml";
38      }
39  
40      public void testSendToEach() throws Exception
41      {
42          sendWithResponse("http://localhost:60211/mycomponent1", "test", "mycomponent1", 10);
43          sendWithResponse("http://localhost:60211/mycomponent2", "test", "mycomponent2", 10);
44      }
45  
46      public void testSendToEachWithBadEndpoint() throws Exception
47      {
48  
49          MuleClient client = new MuleClient(muleContext);
50  
51          sendWithResponse("http://localhost:60211/mycomponent1", "test", "mycomponent1", 5);
52          sendWithResponse("http://localhost:60211/mycomponent2", "test", "mycomponent2", 5);
53  
54          MuleMessage result = client.send("http://localhost:60211/mycomponent-notfound", "test", null);
55          assertNotNull(result);
56          assertNotNull(result.getExceptionPayload());
57          final int status = result.getOutboundProperty("http.status", 0);
58          assertEquals(404, status);
59  
60          // Test that after the exception the endpoints still receive events
61          sendWithResponse("http://localhost:60211/mycomponent1", "test", "mycomponent1", 5);
62          sendWithResponse("http://localhost:60211/mycomponent2", "test", "mycomponent2", 5);
63      }
64  
65      protected void sendWithResponse(String endpoint, String message, String response, int noOfMessages)
66          throws MuleException
67      {
68          MuleClient client = new MuleClient(muleContext);
69  
70          List results = new ArrayList();
71          for (int i = 0; i < noOfMessages; i++)
72          {
73              results.add(client.send(endpoint, message, null).getPayload(DataType.BYTE_ARRAY_DATA_TYPE));
74          }
75          assertEquals(noOfMessages, results.size());
76          for (int i = 0; i < noOfMessages; i++)
77          {
78              assertEquals(response, new String((byte[])results.get(i)));
79          }
80      }
81  }