1 package com.atlassian.plugins.codegen.modules.jira;
2
3 import com.atlassian.plugins.codegen.AbstractModuleCreatorTestCase;
4 import com.atlassian.plugins.codegen.ResourceFile;
5 import com.atlassian.plugins.codegen.SourceFile;
6 import com.atlassian.plugins.codegen.modules.PluginModuleCreator;
7
8 import org.dom4j.Document;
9 import org.dom4j.DocumentHelper;
10 import org.junit.Before;
11 import org.junit.Test;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16
17
18
19
20 public abstract class AbstractTabPanelTest extends AbstractModuleCreatorTestCase<TabPanelProperties>
21 {
22 public static final String PACKAGE_NAME = "com.atlassian.plugins.jira.tabpanels";
23
24 public AbstractTabPanelTest(String type, PluginModuleCreator<TabPanelProperties> creator)
25 {
26 super(type, creator);
27 }
28
29 @Before
30 public void setupObjects() throws Exception
31 {
32 setProps(new TabPanelProperties(PACKAGE_NAME + ".MyTabPanel"));
33 props.setIncludeExamples(false);
34 }
35
36 @Test
37 public void customClassFileIsGenerated() throws Exception
38 {
39 props.setUseCustomClass(true);
40
41 getSourceFile(PACKAGE_NAME, "MyTabPanel");
42 }
43
44 @Test
45 public void customUnitTestFileIsGenerated() throws Exception
46 {
47 props.setUseCustomClass(true);
48
49 getTestSourceFile(PACKAGE_NAME, "MyTabPanelTest");
50 }
51
52 @Test
53 public void customTemplateFileIsGenerated() throws Exception
54 {
55 props.setUseCustomClass(true);
56
57 getResourceFile("templates/tabpanels", "my-tab-panel.vm");
58 }
59
60 @Test
61 public void genericClassFilesAreNotGenerated() throws Exception
62 {
63 props.setUseCustomClass(false);
64
65 assertTrue(getChangesetForModule(SourceFile.class).isEmpty());
66 }
67
68 @Test
69 public void customModuleHasClass() throws Exception
70 {
71 props.setUseCustomClass(true);
72
73 assertEquals(PACKAGE_NAME + ".MyTabPanel", getGeneratedModule().attributeValue("class"));
74 }
75
76 @Test
77 public void genericModuleHasGenericClass() throws Exception
78 {
79 props.setFullyQualifiedClassname(ComponentTabPanelModuleCreator.FQ_GENERIC_CLASS);
80 props.setUseCustomClass(true);
81
82 assertEquals(ComponentTabPanelModuleCreator.FQ_GENERIC_CLASS, getGeneratedModule().attributeValue("class"));
83 }
84
85 @Test
86 public void moduleHasOrder() throws Exception
87 {
88 props.setOrder(10);
89
90 assertEquals("10", getGeneratedModule().selectSingleNode("order").getText());
91 }
92
93 @Test
94 public void labelIsAdded() throws Exception
95 {
96 props.setLabel(label);
97
98 assertNotNull(getGeneratedModule().selectSingleNode("label"));
99 }
100
101 @Test
102 public void labelHasI18nKey() throws Exception
103 {
104 props.setLabel(label);
105
106 assertEquals(label.getKey(), getGeneratedModule().selectSingleNode("label/@key").getText());
107 }
108
109 @Test
110 public void labelHasParams() throws Exception
111 {
112 props.setLabel(label);
113
114 assertEquals(2, getGeneratedModule().selectNodes("label/param").size());
115 }
116
117 @Test
118 public void labelParam0HasName() throws Exception
119 {
120 props.setLabel(label);
121
122 assertEquals("param0", getGeneratedModule().selectSingleNode("label/param[1]/@name").getText());
123 }
124
125 @Test
126 public void labelParam0HasValue() throws Exception
127 {
128 props.setLabel(label);
129
130 assertEquals(label.getParams().get("param0"), getGeneratedModule().selectSingleNode("label/param[1]/@value").getText());
131 }
132
133 @Test
134 public void labelParam1HasName() throws Exception
135 {
136 props.setLabel(label);
137
138 assertEquals("param1", getGeneratedModule().selectSingleNode("label/param[2]/@name").getText());
139 }
140
141 @Test
142 public void labelParam1HasValue() throws Exception
143 {
144 props.setLabel(label);
145
146 assertEquals(label.getParams().get("param1"), getGeneratedModule().selectSingleNode("label/param[2]/@value").getText());
147 }
148
149 @Test
150 public void labelStringIsAddedToI18nProperties() throws Exception
151 {
152 props.setLabel(label);
153
154 getI18nString(label.getKey(), label.getValue());
155 }
156
157 @Test
158 public void labelIsUsedInViewTemplate() throws Exception
159 {
160 props.setLabel(label);
161 props.setUseCustomClass(true);
162
163 Document viewDoc = DocumentHelper.parseText(getChangesetForModule(ResourceFile.class).get(0).getContent());
164 assertNotNull(viewDoc.selectSingleNode("/div/h3[text() = \"$i18n.getText('" + label.getKey() + "')\"]"));
165 }
166 }