1 package com.atlassian.plugins.codegen.modules.jira;
2
3 import java.io.File;
4 import java.util.regex.Matcher;
5
6 import com.atlassian.plugins.codegen.AbstractCodegenTestCase;
7 import com.atlassian.plugins.codegen.modules.PluginModuleLocation;
8
9 import org.dom4j.Document;
10 import org.dom4j.Node;
11 import org.junit.Before;
12 import org.junit.Test;
13
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16
17
18
19
20 public class WorkflowConditionTest extends AbstractCodegenTestCase<WorkflowElementProperties>
21 {
22 public static final String PACKAGE_NAME = "com.atlassian.plugins.workflow";
23 public static final String XPATH = "/atlassian-plugin/workflow-condition[@name='My Workflow Condition' and @key='my-workflow-condition' and @i18n-name-key='my-workflow-condition.name' and @class='" + PACKAGE_NAME + ".MyWorkflowConditionFactory']";
24
25 protected File templatePath;
26
27 @Before
28 public void runGenerator() throws Exception
29 {
30 setCreator(new WorkflowConditionModuleCreator());
31 setModuleLocation(new PluginModuleLocation.Builder(srcDir)
32 .resourcesDirectory(resourcesDir)
33 .testDirectory(testDir)
34 .templateDirectory(templateDir)
35 .build());
36
37 setProps(new WorkflowElementProperties(PACKAGE_NAME + ".MyWorkflowCondition"));
38
39 props.setIncludeExamples(false);
40
41 templatePath = new File(templateDir, "conditions");
42
43 }
44
45 @Test
46 public void allFilesAreGenerated() throws Exception
47 {
48
49 creator.createModule(moduleLocation, props);
50
51 String packagePath = PACKAGE_NAME.replaceAll("\\.", Matcher.quoteReplacement(File.separator));
52
53 assertTrue("main class not generated", new File(srcDir, packagePath + File.separator + "MyWorkflowCondition.java").exists());
54 assertTrue("factory class not generated", new File(srcDir, packagePath + File.separator + "MyWorkflowConditionFactory.java").exists());
55 assertTrue("test class not generated", new File(testDir, packagePath + File.separator + "MyWorkflowConditionTest.java").exists());
56 assertTrue("view template not generated", new File(templatePath, "my-workflow-condition.vm").exists());
57 assertTrue("input template not generated", new File(templatePath, "my-workflow-condition-input.vm").exists());
58 assertTrue("plugin.xml not generated", new File(resourcesDir, "atlassian-plugin.xml").exists());
59
60 }
61
62 @Test
63 public void moduleIsValid() throws Exception
64 {
65
66 creator.createModule(moduleLocation, props);
67 Document pluginDoc = getXmlDocument(pluginXml);
68 Node moduleNode = pluginDoc.selectSingleNode(XPATH);
69
70 assertNotNull("valid workflow-condition not found", moduleNode);
71 }
72
73 @Test
74 public void moduleHasCondition() throws Exception
75 {
76
77 creator.createModule(moduleLocation, props);
78 Document pluginDoc = getXmlDocument(pluginXml);
79 Node moduleNode = pluginDoc.selectSingleNode(XPATH);
80
81 String subXpath = "condition-class[text() = '" + PACKAGE_NAME + ".MyWorkflowCondition']";
82
83 assertNotNull("valid workflow-condition not found", moduleNode);
84 assertNotNull("valid condition-class not found", moduleNode.selectSingleNode(subXpath));
85 }
86
87 }