PageRenderTime 66ms CodeModel.GetById 29ms app.highlight 33ms RepoModel.GetById 1ms app.codeStats 0ms

/plugin-module-codegen-maven-client/src/test/java/com/atlassian/maven/plugins/amps/codegen/prompter/jira/ProjectTabPanelPrompterTest.java

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