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.ActionProperties;
7 import com.atlassian.plugins.codegen.modules.jira.View;
8 import com.atlassian.plugins.codegen.modules.jira.WebworkProperties;
9
10 import org.codehaus.plexus.components.interactivity.Prompter;
11 import org.codehaus.plexus.components.interactivity.PrompterException;
12 import org.junit.Before;
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.mock;
19 import static org.mockito.Mockito.when;
20
21
22
23
24 public class WebworkPrompterTest extends AbstractPrompterTest
25 {
26 public static final String MODULE_NAME = "My Webwork";
27 public static final String MODULE_KEY = "my-webwork";
28 public static final String DESCRIPTION = "The My Webwork Plugin";
29 public static final String I18N_NAME_KEY = "my-webwork.name";
30 public static final String I18N_DESCRIPTION_KEY = "my-webwork.description";
31
32 public static final String ADV_MODULE_NAME = "My Awesome Plugin";
33 public static final String ADV_MODULE_KEY = "awesome-module";
34 public static final String ADV_DESCRIPTION = "The Awesomest Plugin Ever";
35 public static final String ADV_I18N_NAME_KEY = "awesome-plugin.name";
36 public static final String ADV_I18N_DESCRIPTION_KEY = "pluginus-awesomeous.description";
37
38 public static final String DEFAULT_ACTION_PACKAGE = "com.example.jira.webwork";
39 public static final String DEFAULT_ACTION_NAME = "MyWebworkAction";
40 public static final String DEFAULT_ACTION_ALIAS = "MyWebwork";
41 public static final String DEFAULT_TEMPLATE_PATH = "/templates/" + MODULE_KEY + "/";
42
43 public static final String CUSTOM_ACTION_PACKAGE = "my.custom.actions";
44 public static final String CUSTOM_ACTION_ONE_NAME = "CustomActionOne";
45 public static final String CUSTOM_ACTION_ONE_ALIAS = "ActionOne";
46
47 public static final String CUSTOM_ACTION_TWO_NAME = "CustomActionTwo";
48 public static final String CUSTOM_ACTION_TWO_ALIAS = "ActionTwo";
49
50 public static final String SUCCESS_VIEW_NAME = "success";
51 public static final String ACTION_ONE_VIEW_PATH_PREFIX = "/templates/actionone/";
52 public static final String SUCCESS_VIEW_PATH = ACTION_ONE_VIEW_PATH_PREFIX + "success.vm";
53
54 public static final String ERROR_VIEW_NAME = "error";
55 public static final String ERROR_VIEW_PATH = ACTION_ONE_VIEW_PATH_PREFIX + "error.vm";
56
57 public static final String CUSTOM_VIEW_NAME = "custom";
58 public static final String CUSTOM_VIEW_PATH = "/templates/actiontwo/custom.vm";
59
60 Prompter prompter;
61
62
63 @Before
64 public void setup()
65 {
66 prompter = mock(Prompter.class);
67 }
68
69 @Test
70 public void basicPropertiesAreValid() throws PrompterException
71 {
72 when(prompter.prompt("Enter Plugin Module Name", "My Webwork Module")).thenReturn(MODULE_NAME);
73 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
74 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
75
76 WebworkPrompter modulePrompter = new WebworkPrompter(prompter);
77 modulePrompter.setUseAnsiColor(false);
78 WebworkProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
79
80 assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
81 assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
82 assertEquals("wrong description", DESCRIPTION, props.getDescription());
83 assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
84 assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
85 assertEquals("wrong number of actions", 1, props.getActions()
86 .size());
87
88 ActionProperties action = props.getActions()
89 .get(0);
90 assertEquals("wrong action package", DEFAULT_ACTION_PACKAGE, action.getClassId().getPackage());
91 assertEquals("wrong action classname", DEFAULT_ACTION_NAME, action.getClassId().getName());
92 assertEquals("wrong action alias", DEFAULT_ACTION_ALIAS, action.getAlias());
93
94 assertEquals("wrong number of views", 3, action.getViews()
95 .size());
96 View success = action.getViews()
97 .get(0);
98 View input = action.getViews()
99 .get(1);
100 View error = action.getViews()
101 .get(2);
102
103 assertEquals("wrong view name", SUCCESS_VIEW_NAME, success.getName());
104 assertEquals("wrong view path", DEFAULT_TEMPLATE_PATH + "success.vm", success.getPath());
105
106 assertEquals("wrong view name", "input", input.getName());
107 assertEquals("wrong view path", DEFAULT_TEMPLATE_PATH + "input.vm", input.getPath());
108
109 assertEquals("wrong view name", ERROR_VIEW_NAME, error.getName());
110 assertEquals("wrong view path", DEFAULT_TEMPLATE_PATH + "error.vm", error.getPath());
111 }
112
113 @Test
114 public void advancedPropertiesAreValid() throws PrompterException
115 {
116 when(prompter.prompt("Enter Plugin Module Name", "My Webwork Module")).thenReturn(MODULE_NAME);
117 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
118 when(prompter.prompt(MODULE_KEY_PROMPT, MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
119 when(prompter.prompt(MODULE_DESCRIP_PROMPT, DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
120 when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
121 when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
122
123 when(prompter.prompt("Enter Action Classname", "MyActionClass")).thenReturn(CUSTOM_ACTION_ONE_NAME)
124 .thenReturn(CUSTOM_ACTION_TWO_NAME);
125 when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.webwork")).thenReturn(CUSTOM_ACTION_PACKAGE);
126 when(prompter.prompt("Enter Package Name", CUSTOM_ACTION_PACKAGE)).thenReturn(CUSTOM_ACTION_PACKAGE);
127 when(prompter.prompt("Enter Alias", CUSTOM_ACTION_ONE_NAME)).thenReturn(CUSTOM_ACTION_ONE_ALIAS);
128 when(prompter.prompt("Enter Alias", CUSTOM_ACTION_TWO_NAME)).thenReturn(CUSTOM_ACTION_TWO_ALIAS);
129
130 when(prompter.prompt("Enter View Name", "success")).thenReturn(SUCCESS_VIEW_NAME)
131 .thenReturn(ERROR_VIEW_NAME)
132 .thenReturn(CUSTOM_VIEW_NAME);
133
134 String prompterViewPathOne = "/templates/" + ADV_MODULE_KEY + "/" + CUSTOM_ACTION_ONE_NAME.toLowerCase() + "/";
135 String prompterViewPathTwo = "/templates/" + ADV_MODULE_KEY + "/" + CUSTOM_ACTION_TWO_NAME.toLowerCase() + "/";
136
137 when(prompter.prompt("Enter Template Path", prompterViewPathOne + "success.vm")).thenReturn(SUCCESS_VIEW_PATH);
138 when(prompter.prompt("Enter Template Path", ACTION_ONE_VIEW_PATH_PREFIX + "error.vm")).thenReturn(ERROR_VIEW_PATH);
139 when(prompter.prompt("Enter Template Path", prompterViewPathTwo + "custom.vm")).thenReturn(CUSTOM_VIEW_PATH);
140
141 when(prompter.prompt("Add Another Action?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
142 .thenReturn("N");
143 when(prompter.prompt("Add Another View?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
144 .thenReturn("N");
145
146 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
147
148 WebworkPrompter modulePrompter = new WebworkPrompter(prompter);
149 modulePrompter.setUseAnsiColor(false);
150 WebworkProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
151
152 assertEquals("wrong adv module name", MODULE_NAME, props.getModuleName());
153 assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
154 assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
155 assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
156 assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
157
158 assertEquals("wrong number of actions", 2, props.getActions()
159 .size());
160
161 ActionProperties actionOne = props.getActions()
162 .get(0);
163 ActionProperties actionTwo = props.getActions()
164 .get(1);
165
166 assertEquals("wrong action package", CUSTOM_ACTION_PACKAGE, actionOne.getClassId().getPackage());
167 assertEquals("wrong action classname", CUSTOM_ACTION_ONE_NAME, actionOne.getClassId().getName());
168 assertEquals("wrong action alias", CUSTOM_ACTION_ONE_ALIAS, actionOne.getAlias());
169
170 assertEquals("wrong action package", CUSTOM_ACTION_PACKAGE, actionTwo.getClassId().getPackage());
171 assertEquals("wrong action classname", CUSTOM_ACTION_TWO_NAME, actionTwo.getClassId().getName());
172 assertEquals("wrong action alias", CUSTOM_ACTION_TWO_ALIAS, actionTwo.getAlias());
173
174 assertEquals("wrong number of action one views", 2, actionOne.getViews()
175 .size());
176 View success = actionOne.getViews()
177 .get(0);
178 View error = actionOne.getViews()
179 .get(1);
180
181 assertEquals("wrong view name", SUCCESS_VIEW_NAME, success.getName());
182 assertEquals("wrong view path", SUCCESS_VIEW_PATH, success.getPath());
183
184 assertEquals("wrong view name", ERROR_VIEW_NAME, error.getName());
185 assertEquals("wrong view path", ERROR_VIEW_PATH, error.getPath());
186
187 assertEquals("wrong number of action one views", 1, actionTwo.getViews()
188 .size());
189 View custom = actionTwo.getViews()
190 .get(0);
191
192 assertEquals("wrong view name", CUSTOM_VIEW_NAME, custom.getName());
193 assertEquals("wrong view path", CUSTOM_VIEW_PATH, custom.getPath());
194 }
195 }