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