1   package com.atlassian.plugins.codegen.modules.common.web;
2   
3   import com.atlassian.plugins.codegen.modules.PluginModuleLocation;
4   
5   import org.dom4j.Document;
6   import org.junit.Before;
7   import org.junit.Test;
8   
9   import static org.junit.Assert.assertNotNull;
10  
11  /**
12   * @since 3.6
13   */
14  public class WebPanelTest extends AbstractWebFragmentTest<WebPanelProperties>
15  {
16      public static final String MODULE_NAME = "Awesome Web Panel";
17      public static final String CUSTOM_LOCATION = "system.admin/mysection";
18  
19      @Before
20      public void runGenerator() throws Exception
21      {
22          setCreator(new WebPanelModuleCreator());
23          setModuleLocation(new PluginModuleLocation.Builder(srcDir)
24                  .resourcesDirectory(resourcesDir)
25                  .testDirectory(testDir)
26                  .templateDirectory(templateDir)
27                  .build());
28  
29          setProps(new WebPanelProperties(MODULE_NAME, CUSTOM_LOCATION));
30          props.setIncludeExamples(false);
31      }
32  
33      @Test
34      public void moduleIsValid() throws Exception
35      {
36          String xpath = "/atlassian-plugin/web-panel[@name='Awesome Web Panel' and @key='awesome-web-panel' and @i18n-name-key='awesome-web-panel.name' and @location='system.admin/mysection' and @weight='1000']";
37  
38          creator.createModule(moduleLocation, props);
39          Document pluginDoc = getXmlDocument(pluginXml);
40  
41          assertNotNull("valid web-panel not found", pluginDoc.selectSingleNode(xpath));
42      }
43  
44      @Test
45      public void moduleIsValidWithCustomWeight() throws Exception
46      {
47          props.setWeight(20);
48  
49          String xpath = "/atlassian-plugin/web-panel[@name='Awesome Web Panel' and @key='awesome-web-panel' and @i18n-name-key='awesome-web-panel.name' and @location='system.admin/mysection' and @weight='20']";
50  
51          creator.createModule(moduleLocation, props);
52          Document pluginDoc = getXmlDocument(pluginXml);
53  
54          assertNotNull("valid web-panel with custom weight not found", pluginDoc.selectSingleNode(xpath));
55      }
56  
57  }