View Javadoc
1   package it.com.atlassian.plugin.osgi;
2   
3   import com.atlassian.plugin.ModuleDescriptor;
4   import com.atlassian.plugin.PluginInternal;
5   import com.atlassian.plugin.test.PluginJarBuilder;
6   import org.dom4j.Element;
7   import org.dom4j.dom.DOMElement;
8   
9   import static org.hamcrest.Matchers.is;
10  import static org.hamcrest.Matchers.notNullValue;
11  import static org.junit.Assert.assertThat;
12  
13  /**
14   * Tests for non-support of dynamic modules for OsgiBundlePlugin.
15   *
16   * Tests wiring from DefaultPluginManager <-> ScanningPluginLoader <-> OsgiBundleFactory
17   */
18  public class TestOsgiBundlePluginDynamicModules extends AbstractTestDynamicModules {
19      private static final String BUNDLE_SYMBOLIC_NAME = "bundleSymbolicName";
20      private static final String BUNDLE_VERSION = "1.0";
21  
22      private static final String PLUGIN_NAME = "pluginName";
23      private static final String PLUGIN_KEY = BUNDLE_SYMBOLIC_NAME + "-" + BUNDLE_VERSION;
24  
25      private static final String MODULE_KEY = "moduleKey";
26      private static final String MODULE_CLASS = "moduleClass";
27  
28      @Override
29      public void setUp() throws Exception {
30          super.setUp();
31  
32          new PluginJarBuilder(PLUGIN_NAME)
33                  .addFormattedResource("META-INF/MANIFEST.MF",
34                          "Manifest-Version: 1.0",
35                          "Bundle-SymbolicName: " + BUNDLE_SYMBOLIC_NAME,
36                          "Bundle-Version: " + BUNDLE_VERSION)
37                  .addJava(MODULE_CLASS, "public class " + MODULE_CLASS + " {}")
38                  .build(pluginsDir);
39          initPluginManager();
40  
41          plugin = ((PluginInternal) pluginAccessor.getPlugin(PLUGIN_KEY));
42          assertThat("could not retrieve the newly created plugin from pluginManager", plugin, notNullValue());
43  
44          assertThat(plugin.getKey(), is(PLUGIN_KEY));
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  }