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.boot;
8   
9   import org.mule.tck.junit4.AbstractMuleTestCase;
10  import org.mule.util.FileUtils;
11  import org.mule.util.SystemUtils;
12  
13  import java.io.File;
14  import java.net.URL;
15  import java.util.List;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertFalse;
21  import static org.junit.Assert.assertNotNull;
22  import static org.junit.Assert.assertTrue;
23  
24  public class DefaultMuleClassPathConfigTestCase extends AbstractMuleTestCase
25  {
26  
27      /**
28       * $MULE_BASE/lib/user folder should come before $MULE_HOME/lib/user. Note this
29       * test checks folder only, not the jars. See
30       * http://mule.mulesoft.org/jira/browse/MULE-1311 for more details.
31       * 
32       * @throws Exception in case of any error
33       */
34      @Test
35      public void testMuleBaseUserFolderOverridesMuleHome() throws Exception
36      {
37          final File tempDir = SystemUtils.getJavaIoTmpDir();
38          final long now = System.currentTimeMillis();
39          final File currentTestFolder = new File(tempDir, "mule_test_delete_me_" + now);
40  
41          File testMuleHome = new File(currentTestFolder, "mule_home");
42          File testMuleBase = new File(currentTestFolder, "mule_base");
43  
44          try
45          {
46              assertTrue("Couldn't create test Mule home folder.", testMuleHome.mkdirs());
47              assertTrue("Couldn't create test Mule base folder.", testMuleBase.mkdirs());
48  
49              DefaultMuleClassPathConfig cp = new DefaultMuleClassPathConfig(testMuleHome, testMuleBase);
50              List urls = cp.getURLs();
51              assertNotNull("Urls shouldn't be null.", urls);
52              assertFalse("Urls shouldn't be empty.", urls.isEmpty());
53  
54              URL muleBaseUserFolder = new File(testMuleBase, DefaultMuleClassPathConfig.USER_DIR)
55                  .getAbsoluteFile().toURI().toURL();
56              String expectedMuleBaseUserFolder = muleBaseUserFolder.toExternalForm();
57              String firstUrl = ((URL) urls.get(0)).toExternalForm();
58              assertEquals("$MULE_BASE/lib/user must come first.", expectedMuleBaseUserFolder, firstUrl);
59          }
60          finally
61          {
62              // tearDown() may be too late for these calls
63              FileUtils.deleteTree(currentTestFolder);
64          }
65      }
66  
67  }