1   package com.atlassian.plugins.codegen.modules.common.moduletype;
2   
3   import java.io.File;
4   import java.io.IOException;
5   import java.util.regex.Matcher;
6   
7   import com.atlassian.plugins.codegen.AbstractCodegenTestCase;
8   import com.atlassian.plugins.codegen.modules.PluginModuleLocation;
9   
10  import org.apache.commons.io.FileUtils;
11  import org.junit.Before;
12  import org.junit.Test;
13  
14  import static org.junit.Assert.assertTrue;
15  
16  //TODO: update test to use Dom4J
17  
18  /**
19   * @since 3.6
20   */
21  public class ModuleTypeTest extends AbstractCodegenTestCase<ModuleTypeProperties>
22  {
23      public static final String PACKAGE_NAME = "com.atlassian.plugins.modules";
24  
25      @Before
26      public void runGenerator() throws Exception
27      {
28          setCreator(new ModuleTypeModuleCreator());
29          setModuleLocation(new PluginModuleLocation.Builder(srcDir)
30                  .resourcesDirectory(resourcesDir)
31                  .testDirectory(testDir)
32                  .templateDirectory(templateDir)
33                  .build());
34  
35          setProps(new ModuleTypeProperties(PACKAGE_NAME + ".DictionaryModuleDescriptor"));
36  
37          props.setFullyQualifiedInterface(PACKAGE_NAME + ".Dictionary");
38          props.setIncludeExamples(false);
39  
40          creator.createModule(moduleLocation, props);
41      }
42  
43      @Test
44      public void allFilesAreGenerated() throws Exception
45      {
46          String packagePath = PACKAGE_NAME.replaceAll("\\.", Matcher.quoteReplacement(File.separator));
47          String itPackagePath = "it" + File.separator + packagePath;
48          assertTrue("interface class not generated", new File(srcDir, packagePath + File.separator + "Dictionary.java").exists());
49          assertTrue("main class not generated", new File(srcDir, packagePath + File.separator + "DictionaryModuleDescriptor.java").exists());
50          assertTrue("test class not generated", new File(testDir, packagePath + File.separator + "DictionaryModuleDescriptorTest.java").exists());
51          assertTrue("funcTest class not generated", new File(testDir, itPackagePath + File.separator + "DictionaryModuleDescriptorFuncTest.java").exists());
52          assertTrue("plugin.xml not generated", new File(resourcesDir, "atlassian-plugin.xml").exists());
53  
54      }
55  
56      @Test
57      public void pluginXmlContainsModule() throws IOException
58      {
59          String pluginXmlContent = FileUtils.readFileToString(pluginXml);
60  
61          assertTrue("module not found in plugin xml", pluginXmlContent.contains("<module-type"));
62          assertTrue("module class not found in plugin xml", pluginXmlContent.contains("class=\"" + PACKAGE_NAME + ".DictionaryModuleDescriptor\""));
63      }
64  
65  }