1   package com.atlassian.plugins.codegen.modules.jira;
2   
3   import java.io.File;
4   
5   import com.atlassian.plugins.codegen.AbstractCodegenTestCase;
6   import com.atlassian.plugins.codegen.modules.PluginModuleLocation;
7   
8   import org.dom4j.Document;
9   import org.dom4j.Node;
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 KeyboardShortcutTest extends AbstractCodegenTestCase<KeyboardShortcutProperties>
20  {
21  
22      @Before
23      public void runGenerator() throws Exception
24      {
25          setCreator(new KeyboardShortcutModuleCreator());
26          setModuleLocation(new PluginModuleLocation.Builder(srcDir)
27                  .resourcesDirectory(resourcesDir)
28                  .testDirectory(testDir)
29                  .templateDirectory(templateDir)
30                  .build());
31  
32          setProps(new KeyboardShortcutProperties("My Keyboard Shortcut"));
33  
34          props.setIncludeExamples(false);
35  
36  
37      }
38  
39      @Test
40      public void allFilesAreGenerated() throws Exception
41      {
42          creator.createModule(moduleLocation, props);
43          assertTrue("plugin.xml not generated", new File(resourcesDir, "atlassian-plugin.xml").exists());
44  
45      }
46  
47      @Test
48      public void moduleIsValid() throws Exception
49      {
50          props.setOperationType("click");
51          props.setOperationValue("do:something");
52          props.setShortcut("m");
53          props.setContext("issueaction");
54  
55          String xpath = "/atlassian-plugin/keyboard-shortcut[@name='My Keyboard Shortcut' and @key='my-keyboard-shortcut' and @i18n-name-key='my-keyboard-shortcut.name']";
56  
57          creator.createModule(moduleLocation, props);
58          Document pluginDoc = getXmlDocument(pluginXml);
59  
60          Node rootNode = pluginDoc.selectSingleNode(xpath);
61          assertNotNull("valid keyboard-shortcut not found", rootNode);
62  
63          Node order = rootNode.selectSingleNode("order[text() = '10']");
64          Node shortcut = rootNode.selectSingleNode("shortcut[text() = 'm']");
65          Node context = rootNode.selectSingleNode("context[text() = 'issueaction']");
66          Node operation = rootNode.selectSingleNode("operation[@type='click' and text() = 'do:something']");
67  
68          assertNotNull("valid order not found", order);
69          assertNotNull("valid shortcut not found", shortcut);
70          assertNotNull("valid context not found", context);
71          assertNotNull("valid operation not found", operation);
72      }
73  
74  }