View Javadoc

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