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 WebPanelRendererTest extends AbstractCodegenTestCase<WebPanelRendererProperties>
20  {
21      public static final String PACKAGE_NAME = "com.atlassian.plugins.web";
22  
23      @Before
24      public void runGenerator() throws Exception
25      {
26          setCreator(new WebPanelRendererModuleCreator());
27          setModuleLocation(new PluginModuleLocation.Builder(srcDir)
28                  .resourcesDirectory(resourcesDir)
29                  .testDirectory(testDir)
30                  .templateDirectory(templateDir)
31                  .build());
32  
33          setProps(new WebPanelRendererProperties(PACKAGE_NAME + ".MyWebPanelRenderer"));
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          assertTrue("main class not generated", new File(srcDir, packagePath + File.separator + "MyWebPanelRenderer.java").exists());
45          assertTrue("test class not generated", new File(testDir, packagePath + File.separator + "MyWebPanelRendererTest.java").exists());
46          assertTrue("plugin.xml not generated", new File(resourcesDir, "atlassian-plugin.xml").exists());
47  
48      }
49  
50      @Test
51      public void moduleIsValid() throws Exception
52      {
53          String xpath = "/atlassian-plugin/web-panel-renderer[@name='My Web Panel Renderer' and @key='my-web-panel-renderer' and @i18n-name-key='my-web-panel-renderer.name' and @class='" + PACKAGE_NAME + ".MyWebPanelRenderer']";
54  
55          creator.createModule(moduleLocation, props);
56          Document pluginDoc = getXmlDocument(pluginXml);
57  
58          assertNotNull("valid web-panel-renderer not found", pluginDoc.selectSingleNode(xpath));
59      }
60  
61  
62  }