1 package com.atlassian.plugin.web.model;
2
3 import com.atlassian.plugin.Plugin;
4 import com.atlassian.plugin.PluginAccessor;
5 import com.atlassian.plugin.web.renderer.WebPanelRenderer;
6 import com.google.common.collect.ImmutableList;
7 import junit.framework.TestCase;
8
9 import java.util.Collections;
10
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.when;
13
14 public class ResourceTemplateWebPanelTest extends TestCase
15 {
16 public void testGetHtml()
17 {
18 final PluginAccessor accessorMock = mock(PluginAccessor.class);
19 when(accessorMock.getEnabledModulesByClass(WebPanelRenderer.class)).thenReturn(Collections.<WebPanelRenderer>emptyList());
20 final Plugin plugin = mock(Plugin.class);
21 when(plugin.getClassLoader()).thenReturn(this.getClass().getClassLoader());
22
23 final ResourceTemplateWebPanel webPanel = new ResourceTemplateWebPanel(accessorMock);
24 webPanel.setPlugin(plugin);
25 webPanel.setResourceType("static");
26 webPanel.setResourceFilename("ResourceTemplateWebPanelTest.txt");
27
28 assertTrue(webPanel.getHtml(Collections.<String, Object>emptyMap())
29 .contains("This file is used as web panel contents in unit tests."));
30 }
31
32 public void testUnsupportedResourceType()
33 {
34 final PluginAccessor accessorMock = mock(PluginAccessor.class);
35 final WebPanelRenderer renderer = mock(WebPanelRenderer.class);
36 when(renderer.getResourceType()).thenReturn("velocity");
37 when(accessorMock.getEnabledModulesByClass(WebPanelRenderer.class)).thenReturn(ImmutableList.of(renderer));
38 final Plugin plugin = mock(Plugin.class);
39 when(plugin.getClassLoader()).thenReturn(this.getClass().getClassLoader());
40
41 final ResourceTemplateWebPanel webPanel = new ResourceTemplateWebPanel(accessorMock);
42 webPanel.setPlugin(plugin);
43 webPanel.setResourceType("unsupported-type");
44 webPanel.setResourceFilename("ResourceTemplateWebPanelTest.txt");
45
46 final String result = webPanel.getHtml(Collections.<String, Object>emptyMap());
47 assertNotNull(result);
48 assertTrue(result.toLowerCase().contains("error"));
49 }
50 }