1 package com.atlassian.plugins.codegen.modules.common.web;
2
3 import org.junit.Before;
4 import org.junit.Test;
5
6 import static org.junit.Assert.assertEquals;
7 import static org.junit.Assert.assertNotNull;
8
9
10
11
12 public class WebSectionTest extends AbstractWebFragmentTest<WebSectionProperties>
13 {
14 public static final String CUSTOM_LOCATION = "system.admin/mysection";
15
16 public WebSectionTest()
17 {
18 super("web-section", new WebSectionModuleCreator());
19 }
20
21 @Before
22 public void setupProps() throws Exception
23 {
24 setProps(new WebSectionProperties(MODULE_NAME, CUSTOM_LOCATION));
25 props.setIncludeExamples(false);
26 }
27
28 @Test
29 public void moduleHasDefaultKey() throws Exception
30 {
31 assertEquals(MODULE_KEY, getGeneratedModule().attributeValue("key"));
32 }
33
34 @Test
35 public void moduleHasLocation() throws Exception
36 {
37 assertEquals(CUSTOM_LOCATION, getGeneratedModule().attributeValue("location"));
38 }
39
40 @Test
41 public void moduleHasDefaultWeight() throws Exception
42 {
43 assertEquals("1000", getGeneratedModule().attributeValue("weight"));
44 }
45
46 @Test
47 public void moduleHasSpecifiedWeight() throws Exception
48 {
49 props.setWeight(20);
50
51 assertEquals("20", getGeneratedModule().attributeValue("weight"));
52 }
53
54 @Test
55 public void labelIsAdded() throws Exception
56 {
57 props.setLabel(label);
58
59 assertNotNull(getGeneratedModule().selectSingleNode("label"));
60 }
61
62 @Test
63 public void labelHasI18nKey() throws Exception
64 {
65 props.setLabel(label);
66
67 assertEquals(label.getKey(), getGeneratedModule().selectSingleNode("label/@key").getText());
68 }
69
70 @Test
71 public void labelHasParams() throws Exception
72 {
73 props.setLabel(label);
74
75 assertEquals(2, getGeneratedModule().selectNodes("label/param").size());
76 }
77
78 @Test
79 public void labelParam0HasName() throws Exception
80 {
81 props.setLabel(label);
82
83 assertEquals("param0", getGeneratedModule().selectSingleNode("label/param[1]/@name").getText());
84 }
85
86 @Test
87 public void labelParam0HasValue() throws Exception
88 {
89 props.setLabel(label);
90
91 assertEquals(label.getParams().get("param0"), getGeneratedModule().selectSingleNode("label/param[1]/@value").getText());
92 }
93
94 @Test
95 public void labelParam1HasName() throws Exception
96 {
97 props.setLabel(label);
98
99 assertEquals("param1", getGeneratedModule().selectSingleNode("label/param[2]/@name").getText());
100 }
101
102 @Test
103 public void labelParam1HasValue() throws Exception
104 {
105 props.setLabel(label);
106
107 assertEquals(label.getParams().get("param1"), getGeneratedModule().selectSingleNode("label/param[2]/@value").getText());
108 }
109
110 @Test
111 public void labelStringIsAddedToI18nProperties() throws Exception
112 {
113 props.setLabel(label);
114
115 assertEquals(label.getValue(), getChangesetForModule().getI18nProperties().get(label.getKey()));
116 }
117
118 @Test
119 public void paramsAreAdded() throws Exception
120 {
121 createParams();
122
123 assertEquals(2, getGeneratedModule().selectNodes("param").size());
124 }
125
126 @Test
127 public void param0HasValue() throws Exception
128 {
129 createParams();
130
131 assertEquals("true", getGeneratedModule().selectSingleNode("param[@name='isAwesomeSection']/@value").getText());
132 }
133
134 @Test
135 public void param1HasValue() throws Exception
136 {
137 createParams();
138
139 assertEquals("false", getGeneratedModule().selectSingleNode("param[@name='isSuperAwesome']/@value").getText());
140 }
141
142 @Test
143 public void tooltipIsAdded() throws Exception
144 {
145 props.setTooltip(tooltip);
146
147 assertNotNull(getGeneratedModule().selectSingleNode("tooltip"));
148 }
149
150 @Test
151 public void tooltipHasKey() throws Exception
152 {
153 props.setTooltip(tooltip);
154
155 assertEquals(tooltip.getKey(), getGeneratedModule().selectSingleNode("tooltip/@key").getText());
156 }
157
158 @Test
159 public void tooltipStringIsAddedToI18nProperties() throws Exception
160 {
161 props.setTooltip(tooltip);
162
163 assertEquals(tooltip.getValue(), getChangesetForModule().getI18nProperties().get(tooltip.getKey()));
164 }
165
166 protected void createParams()
167 {
168 props.addParam("isAwesomeSection", "true");
169 props.addParam("isSuperAwesome", "false");
170 }
171 }