1   package com.atlassian.plugins.codegen.modules.common.web;
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   * @since 3.6
18   */
19  public class WebResourceTransformerTest extends AbstractCodegenTestCase<WebResourceTransformerProperties>
20  {
21      public static final String PACKAGE_NAME = "com.atlassian.plugin.webresource";
22  
23      @Before
24      public void runGenerator() throws Exception
25      {
26          setCreator(new WebResourceTransformerModuleCreator());
27          setModuleLocation(new PluginModuleLocation.Builder(srcDir)
28                  .resourcesDirectory(resourcesDir)
29                  .testDirectory(testDir)
30                  .templateDirectory(templateDir)
31                  .build());
32  
33          setProps(new WebResourceTransformerProperties(PACKAGE_NAME + ".MyWebResourceTransformer"));
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 + "MyWebResourceTransformer.java").exists());
46          assertTrue("test class not generated", new File(testDir, packagePath + File.separator + "MyWebResourceTransformerTest.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/web-resource-transformer[@name='My Web Resource Transformer' and @key='my-web-resource-transformer' and @i18n-name-key='my-web-resource-transformer.name' and @class='" + PACKAGE_NAME + ".MyWebResourceTransformer']";
55  
56          creator.createModule(moduleLocation, props);
57          Document pluginDoc = getXmlDocument(pluginXml);
58  
59          assertNotNull("valid web-resource-transformer not found", pluginDoc.selectSingleNode(xpath));
60      }
61  
62  }