View Javadoc

1   package com.atlassian.plugin.osgi.factory;
2   
3   import com.atlassian.plugin.Application;
4   import com.atlassian.plugin.ModuleDescriptor;
5   import com.atlassian.plugin.ModuleDescriptorFactory;
6   import com.atlassian.plugin.PluginParseException;
7   import com.google.common.collect.ImmutableSet;
8   import junit.framework.TestCase;
9   import org.dom4j.Element;
10  import org.dom4j.tree.DefaultElement;
11  
12  import java.io.ByteArrayInputStream;
13  
14  import static org.mockito.Mockito.mock;
15  import static org.mockito.Mockito.verify;
16  import static org.mockito.Mockito.when;
17  
18  public class TestOsgiPluginXmlDescriptorParser extends TestCase
19  {
20  
21      public void testCreateModuleDescriptor() throws PluginParseException, IllegalAccessException, ClassNotFoundException, InstantiationException
22      {
23          OsgiPluginXmlDescriptorParser parser = new OsgiPluginXmlDescriptorParser(new ByteArrayInputStream("<foo/>".getBytes()), ImmutableSet.<Application>of());
24  
25          ModuleDescriptor desc = mock(ModuleDescriptor.class);
26          when(desc.getKey()).thenReturn("foo");
27          ModuleDescriptorFactory factory = mock(ModuleDescriptorFactory.class);
28          when(factory.getModuleDescriptor("foo")).thenReturn(desc);
29  
30          OsgiPlugin plugin = mock(OsgiPlugin.class);
31          Element fooElement = new DefaultElement("foo");
32          fooElement.addAttribute("key", "bob");
33          assertNotNull(parser.createModuleDescriptor(plugin, fooElement,factory));
34          verify(plugin).addModuleDescriptorElement("foo", fooElement);
35      }
36  }