/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

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