PageRenderTime 27ms CodeModel.GetById 7ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 1ms

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

https://bitbucket.org/mmeinhold/amps
Java | 126 lines | 103 code | 20 blank | 3 comment | 0 complexity | dff2ba5c4fefd4b63ba635a8a3a52421 MD5 | raw file
  1package com.atlassian.maven.plugins.amps.codegen.prompter.common;
  2
  3import java.util.Arrays;
  4
  5import com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter;
  6import com.atlassian.maven.plugins.amps.codegen.prompter.AbstractPrompterTest;
  7import com.atlassian.maven.plugins.amps.codegen.prompter.PluginModulePrompter;
  8import com.atlassian.plugins.codegen.modules.common.RESTProperties;
  9
 10import org.codehaus.plexus.components.interactivity.Prompter;
 11import org.codehaus.plexus.components.interactivity.PrompterException;
 12import org.junit.Before;
 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 com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_NAME_PROMPT;
 18import static org.junit.Assert.assertEquals;
 19import static org.mockito.Mockito.mock;
 20import static org.mockito.Mockito.when;
 21
 22/**
 23 * @since 3.6
 24 */
 25public class RESTPrompterTest extends AbstractPrompterTest
 26{
 27    public static final String PACKAGE = "com.atlassian.plugins.rest";
 28    public static final String CLASSNAME = "MyRestResource";
 29    public static final String MODULE_NAME = "My Rest Resource";
 30    public static final String MODULE_KEY = "my-rest-resource";
 31    public static final String DESCRIPTION = "The My Rest Resource Plugin";
 32    public static final String I18N_NAME_KEY = "my-rest-resource.name";
 33    public static final String I18N_DESCRIPTION_KEY = "my-rest-resource.description";
 34
 35    public static final String ADV_MODULE_NAME = "My Awesome Plugin";
 36    public static final String ADV_MODULE_KEY = "awesome-module";
 37    public static final String ADV_DESCRIPTION = "The Awesomest Plugin Ever";
 38    public static final String ADV_I18N_NAME_KEY = "awesome-plugin.name";
 39    public static final String ADV_I18N_DESCRIPTION_KEY = "pluginus-awesomeous.description";
 40
 41    public static final String PATH = "/helloworld";
 42    public static final String VERSION = "1.1";
 43
 44    Prompter prompter;
 45
 46    @Before
 47    public void setup()
 48    {
 49        prompter = mock(Prompter.class);
 50    }
 51
 52    @Test
 53    public void basicPropertiesAreValid() throws PrompterException
 54    {
 55        when(prompter.prompt("Enter New Classname", "MyRestResource")).thenReturn(CLASSNAME);
 56        when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".rest")).thenReturn(PACKAGE);
 57        when(prompter.prompt("Enter REST Path", "/myrestresource")).thenReturn(PATH);
 58        when(prompter.prompt("Enter Version", "1.0")).thenReturn(VERSION);
 59        when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
 60        when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
 61
 62        RESTPrompter modulePrompter = new RESTPrompter(prompter);
 63        modulePrompter.setUseAnsiColor(false);
 64        RESTProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
 65
 66        assertEquals("wrong class", CLASSNAME, props.getClassId().getName());
 67        assertEquals("wrong class package", PACKAGE, props.getClassId().getPackage());
 68        assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
 69        assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
 70        assertEquals("wrong description", DESCRIPTION, props.getDescription());
 71        assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
 72        assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
 73        assertEquals("wrong path", PATH, props.getPath());
 74        assertEquals("wrong version", VERSION, props.getVersion());
 75    }
 76
 77    @Test
 78    public void advancedPropertiesAreValid() throws PrompterException
 79    {
 80        String packageToScan = "com.atlassian.plugins.rest.helloworld";
 81
 82        when(prompter.prompt("Enter New Classname", "MyRestResource")).thenReturn(CLASSNAME);
 83        when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".rest")).thenReturn(PACKAGE);
 84        when(prompter.prompt("Enter REST Path", "/myrestresource")).thenReturn(PATH);
 85        when(prompter.prompt("Enter Version", "1.0")).thenReturn(VERSION);
 86        when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
 87
 88        when(prompter.prompt(MODULE_NAME_PROMPT, MODULE_NAME)).thenReturn(ADV_MODULE_NAME);
 89        when(prompter.prompt(MODULE_KEY_PROMPT, MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
 90        when(prompter.prompt(MODULE_DESCRIP_PROMPT, DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
 91        when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
 92        when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
 93        when(prompter.prompt("Add Package To Scan?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("y");
 94        when(prompter.prompt("Enter Package")).thenReturn(packageToScan);
 95        when(prompter.prompt("values:\n" + packageToScan + "\nAdd Package To Scan?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
 96
 97        when(prompter.prompt("Add Dispatcher?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("y")
 98                .thenReturn("N");
 99        when(prompter.prompt("Choose A Dispatcher\n1: REQUEST\n2: INCLUDE\n3: FORWARD\n4: ERROR\nChoose a number: ", Arrays.asList("1", "2", "3", "4"), "1")).thenReturn("3");
100        when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
101
102        RESTPrompter modulePrompter = new RESTPrompter(prompter);
103        modulePrompter.setUseAnsiColor(false);
104        RESTProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
105
106        assertEquals("wrong adv class", CLASSNAME, props.getClassId().getName());
107        assertEquals("wrong adv package", PACKAGE, props.getClassId().getPackage());
108        assertEquals("wrong adv module name", ADV_MODULE_NAME, props.getModuleName());
109        assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
110        assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
111        assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
112        assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
113        assertEquals("wrong path", PATH, props.getPath());
114        assertEquals("wrong version", VERSION, props.getVersion());
115
116        assertEquals("wrong number of packages", 1, props.getPackagesToScan()
117                .size());
118        assertEquals("wrong package", packageToScan, props.getPackagesToScan()
119                .get(0));
120
121        assertEquals("wrong number of dispatcher", 1, props.getDispatchers()
122                .size());
123        assertEquals("wrong dispatcher", "FORWARD", props.getDispatchers()
124                .get(0));
125    }
126}