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

https://bitbucket.org/mmeinhold/amps · Java · 141 lines · 118 code · 20 blank · 3 comment · 0 complexity · 5589ce15c1ff08db6a9522cf1a37824d MD5 · raw file

  1. package com.atlassian.maven.plugins.amps.codegen.prompter.jira;
  2. import java.util.Arrays;
  3. import java.util.Collections;
  4. import java.util.List;
  5. import com.atlassian.maven.plugins.amps.codegen.jira.ActionTypeFactory;
  6. import com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter;
  7. import com.atlassian.maven.plugins.amps.codegen.prompter.AbstractPrompterTest;
  8. import com.atlassian.maven.plugins.amps.codegen.prompter.PluginModulePrompter;
  9. import com.atlassian.plugins.codegen.modules.jira.WorkflowPostFunctionProperties;
  10. import org.apache.commons.lang.StringUtils;
  11. import org.codehaus.plexus.components.interactivity.Prompter;
  12. import org.codehaus.plexus.components.interactivity.PrompterException;
  13. import org.junit.After;
  14. import org.junit.Before;
  15. import org.junit.Test;
  16. import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_DESCRIP_PROMPT;
  17. import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_KEY_PROMPT;
  18. import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_NAME_PROMPT;
  19. import static org.junit.Assert.assertEquals;
  20. import static org.junit.Assert.assertTrue;
  21. import static org.mockito.Mockito.mock;
  22. import static org.mockito.Mockito.when;
  23. /**
  24. * @since 3.6
  25. */
  26. public class WorkflowPostFunctionPrompterTest extends AbstractPrompterTest
  27. {
  28. public static final String PACKAGE = "com.atlassian.plugins.jira.workflow";
  29. public static final String CLASSNAME = "MyPostFunction";
  30. public static final String FACTORY_CLASSNAME = "MyPostFunctionFactory";
  31. public static final String MODULE_NAME = "My Post Function";
  32. public static final String MODULE_KEY = "my-post-function";
  33. public static final String DESCRIPTION = "The My Post Function Plugin";
  34. public static final String I18N_NAME_KEY = "my-post-function.name";
  35. public static final String I18N_DESCRIPTION_KEY = "my-post-function.description";
  36. public static final String ADV_MODULE_NAME = "My Awesome Plugin";
  37. public static final String ADV_MODULE_KEY = "awesome-module";
  38. public static final String ADV_DESCRIPTION = "The Awesomest Plugin Ever";
  39. public static final String ADV_I18N_NAME_KEY = "awesome-plugin.name";
  40. public static final String ADV_I18N_DESCRIPTION_KEY = "pluginus-awesomeous.description";
  41. Prompter prompter;
  42. TestingActionTypeFactory actionTypeFactory;
  43. @Before
  44. public void setup()
  45. {
  46. prompter = mock(Prompter.class);
  47. actionTypeFactory = new TestingActionTypeFactory();
  48. actionTypeFactory.setActionTypes(Arrays.asList("common", "initial", "global", "ordinary"));
  49. }
  50. @After
  51. public void resetActionTypes()
  52. {
  53. actionTypeFactory.setActionTypes(Collections.<String>emptyList());
  54. }
  55. @Test
  56. public void basicPropertiesAreValid() throws PrompterException
  57. {
  58. when(prompter.prompt("Enter New Classname", "MyPostFunction")).thenReturn(CLASSNAME);
  59. when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.workflow")).thenReturn(PACKAGE);
  60. when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  61. when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  62. WorkflowPostFunctionPrompter modulePrompter = new WorkflowPostFunctionPrompter(prompter);
  63. modulePrompter.setUseAnsiColor(false);
  64. WorkflowPostFunctionProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
  65. assertEquals("wrong function class", CLASSNAME, props.getClassId().getName());
  66. assertEquals("wrong factory class", FACTORY_CLASSNAME, props.getFactoryName());
  67. assertEquals("wrong class package", PACKAGE, props.getClassId().getPackage());
  68. assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
  69. assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
  70. assertEquals("wrong description", DESCRIPTION, props.getDescription());
  71. assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
  72. assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
  73. assertTrue("orderable should be blank", StringUtils.isBlank(props.getOrderable()));
  74. assertTrue("unique should be blank", StringUtils.isBlank(props.getUnique()));
  75. assertTrue("deletable should be blank", StringUtils.isBlank(props.getDeletable()));
  76. assertTrue("addable should be blank", StringUtils.isBlank(props.getAddable()));
  77. }
  78. @Test
  79. public void advancedPropertiesAreValid() throws PrompterException
  80. {
  81. when(prompter.prompt("Enter New Classname", "MyPostFunction")).thenReturn(CLASSNAME);
  82. when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.workflow")).thenReturn(PACKAGE);
  83. when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
  84. when(prompter.prompt(MODULE_NAME_PROMPT, MODULE_NAME)).thenReturn(ADV_MODULE_NAME);
  85. when(prompter.prompt(MODULE_KEY_PROMPT, MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
  86. when(prompter.prompt(MODULE_DESCRIP_PROMPT, DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
  87. when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
  88. when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
  89. when(prompter.prompt("Is Function Orderable?", PluginModulePrompter.YN_ANSWERS, "Y")).thenReturn("y");
  90. when(prompter.prompt("Is Function Unique?", PluginModulePrompter.YN_ANSWERS, "Y")).thenReturn("n");
  91. when(prompter.prompt("Is Function Deletable?", PluginModulePrompter.YN_ANSWERS, "Y")).thenReturn("y");
  92. when(prompter.prompt("Define Action Types? (addable)", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("y");
  93. when(prompter.prompt("Choose A Type\n1: common\n2: global\n3: initial\n4: ordinary\nChoose a number: ", Arrays.asList("1", "2", "3", "4"), "1")).thenReturn("2");
  94. when(prompter.prompt("Add Action Type?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("y")
  95. .thenReturn("n");
  96. when(prompter.prompt("Choose A Type\n1: common\n2: initial\n3: ordinary\nChoose a number: ", Arrays.asList("1", "2", "3"), "1")).thenReturn("1");
  97. when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  98. WorkflowPostFunctionPrompter modulePrompter = new WorkflowPostFunctionPrompter(prompter);
  99. modulePrompter.setUseAnsiColor(false);
  100. WorkflowPostFunctionProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
  101. assertEquals("wrong function class", CLASSNAME, props.getClassId().getName());
  102. assertEquals("wrong factory class", FACTORY_CLASSNAME, props.getFactoryName());
  103. assertEquals("wrong adv package", PACKAGE, props.getClassId().getPackage());
  104. assertEquals("wrong adv module name", ADV_MODULE_NAME, props.getModuleName());
  105. assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
  106. assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
  107. assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
  108. assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
  109. assertEquals("wrong orderable", "true", props.getOrderable());
  110. assertEquals("wrong unique", "false", props.getUnique());
  111. assertEquals("wrong deletable", "true", props.getDeletable());
  112. assertEquals("wrong addable", "global,common", props.getAddable());
  113. }
  114. protected class TestingActionTypeFactory extends ActionTypeFactory
  115. {
  116. public void setActionTypes(List<String> types)
  117. {
  118. availableActionTypes = types;
  119. }
  120. }
  121. }