1 package com.atlassian.maven.plugins.amps.codegen.prompter.common;
2
3 import com.atlassian.maven.plugins.amps.codegen.prompter.AbstractPrompterTest;
4 import com.atlassian.maven.plugins.amps.codegen.prompter.PluginModulePrompter;
5 import com.atlassian.plugins.codegen.modules.common.TemplateContextItemProperties;
6
7 import org.codehaus.plexus.components.interactivity.Prompter;
8 import org.codehaus.plexus.components.interactivity.PrompterException;
9 import org.junit.Before;
10 import org.junit.Test;
11
12 import static org.junit.Assert.*;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.when;
15
16
17
18
19 public class TemplateContextItemPrompterTest extends AbstractPrompterTest
20 {
21 public static final String CLASSNAME = "com.atlassian.plugins.MyContextItem";
22 public static final String MODULE_NAME = "My Context Item";
23 public static final String MODULE_KEY = "my-context-item";
24 public static final String DESCRIPTION = "The My Context Item Plugin";
25 public static final String I18N_NAME_KEY = "my-context-item.name";
26 public static final String I18N_DESCRIPTION_KEY = "my-context-item.description";
27
28 public static final String CONTEXT_KEY = "i18n";
29 public static final String COMPONENT_REF = "i18nResolver";
30
31 Prompter prompter;
32
33 @Before
34 public void setup()
35 {
36 prompter = mock(Prompter.class);
37 }
38
39 @Test
40 public void nonGlobalComponentRefIsValid() throws PrompterException
41 {
42 when(prompter.prompt("Enter Plugin Module Name", "My Context Item")).thenReturn(MODULE_NAME);
43 when(prompter.prompt("Enter Context Key")).thenReturn(CONTEXT_KEY);
44 when(prompter.prompt("Enter Component-Ref Key (leave blank to specify class)")).thenReturn(COMPONENT_REF);
45 when(prompter.prompt("Global Access?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
46 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
47 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
48
49 TemplateContextItemPrompter modulePrompter = new TemplateContextItemPrompter(prompter);
50 modulePrompter.setUseAnsiColor(false);
51 TemplateContextItemProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
52
53 assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
54 assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
55 assertEquals("wrong description", DESCRIPTION, props.getDescription());
56 assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
57 assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
58
59 assertEquals("wrong context key", CONTEXT_KEY, props.getContextKey());
60 assertEquals("wrong component-ref", COMPONENT_REF, props.getComponentRef());
61 assertFalse("wong global access", props.isGlobal());
62 }
63
64 @Test
65 public void globalComponentRefIsValid() throws PrompterException
66 {
67 when(prompter.prompt("Enter Plugin Module Name", "My Context Item")).thenReturn(MODULE_NAME);
68 when(prompter.prompt("Enter Context Key")).thenReturn(CONTEXT_KEY);
69 when(prompter.prompt("Enter Component-Ref Key (leave blank to specify class)")).thenReturn(COMPONENT_REF);
70 when(prompter.prompt("Global Access?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
71 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
72 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
73
74 TemplateContextItemPrompter modulePrompter = new TemplateContextItemPrompter(prompter);
75 modulePrompter.setUseAnsiColor(false);
76 TemplateContextItemProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
77
78 assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
79 assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
80 assertEquals("wrong description", DESCRIPTION, props.getDescription());
81 assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
82 assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
83
84 assertEquals("wrong context key", CONTEXT_KEY, props.getContextKey());
85 assertEquals("wrong component-ref", COMPONENT_REF, props.getComponentRef());
86 assertTrue("wong global access", props.isGlobal());
87 }
88
89 @Test
90 public void nonGlobalClassIsValid() throws PrompterException
91 {
92 when(prompter.prompt("Enter Plugin Module Name", "My Context Item")).thenReturn(MODULE_NAME);
93 when(prompter.prompt("Enter Context Key")).thenReturn(CONTEXT_KEY);
94 when(prompter.prompt("Enter Component-Ref Key (leave blank to specify class)")).thenReturn("");
95 when(prompter.prompt("Enter Fully Qualified Class Name")).thenReturn(CLASSNAME);
96 when(prompter.prompt("Global Access?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
97 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
98 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
99
100 TemplateContextItemPrompter modulePrompter = new TemplateContextItemPrompter(prompter);
101 modulePrompter.setUseAnsiColor(false);
102 TemplateContextItemProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
103
104 assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
105 assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
106 assertEquals("wrong description", DESCRIPTION, props.getDescription());
107 assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
108 assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
109
110 assertEquals("wrong context key", CONTEXT_KEY, props.getContextKey());
111 assertEquals("wrong class", CLASSNAME, props.getClassId().getFullName());
112 assertFalse("wong global access", props.isGlobal());
113 }
114
115 @Test
116 public void globalClassIsValid() throws PrompterException
117 {
118 when(prompter.prompt("Enter Plugin Module Name", "My Context Item")).thenReturn(MODULE_NAME);
119 when(prompter.prompt("Enter Context Key")).thenReturn(CONTEXT_KEY);
120 when(prompter.prompt("Enter Component-Ref Key (leave blank to specify class)")).thenReturn("");
121 when(prompter.prompt("Enter Fully Qualified Class Name")).thenReturn(CLASSNAME);
122 when(prompter.prompt("Global Access?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
123 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
124 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
125
126 TemplateContextItemPrompter modulePrompter = new TemplateContextItemPrompter(prompter);
127 modulePrompter.setUseAnsiColor(false);
128 TemplateContextItemProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
129
130 assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
131 assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
132 assertEquals("wrong description", DESCRIPTION, props.getDescription());
133 assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
134 assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
135
136 assertEquals("wrong context key", CONTEXT_KEY, props.getContextKey());
137 assertEquals("wrong class", CLASSNAME, props.getClassId().getFullName());
138 assertTrue("wong global access", props.isGlobal());
139 }
140 }