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.WorkflowElementProperties;
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 WorkflowConditionPrompterTest extends AbstractPrompterTest
21 {
22 public static final String PACKAGE = "com.atlassian.plugins.jira.workflow";
23 public static final String CLASSNAME = "MyWorkflowCondition";
24 public static final String FACTORY_CLASSNAME = "MyWorkflowConditionFactory";
25 public static final String MODULE_NAME = "My Workflow Condition";
26 public static final String MODULE_KEY = "my-workflow-condition";
27 public static final String DESCRIPTION = "The My Workflow Condition Plugin";
28 public static final String I18N_NAME_KEY = "my-workflow-condition.name";
29 public static final String I18N_DESCRIPTION_KEY = "my-workflow-condition.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 Prompter prompter;
38
39 @Before
40 public void setup()
41 {
42 prompter = mock(Prompter.class);
43 }
44
45 @Test
46 public void basicPropertiesAreValid() throws PrompterException
47 {
48 when(prompter.prompt("Enter New Classname", "MyWorkflowCondition")).thenReturn(CLASSNAME);
49 when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.workflow")).thenReturn(PACKAGE);
50 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
51 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
52
53 WorkflowConditionPrompter modulePrompter = new WorkflowConditionPrompter(prompter);
54 modulePrompter.setUseAnsiColor(false);
55 WorkflowElementProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
56
57 assertEquals("wrong condition class", CLASSNAME, props.getClassname());
58 assertEquals("wrong factory class", FACTORY_CLASSNAME, props.getFactoryName());
59 assertEquals("wrong class package", PACKAGE, props.getPackage());
60 assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
61 assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
62 assertEquals("wrong description", DESCRIPTION, props.getDescription());
63 assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
64 assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
65 }
66
67 @Test
68 public void advancedPropertiesAreValid() throws PrompterException
69 {
70 when(prompter.prompt("Enter New Classname", "MyWorkflowCondition")).thenReturn(CLASSNAME);
71 when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.workflow")).thenReturn(PACKAGE);
72 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
73
74 when(prompter.prompt("Plugin Name", MODULE_NAME)).thenReturn(ADV_MODULE_NAME);
75 when(prompter.prompt("Plugin Key", MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
76 when(prompter.prompt("Plugin Description", DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
77 when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
78 when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
79
80 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
81
82 WorkflowConditionPrompter modulePrompter = new WorkflowConditionPrompter(prompter);
83 modulePrompter.setUseAnsiColor(false);
84 WorkflowElementProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
85
86 assertEquals("wrong condition class", CLASSNAME, props.getClassname());
87 assertEquals("wrong factory class", FACTORY_CLASSNAME, props.getFactoryName());
88 assertEquals("wrong adv module name", ADV_MODULE_NAME, props.getModuleName());
89 assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
90 assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
91 assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
92 assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
93 }
94 }