View Javadoc

1   /*
2    * $Id: CustomConfigTestCase.java 22419 2011-07-15 03:41:06Z dirk.olmes $
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.test.integration.config;
12  
13  import org.mule.api.endpoint.ImmutableEndpoint;
14  import org.mule.api.exception.MessagingExceptionHandler;
15  import org.mule.api.transformer.Transformer;
16  import org.mule.tck.junit4.FunctionalTestCase;
17  import org.mule.tck.testmodels.mule.TestCompressionTransformer;
18  import org.mule.tck.testmodels.mule.TestConnector;
19  import org.mule.tck.testmodels.mule.TestExceptionStrategy;
20  
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertNotNull;
25  import static org.junit.Assert.assertTrue;
26  
27  public class CustomConfigTestCase extends FunctionalTestCase
28  {
29  
30      @Override
31      protected String getConfigResources()
32      {
33          return "org/mule/test/integration/config/custom-config.xml";
34      }
35  
36      @Test
37      public void testCustomEndpointConfig() throws Exception
38      {
39          ImmutableEndpoint ep = muleContext.getEndpointFactory().getOutboundEndpoint(
40              "fooEndpoint");
41          assertNotNull("fooEndpoint should not be null", ep);
42          TestFilter tf = (TestFilter)ep.getFilter();
43          assertNotNull("the filter on the endpoint should not be null", tf);
44          assertEquals(tf.getFoo(), "goo");
45          assertEquals(tf.getBar(), 12);
46      }
47  
48      @Test
49      public void testCustomConnectorConfig() throws Exception
50      {
51          TestConnector cnn = (TestConnector)muleContext.getRegistry().lookupConnector("customConnector");
52          assertNotNull("customConnector should not be null", cnn);
53          assertEquals(cnn.getSomeProperty(), "foo");
54  
55          //Test exception strategy
56          MessagingExceptionHandler es = muleContext.getRegistry().lookupModel("main").getExceptionListener();
57          assertNotNull(es);
58          assertTrue(es instanceof TestExceptionStrategy);
59          assertEquals("bar", ((TestExceptionStrategy) es).getTestProperty());
60      }
61  
62      @Test
63      public void testCustomTransformerConfig() throws Exception
64      {
65          Transformer trans = muleContext.getRegistry().lookupTransformer("testTransformer");
66          assertNotNull("testTransformer should not be null", trans);
67          assertTrue("Transformer should be an instance of TestCompressionTransformer", trans instanceof TestCompressionTransformer);
68          assertEquals(((TestCompressionTransformer)trans).getBeanProperty1(), "soo");
69          assertEquals(((TestCompressionTransformer)trans).getBeanProperty2(), 12345);
70      }
71  
72  }