1 package com.atlassian.maven.plugins.amps.codegen.prompter.jira;
2
3 import com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter;
4 import com.atlassian.maven.plugins.amps.codegen.prompter.AbstractPrompterTest;
5 import com.atlassian.maven.plugins.amps.codegen.prompter.PluginModulePrompter;
6 import com.atlassian.plugins.codegen.modules.jira.TabPanelProperties;
7
8 import org.codehaus.plexus.components.interactivity.Prompter;
9 import org.codehaus.plexus.components.interactivity.PrompterException;
10 import org.junit.Before;
11 import org.junit.Test;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.when;
16
17
18
19
20 public class IssueTabPanelPrompterTest extends AbstractPrompterTest
21 {
22 public static final String PACKAGE = "com.atlassian.plugins.jira.tabpanels";
23 public static final String CLASSNAME = "MyIssueTabPanel";
24 public static final String MODULE_NAME = "My Issue Tab Panel";
25 public static final String MODULE_KEY = "my-issue-tab-panel";
26 public static final String DESCRIPTION = "The My Issue Tab Panel Plugin";
27 public static final String I18N_NAME_KEY = "my-issue-tab-panel.name";
28 public static final String I18N_DESCRIPTION_KEY = "my-issue-tab-panel.description";
29
30 public static final String ADV_MODULE_NAME = "My Awesome Plugin";
31 public static final String ADV_MODULE_KEY = "awesome-module";
32 public static final String ADV_DESCRIPTION = "The Awesomest Plugin Ever";
33 public static final String ADV_I18N_NAME_KEY = "awesome-plugin.name";
34 public static final String ADV_I18N_DESCRIPTION_KEY = "pluginus-awesomeous.description";
35
36 public static final String ORDER = "22";
37 public static final String LABEL_KEY = "item.label";
38 public static final String LABEL_VALUE = "this is my label";
39
40 Prompter prompter;
41
42 @Before
43 public void setup()
44 {
45 prompter = mock(Prompter.class);
46 }
47
48 @Test
49 public void basicPropertiesAreValid() throws PrompterException
50 {
51 when(prompter.prompt("Enter New Classname", "MyIssueTabPanel")).thenReturn(CLASSNAME);
52 when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.tabpanels")).thenReturn(PACKAGE);
53 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
54 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
55
56 IssueTabPanelPrompter modulePrompter = new IssueTabPanelPrompter(prompter);
57 modulePrompter.setUseAnsiColor(false);
58 TabPanelProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
59
60 assertEquals("wrong class", CLASSNAME, props.getClassname());
61 assertEquals("wrong class package", PACKAGE, props.getPackage());
62 assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
63 assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
64 assertEquals("wrong description", DESCRIPTION, props.getDescription());
65 assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
66 assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
67 assertEquals("wrong order", "10", props.getOrder());
68 assertEquals("wrong label key", MODULE_KEY + ".label", props.getLabel()
69 .getKey());
70 assertEquals("wrong label value", MODULE_NAME, props.getLabel()
71 .getValue());
72 }
73
74 @Test
75 public void advancedPropertiesAreValid() throws PrompterException
76 {
77 when(prompter.prompt("Enter New Classname", "MyIssueTabPanel")).thenReturn(CLASSNAME);
78 when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.tabpanels")).thenReturn(PACKAGE);
79 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
80
81 when(prompter.prompt("Plugin Name", MODULE_NAME)).thenReturn(ADV_MODULE_NAME);
82 when(prompter.prompt("Plugin Key", MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
83 when(prompter.prompt("Plugin Description", DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
84 when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
85 when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
86
87 when(prompter.prompt("Order", "10")).thenReturn(ORDER);
88 when(prompter.prompt("Enter Label Key", MODULE_KEY + ".label")).thenReturn(LABEL_KEY);
89 when(prompter.prompt("Enter Label Value", MODULE_NAME)).thenReturn(LABEL_VALUE);
90
91 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
92
93 IssueTabPanelPrompter modulePrompter = new IssueTabPanelPrompter(prompter);
94 modulePrompter.setUseAnsiColor(false);
95 TabPanelProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
96
97 assertEquals("wrong adv class", CLASSNAME, props.getClassname());
98 assertEquals("wrong adv package", PACKAGE, props.getPackage());
99 assertEquals("wrong adv module name", ADV_MODULE_NAME, props.getModuleName());
100 assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
101 assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
102 assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
103 assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
104 assertEquals("wrong order", ORDER, props.getOrder());
105 assertEquals("wrong label key", LABEL_KEY, props.getLabel()
106 .getKey());
107 assertEquals("wrong label value", LABEL_VALUE, props.getLabel()
108 .getValue());
109 }
110 }