View Javadoc

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