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.module.xml.config;
8   
9   import org.mule.api.routing.OutboundRouterCollection;
10  import org.mule.api.service.Service;
11  import org.mule.module.xml.routing.XmlMessageSplitter;
12  import org.mule.routing.CorrelationMode;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  
15  import java.util.List;
16  import java.util.Map;
17  
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertEquals;
21  import static org.junit.Assert.assertTrue;
22  
23  public class XmlOutboundNamespaceHandlerTestCase extends FunctionalTestCase
24  {
25  
26      @Override
27      protected String getConfigResources()
28      {
29          return "org/mule/module/xml/xml-outbound-namespace-test.xml";
30      }
31  
32      @Test
33      public void testMessageSplitter()
34      {
35          XmlMessageSplitter splitter =
36                  (XmlMessageSplitter) getRouter("fancy config splitter", XmlMessageSplitter.class);
37  
38          assertEquals(CorrelationMode.ALWAYS, splitter.getEnableCorrelation());
39          assertEquals("external", splitter.getExternalSchemaLocation());
40          assertEquals("/expression", splitter.getSplitExpression());
41          assertTrue(splitter.isDeterministic());
42          assertTrue(splitter.isValidateSchema());
43          Map namespaces = splitter.getNamespaces();
44          assertEquals(1, namespaces.size());
45          assertEquals("foo", namespaces.get("bar"));
46      }
47  
48      protected Object getRouter(String name, Class clazz)
49      {
50          Service service = muleContext.getRegistry().lookupService(name);
51          List routers = ((OutboundRouterCollection) service.getOutboundMessageProcessor()).getRoutes();
52          assertEquals(1, routers.size());
53          assertTrue(routers.get(0).getClass().getName(), clazz.isAssignableFrom(routers.get(0).getClass()));
54          return routers.get(0);
55      }
56  
57  }