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