1   package com.atlassian.plugin.osgi.bridge;
2   
3   import com.atlassian.plugin.Plugin;
4   import com.atlassian.plugin.PluginAccessor;
5   import com.atlassian.plugin.osgi.bridge.external.PluginRetrievalService;
6   import junit.framework.TestCase;
7   import org.osgi.framework.Bundle;
8   
9   import java.util.Hashtable;
10  
11  import static org.mockito.Mockito.mock;
12  import static org.mockito.Mockito.when;
13  
14  /**
15   *
16   */
17  public class TestPluginRetrievalServiceFactory extends TestCase
18  {
19      public void testGetPlugin()
20      {
21          PluginAccessor pluginAccessor = mock(PluginAccessor.class);
22          Bundle bundle = mock(Bundle.class);
23          Hashtable headers = new Hashtable();
24          headers.put("Atlassian-Plugin-Key", "foo");
25          when(bundle.getHeaders()).thenReturn(headers);
26          Plugin plugin = mock(Plugin.class);
27          when(pluginAccessor.getPlugin("foo")).thenReturn(plugin);
28  
29          PluginRetrievalServiceFactory factory = new PluginRetrievalServiceFactory(pluginAccessor);
30          assertEquals(plugin, ((PluginRetrievalService)factory.getService(bundle, null)).getPlugin());
31      }
32  
33      public void testGetPluginButFrameworkBundle()
34      {
35          PluginAccessor pluginAccessor = mock(PluginAccessor.class);
36          Bundle bundle = mock(Bundle.class);
37          Hashtable headers = new Hashtable();
38          headers.put("Atlassian-Plugin-Key", "foo");
39          when(bundle.getHeaders()).thenReturn(headers);
40  
41          PluginRetrievalServiceFactory factory = new PluginRetrievalServiceFactory(pluginAccessor);
42          assertNull(((PluginRetrievalService)factory.getService(bundle, null)).getPlugin());
43      }
44  }