1 package com.atlassian.plugin.servlet.descriptors;
2
3 import junit.framework.TestCase;
4
5 import org.dom4j.Element;
6 import org.dom4j.dom.DOMElement;
7
8 import com.atlassian.plugin.Plugin;
9 import com.atlassian.plugin.PluginParseException;
10 import com.atlassian.plugin.impl.StaticPlugin;
11
12 public class TestServletContextParamDescriptor extends TestCase
13 {
14 ServletContextParamModuleDescriptor descriptor;
15
16 @Override
17 public void setUp()
18 {
19 descriptor = new ServletContextParamModuleDescriptor();
20 }
21
22 @Override
23 public void tearDown()
24 {
25 descriptor = null;
26 }
27
28 public void testInit()
29 {
30 Plugin plugin = new StaticPlugin();
31 plugin.setKey("somekey");
32 Element e = getValidConfig();
33 descriptor.init(plugin, e);
34 }
35
36 private Element getValidConfig()
37 {
38 Element e = new DOMElement("servlet-context-param");
39 e.addAttribute("key", "key2");
40 Element paramName = new DOMElement("param-name");
41 paramName.setText("test.param.name");
42 e.add(paramName);
43 Element paramValue = new DOMElement("param-value");
44 paramValue.setText("test.param.value");
45 e.add(paramValue);
46 return e;
47 }
48
49 public void testInitWithNoParamName()
50 {
51 Plugin plugin = new StaticPlugin();
52 plugin.setKey("somekey");
53 Element e = new DOMElement("servlet-context-param");
54 e.addAttribute("key", "key2");
55 Element paramValue = new DOMElement("param-value");
56 paramValue.setText("test.param.value");
57 e.add(paramValue);
58 try
59 {
60 descriptor.init(plugin, e);
61 fail("Should have thrown exception");
62 } catch (PluginParseException ex)
63 {
64
65 }
66 }
67
68 public void testInitWithNoParamValue()
69 {
70 Plugin plugin = new StaticPlugin();
71 plugin.setKey("somekey");
72 Element e = new DOMElement("servlet-context-param");
73 e.addAttribute("key", "key2");
74 Element paramName = new DOMElement("param-name");
75 paramName.setText("test.param.name");
76 e.add(paramName);
77 try
78 {
79 descriptor.init(plugin, e);
80 fail("Should have thrown exception");
81 } catch (PluginParseException ex)
82 {
83
84 }
85 }
86 }