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;
8   
9   import org.mule.tck.junit4.AbstractMuleTestCase;
10  import org.mule.util.ClassUtils;
11  import org.mule.util.FilenameUtils;
12  
13  import org.junit.Test;
14  
15  import static org.junit.Assert.assertEquals;
16  import static org.junit.Assert.assertTrue;
17  
18  public class MuleServerTestCase extends AbstractMuleTestCase
19  {
20  
21      @Test
22      public void testMuleServer() throws Exception
23      {
24          MuleServer muleServer = new MuleServer();
25          assertEquals(ClassUtils.getResource("mule-config.xml", MuleServer.class).toString(),
26              muleServer.getConfigurationResources());
27          assertEquals(MuleServer.CLASSNAME_DEFAULT_CONFIG_BUILDER, MuleServer.getConfigBuilderClassName());
28          muleServer.initialize();
29      }
30  
31      @Test
32      public void testMuleServerResource() throws Exception
33      {
34          MuleServer muleServer = new MuleServer("org/mule/test/spring/config1/test-xml-mule2-config.xml");
35          assertEquals("org/mule/test/spring/config1/test-xml-mule2-config.xml", muleServer.getConfigurationResources());
36          assertEquals(MuleServer.CLASSNAME_DEFAULT_CONFIG_BUILDER, MuleServer.getConfigBuilderClassName());
37          muleServer.initialize();
38      }
39  
40      @Test
41      public void testMuleServerConfigArg() throws Exception
42      {
43          MuleServer muleServer = new MuleServer(new String[]{"-config",
44              "org/mule/test/spring/config1/test-xml-mule2-config.xml"});
45          assertEquals("org/mule/test/spring/config1/test-xml-mule2-config.xml", muleServer.getConfigurationResources());
46          assertEquals(MuleServer.CLASSNAME_DEFAULT_CONFIG_BUILDER, MuleServer.getConfigBuilderClassName());
47          muleServer.initialize();
48      }
49  
50      @Test
51      public void testMuleServerMultipleSpringConfigArgs() throws Exception
52      {
53          MuleServer muleServer = new MuleServer(new String[]{"-config",
54              "mule-config.xml,org/mule/test/spring/config1/test-xml-mule2-config.xml"});
55          assertEquals("mule-config.xml,org/mule/test/spring/config1/test-xml-mule2-config.xml",
56              muleServer.getConfigurationResources());
57          assertEquals(MuleServer.CLASSNAME_DEFAULT_CONFIG_BUILDER, MuleServer.getConfigBuilderClassName());
58          muleServer.initialize();
59      }
60  
61      @Test
62      public void testMuleServerBuilerArg() throws Exception
63      {
64          MuleServer muleServer = new MuleServer(new String[]{"-builder",
65              "org.mule.config.spring.SpringXmlConfigurationBuilder"});
66          assertEquals(ClassUtils.getResource("mule-config.xml", MuleServer.class).toString(),
67              muleServer.getConfigurationResources());
68          assertEquals("org.mule.config.spring.SpringXmlConfigurationBuilder", MuleServer.getConfigBuilderClassName());
69          muleServer.initialize();
70      }
71  
72      @Test
73      public void testMuleServerSpringBuilerArg() throws Exception
74      {
75          MuleServer muleServer = new MuleServer(new String[]{"-builder", "spring"});
76          assertEquals(ClassUtils.getResource("mule-config.xml", MuleServer.class).toString(),
77              muleServer.getConfigurationResources());
78          assertEquals("org.mule.config.spring.SpringXmlConfigurationBuilder", MuleServer.getConfigBuilderClassName());
79          muleServer.initialize();
80      }
81      
82      @Test
83      public void testMuleServerAppConfig() throws Exception
84      {
85          MuleServer muleServer = new MuleServer(new String[]{
86              "-config",
87              "mule-config.xml",
88              "-appconfig",
89              "org/mule/test/spring/config1/test-app-config.properties"});
90          muleServer.initialize();
91          final String workingDirectory = MuleServer.muleContext.getConfiguration().getWorkingDirectory();
92          assertTrue(FilenameUtils.separatorsToUnix(workingDirectory).endsWith("/target/.appT"));
93      }
94  }