View Javadoc

1   package com.atlassian.plugin.osgi.factory;
2   
3   import junit.framework.TestCase;
4   import com.atlassian.plugin.osgi.container.OsgiContainerManager;
5   import com.atlassian.plugin.PluginArtifact;
6   import static org.mockito.Mockito.mock;
7   import static org.mockito.Mockito.when;
8   import org.osgi.framework.Bundle;
9   
10  import java.util.Hashtable;
11  import java.util.Dictionary;
12  
13  public class TestOsgiPluginUninstalledHelper extends TestCase
14  {
15      private String key = "key";
16      private OsgiContainerManager mgr;
17      private OsgiPluginUninstalledHelper helper;
18  
19      @Override
20       protected void setUp() throws Exception
21      {
22          super.setUp();
23          PluginArtifact pluginArtifact = mock(PluginArtifact.class);
24          mgr = mock(OsgiContainerManager.class);
25          helper = new OsgiPluginUninstalledHelper(key, mgr, pluginArtifact);
26      }
27  
28      public void testInstall()
29      {
30          Dictionary dict = new Hashtable();
31          dict.put(OsgiPlugin.ATLASSIAN_PLUGIN_KEY, key);
32          Bundle bundle = mock(Bundle.class);
33          when(bundle.getHeaders()).thenReturn(dict);
34          when(bundle.getSymbolicName()).thenReturn(key);
35          when(mgr.installBundle(null)).thenReturn(bundle);
36          assertEquals(bundle, helper.install());
37  
38      }
39  
40      public void testInstallDifferentSymbolicName()
41      {
42          Dictionary dict = new Hashtable();
43          Bundle bundle = mock(Bundle.class);
44          when(bundle.getHeaders()).thenReturn(dict);
45          when(bundle.getSymbolicName()).thenReturn("bar");
46          when(mgr.installBundle(null)).thenReturn(bundle);
47          try
48          {
49              helper.install();
50              fail();
51          }
52          catch (IllegalArgumentException ex)
53          {
54              //test passed
55          }
56      }
57  
58      public void testInstallDifferentSymbolicNameButAltassianKeyFound()
59      {
60          Dictionary dict = new Hashtable();
61          dict.put(OsgiPlugin.ATLASSIAN_PLUGIN_KEY, key);
62          Bundle bundle = mock(Bundle.class);
63          when(bundle.getHeaders()).thenReturn(dict);
64          when(bundle.getSymbolicName()).thenReturn("bar");
65          when(mgr.installBundle(null)).thenReturn(bundle);
66          try
67          {
68              helper.install();
69              // test passed
70          }
71          catch (IllegalArgumentException ex)
72          {
73              fail();
74          }
75      }
76  }