PageRenderTime 33ms CodeModel.GetById 12ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/mmeinhold/amps
Java | 228 lines | 175 code | 50 blank | 3 comment | 0 complexity | 0e937d393ca9066687e0c1375847578f MD5 | raw file
  1package com.atlassian.plugins.codegen.modules.jira;
  2
  3import com.atlassian.plugins.codegen.AbstractModuleCreatorTestCase;
  4import com.atlassian.plugins.codegen.SourceFile;
  5import com.atlassian.plugins.codegen.modules.common.Resource;
  6
  7import org.junit.Before;
  8import org.junit.Test;
  9
 10import static junit.framework.Assert.assertEquals;
 11import static junit.framework.Assert.assertNotNull;
 12import static org.junit.Assert.assertNull;
 13import static org.junit.Assert.assertTrue;
 14
 15/**
 16 * @since 3.6
 17 */
 18public class CustomFieldSearcherTest extends AbstractModuleCreatorTestCase<CustomFieldSearcherProperties>
 19{
 20    
 21    public CustomFieldSearcherTest()
 22    {
 23        super("customfield-searcher", new CustomFieldSearcherModuleCreator());
 24    }
 25
 26    @Before
 27    public void setupProps() throws Exception
 28    {
 29        setProps(new CustomFieldSearcherProperties(PACKAGE_NAME + ".MyCustomFieldSearcher"));
 30        props.setIncludeExamples(false);
 31    }
 32
 33    @Test
 34    public void customClassFileIsGenerated() throws Exception
 35    {
 36        props.setGenerateClass(true);
 37        
 38        getSourceFile(PACKAGE_NAME, "MyCustomFieldSearcher");
 39    }
 40
 41    @Test
 42    public void customUnitTestFileIsGenerated() throws Exception
 43    {
 44        props.setGenerateClass(true);
 45        
 46        getTestSourceFile(TEST_PACKAGE_NAME, "MyCustomFieldSearcherTest");
 47    }
 48
 49    @Test
 50    public void genericClassFilesAreNotGenerated() throws Exception
 51    {
 52        props.setGenerateClass(false);
 53        
 54        assertTrue(getChangesetForModule(SourceFile.class).isEmpty());
 55    }
 56    
 57    @Test
 58    public void moduleHasDefaultKey() throws Exception
 59    {
 60        assertEquals("my-custom-field-searcher",
 61                     getGeneratedModule().attributeValue("key"));
 62    }
 63    
 64    @Test
 65    public void moduleHasClass() throws Exception
 66    {
 67        assertEquals(PACKAGE_NAME + ".MyCustomFieldSearcher",
 68                     getGeneratedModule().attributeValue("class"));
 69    }
 70
 71    @Test
 72    public void moduleHasValidCustomFieldPackage() throws Exception
 73    {
 74        props.setValidCustomFieldPackage("com.atlassian.customfields");
 75        props.setValidCustomFieldKey("some-searcher");
 76
 77        assertEquals("com.atlassian.customfields", getGeneratedModule().selectSingleNode("valid-customfield-type/@package").getText());
 78    }
 79
 80    @Test
 81    public void moduleHasValidCustomFieldKey() throws Exception
 82    {
 83        props.setValidCustomFieldPackage("com.atlassian.customfields");
 84        props.setValidCustomFieldKey("some-searcher");
 85
 86        assertEquals("some-searcher", getGeneratedModule().selectSingleNode("valid-customfield-type/@key").getText());
 87    }
 88
 89    @Test
 90    public void resourceIsAdded() throws Exception
 91    {
 92        props.getResources().add(cssResource);
 93        
 94        assertNotNull(getGeneratedModule().selectSingleNode("resource"));
 95    }
 96    
 97    @Test
 98    public void resourceHasName() throws Exception
 99    {
100        props.getResources().add(cssResource);
101        
102        assertEquals("style.css", getGeneratedModule().selectSingleNode("resource/@name").getText());
103    }
104
105    @Test
106    public void resourceHasLocation() throws Exception
107    {
108        props.getResources().add(cssResource);
109
110        assertEquals("com/example/plugin/style.css", getGeneratedModule().selectSingleNode("resource/@location").getText());
111    }
112    
113    @Test
114    public void resourceHasType() throws Exception
115    {
116        props.getResources().add(cssResource);
117
118        assertEquals("download", getGeneratedModule().selectSingleNode("resource/@type").getText());
119    }
120
121    @Test
122    public void namePatternResourceAdded() throws Exception
123    {
124        props.getResources().add(cssNamePatternResource);
125
126        assertNotNull(getGeneratedModule().selectSingleNode("resource"));
127    }
128    
129    @Test
130    public void namePatternResourceHasNamePattern() throws Exception
131    {
132        props.getResources().add(cssNamePatternResource);
133        
134        assertEquals("*.css", getGeneratedModule().selectSingleNode("resource/@namePattern").getText());
135    }
136
137    @Test
138    public void namePatternResourceHasLocation() throws Exception
139    {
140        props.getResources().add(cssNamePatternResource);
141        
142        assertEquals("com/example/plugin", getGeneratedModule().selectSingleNode("resource/@location").getText());
143    }
144
145    @Test
146    public void namePatternResourceHasType() throws Exception
147    {
148        props.getResources().add(cssNamePatternResource);
149
150        assertEquals("download", getGeneratedModule().selectSingleNode("resource/@type").getText());
151    }
152
153    @Test
154    public void resourceNameChosenOverPattern() throws Exception
155    {
156        cssResource.setNamePattern("*.css");
157        props.getResources().add(cssResource);
158
159        assertNull(getGeneratedModule().selectSingleNode("resource/@namePattern"));
160    }
161
162    @Test
163    public void resourceParamHasName() throws Exception
164    {
165        cssResource.getParams().put("content-type", "text/css");
166        props.getResources().add(cssResource);
167
168        assertEquals("content-type", getGeneratedModule().selectSingleNode("resource/param/@name").getText());
169    }
170
171    @Test
172    public void resourceParamHasValue() throws Exception
173    {
174        cssResource.getParams().put("content-type", "text/css");
175        props.getResources().add(cssResource);
176
177        assertEquals("text/css", getGeneratedModule().selectSingleNode("resource/param/@value").getText());
178    }
179    
180    @Test
181    public void secondResourceParamAdded() throws Exception
182    {
183        cssResource.getParams().put("content-type", "text/css");
184        cssResource.getParams().put("awesome", "me");
185        props.getResources().add(cssResource);
186        
187        assertEquals("me", getGeneratedModule().selectSingleNode("resource/param[@name='awesome']/@value").getText());
188    }
189
190    @Test
191    public void allResourceParamsAdded() throws Exception
192    {
193        cssResource.getParams().put("content-type", "text/css");
194        cssResource.getParams().put("awesome", "me");
195        props.getResources().add(cssResource);
196        
197        assertEquals(2, getGeneratedModule().selectNodes("resource/param").size());
198    }
199
200    @Test
201    public void secondResourceAdded() throws Exception
202    {
203        Resource resource2 = new Resource();
204        resource2.setName("custom.js");
205        resource2.setLocation("com/example/plugin/custom.js");
206        resource2.setType("download");
207
208        props.getResources().add(cssResource);
209        props.getResources().add(resource2);
210        
211        assertEquals("com/example/plugin/custom.js",
212                     getGeneratedModule().selectSingleNode("resource[@name='custom.js']/@location").getText());
213    }
214
215    @Test
216    public void allResourcesAdded() throws Exception
217    {
218        Resource resource2 = new Resource();
219        resource2.setName("custom.js");
220        resource2.setLocation("com/example/plugin/custom.js");
221        resource2.setType("download");
222
223        props.getResources().add(cssResource);
224        props.getResources().add(resource2);
225        
226        assertEquals(2, getGeneratedModule().selectNodes("resource").size());
227    }
228}