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

https://bitbucket.org/mmeinhold/amps · Java · 182 lines · 153 code · 26 blank · 3 comment · 0 complexity · e8ef156f695b97725df8f219e5e7cfbe 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.ProjectTabPanelModuleCreator;
  6. import com.atlassian.plugins.codegen.modules.jira.TabPanelProperties;
  7. import org.codehaus.plexus.components.interactivity.Prompter;
  8. import org.codehaus.plexus.components.interactivity.PrompterException;
  9. import org.junit.Before;
  10. import org.junit.Test;
  11. import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_DESCRIP_PROMPT;
  12. import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_KEY_PROMPT;
  13. import static com.atlassian.maven.plugins.amps.codegen.prompter.AbstractModulePrompter.MODULE_NAME_PROMPT;
  14. import static org.junit.Assert.*;
  15. import static org.mockito.Mockito.mock;
  16. import static org.mockito.Mockito.when;
  17. /**
  18. * @since 3.6
  19. */
  20. public class ProjectTabPanelPrompterTest extends AbstractPrompterTest
  21. {
  22. public static final String PACKAGE = "com.atlassian.plugins.jira.tabpanels";
  23. public static final String CLASSNAME = "MyProjectTabPanel";
  24. public static final String MODULE_NAME = "My Project Tab Panel";
  25. public static final String MODULE_KEY = "my-project-tab-panel";
  26. public static final String DESCRIPTION = "The My Project Tab Panel Plugin";
  27. public static final String I18N_NAME_KEY = "my-project-tab-panel.name";
  28. public static final String I18N_DESCRIPTION_KEY = "my-project-tab-panel.description";
  29. public static final String ADV_MODULE_NAME = "My Awesome Plugin";
  30. public static final String ADV_MODULE_KEY = "awesome-module";
  31. public static final String ADV_DESCRIPTION = "The Awesomest Plugin Ever";
  32. public static final String ADV_I18N_NAME_KEY = "awesome-plugin.name";
  33. public static final String ADV_I18N_DESCRIPTION_KEY = "pluginus-awesomeous.description";
  34. public static final String ORDER = "22";
  35. public static final String LABEL_KEY = "item.label";
  36. public static final String LABEL_VALUE = "this is my label";
  37. Prompter prompter;
  38. @Before
  39. public void setup()
  40. {
  41. prompter = mock(Prompter.class);
  42. }
  43. @Test
  44. public void basicCustomPropertiesAreValid() throws PrompterException
  45. {
  46. when(prompter.prompt("Use " + ProjectTabPanelModuleCreator.GENERIC_CLASS + "?", PluginModulePrompter.YN_ANSWERS, "Y")).thenReturn("n");
  47. when(prompter.prompt("Enter New Classname", "MyProjectTabPanel")).thenReturn(CLASSNAME);
  48. when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.tabpanels")).thenReturn(PACKAGE);
  49. when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  50. when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  51. ProjectTabPanelPrompter modulePrompter = new ProjectTabPanelPrompter(prompter);
  52. modulePrompter.setUseAnsiColor(false);
  53. TabPanelProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
  54. assertEquals("wrong class", CLASSNAME, props.getClassId().getName());
  55. assertEquals("wrong class package", PACKAGE, props.getClassId().getPackage());
  56. assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
  57. assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
  58. assertEquals("wrong description", DESCRIPTION, props.getDescription());
  59. assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
  60. assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
  61. assertEquals("wrong order", "10", props.getOrder());
  62. assertEquals("wrong label key", MODULE_KEY + ".label", props.getLabel()
  63. .getKey());
  64. assertEquals("wrong label value", MODULE_NAME, props.getLabel()
  65. .getValue());
  66. assertTrue("use custom class should be true", props.isUseCustomClass());
  67. }
  68. @Test
  69. public void basicGenericPropertiesAreValid() throws PrompterException
  70. {
  71. when(prompter.prompt("Use " + ProjectTabPanelModuleCreator.GENERIC_CLASS + "?", PluginModulePrompter.YN_ANSWERS, "Y")).thenReturn("y");
  72. when(prompter.prompt("Enter Plugin Module Name", "My Project Tab Panel")).thenReturn(MODULE_NAME);
  73. when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  74. when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  75. ProjectTabPanelPrompter modulePrompter = new ProjectTabPanelPrompter(prompter);
  76. modulePrompter.setUseAnsiColor(false);
  77. TabPanelProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
  78. assertEquals("wrong class", ProjectTabPanelModuleCreator.GENERIC_CLASS, props.getClassId().getName());
  79. assertEquals("wrong class package", ProjectTabPanelModuleCreator.GENERIC_PACKAGE, props.getClassId().getPackage());
  80. assertEquals("wrong module name", MODULE_NAME, props.getModuleName());
  81. assertEquals("wrong module key", MODULE_KEY, props.getModuleKey());
  82. assertEquals("wrong description", DESCRIPTION, props.getDescription());
  83. assertEquals("wrong i18n name key", I18N_NAME_KEY, props.getNameI18nKey());
  84. assertEquals("wrong i18n desc key", I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
  85. assertEquals("wrong order", "10", props.getOrder());
  86. assertEquals("wrong label key", MODULE_KEY + ".label", props.getLabel()
  87. .getKey());
  88. assertEquals("wrong label value", MODULE_NAME, props.getLabel()
  89. .getValue());
  90. assertFalse("use custom class should be false", props.isUseCustomClass());
  91. }
  92. @Test
  93. public void advancedCustomPropertiesAreValid() throws PrompterException
  94. {
  95. when(prompter.prompt("Use " + ProjectTabPanelModuleCreator.GENERIC_CLASS + "?", PluginModulePrompter.YN_ANSWERS, "Y")).thenReturn("n");
  96. when(prompter.prompt("Enter New Classname", "MyProjectTabPanel")).thenReturn(CLASSNAME);
  97. when(prompter.prompt("Enter Package Name", AbstractModulePrompter.DEFAULT_BASE_PACKAGE + ".jira.tabpanels")).thenReturn(PACKAGE);
  98. when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("y");
  99. when(prompter.prompt(MODULE_NAME_PROMPT, MODULE_NAME)).thenReturn(ADV_MODULE_NAME);
  100. when(prompter.prompt(MODULE_KEY_PROMPT, MODULE_KEY)).thenReturn(ADV_MODULE_KEY);
  101. when(prompter.prompt(MODULE_DESCRIP_PROMPT, DESCRIPTION)).thenReturn(ADV_DESCRIPTION);
  102. when(prompter.prompt("i18n Name Key", I18N_NAME_KEY)).thenReturn(ADV_I18N_NAME_KEY);
  103. when(prompter.prompt("i18n Description Key", I18N_DESCRIPTION_KEY)).thenReturn(ADV_I18N_DESCRIPTION_KEY);
  104. when(prompter.prompt("Order", "10")).thenReturn(ORDER);
  105. when(prompter.prompt("Enter Label Key", MODULE_KEY + ".label")).thenReturn(LABEL_KEY);
  106. when(prompter.prompt("Enter Label Value", MODULE_NAME)).thenReturn(LABEL_VALUE);
  107. when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  108. ProjectTabPanelPrompter modulePrompter = new ProjectTabPanelPrompter(prompter);
  109. modulePrompter.setUseAnsiColor(false);
  110. TabPanelProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
  111. assertEquals("wrong adv class", CLASSNAME, props.getClassId().getName());
  112. assertEquals("wrong adv package", PACKAGE, props.getClassId().getPackage());
  113. assertEquals("wrong adv module name", ADV_MODULE_NAME, props.getModuleName());
  114. assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
  115. assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
  116. assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
  117. assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
  118. assertEquals("wrong order", ORDER, props.getOrder());
  119. assertEquals("wrong label key", LABEL_KEY, props.getLabel()
  120. .getKey());
  121. assertEquals("wrong label value", LABEL_VALUE, props.getLabel()
  122. .getValue());
  123. assertTrue("use custom class should be true", props.isUseCustomClass());
  124. }
  125. @Test
  126. public void advancedGenericPropertiesAreValid() throws PrompterException
  127. {
  128. when(prompter.prompt("Use " + ProjectTabPanelModuleCreator.GENERIC_CLASS + "?", PluginModulePrompter.YN_ANSWERS, "Y")).thenReturn("y");
  129. when(prompter.prompt("Enter Plugin Module Name", "My Project Tab Panel")).thenReturn(ADV_MODULE_NAME);
  130. when(prompter.prompt("Show Advanced Setup?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("y");
  131. when(prompter.prompt(MODULE_KEY_PROMPT, "my-awesome-plugin")).thenReturn(ADV_MODULE_KEY);
  132. when(prompter.prompt(MODULE_DESCRIP_PROMPT, "The My Awesome Plugin Plugin")).thenReturn(ADV_DESCRIPTION);
  133. when(prompter.prompt("i18n Name Key", "my-awesome-plugin.name")).thenReturn(ADV_I18N_NAME_KEY);
  134. when(prompter.prompt("i18n Description Key", "my-awesome-plugin.description")).thenReturn(ADV_I18N_DESCRIPTION_KEY);
  135. when(prompter.prompt("Order", "10")).thenReturn(ORDER);
  136. when(prompter.prompt("Enter Label Key", "my-awesome-plugin.label")).thenReturn(LABEL_KEY);
  137. when(prompter.prompt("Enter Label Value", ADV_MODULE_NAME)).thenReturn(LABEL_VALUE);
  138. when(prompter.prompt("Include Example Code?", PluginModulePrompter.YN_ANSWERS, "N")).thenReturn("N");
  139. ProjectTabPanelPrompter modulePrompter = new ProjectTabPanelPrompter(prompter);
  140. modulePrompter.setUseAnsiColor(false);
  141. TabPanelProperties props = modulePrompter.getModulePropertiesFromInput(moduleLocation);
  142. assertEquals("wrong adv class", ProjectTabPanelModuleCreator.GENERIC_CLASS, props.getClassId().getName());
  143. assertEquals("wrong adv class package", ProjectTabPanelModuleCreator.GENERIC_PACKAGE, props.getClassId().getPackage());
  144. assertEquals("wrong adv module name", ADV_MODULE_NAME, props.getModuleName());
  145. assertEquals("wrong adv module key", ADV_MODULE_KEY, props.getModuleKey());
  146. assertEquals("wrong adv description", ADV_DESCRIPTION, props.getDescription());
  147. assertEquals("wrong adv i18n name key", ADV_I18N_NAME_KEY, props.getNameI18nKey());
  148. assertEquals("wrong adv i18n desc key", ADV_I18N_DESCRIPTION_KEY, props.getDescriptionI18nKey());
  149. assertEquals("wrong order", ORDER, props.getOrder());
  150. assertEquals("wrong label key", LABEL_KEY, props.getLabel()
  151. .getKey());
  152. assertEquals("wrong label value", LABEL_VALUE, props.getLabel()
  153. .getValue());
  154. assertFalse("use custom class should be false", props.isUseCustomClass());
  155. }
  156. }