/plugin-module-codegen-engine/src/test/java/com/atlassian/plugins/codegen/modules/jira/AbstractTabPanelTest.java

https://bitbucket.org/mmeinhold/amps · Java · 167 lines · 126 code · 38 blank · 3 comment · 0 complexity · a7b96e6d4e865bb0eeb4dbdb4afdf663 MD5 · raw file

  1. package com.atlassian.plugins.codegen.modules.jira;
  2. import com.atlassian.plugins.codegen.AbstractModuleCreatorTestCase;
  3. import com.atlassian.plugins.codegen.ResourceFile;
  4. import com.atlassian.plugins.codegen.SourceFile;
  5. import com.atlassian.plugins.codegen.modules.PluginModuleCreator;
  6. import org.dom4j.Document;
  7. import org.dom4j.DocumentHelper;
  8. import org.junit.Before;
  9. import org.junit.Test;
  10. import static org.junit.Assert.assertEquals;
  11. import static org.junit.Assert.assertNotNull;
  12. import static org.junit.Assert.assertTrue;
  13. /**
  14. * @since 3.8
  15. */
  16. public abstract class AbstractTabPanelTest extends AbstractModuleCreatorTestCase<TabPanelProperties>
  17. {
  18. public static final String PACKAGE_NAME = "com.atlassian.plugins.jira.tabpanels";
  19. public static final String TEST_PACKAGE_NAME = "ut.com.atlassian.plugins.jira.tabpanels";
  20. public AbstractTabPanelTest(String type, PluginModuleCreator<TabPanelProperties> creator)
  21. {
  22. super(type, creator);
  23. }
  24. @Before
  25. public void setupObjects() throws Exception
  26. {
  27. setProps(new TabPanelProperties(PACKAGE_NAME + ".MyTabPanel"));
  28. props.setIncludeExamples(false);
  29. }
  30. @Test
  31. public void customClassFileIsGenerated() throws Exception
  32. {
  33. props.setUseCustomClass(true);
  34. getSourceFile(PACKAGE_NAME, "MyTabPanel");
  35. }
  36. @Test
  37. public void customUnitTestFileIsGenerated() throws Exception
  38. {
  39. props.setUseCustomClass(true);
  40. getTestSourceFile(TEST_PACKAGE_NAME, "MyTabPanelTest");
  41. }
  42. @Test
  43. public void customTemplateFileIsGenerated() throws Exception
  44. {
  45. props.setUseCustomClass(true);
  46. getResourceFile("templates/tabpanels", "my-tab-panel.vm");
  47. }
  48. @Test
  49. public void genericClassFilesAreNotGenerated() throws Exception
  50. {
  51. props.setUseCustomClass(false);
  52. assertTrue(getChangesetForModule(SourceFile.class).isEmpty());
  53. }
  54. @Test
  55. public void customModuleHasClass() throws Exception
  56. {
  57. props.setUseCustomClass(true);
  58. assertEquals(PACKAGE_NAME + ".MyTabPanel", getGeneratedModule().attributeValue("class"));
  59. }
  60. @Test
  61. public void genericModuleHasGenericClass() throws Exception
  62. {
  63. props.setFullyQualifiedClassname(ComponentTabPanelModuleCreator.FQ_GENERIC_CLASS);
  64. props.setUseCustomClass(true);
  65. assertEquals(ComponentTabPanelModuleCreator.FQ_GENERIC_CLASS, getGeneratedModule().attributeValue("class"));
  66. }
  67. @Test
  68. public void moduleHasOrder() throws Exception
  69. {
  70. props.setOrder(10);
  71. assertEquals("10", getGeneratedModule().selectSingleNode("order").getText());
  72. }
  73. @Test
  74. public void labelIsAdded() throws Exception
  75. {
  76. props.setLabel(label);
  77. assertNotNull(getGeneratedModule().selectSingleNode("label"));
  78. }
  79. @Test
  80. public void labelHasI18nKey() throws Exception
  81. {
  82. props.setLabel(label);
  83. assertEquals(label.getKey(), getGeneratedModule().selectSingleNode("label/@key").getText());
  84. }
  85. @Test
  86. public void labelHasParams() throws Exception
  87. {
  88. props.setLabel(label);
  89. assertEquals(2, getGeneratedModule().selectNodes("label/param").size());
  90. }
  91. @Test
  92. public void labelParam0HasName() throws Exception
  93. {
  94. props.setLabel(label);
  95. assertEquals("param0", getGeneratedModule().selectSingleNode("label/param[1]/@name").getText());
  96. }
  97. @Test
  98. public void labelParam0HasValue() throws Exception
  99. {
  100. props.setLabel(label);
  101. assertEquals(label.getParams().get("param0"), getGeneratedModule().selectSingleNode("label/param[1]/@value").getText());
  102. }
  103. @Test
  104. public void labelParam1HasName() throws Exception
  105. {
  106. props.setLabel(label);
  107. assertEquals("param1", getGeneratedModule().selectSingleNode("label/param[2]/@name").getText());
  108. }
  109. @Test
  110. public void labelParam1HasValue() throws Exception
  111. {
  112. props.setLabel(label);
  113. assertEquals(label.getParams().get("param1"), getGeneratedModule().selectSingleNode("label/param[2]/@value").getText());
  114. }
  115. @Test
  116. public void labelStringIsAddedToI18nProperties() throws Exception
  117. {
  118. props.setLabel(label);
  119. getI18nString(label.getKey(), label.getValue());
  120. }
  121. @Test
  122. public void labelIsUsedInViewTemplate() throws Exception
  123. {
  124. props.setLabel(label);
  125. props.setUseCustomClass(true);
  126. Document viewDoc = DocumentHelper.parseText(new String(getChangesetForModule(ResourceFile.class).get(0).getContent(), "UTF-8"));
  127. assertNotNull(viewDoc.selectSingleNode("/div/h3[text() = \"$i18n.getText('" + label.getKey() + "')\"]"));
  128. }
  129. }