PageRenderTime 22ms CodeModel.GetById 2ms app.highlight 15ms RepoModel.GetById 2ms app.codeStats 0ms

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

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