View Javadoc

1   /*
2    * $Id: AbstractBadConfigTestCase.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.config.spring.parsers;
12  
13  import org.mule.api.config.ConfigurationBuilder;
14  import org.mule.config.spring.SpringXmlConfigurationBuilder;
15  import org.mule.context.DefaultMuleContextFactory;
16  
17  import junit.framework.TestCase;
18  
19  import org.apache.commons.logging.Log;
20  import org.apache.commons.logging.LogFactory;
21  
22  /**
23   * A stripped-down version of FunctionalTestCase that allows us to test the parsing of a bad configuration. 
24   */
25  public abstract class AbstractBadConfigTestCase extends TestCase
26  {
27      protected final transient Log logger = LogFactory.getLog(getClass());
28  
29      public void assertErrorContains(String phrase) throws Exception
30      {
31          try 
32          {
33              parseConfig();
34              fail("expected error");
35          } 
36          catch (Exception e) 
37          {
38              logger.debug("Caught " + e);
39              assertTrue("Missing phrase '" + phrase + "' in '" + e.toString() + "'",
40                      e.toString().indexOf(phrase) > -1);
41          }
42      }
43  
44      protected void parseConfig() throws Exception
45      {
46          new DefaultMuleContextFactory().createMuleContext(getBuilder());
47      }
48  
49      protected ConfigurationBuilder getBuilder() throws Exception
50      {
51          return new SpringXmlConfigurationBuilder(getConfigResources());
52      }
53  
54      protected abstract String getConfigResources();
55  }