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

https://bitbucket.org/mmeinhold/amps · Java · 84 lines · 68 code · 13 blank · 3 comment · 0 complexity · 5c90421647fc786ab799ec9f6f86ed79 MD5 · raw file

  1. package com.atlassian.maven.plugins.amps.codegen.prompter.common;
  2. import com.atlassian.maven.plugins.amps.codegen.prompter.AbstractPrompterTest;
  3. import com.atlassian.maven.plugins.amps.codegen.prompter.PluginModulePrompter;
  4. import com.atlassian.plugins.codegen.modules.common.DownloadablePluginResourceProperties;
  5. import com.atlassian.plugins.codegen.modules.common.Resource;
  6. import org.apache.commons.lang.StringUtils;
  7. import org.codehaus.plexus.components.interactivity.PrompterException;
  8. import org.junit.Test;
  9. import static org.junit.Assert.assertEquals;
  10. import static org.junit.Assert.assertTrue;
  11. import static org.mockito.Mockito.when;
  12. /**
  13. * @since 3.6
  14. */
  15. public class DownloadablePluginResourcePrompterTest extends AbstractPrompterTest
  16. {
  17. public static final String RESOURCE_NAME = "resourceCSS";
  18. public static final String RESOURCE_NAME_PATTERN = "templates/*.vm";
  19. public static final String DOWNLOAD_TYPE = "download";
  20. public static final String VELOCITY_TYPE = "velocity";
  21. public static final String RESOURCE_CSS_PATH = "templates/resource.css";
  22. public static final String RESOURCE_VM_PATH = "templates/resource.vm";
  23. public static final String PARAM_KEY = "paramKey";
  24. public static final String PARAM_VAL = "paramVal";
  25. @Test
  26. public void resourceWithNameIsValid() throws PrompterException
  27. {
  28. when(prompter.prompt("Enter Resource Name (leave blank to use namePattern)")).thenReturn(RESOURCE_NAME);
  29. when(prompter.prompt("Enter Resource Type", "download")).thenReturn(DOWNLOAD_TYPE);
  30. when(prompter.prompt("Enter Location (path to resource file)")).thenReturn(RESOURCE_CSS_PATH);
  31. when(prompter.prompt("Add Resource Parameter?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("Y");
  32. when(prompter.prompt("params:\nparamKey->paramVal\nAdd Resource Parameter?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  33. when(prompter.prompt("param name")).thenReturn(PARAM_KEY);
  34. when(prompter.prompt("param value")).thenReturn(PARAM_VAL);
  35. when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  36. DownloadablePluginResourcePrompter modulePrompter = new DownloadablePluginResourcePrompter(prompter);
  37. modulePrompter.setUseAnsiColor(false);
  38. DownloadablePluginResourceProperties props = (DownloadablePluginResourceProperties) modulePrompter.getModulePropertiesFromInput(moduleLocation);
  39. Resource cssResource = props.getResource();
  40. assertEquals("wrong css resource name", RESOURCE_NAME, cssResource.getName());
  41. assertTrue("css name pattern found when name is set", StringUtils.isBlank(cssResource.getNamePattern()));
  42. assertEquals("wrong css resource type", DOWNLOAD_TYPE, cssResource.getType());
  43. assertEquals("wrong css resource location", RESOURCE_CSS_PATH, cssResource.getLocation());
  44. assertEquals("wrong number of css resource params", 1, cssResource.getParams()
  45. .size());
  46. assertTrue("css resource param key not found", cssResource.getParams()
  47. .containsKey(PARAM_KEY));
  48. assertEquals("wrong css resource param value", PARAM_VAL, cssResource.getParams()
  49. .get(PARAM_KEY));
  50. }
  51. @Test
  52. public void resourceWithNamePatternIsValid() throws PrompterException
  53. {
  54. when(prompter.prompt("Enter Resource Name (leave blank to use namePattern)")).thenReturn("");
  55. when(prompter.prompt("Enter Resource Name Pattern")).thenReturn(RESOURCE_NAME_PATTERN);
  56. when(prompter.prompt("Enter Resource Type", "download")).thenReturn(VELOCITY_TYPE);
  57. when(prompter.prompt("Enter Location (path to resource file)")).thenReturn(RESOURCE_VM_PATH);
  58. when(prompter.prompt("Add Resource Parameter?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  59. when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  60. DownloadablePluginResourcePrompter modulePrompter = new DownloadablePluginResourcePrompter(prompter);
  61. modulePrompter.setUseAnsiColor(false);
  62. DownloadablePluginResourceProperties props = (DownloadablePluginResourceProperties) modulePrompter.getModulePropertiesFromInput(moduleLocation);
  63. Resource vmResource = props.getResource();
  64. assertTrue("vm name found when name pattern is set", StringUtils.isBlank(vmResource.getName()));
  65. assertEquals("wrong vm resource name pattern", RESOURCE_NAME_PATTERN, vmResource.getNamePattern());
  66. assertEquals("wrong vm resource type", VELOCITY_TYPE, vmResource.getType());
  67. assertEquals("wrong vm resource location", RESOURCE_VM_PATH, vmResource.getLocation());
  68. assertEquals("wrong number of vm resource params", 0, vmResource.getParams()
  69. .size());
  70. }
  71. }