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.tck.junit4.FunctionalTestCase;
10  import org.mule.util.ClassUtils;
11  
12  import java.io.File;
13  import java.io.IOException;
14  import java.net.URL;
15  
16  import org.apache.commons.httpclient.HttpClient;
17  import org.apache.commons.httpclient.HttpStatus;
18  import org.apache.commons.httpclient.methods.GetMethod;
19  import org.apache.commons.io.FileUtils;
20  
21  import static org.junit.Assert.assertEquals;
22  
23  public abstract class AbstractWebappsTestCase extends FunctionalTestCase
24  {
25      @Override
26      protected boolean isStartContext()
27      {
28          // prepare the test webapp before starting Mule
29          return false;
30      }
31  
32      @Override
33      protected void doSetUp() throws Exception
34      {
35          super.doSetUp();
36  
37          final URL url = ClassUtils.getClassPathRoot(getClass());
38          File webapps = new File(url.getFile(), "../webapps");
39          FileUtils.deleteDirectory(webapps);
40          webapps.mkdir();
41  
42          FileUtils.copyFile(new File(url.getFile(), "../../src/test/resources/test.war"),
43                             new File(webapps, "test.war"));
44  
45          muleContext.start();
46      }
47  
48      protected void sendRequestAndAssertCorrectResponse(String url) throws IOException
49      {
50          GetMethod method = new GetMethod(url);
51          int rc = new HttpClient().executeMethod(method);
52          assertEquals(HttpStatus.SC_OK, rc);
53          assertEquals("Hello", method.getResponseBodyAsString());
54      }
55  }
56  
57