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.junit.Before;
11 import org.junit.Test;
12
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
15
16
17
18
19 public class JqlFunctionTest extends AbstractCodegenTestCase<JqlFunctionProperties>
20 {
21 public static final String PACKAGE_NAME = "com.atlassian.plugins.jira.jql";
22
23 @Before
24 public void runGenerator() throws Exception
25 {
26 setCreator(new JqlFunctionModuleCreator());
27 setModuleLocation(new PluginModuleLocation.Builder(srcDir)
28 .resourcesDirectory(resourcesDir)
29 .testDirectory(testDir)
30 .templateDirectory(templateDir)
31 .build());
32
33 setProps(new JqlFunctionProperties(PACKAGE_NAME + ".MyJqlFunction"));
34
35 props.setIncludeExamples(false);
36
37 creator.createModule(moduleLocation, props);
38 }
39
40 @Test
41 public void allFilesAreGenerated() throws Exception
42 {
43 String packagePath = PACKAGE_NAME.replaceAll("\\.", Matcher.quoteReplacement(File.separator));
44 String itPackagePath = "it" + File.separator + packagePath;
45 assertTrue("main class not generated", new File(srcDir, packagePath + File.separator + "MyJqlFunction.java").exists());
46 assertTrue("test class not generated", new File(testDir, packagePath + File.separator + "MyJqlFunctionTest.java").exists());
47 assertTrue("plugin.xml not generated", new File(resourcesDir, "atlassian-plugin.xml").exists());
48
49 }
50
51 @Test
52 public void moduleIsValid() throws Exception
53 {
54 String xpath = "/atlassian-plugin/jql-function[@name='My Jql Function' and @key='my-jql-function' and @i18n-name-key='my-jql-function.name' and @class='" + PACKAGE_NAME + ".MyJqlFunction']";
55
56 creator.createModule(moduleLocation, props);
57 Document pluginDoc = getXmlDocument(pluginXml);
58
59 assertNotNull("valid jql-function not found", pluginDoc.selectSingleNode(xpath));
60 }
61
62 }