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