View Javadoc
1   package com.atlassian.plugin.servlet.descriptors;
2   
3   import com.atlassian.plugin.Plugin;
4   import com.atlassian.plugin.PluginParseException;
5   import com.atlassian.plugin.impl.StaticPlugin;
6   import org.dom4j.Element;
7   import org.dom4j.dom.DOMElement;
8   import org.junit.Before;
9   import org.junit.Rule;
10  import org.junit.Test;
11  import org.junit.rules.ExpectedException;
12  
13  public class TestServletContextParamDescriptor {
14      @Rule
15      public final ExpectedException expectedException = ExpectedException.none();
16  
17      ServletContextParamModuleDescriptor descriptor;
18  
19      @Before
20      public void setUp() {
21          descriptor = new ServletContextParamModuleDescriptor();
22      }
23  
24      @Test
25      public void testInit() {
26          Plugin plugin = new StaticPlugin();
27          plugin.setKey("somekey");
28          Element e = getValidConfig();
29          descriptor.init(plugin, e);
30      }
31  
32      private Element getValidConfig() {
33          Element e = new DOMElement("servlet-context-param");
34          e.addAttribute("key", "key2");
35          Element paramName = new DOMElement("param-name");
36          paramName.setText("test.param.name");
37          e.add(paramName);
38          Element paramValue = new DOMElement("param-value");
39          paramValue.setText("test.param.value");
40          e.add(paramValue);
41          return e;
42      }
43  
44      @Test
45      public void testInitWithNoParamName() {
46          Plugin plugin = new StaticPlugin();
47          plugin.setKey("somekey");
48          Element e = new DOMElement("servlet-context-param");
49          e.addAttribute("key", "key2");
50          Element paramValue = new DOMElement("param-value");
51          paramValue.setText("test.param.value");
52          e.add(paramValue);
53          expectedException.expect(PluginParseException.class);
54          descriptor.init(plugin, e);
55      }
56  
57      @Test
58      public void testInitWithNoParamValue() {
59          Plugin plugin = new StaticPlugin();
60          plugin.setKey("somekey");
61          Element e = new DOMElement("servlet-context-param");
62          e.addAttribute("key", "key2");
63          Element paramName = new DOMElement("param-name");
64          paramName.setText("test.param.name");
65          e.add(paramName);
66          expectedException.expect(PluginParseException.class);
67          descriptor.init(plugin, e);
68      }
69  }