1   package com.atlassian.plugins.codegen.modules.jira;
2   
3   import com.atlassian.plugins.codegen.AbstractModuleCreatorTestCase;
4   
5   import org.junit.Before;
6   import org.junit.Test;
7   
8   import static junit.framework.Assert.assertEquals;
9   import static org.junit.Assert.assertNull;
10  
11  /**
12   * @since 3.6
13   */
14  public class WorkflowPostFunctionTest extends AbstractModuleCreatorTestCase<WorkflowPostFunctionProperties>
15  {
16      public WorkflowPostFunctionTest()
17      {
18          super("workflow-function", new WorkflowPostFunctionModuleCreator());
19      }
20  
21      @Before
22      public void setupProps() throws Exception
23      {
24          setProps(new WorkflowPostFunctionProperties(PACKAGE_NAME + ".MyWorkflowFunction"));
25          props.setIncludeExamples(false);
26      }
27  
28      @Test
29      public void classFileIsGenerated() throws Exception
30      {
31          getSourceFile(PACKAGE_NAME, "MyWorkflowFunction");
32      }
33  
34      @Test
35      public void factoryClassFileIsGenerated() throws Exception
36      {
37          getSourceFile(PACKAGE_NAME, "MyWorkflowFunctionFactory");
38      }
39      
40      @Test
41      public void unitTestFileIsGenerated() throws Exception
42      {
43          getTestSourceFile(PACKAGE_NAME, "MyWorkflowFunctionTest");
44      }
45     
46      @Test
47      public void viewTemplateIsGenerated() throws Exception
48      {
49          getResourceFile("templates/postfunctions", "my-workflow-function-input.vm");
50      }
51      
52      @Test
53      public void inputTemplateIsGenerated() throws Exception
54      {
55          getResourceFile("templates/postfunctions", "my-workflow-function-input.vm");
56      }
57      
58      @Test
59      public void moduleHasDefaultKey() throws Exception
60      {
61          assertEquals("my-workflow-function",
62                       getGeneratedModule().attributeValue("key"));
63      }
64      
65      @Test
66      public void moduleHasClass() throws Exception
67      {
68          assertEquals(PACKAGE_NAME + ".MyWorkflowFunctionFactory",
69                       getGeneratedModule().attributeValue("class"));
70      }
71      
72      @Test
73      public void moduleHasFunctionClass() throws Exception
74      {
75          assertEquals(PACKAGE_NAME + ".MyWorkflowFunction", getGeneratedModule().selectSingleNode("function-class").getText());
76      }
77      
78      @Test
79      public void moduleIsNotOrderableByDefault() throws Exception
80      {
81          assertNull(getGeneratedModule().selectSingleNode("orderable"));
82      }
83  
84      @Test
85      public void moduleIsNotUniqueByDefault() throws Exception
86      {
87          assertNull(getGeneratedModule().selectSingleNode("unique"));
88      }
89  
90      @Test
91      public void moduleIsNotDeletableByDefault() throws Exception
92      {
93          assertNull(getGeneratedModule().selectSingleNode("deletable"));
94      }
95  
96      @Test
97      public void moduleIsNotAddableByDefault() throws Exception
98      {
99          assertNull(getGeneratedModule().selectSingleNode("addable"));
100     }
101 
102     @Test
103     public void moduleHasOrderable() throws Exception
104     {
105         props.setOrderable(true);
106         
107         assertEquals("true", getGeneratedModule().selectSingleNode("orderable").getText());
108     }
109 
110     @Test
111     public void moduleHasDeletable() throws Exception
112     {
113         props.setDeletable(false);
114 
115         assertEquals("false", getGeneratedModule().selectSingleNode("deletable").getText());
116     }
117 
118     @Test
119     public void moduleHasUnique() throws Exception
120     {
121         props.setUnique(true);
122 
123         assertEquals("true", getGeneratedModule().selectSingleNode("unique").getText());
124     }
125 
126     @Test
127     public void moduleHasAddable() throws Exception
128     {
129         props.setAddable("global,common");
130 
131         assertEquals("global,common", getGeneratedModule().selectSingleNode("addable").getText());
132     }
133 
134     @Test
135     public void moduleWithMultipleFlagsHasAddable() throws Exception
136     {
137         props.setAddable("global,common");
138         props.setUnique(true);
139 
140         assertEquals("global,common", getGeneratedModule().selectSingleNode("addable").getText());
141     }
142     
143     @Test
144     public void moduleWithMultipleFlagsHasUnique() throws Exception
145     {
146         props.setAddable("global,common");
147         props.setUnique(true);
148 
149         assertEquals("true", getGeneratedModule().selectSingleNode("unique").getText());
150     }
151 }