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