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