1   package com.atlassian.plugins.codegen;
2   
3   import com.atlassian.plugins.codegen.modules.NameBasedModuleProperties;
4   import com.atlassian.plugins.codegen.modules.PluginModuleCreator;
5   import com.atlassian.plugins.codegen.modules.common.Icon;
6   import com.atlassian.plugins.codegen.modules.common.Label;
7   import com.atlassian.plugins.codegen.modules.common.Link;
8   import com.atlassian.plugins.codegen.modules.common.Resource;
9   import com.atlassian.plugins.codegen.modules.common.Tooltip;
10  
11  import org.dom4j.Element;
12  import org.junit.Before;
13  import org.junit.Test;
14  
15  import static junit.framework.Assert.assertEquals;
16  
17  public abstract class AbstractModuleCreatorTestCase<T extends NameBasedModuleProperties> extends AbstractCodegenTestCase<T>
18  {
19      protected String moduleType;
20      
21      // useful objects, not used in all tests
22      protected Resource cssResource;
23      protected Resource cssNamePatternResource;
24      protected Icon icon;
25      protected Label label;
26      protected Link link;
27      protected Tooltip tooltip;
28      
29      public AbstractModuleCreatorTestCase(String moduleType, PluginModuleCreator<T> creator)
30      {
31          this.moduleType = moduleType;
32          setCreator(creator);
33      }
34  
35      @Before
36      public final void setupUsefulObjects()
37      {
38          cssResource = new Resource();
39          cssResource.setName("style.css");
40          cssResource.setLocation("com/example/plugin/style.css");
41          cssResource.setType("download");
42  
43          cssNamePatternResource = new Resource();
44          cssNamePatternResource.setNamePattern("*.css");
45          cssNamePatternResource.setLocation("com/example/plugin");
46          cssNamePatternResource.setType("download");
47          
48          label = new Label("my.label.key", "this is a label");
49          label.addParam("$helper.project.name");
50          label.addParam("$helper.project.description");
51  
52          icon = new Icon(32, 16);
53          icon.setLink(new Link("/images/myicon.png"));
54  
55          link = new Link("/secure/CreateIssue!default.jspa");
56          link.setLinkId("create link");
57  
58          tooltip = new Tooltip("my.tooltip.key", "this is a tooltip");
59      }
60      
61      @Test
62      public void moduleIsCreated() throws Exception
63      {
64          getGeneratedModule();
65      }
66      
67      @Test
68      public void moduleHasSpecifiedKey() throws Exception
69      {
70          props.setModuleKey("newkey");
71          assertEquals("newkey", getGeneratedModule().attributeValue("key"));
72      }
73  
74      @Test
75      public void moduleHasName() throws Exception
76      {
77          props.setModuleName("newname");
78          assertEquals("newname", getGeneratedModule().attributeValue("name"));
79      }
80  
81      @Test
82      public void moduleHasNameI18nKey() throws Exception
83      {
84          props.setNameI18nKey("name-key");
85          assertEquals("name-key", getGeneratedModule().attributeValue("i18n-name-key"));
86      }
87  
88      @Test
89      public void moduleHasDescription() throws Exception
90      {
91          props.setDescription("desc");
92          assertEquals("desc", getGeneratedModule().selectSingleNode("description").getText());
93      }
94  
95      @Test
96      public void moduleHasDescriptionI18nKey() throws Exception
97      {
98          props.setDescriptionI18nKey("desc-key");
99          assertEquals("desc-key", getGeneratedModule().selectSingleNode("description/@key").getText());
100     }
101     
102     protected Element getGeneratedModule() throws Exception
103     {
104         return getGeneratedModule(moduleType);
105     }
106 }