View Javadoc

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