PageRenderTime 42ms CodeModel.GetById 8ms app.highlight 29ms RepoModel.GetById 1ms app.codeStats 1ms

/plugin-module-codegen-engine/src/test/java/com/atlassian/plugins/codegen/modules/jira/ReportTest.java

https://bitbucket.org/mmeinhold/amps
Java | 272 lines | 209 code | 60 blank | 3 comment | 0 complexity | ed747dd30918a272efa0021cc3e02e7a MD5 | raw file
  1package com.atlassian.plugins.codegen.modules.jira;
  2
  3import com.atlassian.plugins.codegen.AbstractModuleCreatorTestCase;
  4import com.atlassian.plugins.codegen.modules.common.Resource;
  5
  6import org.junit.Before;
  7import org.junit.Test;
  8
  9import static junit.framework.Assert.assertEquals;
 10import static junit.framework.Assert.assertNotNull;
 11import static org.junit.Assert.assertNull;
 12
 13/**
 14 * @since 3.6
 15 */
 16public class ReportTest extends AbstractModuleCreatorTestCase<ReportProperties>
 17{
 18    public ReportTest()
 19    {
 20        super("report", new ReportModuleCreator());
 21    }
 22    
 23    @Before
 24    public void setupProps() throws Exception
 25    {
 26        setProps(new ReportProperties(PACKAGE_NAME + ".MyReport"));
 27        props.setIncludeExamples(false);
 28    }
 29
 30    @Test
 31    public void classFileIsGenerated() throws Exception
 32    {
 33        getSourceFile(PACKAGE_NAME, "MyReport");
 34    }
 35
 36    @Test
 37    public void unitTestFileIsGenerated() throws Exception
 38    {
 39        getTestSourceFile(TEST_PACKAGE_NAME, "MyReportTest");
 40    }
 41    
 42    @Test
 43    public void moduleHasDefaultKey() throws Exception
 44    {
 45        assertEquals("my-report",
 46                     getGeneratedModule().attributeValue("key"));
 47    }
 48    
 49    @Test
 50    public void moduleHasClass() throws Exception
 51    {
 52        assertEquals(PACKAGE_NAME + ".MyReport",
 53                     getGeneratedModule().attributeValue("class"));
 54    }
 55
 56    @Test
 57    public void i18nResourceIsGenerated() throws Exception
 58    {
 59        Resource resource = new Resource();
 60        resource.setName("i18n");
 61        resource.setLocation("MyReport");
 62        resource.setType("i18n");
 63
 64        props.getResources().add(resource);
 65
 66        getResourceFile("", "MyReport.properties");
 67    }
 68
 69    @Test
 70    public void labelIsAdded() throws Exception
 71    {
 72        props.setLabel(label);
 73
 74        assertNotNull(getGeneratedModule().selectSingleNode("label"));
 75    }
 76    
 77    @Test
 78    public void labelHasI18nKey() throws Exception
 79    {
 80        props.setLabel(label);
 81        
 82        assertEquals(label.getKey(), getGeneratedModule().selectSingleNode("label/@key").getText());
 83    }
 84
 85    @Test
 86    public void labelHasParams() throws Exception
 87    {
 88        props.setLabel(label);
 89        
 90        assertEquals(2, getGeneratedModule().selectNodes("label/param").size());
 91    }
 92
 93    @Test
 94    public void labelParam0HasName() throws Exception
 95    {
 96        props.setLabel(label);
 97        
 98        assertEquals("param0", getGeneratedModule().selectSingleNode("label/param[1]/@name").getText());
 99    }
100
101    @Test
102    public void labelParam0HasValue() throws Exception
103    {
104        props.setLabel(label);
105        
106        assertEquals(label.getParams().get("param0"), getGeneratedModule().selectSingleNode("label/param[1]/@value").getText());
107    }
108
109    @Test
110    public void labelParam1HasName() throws Exception
111    {
112        props.setLabel(label);
113        
114        assertEquals("param1", getGeneratedModule().selectSingleNode("label/param[2]/@name").getText());
115    }
116
117    @Test
118    public void labelParam1HasValue() throws Exception
119    {
120        props.setLabel(label);
121        
122        assertEquals(label.getParams().get("param1"), getGeneratedModule().selectSingleNode("label/param[2]/@value").getText());
123    }
124
125    @Test
126    public void labelStringIsAddedToI18nProperties() throws Exception
127    {
128        props.setLabel(label);
129        
130        getI18nString(label.getKey(), label.getValue());
131    }
132
133    @Test
134    public void resourceIsAdded() throws Exception
135    {
136        props.getResources().add(cssResource);
137        
138        assertNotNull(getGeneratedModule().selectSingleNode("resource"));
139    }
140    
141    @Test
142    public void resourceHasName() throws Exception
143    {
144        props.getResources().add(cssResource);
145        
146        assertEquals("style.css", getGeneratedModule().selectSingleNode("resource/@name").getText());
147    }
148
149    @Test
150    public void resourceHasLocation() throws Exception
151    {
152        props.getResources().add(cssResource);
153
154        assertEquals("com/example/plugin/style.css", getGeneratedModule().selectSingleNode("resource/@location").getText());
155    }
156    
157    @Test
158    public void resourceHasType() throws Exception
159    {
160        props.getResources().add(cssResource);
161
162        assertEquals("download", getGeneratedModule().selectSingleNode("resource/@type").getText());
163    }
164
165    @Test
166    public void namePatternResourceAdded() throws Exception
167    {
168        props.getResources().add(cssNamePatternResource);
169
170        assertNotNull(getGeneratedModule().selectSingleNode("resource"));
171    }
172    
173    @Test
174    public void namePatternResourceHasNamePattern() throws Exception
175    {
176        props.getResources().add(cssNamePatternResource);
177        
178        assertEquals("*.css", getGeneratedModule().selectSingleNode("resource/@namePattern").getText());
179    }
180
181    @Test
182    public void namePatternResourceHasLocation() throws Exception
183    {
184        props.getResources().add(cssNamePatternResource);
185        
186        assertEquals("com/example/plugin", getGeneratedModule().selectSingleNode("resource/@location").getText());
187    }
188
189    @Test
190    public void namePatternResourceHasType() throws Exception
191    {
192        props.getResources().add(cssNamePatternResource);
193
194        assertEquals("download", getGeneratedModule().selectSingleNode("resource/@type").getText());
195    }
196
197    @Test
198    public void resourceNameChosenOverPattern() throws Exception
199    {
200        cssResource.setNamePattern("*.css");
201        props.getResources().add(cssResource);
202
203        assertNull(getGeneratedModule().selectSingleNode("resource/@namePattern"));
204    }
205
206    @Test
207    public void resourceParamHasName() throws Exception
208    {
209        cssResource.getParams().put("content-type", "text/css");
210        props.getResources().add(cssResource);
211
212        assertEquals("content-type", getGeneratedModule().selectSingleNode("resource/param/@name").getText());
213    }
214
215    @Test
216    public void resourceParamHasValue() throws Exception
217    {
218        cssResource.getParams().put("content-type", "text/css");
219        props.getResources().add(cssResource);
220
221        assertEquals("text/css", getGeneratedModule().selectSingleNode("resource/param/@value").getText());
222    }
223    
224    @Test
225    public void secondResourceParamAdded() throws Exception
226    {
227        cssResource.getParams().put("content-type", "text/css");
228        cssResource.getParams().put("awesome", "me");
229        props.getResources().add(cssResource);
230        
231        assertEquals("me", getGeneratedModule().selectSingleNode("resource/param[@name='awesome']/@value").getText());
232    }
233
234    @Test
235    public void allResourceParamsAdded() throws Exception
236    {
237        cssResource.getParams().put("content-type", "text/css");
238        cssResource.getParams().put("awesome", "me");
239        props.getResources().add(cssResource);
240        
241        assertEquals(2, getGeneratedModule().selectNodes("resource/param").size());
242    }
243
244    @Test
245    public void secondResourceAdded() throws Exception
246    {
247        Resource resource2 = new Resource();
248        resource2.setName("custom.js");
249        resource2.setLocation("com/example/plugin/custom.js");
250        resource2.setType("download");
251
252        props.getResources().add(cssResource);
253        props.getResources().add(resource2);
254        
255        assertEquals("com/example/plugin/custom.js",
256                     getGeneratedModule().selectSingleNode("resource[@name='custom.js']/@location").getText());
257    }
258
259    @Test
260    public void allResourcesAdded() throws Exception
261    {
262        Resource resource2 = new Resource();
263        resource2.setName("custom.js");
264        resource2.setLocation("com/example/plugin/custom.js");
265        resource2.setType("download");
266
267        props.getResources().add(cssResource);
268        props.getResources().add(resource2);
269        
270        assertEquals(2, getGeneratedModule().selectNodes("resource").size());
271    }
272}