1   /*
2    * $Id: MockTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.examples.webapp;
12  
13  import org.mule.MuleManager;
14  import org.mule.config.ConfigurationBuilder;
15  import org.mule.config.builders.WebappMuleXmlConfigurationBuilder;
16  import org.mule.tck.TestingWorkListener;
17  import org.mule.umo.manager.UMOManager;
18  
19  import com.mockobjects.constraint.IsInstanceOf;
20  import com.mockobjects.dynamic.FullConstraintMatcher;
21  import com.mockobjects.dynamic.Mock;
22  
23  import javax.servlet.ServletContext;
24  
25  public class MockTestCase extends AbstractWebappTestCase
26  {
27      UMOManager manager = null;
28      
29      protected final void doSetUp() throws Exception
30      {
31          super.doSetUp();
32  
33          if (manager == null)
34          {
35              MuleManager.getConfiguration().setWorkListener(new TestingWorkListener());
36              ConfigurationBuilder builder = getBuilder();
37              manager = builder.configure(getConfigResources(), null);
38          }
39      }
40  
41      protected String getConfigResources()
42      {
43          return "jmx-config.xml," +
44                  "echo-config.xml," +
45                  "hello-http-config.xml," +
46                  "servlet-config.xml," +
47                  "stockquote-rest-config.xml," +
48                  "loan-broker-sync-config.xml," +
49                  "loan-broker-axis-endpoints-config.xml";
50      }
51      
52      protected ConfigurationBuilder getBuilder() throws Exception
53      {
54          Mock context = new Mock(ServletContext.class);
55          context.expectAndReturn("getResourceAsStream", new FullConstraintMatcher(new IsInstanceOf(String.class)), null);
56          context.expectAndReturn("getResourceAsStream", new FullConstraintMatcher(new IsInstanceOf(String.class)), null);
57          context.expectAndReturn("getResourceAsStream", new FullConstraintMatcher(new IsInstanceOf(String.class)), null);
58          context.expectAndReturn("getResourceAsStream", new FullConstraintMatcher(new IsInstanceOf(String.class)), null);
59          context.expectAndReturn("getResourceAsStream", new FullConstraintMatcher(new IsInstanceOf(String.class)), null);
60          context.expectAndReturn("getResourceAsStream", new FullConstraintMatcher(new IsInstanceOf(String.class)), null);
61          context.expectAndReturn("getResourceAsStream", new FullConstraintMatcher(new IsInstanceOf(String.class)), null);
62          return new WebappMuleXmlConfigurationBuilder((ServletContext) context.proxy(), null);
63      }
64  }