PageRenderTime 30ms CodeModel.GetById 13ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/mmeinhold/amps
Java | 136 lines | 109 code | 23 blank | 4 comment | 0 complexity | 682be1d6e5284042dd72e92d2cfad161 MD5 | raw file
  1package com.atlassian.maven.plugins.amps.codegen.prompter.jira;
  2
  3import java.util.List;
  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.Resource;
  9import com.atlassian.plugins.codegen.modules.jira.SearchRequestViewProperties;
 10
 11import org.apache.commons.lang.StringUtils;
 12import org.codehaus.plexus.components.interactivity.Prompter;
 13import org.codehaus.plexus.components.interactivity.PrompterException;
 14import org.junit.Before;
 15import org.junit.Test;
 16
 17import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_DESCRIP_PROMPT;
 18import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_KEY_PROMPT;
 19import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_NAME_PROMPT;
 20import static org.junit.Assert.assertEquals;
 21import static org.junit.Assert.assertTrue;
 22import static org.mockito.Mockito.mock;
 23import static org.mockito.Mockito.when;
 24
 25/**
 26 * @since 3.6
 27 */
 28public class SearchRequestViewPrompterTest extends AbstractPrompterTest
 29{
 30    public static final String PACKAGE = "com.atlassian.plugins.jira.search";
 31    public static final String CLASSNAME = "MySearchRequestView";
 32    public static final String MODULE_NAME = "My Search Request View";
 33    public static final String MODULE_KEY = "my-search-request-view";
 34    public static final String DESCRIPTION = "The My Search Request View Plugin";
 35    public static final String I18N_NAME_KEY = "my-search-request-view.name";
 36    public static final String I18N_DESCRIPTION_KEY = "my-search-request-view.description";
 37
 38    public static final String ADV_MODULE_NAME = "My Awesome Plugin";
 39    public static final String ADV_MODULE_KEY = "awesome-module";
 40    public static final String ADV_DESCRIPTION = "The Awesomest Plugin Ever";
 41    public static final String ADV_I18N_NAME_KEY = "awesome-plugin.name";
 42    public static final String ADV_I18N_DESCRIPTION_KEY = "pluginus-awesomeous.description";
 43
 44    public static final String EXT = "html";
 45    public static final String CTYPE = "text/html";
 46
 47    public static final String RESOURCE_NAME = "view";
 48    public static final String RESOURCE_VM_PATH = "templates/resource.vm";
 49
 50    Prompter prompter;
 51
 52    @Before
 53    public void setup()
 54    {
 55        prompter = mock(Prompter.class);
 56    }
 57
 58    @Test
 59    public void basicPropertiesAreValid() throws PrompterException
 60    {
 61        when(prompter.prompt("Enter New Classname", "MySearchRequestView")).thenReturn(CLASSNAME);
 62        when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.search")).thenReturn(PACKAGE);
 63        when(prompter.prompt("Enter File Extension (i.e. html)")).thenReturn(EXT);
 64        when(prompter.prompt("Enter Content Type (i.e. text/html)")).thenReturn(CTYPE);
 65
 66        when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
 67        when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
 68
 69        SearchRequestViewPrompter modulePrompter = new SearchRequestViewPrompter(prompter);
 70        modulePrompter.setUseAnsiColor(false);
 71        SearchRequestViewProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
 72
 73        assertEquals("wrong class", CLASSNAME, props.getClassId().getName());
 74        assertEquals("wrong class package", PACKAGE, props.getClassId().getPackage());
 75        assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
 76        assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
 77        assertEquals("wrong description", DESCRIPTION, props.getDescription());
 78        assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
 79        assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
 80        assertEquals("wrong extension", EXT, props.getFileExtension());
 81        assertEquals("wrong content type", CTYPE, props.getContentType());
 82        assertEquals("wrong default order", "10", props.getOrder());
 83    }
 84
 85    @Test
 86    public void advancedPropertiesAreValid() throws PrompterException
 87    {
 88        when(prompter.prompt("Enter New Classname", "MySearchRequestView")).thenReturn(CLASSNAME);
 89        when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.search")).thenReturn(PACKAGE);
 90        when(prompter.prompt("Enter File Extension (i.e. html)")).thenReturn(EXT);
 91        when(prompter.prompt("Enter Content Type (i.e. text/html)")).thenReturn(CTYPE);
 92        when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
 93
 94        when(prompter.prompt(MODULE_NAME_PROMPT, MODULE_NAME)).thenReturn(ADV_MODULE_NAME);
 95        when(prompter.prompt(MODULE_KEY_PROMPT, MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
 96        when(prompter.prompt(MODULE_DESCRIP_PROMPT, DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
 97        when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
 98        when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
 99
100        when(prompter.prompt("Enter Order", "10")).thenReturn("100");
101        when(prompter.prompt("Add Resource", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
102                .thenReturn("N");
103        when(prompter.prompt("Enter Resource Name")).thenReturn(RESOURCE_NAME)
104                .thenReturn("");
105        when(prompter.prompt("Enter Location (path to resource file)")).thenReturn(RESOURCE_VM_PATH);
106
107        when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
108
109        SearchRequestViewPrompter modulePrompter = new SearchRequestViewPrompter(prompter);
110        modulePrompter.setUseAnsiColor(false);
111        SearchRequestViewProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
112
113        assertEquals("wrong adv class", CLASSNAME, props.getClassId().getName());
114        assertEquals("wrong adv package", PACKAGE, props.getClassId().getPackage());
115        assertEquals("wrong adv module name", ADV_MODULE_NAME, props.getModuleName());
116        assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
117        assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
118        assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
119        assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
120        assertEquals("wrong extension", EXT, props.getFileExtension());
121        assertEquals("wrong content type", CTYPE, props.getContentType());
122        assertEquals("wrong order", "100", props.getOrder());
123
124        //resources
125        List<Resource> resources = props.getResources();
126        assertTrue("resources not found", !resources.isEmpty());
127        assertEquals("wrong number of resources", 1, resources.size());
128
129        Resource viewResource = resources.get(0);
130
131        assertEquals("wrong css resource name", RESOURCE_NAME, viewResource.getName());
132        assertTrue("name pattern found when name is set", StringUtils.isBlank(viewResource.getNamePattern()));
133        assertEquals("wrong resource type", "velocity", viewResource.getType());
134        assertEquals("wrong resource location", RESOURCE_VM_PATH, viewResource.getLocation());
135    }
136}