1   /*
2    * $Id: XmlOutboundNamespaceHandlerTestCase.java 11195 2008-03-06 04:13:01Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.module.xml.config;
12  
13  import org.mule.api.service.Service;
14  import org.mule.module.xml.routing.FilteringXmlMessageSplitter;
15  import org.mule.module.xml.routing.RoundRobinXmlSplitter;
16  import org.mule.routing.outbound.AbstractOutboundRouter;
17  import org.mule.tck.FunctionalTestCase;
18  
19  import java.util.List;
20  import java.util.Map;
21  
22  public class XmlOutboundNamespaceHandlerTestCase extends FunctionalTestCase
23  {
24  
25      protected String getConfigResources()
26      {
27          return "org/mule/module/xml/xml-outbound-namespace-test.xml";
28      }
29  
30      public void testMessageSplitter()
31      {
32          FilteringXmlMessageSplitter splitter =
33                  (FilteringXmlMessageSplitter) getRouter("fancy config splitter", FilteringXmlMessageSplitter.class);
34          assertOk(splitter, AbstractOutboundRouter.ENABLE_CORRELATION_ALWAYS);
35      }
36  
37      public void testRoundRobin()
38      {
39          RoundRobinXmlSplitter splitter =
40                  (RoundRobinXmlSplitter) getRouter("fancy config round robin", RoundRobinXmlSplitter.class);
41          assertOk(splitter, AbstractOutboundRouter.ENABLE_CORRELATION_IF_NOT_SET);
42          assertTrue(splitter.isEnableEndpointFiltering());
43      }
44  
45      protected Object getRouter(String name, Class clazz)
46      {
47          Service service = muleContext.getRegistry().lookupService(name);
48          List routers = service.getOutboundRouter().getRouters();
49          assertEquals(1, routers.size());
50          assertTrue(routers.get(0).getClass().getName(), clazz.isAssignableFrom(routers.get(0).getClass()));
51          return routers.get(0);
52      }
53  
54      protected void assertOk(FilteringXmlMessageSplitter splitter, int correln)
55      {
56          assertEquals(correln, splitter.getEnableCorrelation());
57          assertEquals("external", splitter.getExternalSchemaLocation());
58          assertEquals("/expression", splitter.getSplitExpression());
59          assertTrue(splitter.isHonorSynchronicity());
60          assertTrue(splitter.isValidateSchema());
61          Map namespaces = splitter.getNamespaces();
62          assertEquals(1, namespaces.size());
63          assertEquals("foo", namespaces.get("bar"));
64      }
65  
66  }