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 org.junit.Test;
7 import org.osgi.framework.Bundle;
8
9 import java.util.Hashtable;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNull;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.when;
15
16 public class TestPluginRetrievalServiceFactory {
17
18 @Test
19 public void testGetPlugin() {
20 PluginAccessor pluginAccessor = mock(PluginAccessor.class);
21 Bundle bundle = mock(Bundle.class);
22 Hashtable<String, String> headers = new Hashtable<>();
23 headers.put("Atlassian-Plugin-Key", "foo");
24 when(bundle.getHeaders()).thenReturn(headers);
25 Plugin plugin = mock(Plugin.class);
26 when(pluginAccessor.getPlugin("foo")).thenReturn(plugin);
27
28 PluginRetrievalServiceFactory factory = new PluginRetrievalServiceFactory(pluginAccessor);
29 assertEquals(plugin, ((PluginRetrievalService) factory.getService(bundle, null)).getPlugin());
30 }
31
32 @Test
33 public void testGetPluginButFrameworkBundle() {
34 PluginAccessor pluginAccessor = mock(PluginAccessor.class);
35 Bundle bundle = mock(Bundle.class);
36 Hashtable<String, String> headers = new Hashtable<>();
37 headers.put("Atlassian-Plugin-Key", "foo");
38 when(bundle.getHeaders()).thenReturn(headers);
39
40 PluginRetrievalServiceFactory factory = new PluginRetrievalServiceFactory(pluginAccessor);
41 assertNull(((PluginRetrievalService) factory.getService(bundle, null)).getPlugin());
42 }
43 }