PageRenderTime 55ms CodeModel.GetById 12ms app.highlight 39ms RepoModel.GetById 1ms app.codeStats 0ms

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

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