1 package com.atlassian.maven.plugins.amps.codegen.prompter.jira;
2
3 import com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter;
4 import com.atlassian.maven.plugins.amps.codegen.prompter.AbstractPrompterTest;
5 import com.atlassian.maven.plugins.amps.codegen.prompter.PluginModulePrompter;
6 import com.atlassian.plugins.codegen.modules.jira.RPCProperties;
7
8 import org.codehaus.plexus.components.interactivity.Prompter;
9 import org.codehaus.plexus.components.interactivity.PrompterException;
10 import org.junit.Before;
11 import org.junit.Test;
12
13 import static org.junit.Assert.*;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.when;
16
17
18
19
20 public class RPCPrompterTest extends AbstractPrompterTest
21 {
22 public static final String PACKAGE = "com.atlassian.plugins.jira.rpc";
23 public static final String SOAP_CLASSNAME = "MySoapEndpointImpl";
24 public static final String SOAP_INTERFACE = "MySoapEndpoint";
25 public static final String SOAP_MODULE_NAME = "My Soap Endpoint";
26 public static final String SOAP_MODULE_KEY = "my-soap-endpoint";
27 public static final String SOAP_DESCRIPTION = "The My Soap Endpoint Plugin";
28 public static final String SOAP_I18N_NAME_KEY = "my-soap-endpoint.name";
29 public static final String SOAP_I18N_DESCRIPTION_KEY = "my-soap-endpoint.description";
30 public static final String SOAP_PATH = "mysoapservice-v1";
31
32 public static final String XML_CLASSNAME = "MyXmlEndpointImpl";
33 public static final String XML_INTERFACE = "MyXmlEndpoint";
34 public static final String XML_MODULE_NAME = "My Xml Endpoint";
35 public static final String XML_MODULE_KEY = "my-xml-endpoint";
36 public static final String XML_DESCRIPTION = "The My Xml Endpoint Plugin";
37 public static final String XML_I18N_NAME_KEY = "my-xml-endpoint.name";
38 public static final String XML_I18N_DESCRIPTION_KEY = "my-xml-endpoint.description";
39 public static final String XML_PATH = "myxmlservice-v1";
40
41 public static final String ADV_MODULE_NAME = "My Awesome Plugin";
42 public static final String ADV_MODULE_KEY = "awesome-module";
43 public static final String ADV_DESCRIPTION = "The Awesomest Plugin Ever";
44 public static final String ADV_I18N_NAME_KEY = "awesome-plugin.name";
45 public static final String ADV_I18N_DESCRIPTION_KEY = "pluginus-awesomeous.description";
46
47 Prompter prompter;
48
49 @Before
50 public void setup()
51 {
52 prompter = mock(Prompter.class);
53 }
54
55 @Test
56 public void basicSoapPropertiesAreValid() throws PrompterException
57 {
58 when(prompter.prompt("[S]OAP or [X]ML-RPC?", RPCPrompter.RPC_ANSWERS, "S")).thenReturn("S");
59 when(prompter.prompt("Enter Interface name", "MYSoapEndpoint")).thenReturn(SOAP_INTERFACE);
60 when(prompter.prompt("Enter Interface package", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.rpc")).thenReturn(PACKAGE);
61 when(prompter.prompt("Enter Class name", "MySoapEndpointImpl")).thenReturn(SOAP_CLASSNAME);
62 when(prompter.prompt("Enter Package Name", PACKAGE)).thenReturn(PACKAGE);
63 when(prompter.prompt("Enter Service Path", "mysoapendpoint-v1")).thenReturn(SOAP_PATH);
64 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
65 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
66
67 RPCPrompter modulePrompter = new RPCPrompter(prompter);
68 modulePrompter.setUseAnsiColor(false);
69 RPCProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
70
71 assertEquals("wrong interface", SOAP_INTERFACE, props.getInterfaceClass());
72 assertEquals("wrong interface package", PACKAGE, props.getInterfacePackage());
73 assertEquals("wrong class", SOAP_CLASSNAME, props.getClassname());
74 assertEquals("wrong class package", PACKAGE, props.getPackage());
75 assertEquals("wrong service path", SOAP_PATH, props.getServicePath());
76 assertEquals("wrong module name", SOAP_MODULE_NAME, props.getModuleName());
77 assertEquals("wrong module key", SOAP_MODULE_KEY, props.getModuleKey());
78 assertEquals("wrong description", SOAP_DESCRIPTION, props.getDescription());
79 assertEquals("wrong i18n name key", SOAP_I18N_NAME_KEY, props.getNameI18nKey());
80 assertEquals("wrong i18n desc key", SOAP_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
81 assertTrue("isSoap should be true", props.isSoap());
82 }
83
84 @Test
85 public void advancedSoapPropertiesAreValid() throws PrompterException
86 {
87 when(prompter.prompt("[S]OAP or [X]ML-RPC?", RPCPrompter.RPC_ANSWERS, "S")).thenReturn("S");
88 when(prompter.prompt("Enter Interface name", "MYSoapEndpoint")).thenReturn(SOAP_INTERFACE);
89 when(prompter.prompt("Enter Interface package", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.rpc")).thenReturn(PACKAGE);
90 when(prompter.prompt("Enter Class name", "MySoapEndpointImpl")).thenReturn(SOAP_CLASSNAME);
91 when(prompter.prompt("Enter Package Name", PACKAGE)).thenReturn(PACKAGE);
92 when(prompter.prompt("Enter Service Path", "mysoapendpoint-v1")).thenReturn(SOAP_PATH);
93 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
94
95 when(prompter.prompt("Plugin Name", SOAP_MODULE_NAME)).thenReturn(ADV_MODULE_NAME);
96 when(prompter.prompt("Plugin Key", SOAP_MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
97 when(prompter.prompt("Plugin Description", SOAP_DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
98 when(prompter.prompt("i18n Name Key", SOAP_I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
99 when(prompter.prompt("i18n Description Key", SOAP_I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
100
101 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
102
103 RPCPrompter modulePrompter = new RPCPrompter(prompter);
104 modulePrompter.setUseAnsiColor(false);
105 RPCProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
106
107 assertEquals("wrong adv interface", SOAP_INTERFACE, props.getInterfaceClass());
108 assertEquals("wrong adv interface package", PACKAGE, props.getInterfacePackage());
109 assertEquals("wrong adv class", SOAP_CLASSNAME, props.getClassname());
110 assertEquals("wrong adv package", PACKAGE, props.getPackage());
111 assertEquals("wrong adv service path", SOAP_PATH, props.getServicePath());
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 assertTrue("isSoap should be true", props.isSoap());
118 }
119
120 @Test
121 public void basicXmlPropertiesAreValid() throws PrompterException
122 {
123 when(prompter.prompt("[S]OAP or [X]ML-RPC?", RPCPrompter.RPC_ANSWERS, "S")).thenReturn("x");
124 when(prompter.prompt("Enter Interface name", "MYXmlEndpoint")).thenReturn(XML_INTERFACE);
125 when(prompter.prompt("Enter Interface package", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.rpc")).thenReturn(PACKAGE);
126 when(prompter.prompt("Enter Class name", "MyXmlEndpointImpl")).thenReturn(XML_CLASSNAME);
127 when(prompter.prompt("Enter Package Name", PACKAGE)).thenReturn(PACKAGE);
128 when(prompter.prompt("Enter Service Path", "myxmlendpoint-v1")).thenReturn(XML_PATH);
129 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
130 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
131
132 RPCPrompter modulePrompter = new RPCPrompter(prompter);
133 modulePrompter.setUseAnsiColor(false);
134 RPCProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
135
136 assertEquals("wrong interface", XML_INTERFACE, props.getInterfaceClass());
137 assertEquals("wrong interface package", PACKAGE, props.getInterfacePackage());
138 assertEquals("wrong class", XML_CLASSNAME, props.getClassname());
139 assertEquals("wrong class package", PACKAGE, props.getPackage());
140 assertEquals("wrong service path", XML_PATH, props.getServicePath());
141 assertEquals("wrong module name", XML_MODULE_NAME, props.getModuleName());
142 assertEquals("wrong module key", XML_MODULE_KEY, props.getModuleKey());
143 assertEquals("wrong description", XML_DESCRIPTION, props.getDescription());
144 assertEquals("wrong i18n name key", XML_I18N_NAME_KEY, props.getNameI18nKey());
145 assertEquals("wrong i18n desc key", XML_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
146 assertFalse("isSoap should be false", props.isSoap());
147 }
148
149 @Test
150 public void advancedXmlPropertiesAreValid() throws PrompterException
151 {
152 when(prompter.prompt("[S]OAP or [X]ML-RPC?", RPCPrompter.RPC_ANSWERS, "S")).thenReturn("X");
153 when(prompter.prompt("Enter Interface name", "MYXmlEndpoint")).thenReturn(XML_INTERFACE);
154 when(prompter.prompt("Enter Interface package", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.rpc")).thenReturn(PACKAGE);
155 when(prompter.prompt("Enter Class name", "MyXmlEndpointImpl")).thenReturn(XML_CLASSNAME);
156 when(prompter.prompt("Enter Package Name", PACKAGE)).thenReturn(PACKAGE);
157 when(prompter.prompt("Enter Service Path", "myxmlendpoint-v1")).thenReturn(XML_PATH);
158 when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
159
160 when(prompter.prompt("Plugin Name", XML_MODULE_NAME)).thenReturn(ADV_MODULE_NAME);
161 when(prompter.prompt("Plugin Key", XML_MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
162 when(prompter.prompt("Plugin Description", XML_DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
163 when(prompter.prompt("i18n Name Key", XML_I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
164 when(prompter.prompt("i18n Description Key", XML_I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
165
166 when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
167
168 RPCPrompter modulePrompter = new RPCPrompter(prompter);
169 modulePrompter.setUseAnsiColor(false);
170 RPCProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
171
172 assertEquals("wrong adv interface", XML_INTERFACE, props.getInterfaceClass());
173 assertEquals("wrong adv interface package", PACKAGE, props.getInterfacePackage());
174 assertEquals("wrong adv class", XML_CLASSNAME, props.getClassname());
175 assertEquals("wrong adv package", PACKAGE, props.getPackage());
176 assertEquals("wrong adv service path", XML_PATH, props.getServicePath());
177 assertEquals("wrong adv module name", ADV_MODULE_NAME, props.getModuleName());
178 assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
179 assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
180 assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
181 assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
182 assertFalse("isSoap should be false", props.isSoap());
183 }
184 }