View Javadoc

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