/maven-amps-plugin/src/test/java/com/atlassian/maven/plugins/amps/product/studio/TestStudioProductHandler.java

https://bitbucket.org/mmeinhold/amps · Java · 191 lines · 163 code · 24 blank · 4 comment · 1 complexity · 0ef729791f1188967b1418c9ab648891 MD5 · raw file

  1. package com.atlassian.maven.plugins.amps.product.studio;
  2. import com.atlassian.maven.plugins.amps.MavenContext;
  3. import com.atlassian.maven.plugins.amps.MavenGoals;
  4. import com.atlassian.maven.plugins.amps.Product;
  5. import com.google.inject.internal.util.ImmutableMap;
  6. import com.google.inject.internal.util.Maps;
  7. import org.apache.commons.io.FileUtils;
  8. import org.apache.maven.model.Build;
  9. import org.apache.maven.model.Model;
  10. import org.apache.maven.plugin.MojoExecutionException;
  11. import org.apache.maven.plugin.logging.Log;
  12. import org.apache.maven.project.MavenProject;
  13. import org.junit.After;
  14. import org.junit.Before;
  15. import org.junit.Ignore;
  16. import org.junit.Test;
  17. import org.junit.runner.RunWith;
  18. import org.mockito.Mock;
  19. import org.mockito.runners.MockitoJUnitRunner;
  20. import java.io.File;
  21. import java.util.Map;
  22. import static com.atlassian.maven.plugins.amps.product.ProductHandlerFactory.STUDIO;
  23. import static com.atlassian.maven.plugins.amps.product.ProductHandlerFactory.STUDIO_BAMBOO;
  24. import static com.atlassian.maven.plugins.amps.product.ProductHandlerFactory.STUDIO_CONFLUENCE;
  25. import static com.atlassian.maven.plugins.amps.product.ProductHandlerFactory.STUDIO_CROWD;
  26. import static com.atlassian.maven.plugins.amps.product.ProductHandlerFactory.STUDIO_FECRU;
  27. import static com.atlassian.maven.plugins.amps.product.ProductHandlerFactory.STUDIO_JIRA;
  28. import static org.junit.Assert.assertEquals;
  29. import static org.mockito.Mockito.verify;
  30. import static org.mockito.Mockito.when;
  31. /**
  32. * Test case for {@link com.atlassian.maven.plugins.amps.product.studio.StudioProductHandler}.
  33. *
  34. */
  35. @RunWith(MockitoJUnitRunner.class)
  36. public class TestStudioProductHandler
  37. {
  38. private static final String TEST_ONDEMAND_VERSION = "131";
  39. @Mock private MavenContext mockContext;
  40. @Mock private MavenProject mockProject;
  41. @Mock private Build mockBuild;
  42. @Mock private Log mockLog;
  43. @Mock private MavenGoals mockGoals;
  44. private File mockBuildDir;
  45. @Before
  46. public void initMocks()
  47. {
  48. mockBuildDir = new File(System.getProperty("java.io.tmpdir"), "TestStudioProductHandler");
  49. when(mockBuild.getDirectory()).thenReturn(mockBuildDir.getAbsolutePath());
  50. when(mockProject.getBuild()).thenReturn(mockBuild);
  51. when(mockContext.getProject()).thenReturn(mockProject);
  52. when(mockContext.getLog()).thenReturn(mockLog);
  53. }
  54. @After
  55. public void deleteMockBuildDir()
  56. {
  57. FileUtils.deleteQuietly(mockBuildDir);
  58. }
  59. @Ignore("AMPS-757 - Studio products are disabled")
  60. @Test
  61. public void configureProductsShouldSetCorrectJiraVersionFromOnDemandPom() throws MojoExecutionException
  62. {
  63. final Model model = new Model();
  64. model.addProperty("jira.version", "5.0");
  65. final TestedStudioProductHandler testedHandler = new TestedStudioProductHandler(mockContext, mockGoals, model);
  66. final Product jira = createProduct(STUDIO_JIRA, null);
  67. Map<String,Product> products = createProductsWith(STUDIO_JIRA, jira);
  68. initDefaultValues(products);
  69. testedHandler.configureStudioProducts(products);
  70. assertEquals("5.0", jira.getVersion());
  71. }
  72. @Ignore("AMPS-757 - Studio products are disabled")
  73. @Test
  74. public void configureProductsShouldSetCorrectConfluenceVersionFromOnDemandPom() throws MojoExecutionException
  75. {
  76. final Model model = new Model();
  77. model.addProperty("confluence.version", "4.2");
  78. final TestedStudioProductHandler testedHandler = new TestedStudioProductHandler(mockContext, mockGoals, model);
  79. final Product confluence = createProduct(STUDIO_CONFLUENCE, null);
  80. Map<String,Product> products = createProductsWith(STUDIO_CONFLUENCE, confluence);
  81. initDefaultValues(products);
  82. testedHandler.configureStudioProducts(products);
  83. assertEquals("4.2", confluence.getVersion());
  84. }
  85. @Ignore("AMPS-757 - Studio products are disabled")
  86. @Test
  87. public void configureProductsShouldSetOnDemandFecruVersion() throws MojoExecutionException
  88. {
  89. final Model model = new Model();
  90. model.addProperty("crucible.version", "2.8");
  91. final TestedStudioProductHandler testedHandler = new TestedStudioProductHandler(mockContext, mockGoals, model);
  92. final Product fecru = createProduct(STUDIO_FECRU, null);
  93. Map<String,Product> products = createProductsWith(STUDIO_FECRU, fecru);
  94. initDefaultValues(products);
  95. testedHandler.configureStudioProducts(products);
  96. assertEquals(TEST_ONDEMAND_VERSION, fecru.getVersion());
  97. }
  98. @Ignore("AMPS-757 - Studio products are disabled")
  99. @Test
  100. public void configureProductsShouldLogWarningIfJiraVersionNotPresentInOnDemandPom() throws MojoExecutionException
  101. {
  102. final Model model = new Model();
  103. model.addProperty("confluence.version", "4.2");
  104. final TestedStudioProductHandler testedHandler = new TestedStudioProductHandler(mockContext, mockGoals, model);
  105. testedHandler.configureStudioProducts(createDefaultStudioProducts());
  106. verify(mockLog).warn("Expected property 'jira.version' in the OnDemand fireball POM (version "
  107. + TEST_ONDEMAND_VERSION + ") not found. OnDemand version will be used instead");
  108. }
  109. @Ignore("AMPS-757 - Studio products are disabled")
  110. @Test
  111. public void configureProductsShouldLogWarningIfConfluenceVersionNotPresentInOnDemandPom() throws MojoExecutionException
  112. {
  113. final Model model = new Model();
  114. model.addProperty("jira.version", "5.1");
  115. final TestedStudioProductHandler testedHandler = new TestedStudioProductHandler(mockContext, mockGoals, model);
  116. testedHandler.configureStudioProducts(createDefaultStudioProducts());
  117. verify(mockLog).warn("Expected property 'confluence.version' in the OnDemand fireball POM (version "
  118. + TEST_ONDEMAND_VERSION + ") not found. OnDemand version will be used instead");
  119. }
  120. private void initDefaultValues(Map<String,Product> products)
  121. {
  122. for (Product product : products.values())
  123. {
  124. StudioProductHandler.setDefaultValues(mockContext, product);
  125. }
  126. }
  127. private Map<String,Product> createProductsWith(String productId, Product product)
  128. {
  129. final Map<String,Product> products = Maps.newHashMap();
  130. products.putAll(createDefaultStudioProducts());
  131. products.put(productId, product);
  132. return ImmutableMap.copyOf(products);
  133. }
  134. private Map<String,Product> createDefaultStudioProducts()
  135. {
  136. return ImmutableMap.<String,Product>builder()
  137. .put(STUDIO, createProduct(STUDIO, TEST_ONDEMAND_VERSION))
  138. .put(STUDIO_JIRA, createProduct(STUDIO_JIRA, "5.0"))
  139. .put(STUDIO_CROWD, createProduct(STUDIO_CROWD, TEST_ONDEMAND_VERSION))
  140. .put(STUDIO_CONFLUENCE, createProduct(STUDIO_CONFLUENCE, "4.1"))
  141. .put(STUDIO_BAMBOO, createProduct(STUDIO_BAMBOO, TEST_ONDEMAND_VERSION))
  142. .put(STUDIO_FECRU, createProduct(STUDIO_FECRU, TEST_ONDEMAND_VERSION))
  143. .build();
  144. }
  145. private Product createProduct(String id, String version)
  146. {
  147. final Product answer = new Product();
  148. answer.setId(id);
  149. answer.setInstanceId(id);
  150. answer.setVersion(version);
  151. return answer;
  152. }
  153. private static class TestedStudioProductHandler extends StudioProductHandler
  154. {
  155. private final Model onDemandModelMock;
  156. public TestedStudioProductHandler(MavenContext context, MavenGoals goals, Model onDemandModelMock)
  157. {
  158. super(context, goals);
  159. this.onDemandModelMock = onDemandModelMock;
  160. }
  161. @Override
  162. protected Model getOnDemandPomModel(Product ondemand, StudioProperties properties) throws MojoExecutionException
  163. {
  164. return onDemandModelMock;
  165. }
  166. }
  167. }