PageRenderTime 19ms CodeModel.GetById 1ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/mmeinhold/amps
Java | 212 lines | 165 code | 44 blank | 3 comment | 0 complexity | b425e6b6d12fc5810e90871640a3aeb7 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 SearchRequestViewTest extends AbstractModuleCreatorTestCase<SearchRequestViewProperties>
 17{
 18    public static final String EXT = "html";
 19    public static final String CTYPE = "text/html";
 20
 21    public SearchRequestViewTest()
 22    {
 23        super("search-request-view", new SearchRequestViewModuleCreator());
 24    }
 25
 26    @Before
 27    public void setupProps() throws Exception
 28    {
 29        setProps(new SearchRequestViewProperties(PACKAGE_NAME + ".MySearchRequestView"));
 30        props.setIncludeExamples(false);
 31        props.setFileExtension(EXT);
 32        props.setContentType(CTYPE);
 33    }
 34
 35    @Test
 36    public void classFileIsGenerated() throws Exception
 37    {
 38        getSourceFile(PACKAGE_NAME, "MySearchRequestView");
 39    }
 40
 41    @Test
 42    public void unitTestFileIsGenerated() throws Exception
 43    {
 44        getTestSourceFile(TEST_PACKAGE_NAME, "MySearchRequestViewTest");
 45    }
 46    
 47    @Test
 48    public void moduleHasDefaultKey() throws Exception
 49    {
 50        assertEquals("my-search-request-view",
 51                     getGeneratedModule().attributeValue("key"));
 52    }
 53    
 54    @Test
 55    public void moduleHasClass() throws Exception
 56    {
 57        assertEquals(PACKAGE_NAME + ".MySearchRequestView",
 58                     getGeneratedModule().attributeValue("class"));
 59    }
 60    
 61    @Test
 62    public void moduleHasExtension() throws Exception
 63    {
 64        assertEquals(EXT, getGeneratedModule().attributeValue("fileExtension"));
 65    }
 66
 67    @Test
 68    public void moduleHasContentType() throws Exception
 69    {
 70        assertEquals(CTYPE, getGeneratedModule().attributeValue("contentType"));
 71    }
 72
 73    @Test
 74    public void resourceIsAdded() throws Exception
 75    {
 76        props.getResources().add(cssResource);
 77        
 78        assertNotNull(getGeneratedModule().selectSingleNode("resource"));
 79    }
 80    
 81    @Test
 82    public void resourceHasName() throws Exception
 83    {
 84        props.getResources().add(cssResource);
 85        
 86        assertEquals("style.css", getGeneratedModule().selectSingleNode("resource/@name").getText());
 87    }
 88
 89    @Test
 90    public void resourceHasLocation() throws Exception
 91    {
 92        props.getResources().add(cssResource);
 93
 94        assertEquals("com/example/plugin/style.css", getGeneratedModule().selectSingleNode("resource/@location").getText());
 95    }
 96    
 97    @Test
 98    public void resourceHasType() throws Exception
 99    {
100        props.getResources().add(cssResource);
101
102        assertEquals("download", getGeneratedModule().selectSingleNode("resource/@type").getText());
103    }
104
105    @Test
106    public void namePatternResourceAdded() throws Exception
107    {
108        props.getResources().add(cssNamePatternResource);
109
110        assertNotNull(getGeneratedModule().selectSingleNode("resource"));
111    }
112    
113    @Test
114    public void namePatternResourceHasNamePattern() throws Exception
115    {
116        props.getResources().add(cssNamePatternResource);
117        
118        assertEquals("*.css", getGeneratedModule().selectSingleNode("resource/@namePattern").getText());
119    }
120
121    @Test
122    public void namePatternResourceHasLocation() throws Exception
123    {
124        props.getResources().add(cssNamePatternResource);
125        
126        assertEquals("com/example/plugin", getGeneratedModule().selectSingleNode("resource/@location").getText());
127    }
128
129    @Test
130    public void namePatternResourceHasType() throws Exception
131    {
132        props.getResources().add(cssNamePatternResource);
133
134        assertEquals("download", getGeneratedModule().selectSingleNode("resource/@type").getText());
135    }
136
137    @Test
138    public void resourceNameChosenOverPattern() throws Exception
139    {
140        cssResource.setNamePattern("*.css");
141        props.getResources().add(cssResource);
142
143        assertNull(getGeneratedModule().selectSingleNode("resource/@namePattern"));
144    }
145
146    @Test
147    public void resourceParamHasName() throws Exception
148    {
149        cssResource.getParams().put("content-type", "text/css");
150        props.getResources().add(cssResource);
151
152        assertEquals("content-type", getGeneratedModule().selectSingleNode("resource/param/@name").getText());
153    }
154
155    @Test
156    public void resourceParamHasValue() throws Exception
157    {
158        cssResource.getParams().put("content-type", "text/css");
159        props.getResources().add(cssResource);
160
161        assertEquals("text/css", getGeneratedModule().selectSingleNode("resource/param/@value").getText());
162    }
163    
164    @Test
165    public void secondResourceParamAdded() throws Exception
166    {
167        cssResource.getParams().put("content-type", "text/css");
168        cssResource.getParams().put("awesome", "me");
169        props.getResources().add(cssResource);
170        
171        assertEquals("me", getGeneratedModule().selectSingleNode("resource/param[@name='awesome']/@value").getText());
172    }
173
174    @Test
175    public void allResourceParamsAdded() throws Exception
176    {
177        cssResource.getParams().put("content-type", "text/css");
178        cssResource.getParams().put("awesome", "me");
179        props.getResources().add(cssResource);
180        
181        assertEquals(2, getGeneratedModule().selectNodes("resource/param").size());
182    }
183
184    @Test
185    public void secondResourceAdded() throws Exception
186    {
187        Resource resource2 = new Resource();
188        resource2.setName("custom.js");
189        resource2.setLocation("com/example/plugin/custom.js");
190        resource2.setType("download");
191
192        props.getResources().add(cssResource);
193        props.getResources().add(resource2);
194        
195        assertEquals("com/example/plugin/custom.js",
196                     getGeneratedModule().selectSingleNode("resource[@name='custom.js']/@location").getText());
197    }
198
199    @Test
200    public void allResourcesAdded() throws Exception
201    {
202        Resource resource2 = new Resource();
203        resource2.setName("custom.js");
204        resource2.setLocation("com/example/plugin/custom.js");
205        resource2.setType("download");
206
207        props.getResources().add(cssResource);
208        props.getResources().add(resource2);
209        
210        assertEquals(2, getGeneratedModule().selectNodes("resource").size());
211    }
212}