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

https://bitbucket.org/mmeinhold/amps · Java · 136 lines · 109 code · 23 blank · 4 comment · 0 complexity · 682be1d6e5284042dd72e92d2cfad161 MD5 · raw file

  1. package com.atlassian.maven.plugins.amps.codegen.prompter.jira;
  2. import java.util.List;
  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.common.Resource;
  7. import com.atlassian.plugins.codegen.modules.jira.SearchRequestViewProperties;
  8. import org.apache.commons.lang.StringUtils;
  9. import org.codehaus.plexus.components.interactivity.Prompter;
  10. import org.codehaus.plexus.components.interactivity.PrompterException;
  11. import org.junit.Before;
  12. import org.junit.Test;
  13. import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_DESCRIP_PROMPT;
  14. import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_KEY_PROMPT;
  15. import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_NAME_PROMPT;
  16. import static org.junit.Assert.assertEquals;
  17. import static org.junit.Assert.assertTrue;
  18. import static org.mockito.Mockito.mock;
  19. import static org.mockito.Mockito.when;
  20. /**
  21. * @since 3.6
  22. */
  23. public class SearchRequestViewPrompterTest extends AbstractPrompterTest
  24. {
  25. public static final String PACKAGE = "com.atlassian.plugins.jira.search";
  26. public static final String CLASSNAME = "MySearchRequestView";
  27. public static final String MODULE_NAME = "My Search Request View";
  28. public static final String MODULE_KEY = "my-search-request-view";
  29. public static final String DESCRIPTION = "The My Search Request View Plugin";
  30. public static final String I18N_NAME_KEY = "my-search-request-view.name";
  31. public static final String I18N_DESCRIPTION_KEY = "my-search-request-view.description";
  32. public static final String ADV_MODULE_NAME = "My Awesome Plugin";
  33. public static final String ADV_MODULE_KEY = "awesome-module";
  34. public static final String ADV_DESCRIPTION = "The Awesomest Plugin Ever";
  35. public static final String ADV_I18N_NAME_KEY = "awesome-plugin.name";
  36. public static final String ADV_I18N_DESCRIPTION_KEY = "pluginus-awesomeous.description";
  37. public static final String EXT = "html";
  38. public static final String CTYPE = "text/html";
  39. public static final String RESOURCE_NAME = "view";
  40. public static final String RESOURCE_VM_PATH = "templates/resource.vm";
  41. Prompter prompter;
  42. @Before
  43. public void setup()
  44. {
  45. prompter = mock(Prompter.class);
  46. }
  47. @Test
  48. public void basicPropertiesAreValid() throws PrompterException
  49. {
  50. when(prompter.prompt("Enter New Classname", "MySearchRequestView")).thenReturn(CLASSNAME);
  51. when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.search")).thenReturn(PACKAGE);
  52. when(prompter.prompt("Enter File Extension (i.e. html)")).thenReturn(EXT);
  53. when(prompter.prompt("Enter Content Type (i.e. text/html)")).thenReturn(CTYPE);
  54. when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  55. when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  56. SearchRequestViewPrompter modulePrompter = new SearchRequestViewPrompter(prompter);
  57. modulePrompter.setUseAnsiColor(false);
  58. SearchRequestViewProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
  59. assertEquals("wrong class", CLASSNAME, props.getClassId().getName());
  60. assertEquals("wrong class package", PACKAGE, props.getClassId().getPackage());
  61. assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
  62. assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
  63. assertEquals("wrong description", DESCRIPTION, props.getDescription());
  64. assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
  65. assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
  66. assertEquals("wrong extension", EXT, props.getFileExtension());
  67. assertEquals("wrong content type", CTYPE, props.getContentType());
  68. assertEquals("wrong default order", "10", props.getOrder());
  69. }
  70. @Test
  71. public void advancedPropertiesAreValid() throws PrompterException
  72. {
  73. when(prompter.prompt("Enter New Classname", "MySearchRequestView")).thenReturn(CLASSNAME);
  74. when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.search")).thenReturn(PACKAGE);
  75. when(prompter.prompt("Enter File Extension (i.e. html)")).thenReturn(EXT);
  76. when(prompter.prompt("Enter Content Type (i.e. text/html)")).thenReturn(CTYPE);
  77. when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
  78. when(prompter.prompt(MODULE_NAME_PROMPT, MODULE_NAME)).thenReturn(ADV_MODULE_NAME);
  79. when(prompter.prompt(MODULE_KEY_PROMPT, MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
  80. when(prompter.prompt(MODULE_DESCRIP_PROMPT, DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
  81. when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
  82. when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
  83. when(prompter.prompt("Enter Order", "10")).thenReturn("100");
  84. when(prompter.prompt("Add Resource", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y")
  85. .thenReturn("N");
  86. when(prompter.prompt("Enter Resource Name")).thenReturn(RESOURCE_NAME)
  87. .thenReturn("");
  88. when(prompter.prompt("Enter Location (path to resource file)")).thenReturn(RESOURCE_VM_PATH);
  89. when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  90. SearchRequestViewPrompter modulePrompter = new SearchRequestViewPrompter(prompter);
  91. modulePrompter.setUseAnsiColor(false);
  92. SearchRequestViewProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
  93. assertEquals("wrong adv class", CLASSNAME, props.getClassId().getName());
  94. assertEquals("wrong adv package", PACKAGE, props.getClassId().getPackage());
  95. assertEquals("wrong adv module name", ADV_MODULE_NAME, props.getModuleName());
  96. assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
  97. assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
  98. assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
  99. assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
  100. assertEquals("wrong extension", EXT, props.getFileExtension());
  101. assertEquals("wrong content type", CTYPE, props.getContentType());
  102. assertEquals("wrong order", "100", props.getOrder());
  103. //resources
  104. List<Resource> resources = props.getResources();
  105. assertTrue("resources not found", !resources.isEmpty());
  106. assertEquals("wrong number of resources", 1, resources.size());
  107. Resource viewResource = resources.get(0);
  108. assertEquals("wrong css resource name", RESOURCE_NAME, viewResource.getName());
  109. assertTrue("name pattern found when name is set", StringUtils.isBlank(viewResource.getNamePattern()));
  110. assertEquals("wrong resource type", "velocity", viewResource.getType());
  111. assertEquals("wrong resource location", RESOURCE_VM_PATH, viewResource.getLocation());
  112. }
  113. }