View Javadoc

1   /*
2    * $Id: AppBloodhoundTestCase.java 22140 2011-06-07 14:43:17Z aperepel $
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.launcher;
12  
13  import org.mule.api.config.MuleProperties;
14  import org.mule.module.launcher.descriptor.ApplicationDescriptor;
15  import org.mule.module.launcher.plugin.PluginClasspath;
16  import org.mule.module.launcher.plugin.PluginDescriptor;
17  import org.mule.tck.AbstractMuleTestCase;
18  import org.mule.util.IOUtils;
19  
20  import java.io.File;
21  import java.io.FileOutputStream;
22  import java.io.InputStream;
23  import java.util.Set;
24  
25  public class AppBloodhoundTestCase extends AbstractMuleTestCase
26  {
27  
28      private File muleHome;
29      private File appsDir;
30  
31      public void testPlugin() throws Exception
32      {
33          // set up some mule home structure
34          final String tmpDir = System.getProperty("java.io.tmpdir");
35          muleHome = new File(tmpDir, getClass().getSimpleName() + System.currentTimeMillis());
36          appsDir = new File(muleHome, "apps");
37          appsDir.mkdirs();
38          System.setProperty(MuleProperties.MULE_HOME_DIRECTORY_PROPERTY, muleHome.getCanonicalPath());
39  
40          final String appName = "app-with-plugin";
41          final File appDir = new File(appsDir, appName);
42          appDir.mkdirs();
43          final File pluginDir = new File(appDir, "plugins");
44          pluginDir.mkdirs();
45          final InputStream sourcePlugin = IOUtils.getResourceAsStream("plugins/groovy-plugin.zip", getClass());
46          IOUtils.copy(sourcePlugin, new FileOutputStream(new File(pluginDir, "groovy-plugin.zip")));
47  
48          AppBloodhound hound = new DefaultAppBloodhound();
49          ApplicationDescriptor desc = hound.fetch(appName);
50          assertNotNull(desc);
51          Set<PluginDescriptor> plugins = desc.getPlugins();
52          assertNotNull(plugins);
53          assertEquals(1, plugins.size());
54  
55          final PluginDescriptor plugin = plugins.iterator().next();
56          assertEquals("groovy-plugin", plugin.getName());
57          final PluginClasspath cp = plugin.getClasspath();
58          assertEquals(2, cp.toURLs().length);
59          assertTrue(cp.getRuntimeLibs()[0].toExternalForm().endsWith("groovy-all-1.8.0.jar"));
60      }
61  }