View Javadoc
1   package it.com.atlassian.plugin.osgi;
2   
3   import com.atlassian.plugin.JarPluginArtifact;
4   import com.atlassian.plugin.ModuleDescriptor;
5   import com.atlassian.plugin.PluginInternal;
6   import com.atlassian.plugin.test.PluginJarBuilder;
7   import org.dom4j.Element;
8   import org.dom4j.dom.DOMElement;
9   import org.junit.Before;
10  
11  import java.io.File;
12  
13  import static org.hamcrest.Matchers.contains;
14  import static org.hamcrest.Matchers.notNullValue;
15  import static org.hamcrest.core.Is.is;
16  import static org.junit.Assert.assertThat;
17  
18  /**
19   * Tests for addition, enumeration and removal of dynamic modules for an OsgiPlugin
20   *
21   * Tests wiring from DefaultPluginManager <-> ScanningPluginLoader <-> OsgiPluginFactory
22   */
23  public class TestOsgiPluginDynamicModules extends AbstractTestDynamicModules {
24      private static final String PLUGIN_KEY = "pluginKey";
25      private static final String PLUGIN_NAME = "pluginName";
26      private static final String PLUGIN_VERSION = "3.2.1";
27  
28      private static final String MODULE_KEY = "moduleKey";
29      private static final String MODULE_CLASS = "moduleClass";
30  
31      @Override
32      @Before
33      public void setUp() throws Exception {
34          super.setUp();
35  
36          final File pluginJar = new PluginJarBuilder(PLUGIN_NAME)
37                  .addPluginInformation(PLUGIN_KEY, PLUGIN_NAME, PLUGIN_VERSION)
38                  .addJava(MODULE_CLASS, "public class " + MODULE_CLASS + " {}")
39                  .build();
40          initPluginManager(null);
41  
42          assertThat(pluginController.installPlugins(new JarPluginArtifact(pluginJar)), contains(PLUGIN_KEY));
43  
44          plugin = ((PluginInternal) pluginAccessor.getPlugin(PLUGIN_KEY));
45          assertThat("could not retrieve the newly created plugin from pluginManager", plugin, notNullValue());
46      }
47  
48      @Override
49      ModuleDescriptor addModule() {
50          // add a component which uses a class in the plugin
51          final Element e = new DOMElement("component");
52          e.addAttribute("key", MODULE_KEY);
53          e.addAttribute("class", MODULE_CLASS);
54          return pluginController.addDynamicModule(plugin, e);
55      }
56  
57      @Override
58      String getPluginKey() {
59          return PLUGIN_KEY;
60      }
61  
62      @Override
63      String getModuleKey() {
64          return MODULE_KEY;
65      }
66  }