View Javadoc

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