1 package com.atlassian.maven.plugins.amps.codegen.prompter.common.web;
2
3 import java.util.Arrays;
4 import java.util.SortedMap;
5 import java.util.TreeMap;
6
7 import com.atlassian.maven.plugins.amps.codegen.prompter.PluginModulePrompter;
8 import com.atlassian.plugins.codegen.modules.common.Condition;
9 import com.atlassian.plugins.codegen.modules.common.Conditions;
10 import com.atlassian.plugins.codegen.modules.common.web.WebItemProperties;
11
12 import org.codehaus.plexus.components.interactivity.PrompterException;
13 import org.junit.Test;
14
15 import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_DESCRIP_PROMPT;
16 import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_KEY_PROMPT;
17 import static org.junit.Assert.assertEquals;
18 import static org.mockito.Mockito.when;
19
20
21
22
23 public class WebItemPrompterTest extends AbstractWebFragmentPrompterTest<WebItemProperties>
24 {
25 public static final String MODULE_NAME = "My Web Item";
26 public static final String MODULE_KEY = "my-web-item";
27 public static final String LINK_ID = "item-link";
28 public static final String DESCRIPTION = "The My Web Item Plugin";
29 public static final String I18N_NAME_KEY = "my-web-item.name";
30 public static final String I18N_DESCRIPTION_KEY = "my-web-item.description";
31
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 public static final String SYSTEM_ADMIN_SETTINGS = "system.admin/settings";
37 public static final String LINK_URL = "/secure/MyAction.jspa";
38 public static final String WEIGHT = "20";
39 public static final String LABEL_KEY = "item.label";
40 public static final String LABEL_VALUE = "this is my label";
41 public static final String LABEL_PARAM = "label param";
42 public static final String ICON_PATH = "/images/icon.png";
43 public static final String ICON_WIDTH = "32";
44 public static final String ICON_HEIGHT = "20";
45 public static final String TOOLTIP_KEY = "item.toolip";
46 public static final String TOOLTIP_VALUE = "this is a tooltip";
47
48 @Test
49 public void basicPropertiesAreValid() throws PrompterException
50 {
51 when(prompter.prompt("Enter Plugin Module Name", "My Web Item")).thenReturn(MODULE_NAME);
52 when(prompter.prompt("Enter Section (e.g. system.admin/globalsettings)")).thenReturn(SYSTEM_ADMIN_SETTINGS);
53 when(prompter.prompt("Enter Link URL (e.g. /secure/CreateIssue!default.jspa)")).thenReturn(LINK_URL);
54
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 WebItemPrompter modulePrompter = new WebItemPrompter(prompter);
59 modulePrompter.setUseAnsiColor(false);
60 setProps((WebItemProperties) modulePrompter.getModulePropertiesFromInput(moduleLocation));
61
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 section", SYSTEM_ADMIN_SETTINGS, props.getSection());
68 assertEquals("wrong link", LINK_URL, props.getLink()
69 .getValue());
70 }
71
72 @Test
73 public void advancedPropertiesAreValid() throws PrompterException
74 {
75 when(prompter.prompt("Enter Plugin Module Name", "My Web Item")).thenReturn(MODULE_NAME);
76 when(prompter.prompt("Enter Section (e.g. system.admin/globalsettings)")).thenReturn(SYSTEM_ADMIN_SETTINGS);
77 when(prompter.prompt("Enter Link URL (e.g. /secure/CreateIssue!default.jspa)")).thenReturn(LINK_URL);
78
79 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
80 when(prompter.prompt(MODULE_KEY_PROMPT, MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
81 when(prompter.prompt(MODULE_DESCRIP_PROMPT, DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
82 when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
83 when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
84 when(prompter.prompt("Weight", "1000")).thenReturn(WEIGHT);
85 when(prompter.prompt("Link Id", "my-web-item-link")).thenReturn(LINK_ID);
86 when(prompter.prompt("Enter Label Key", "my-web-item.label")).thenReturn(LABEL_KEY);
87 when(prompter.prompt("Enter Label Value", "My Web Item")).thenReturn(LABEL_VALUE);
88 when(prompter.prompt("Add Label Param?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
89 .thenReturn("N");
90 when(prompter.prompt("values:\nlabel param\nAdd Label Param?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
91 when(prompter.prompt("Enter Param Value")).thenReturn(LABEL_PARAM);
92 when(prompter.prompt("Add Icon?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
93 .thenReturn("N");
94 when(prompter.prompt("Icon Location (e.g. /images/icons/print.gif)")).thenReturn(ICON_PATH);
95 when(prompter.prompt("Icon Width", "16")).thenReturn(ICON_WIDTH);
96 when(prompter.prompt("Icon Height", "16")).thenReturn(ICON_HEIGHT);
97 when(prompter.prompt("Add Tooltip?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
98 .thenReturn("N");
99 when(prompter.prompt("Enter Tooltip Key", "awesome-module.tooltip")).thenReturn(TOOLTIP_KEY);
100 when(prompter.prompt("Enter Tooltip Value", "My Web Item Tooltip")).thenReturn(TOOLTIP_VALUE);
101 when(prompter.prompt("Add Tooltip Param?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
102 when(prompter.prompt("Add Plugin Module Param?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
103 .thenReturn("N");
104 when(prompter.prompt("params:\nparamKey->paramVal\nAdd Plugin Module Param?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
105
106
107 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
108
109 WebItemPrompter modulePrompter = new WebItemPrompter(prompter);
110 modulePrompter.setUseAnsiColor(false);
111 setProps((WebItemProperties) modulePrompter.getModulePropertiesFromInput(moduleLocation));
112
113 assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
114 assertEquals("wrong module key", ADV_MODULE_KEY, props.getModuleKey());
115 assertEquals("wrong description", ADV_DESCRIPTION, props.getDescription());
116 assertEquals("wrong i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
117 assertEquals("wrong i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
118 assertEquals("wrong section", SYSTEM_ADMIN_SETTINGS, props.getSection());
119 assertEquals("wrong link", LINK_URL, props.getLink()
120 .getValue());
121 assertEquals("wrong weight", WEIGHT, props.getWeight());
122
123 assertAdvancedCommonProps();
124
125
126 assertEquals("wrong context provider", CUSTOM_CONTEXT_PROVIDER, props.getContextProvider());
127
128
129 Condition condition = (Condition) ((Conditions) props.getConditions()
130 .get(0)).getConditions()
131 .get(0);
132 assertEquals("wrong condition name", CUSTOM_CONDITION, condition.getFullyQualifiedClassName());
133 }
134
135 @Test
136 public void providerContextFromListIsValid() throws PrompterException
137 {
138 SortedMap<String, String> providersMap = new TreeMap<String, String>();
139 providersMap.put("HeightContextProvider", "com.atlassian.test.HeightContextPRovider");
140 providersMap.put("WidthContextProvider", "com.atlassian.test.WidthContextProvider");
141
142 contextProviderFactory.setProvidersMap(providersMap);
143
144 when(prompter.prompt("Enter Plugin Module Name", "My Web Item")).thenReturn(MODULE_NAME);
145 when(prompter.prompt("Enter Section (e.g. system.admin/globalsettings)")).thenReturn(SYSTEM_ADMIN_SETTINGS);
146 when(prompter.prompt("Enter Link URL (e.g. /secure/CreateIssue!default.jspa)")).thenReturn(LINK_URL);
147
148 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
149 when(prompter.prompt(MODULE_KEY_PROMPT, MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
150 when(prompter.prompt(MODULE_DESCRIP_PROMPT, DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
151 when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
152 when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
153 when(prompter.prompt("Weight", "1000")).thenReturn(WEIGHT);
154 when(prompter.prompt("Link Id", "my-web-item-link")).thenReturn(LINK_ID);
155 when(prompter.prompt("Enter Label Key", "my-web-item.label")).thenReturn(LABEL_KEY);
156 when(prompter.prompt("Enter Label Value", "My Web Item")).thenReturn(LABEL_VALUE);
157 when(prompter.prompt("Add Label Param?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
158 .thenReturn("N");
159 when(prompter.prompt("values:\nlabel param\nAdd Label Param?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
160 when(prompter.prompt("Enter Param Value")).thenReturn(LABEL_PARAM);
161 when(prompter.prompt("Add Icon?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
162 .thenReturn("N");
163 when(prompter.prompt("Icon Location (e.g. /images/icons/print.gif)")).thenReturn(ICON_PATH);
164 when(prompter.prompt("Icon Width", "16")).thenReturn(ICON_WIDTH);
165 when(prompter.prompt("Icon Height", "16")).thenReturn(ICON_HEIGHT);
166 when(prompter.prompt("Add Tooltip?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
167 .thenReturn("N");
168 when(prompter.prompt("Enter Tooltip Key", "awesome-module.tooltip")).thenReturn(TOOLTIP_KEY);
169 when(prompter.prompt("Enter Tooltip Value", "My Web Item Tooltip")).thenReturn(TOOLTIP_VALUE);
170 when(prompter.prompt("Add Tooltip Param?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
171 when(prompter.prompt("Add Plugin Module Param?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
172 .thenReturn("N");
173 when(prompter.prompt("params:\nparamKey->paramVal\nAdd Plugin Module Param?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
174
175 when(prompter.prompt("Choose A Context Provider\n1: HeightContextProvider\n2: WidthContextProvider\n3: Custom Context Provider\nChoose a number: ", Arrays.asList("1", "2", "3"), "")).thenReturn("2");
176
177 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
178
179 WebItemPrompter modulePrompter = new WebItemPrompter(prompter);
180 modulePrompter.setUseAnsiColor(false);
181 setProps((WebItemProperties) modulePrompter.getModulePropertiesFromInput(moduleLocation));
182
183 assertEquals("wrong context provider", "com.atlassian.test.WidthContextProvider", props.getContextProvider());
184 }
185
186 @Test
187 public void conditionFromListIsValid() throws PrompterException
188 {
189 SortedMap<String, String> conditionMap = new TreeMap<String, String>();
190 conditionMap.put("NoFacialHairCondition", "com.atlassian.test.NoFacialHairCondition");
191 conditionMap.put("HasGlobalAdminPermissionCondition", "com.atlassian.test.HasGlobalAdminPermissionCondition");
192
193 conditionFactory.setConditions(conditionMap);
194
195 when(prompter.prompt("Enter Plugin Module Name", "My Web Item")).thenReturn(MODULE_NAME);
196 when(prompter.prompt("Enter Section (e.g. system.admin/globalsettings)")).thenReturn(SYSTEM_ADMIN_SETTINGS);
197 when(prompter.prompt("Enter Link URL (e.g. /secure/CreateIssue!default.jspa)")).thenReturn(LINK_URL);
198
199 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
200 when(prompter.prompt(MODULE_KEY_PROMPT, MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
201 when(prompter.prompt(MODULE_DESCRIP_PROMPT, DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
202 when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
203 when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
204 when(prompter.prompt("Weight", "1000")).thenReturn(WEIGHT);
205 when(prompter.prompt("Link Id", "my-web-item-link")).thenReturn(LINK_ID);
206 when(prompter.prompt("Enter Label Key", "my-web-item.label")).thenReturn(LABEL_KEY);
207 when(prompter.prompt("Enter Label Value", "My Web Item")).thenReturn(LABEL_VALUE);
208 when(prompter.prompt("Add Label Param?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
209 .thenReturn("N");
210 when(prompter.prompt("values:\nlabel param\nAdd Label Param?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
211 when(prompter.prompt("Enter Param Value")).thenReturn(LABEL_PARAM);
212 when(prompter.prompt("Add Icon?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
213 .thenReturn("N");
214 when(prompter.prompt("Icon Location (e.g. /images/icons/print.gif)")).thenReturn(ICON_PATH);
215 when(prompter.prompt("Icon Width", "16")).thenReturn(ICON_WIDTH);
216 when(prompter.prompt("Icon Height", "16")).thenReturn(ICON_HEIGHT);
217 when(prompter.prompt("Add Tooltip?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
218 .thenReturn("N");
219 when(prompter.prompt("Enter Tooltip Key", "awesome-module.tooltip")).thenReturn(TOOLTIP_KEY);
220 when(prompter.prompt("Enter Tooltip Value", "My Web Item Tooltip")).thenReturn(TOOLTIP_VALUE);
221 when(prompter.prompt("Add Tooltip Param?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
222 when(prompter.prompt("Add Plugin Module Param?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
223 .thenReturn("N");
224 when(prompter.prompt("params:\nparamKey->paramVal\nAdd Plugin Module Param?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
225
226 when(prompter.prompt("Choose A Condition\n1: HasGlobalAdminPermissionCondition\n2: NoFacialHairCondition\n3: Custom Condition\nChoose a number: ", Arrays.asList("1", "2", "3"), "")).thenReturn("2");
227
228 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
229
230 WebItemPrompter modulePrompter = new WebItemPrompter(prompter);
231 modulePrompter.setUseAnsiColor(false);
232 setProps((WebItemProperties) modulePrompter.getModulePropertiesFromInput(moduleLocation));
233
234 Condition condition = (Condition) ((Conditions) props.getConditions()
235 .get(0)).getConditions()
236 .get(0);
237 assertEquals("wrong condition name", "com.atlassian.test.NoFacialHairCondition", condition.getFullyQualifiedClassName());
238
239 }
240
241 }