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 import com.atlassian.plugins.codegen.modules.jira.VersionTabPanelModuleCreator;
8
9 import org.codehaus.plexus.components.interactivity.Prompter;
10 import org.codehaus.plexus.components.interactivity.PrompterException;
11 import org.junit.Before;
12 import org.junit.Test;
13
14 import static org.junit.Assert.*;
15 import static org.mockito.Mockito.mock;
16 import static org.mockito.Mockito.when;
17
18
19
20
21 public class VersionTabPanelPrompterTest extends AbstractPrompterTest
22 {
23 public static final String PACKAGE = "com.atlassian.plugins.jira.tabpanels";
24 public static final String CLASSNAME = "MyVersionTabPanel";
25 public static final String MODULE_NAME = "My Version Tab Panel";
26 public static final String MODULE_KEY = "my-version-tab-panel";
27 public static final String DESCRIPTION = "The My Version Tab Panel Plugin";
28 public static final String I18N_NAME_KEY = "my-version-tab-panel.name";
29 public static final String I18N_DESCRIPTION_KEY = "my-version-tab-panel.description";
30
31 public static final String ADV_MODULE_NAME = "My Awesome Plugin";
32 public static final String ADV_MODULE_KEY = "awesome-module";
33 public static final String ADV_DESCRIPTION = "The Awesomest Plugin Ever";
34 public static final String ADV_I18N_NAME_KEY = "awesome-plugin.name";
35 public static final String ADV_I18N_DESCRIPTION_KEY = "pluginus-awesomeous.description";
36
37 public static final String ORDER = "22";
38 public static final String LABEL_KEY = "item.label";
39 public static final String LABEL_VALUE = "this is my label";
40
41 Prompter prompter;
42
43 @Before
44 public void setup()
45 {
46 prompter = mock(Prompter.class);
47 }
48
49 @Test
50 public void basicCustomPropertiesAreValid() throws PrompterException
51 {
52 when(prompter.prompt("Use " + VersionTabPanelModuleCreator.GENERIC_CLASS + "?", PluginModulePrompter.YN_ANSWERS, "Y")).thenReturn("n");
53 when(prompter.prompt("Enter New Classname", "MyVersionTabPanel")).thenReturn(CLASSNAME);
54 when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.tabpanels")).thenReturn(PACKAGE);
55 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
56 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
57
58 VersionTabPanelPrompter modulePrompter = new VersionTabPanelPrompter(prompter);
59 modulePrompter.setUseAnsiColor(false);
60 TabPanelProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
61
62 assertEquals("wrong class", CLASSNAME, props.getClassname());
63 assertEquals("wrong class package", PACKAGE, props.getPackage());
64 assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
65 assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
66 assertEquals("wrong description", DESCRIPTION, props.getDescription());
67 assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
68 assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
69 assertEquals("wrong order", "10", props.getOrder());
70 assertEquals("wrong label key", MODULE_KEY + ".label", props.getLabel()
71 .getKey());
72 assertEquals("wrong label value", MODULE_NAME, props.getLabel()
73 .getValue());
74 assertTrue("use custom class should be true", props.isUseCustomClass());
75 }
76
77 @Test
78 public void basicGenericPropertiesAreValid() throws PrompterException
79 {
80 when(prompter.prompt("Use " + VersionTabPanelModuleCreator.GENERIC_CLASS + "?", PluginModulePrompter.YN_ANSWERS, "Y")).thenReturn("y");
81 when(prompter.prompt("Enter Plugin Module Name", "My Version Tab Panel")).thenReturn(MODULE_NAME);
82 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
83 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
84
85 VersionTabPanelPrompter modulePrompter = new VersionTabPanelPrompter(prompter);
86 modulePrompter.setUseAnsiColor(false);
87 TabPanelProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
88
89 assertEquals("wrong class", VersionTabPanelModuleCreator.GENERIC_CLASS, props.getClassname());
90 assertEquals("wrong class package", VersionTabPanelModuleCreator.GENERIC_PACKAGE, props.getPackage());
91 assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
92 assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
93 assertEquals("wrong description", DESCRIPTION, props.getDescription());
94 assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
95 assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
96 assertEquals("wrong order", "10", props.getOrder());
97 assertEquals("wrong label key", MODULE_KEY + ".label", props.getLabel()
98 .getKey());
99 assertEquals("wrong label value", MODULE_NAME, props.getLabel()
100 .getValue());
101 assertFalse("use custom class should be false", props.isUseCustomClass());
102 }
103
104 @Test
105 public void advancedCustomPropertiesAreValid() throws PrompterException
106 {
107 when(prompter.prompt("Use " + VersionTabPanelModuleCreator.GENERIC_CLASS + "?", PluginModulePrompter.YN_ANSWERS, "Y")).thenReturn("n");
108 when(prompter.prompt("Enter New Classname", "MyVersionTabPanel")).thenReturn(CLASSNAME);
109 when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.tabpanels")).thenReturn(PACKAGE);
110 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("y");
111
112 when(prompter.prompt("Plugin Name", MODULE_NAME)).thenReturn(ADV_MODULE_NAME);
113 when(prompter.prompt("Plugin Key", MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
114 when(prompter.prompt("Plugin Description", DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
115 when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
116 when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
117
118 when(prompter.prompt("Order", "10")).thenReturn(ORDER);
119 when(prompter.prompt("Enter Label Key", MODULE_KEY + ".label")).thenReturn(LABEL_KEY);
120 when(prompter.prompt("Enter Label Value", MODULE_NAME)).thenReturn(LABEL_VALUE);
121
122 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
123
124 VersionTabPanelPrompter modulePrompter = new VersionTabPanelPrompter(prompter);
125 modulePrompter.setUseAnsiColor(false);
126 TabPanelProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
127
128 assertEquals("wrong adv class", CLASSNAME, props.getClassname());
129 assertEquals("wrong adv package", PACKAGE, props.getPackage());
130 assertEquals("wrong adv module name", ADV_MODULE_NAME, props.getModuleName());
131 assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
132 assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
133 assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
134 assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
135 assertEquals("wrong order", ORDER, props.getOrder());
136 assertEquals("wrong label key", LABEL_KEY, props.getLabel()
137 .getKey());
138 assertEquals("wrong label value", LABEL_VALUE, props.getLabel()
139 .getValue());
140 assertTrue("use custom class should be true", props.isUseCustomClass());
141 }
142
143 @Test
144 public void advancedGenericPropertiesAreValid() throws PrompterException
145 {
146 when(prompter.prompt("Use " + VersionTabPanelModuleCreator.GENERIC_CLASS + "?", PluginModulePrompter.YN_ANSWERS, "Y")).thenReturn("y");
147 when(prompter.prompt("Enter Plugin Module Name", "My Version Tab Panel")).thenReturn(ADV_MODULE_NAME);
148 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("y");
149
150 when(prompter.prompt("Plugin Key", "my-awesome-plugin")).thenReturn(ADV_MODULE_KEY);
151 when(prompter.prompt("Plugin Description", "The My Awesome Plugin Plugin")).thenReturn(ADV_DESCRIPTION);
152 when(prompter.prompt("i18n Name Key", "my-awesome-plugin.name")).thenReturn(ADV_I18N_NAME_KEY);
153 when(prompter.prompt("i18n Description Key", "my-awesome-plugin.description")).thenReturn(ADV_I18N_DESCRIPTION_KEY);
154
155 when(prompter.prompt("Order", "10")).thenReturn(ORDER);
156 when(prompter.prompt("Enter Label Key", "my-awesome-plugin.label")).thenReturn(LABEL_KEY);
157 when(prompter.prompt("Enter Label Value", ADV_MODULE_NAME)).thenReturn(LABEL_VALUE);
158
159 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
160
161 VersionTabPanelPrompter modulePrompter = new VersionTabPanelPrompter(prompter);
162 modulePrompter.setUseAnsiColor(false);
163 TabPanelProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
164
165 assertEquals("wrong adv class", VersionTabPanelModuleCreator.GENERIC_CLASS, props.getClassname());
166 assertEquals("wrong adv class package", VersionTabPanelModuleCreator.GENERIC_PACKAGE, props.getPackage());
167 assertEquals("wrong adv module name", ADV_MODULE_NAME, props.getModuleName());
168 assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
169 assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
170 assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
171 assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
172 assertEquals("wrong order", ORDER, props.getOrder());
173 assertEquals("wrong label key", LABEL_KEY, props.getLabel()
174 .getKey());
175 assertEquals("wrong label value", LABEL_VALUE, props.getLabel()
176 .getValue());
177 assertFalse("use custom class should be false", props.isUseCustomClass());
178 }
179 }