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 public void testGetPlugin() {
19 PluginAccessor pluginAccessor = mock(PluginAccessor.class);
20 Bundle bundle = mock(Bundle.class);
21 Hashtable headers = new Hashtable();
22 headers.put("Atlassian-Plugin-Key", "foo");
23 when(bundle.getHeaders()).thenReturn(headers);
24 Plugin plugin = mock(Plugin.class);
25 when(pluginAccessor.getPlugin("foo")).thenReturn(plugin);
26
27 PluginRetrievalServiceFactory factory = new PluginRetrievalServiceFactory(pluginAccessor);
28 assertEquals(plugin, ((PluginRetrievalService) factory.getService(bundle, null)).getPlugin());
29 }
30
31 public void testGetPluginButFrameworkBundle() {
32 PluginAccessor pluginAccessor = mock(PluginAccessor.class);
33 Bundle bundle = mock(Bundle.class);
34 Hashtable headers = new Hashtable();
35 headers.put("Atlassian-Plugin-Key", "foo");
36 when(bundle.getHeaders()).thenReturn(headers);
37
38 PluginRetrievalServiceFactory factory = new PluginRetrievalServiceFactory(pluginAccessor);
39 assertNull(((PluginRetrievalService) factory.getService(bundle, null)).getPlugin());
40 }
41 }