PageRenderTime 35ms CodeModel.GetById 15ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

/plugin-module-codegen-maven-client/src/test/java/com/atlassian/maven/plugins/amps/codegen/prompter/common/web/WebPanelPrompterTest.java

https://bitbucket.org/mmeinhold/amps
Java | 161 lines | 121 code | 35 blank | 5 comment | 0 complexity | 00429a55fc6dd2041ffac20c418f2a5d MD5 | raw file
  1package com.atlassian.maven.plugins.amps.codegen.prompter.common.web;
  2
  3import java.util.Arrays;
  4import java.util.SortedMap;
  5import java.util.TreeMap;
  6
  7import com.atlassian.maven.plugins.amps.codegen.prompter.PluginModulePrompter;
  8import com.atlassian.plugins.codegen.modules.common.Condition;
  9import com.atlassian.plugins.codegen.modules.common.Conditions;
 10import com.atlassian.plugins.codegen.modules.common.web.WebPanelProperties;
 11
 12import org.codehaus.plexus.components.interactivity.PrompterException;
 13import org.junit.Test;
 14
 15import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_DESCRIP_PROMPT;
 16import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_KEY_PROMPT;
 17import static org.junit.Assert.assertEquals;
 18import static org.mockito.Mockito.when;
 19
 20/**
 21 * @since 3.6
 22 */
 23public class WebPanelPrompterTest extends AbstractWebFragmentPrompterTest<WebPanelProperties>
 24{
 25    public static final String MODULE_NAME = "My Web Panel";
 26    public static final String MODULE_KEY = "my-web-panel";
 27    public static final String DESCRIPTION = "The My Web Panel Plugin";
 28    public static final String I18N_NAME_KEY = "my-web-panel.name";
 29    public static final String I18N_DESCRIPTION_KEY = "my-web-panel.description";
 30
 31    public static final String ADV_MODULE_KEY = "awesome-module";
 32    public static final String ADV_DESCRIPTION = "The Awesomest Plugin Ever";
 33    public static final String ADV_I18N_NAME_KEY = "awesome-plugin.name";
 34    public static final String ADV_I18N_DESCRIPTION_KEY = "pluginus-awesomeous.description";
 35    public static final String CUSTOM_SECTION = "system.admin/globalsettings";
 36    public static final String WEIGHT = "20";
 37
 38    @Test
 39    public void basicPropertiesAreValid() throws PrompterException
 40    {
 41        when(prompter.prompt("Enter Plugin Module Name", "My Web Panel")).thenReturn(MODULE_NAME);
 42        when(prompter.prompt("Enter Location (e.g. system.admin/globalsettings)")).thenReturn(CUSTOM_SECTION);
 43
 44        when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
 45        when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
 46
 47        WebPanelPrompter modulePrompter = new WebPanelPrompter(prompter);
 48        modulePrompter.setUseAnsiColor(false);
 49        setProps((WebPanelProperties) modulePrompter.getModulePropertiesFromInput(moduleLocation));
 50
 51        assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
 52        assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
 53        assertEquals("wrong description", DESCRIPTION, props.getDescription());
 54        assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
 55        assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
 56        assertEquals("wrong location", CUSTOM_SECTION, props.getLocation());
 57    }
 58
 59    @Test
 60    public void advancedPropertiesAreValid() throws PrompterException
 61    {
 62        when(prompter.prompt("Enter Plugin Module Name", "My Web Panel")).thenReturn(MODULE_NAME);
 63        when(prompter.prompt("Enter Location (e.g. system.admin/globalsettings)")).thenReturn(CUSTOM_SECTION);
 64
 65        when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
 66        when(prompter.prompt(MODULE_KEY_PROMPT, MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
 67        when(prompter.prompt(MODULE_DESCRIP_PROMPT, DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
 68        when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
 69        when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
 70        when(prompter.prompt("Weight", "1000")).thenReturn(WEIGHT);
 71
 72        when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
 73
 74        WebPanelPrompter modulePrompter = new WebPanelPrompter(prompter);
 75        modulePrompter.setUseAnsiColor(false);
 76        setProps((WebPanelProperties) modulePrompter.getModulePropertiesFromInput(moduleLocation));
 77
 78        assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
 79        assertEquals("wrong module key", ADV_MODULE_KEY, props.getModuleKey());
 80        assertEquals("wrong description", ADV_DESCRIPTION, props.getDescription());
 81        assertEquals("wrong i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
 82        assertEquals("wrong i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
 83        assertEquals("wrong location", CUSTOM_SECTION, props.getLocation());
 84        assertEquals("wrong weight", WEIGHT, props.getWeight());
 85
 86        assertAdvancedCommonProps();
 87
 88        //custom context-provider name check
 89        assertEquals("wrong context provider", CUSTOM_CONTEXT_PROVIDER, props.getContextProvider());
 90
 91        //custom condition name check
 92        Condition condition = (Condition) ((Conditions) props.getConditions()
 93                .get(0)).getConditions()
 94                .get(0);
 95        assertEquals("wrong condition name", CUSTOM_CONDITION, condition.getFullyQualifiedClassName());
 96    }
 97
 98    @Test
 99    public void providerContextFromListIsValid() throws PrompterException
100    {
101        SortedMap<String, String> providersMap = new TreeMap<String, String>();
102        providersMap.put("HeightContextProvider", "com.atlassian.test.HeightContextProvider");
103        providersMap.put("WidthContextProvider", "com.atlassian.test.WidthContextProvider");
104
105        contextProviderFactory.setProvidersMap(providersMap);
106
107        when(prompter.prompt("Enter Plugin Module Name", "My Web Panel")).thenReturn(MODULE_NAME);
108        when(prompter.prompt("Enter Location (e.g. system.admin/globalsettings)")).thenReturn(CUSTOM_SECTION);
109
110        when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
111        when(prompter.prompt(MODULE_KEY_PROMPT, MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
112        when(prompter.prompt(MODULE_DESCRIP_PROMPT, DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
113        when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
114        when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
115        when(prompter.prompt("Weight", "1000")).thenReturn(WEIGHT);
116
117        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");
118
119        when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
120
121        WebPanelPrompter modulePrompter = new WebPanelPrompter(prompter);
122        modulePrompter.setUseAnsiColor(false);
123        setProps((WebPanelProperties) modulePrompter.getModulePropertiesFromInput(moduleLocation));
124
125        assertEquals("wrong context provider", "com.atlassian.test.WidthContextProvider", props.getContextProvider());
126
127    }
128
129    @Test
130    public void conditionFromListIsValid() throws PrompterException
131    {
132        SortedMap<String, String> conditionMap = new TreeMap<String, String>();
133        conditionMap.put("NoFacialHairCondition", "com.atlassian.test.NoFacialHairCondition");
134        conditionMap.put("HasGlobalAdminPermissionCondition", "com.atlassian.test.HasGlobalAdminPermissionCondition");
135
136        conditionFactory.setConditions(conditionMap);
137
138        when(prompter.prompt("Enter Plugin Module Name", "My Web Panel")).thenReturn(MODULE_NAME);
139        when(prompter.prompt("Enter Location (e.g. system.admin/globalsettings)")).thenReturn(CUSTOM_SECTION);
140
141        when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
142        when(prompter.prompt(MODULE_KEY_PROMPT, MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
143        when(prompter.prompt(MODULE_DESCRIP_PROMPT, DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
144        when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
145        when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
146        when(prompter.prompt("Weight", "1000")).thenReturn(WEIGHT);
147
148        when(prompter.prompt("Choose A Condition\n1: HasGlobalAdminPermissionCondition\n2: NoFacialHairCondition\n3: Custom Condition\nChoose a number: ", Arrays.asList("1", "2", "3"), "")).thenReturn("2");
149
150        when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
151
152        WebPanelPrompter modulePrompter = new WebPanelPrompter(prompter);
153        modulePrompter.setUseAnsiColor(false);
154        setProps((WebPanelProperties) modulePrompter.getModulePropertiesFromInput(moduleLocation));
155
156        Condition condition = (Condition) ((Conditions) props.getConditions()
157                .get(0)).getConditions()
158                .get(0);
159        assertEquals("wrong condition name", "com.atlassian.test.NoFacialHairCondition", condition.getFullyQualifiedClassName());
160    }
161}