PageRenderTime 55ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/jira-project/jira-components/jira-tests-parent/jira-tests-unit/src/test/java/com/atlassian/jira/license/RenaissanceSwitchingMultiLicenseStoreTest.java

https://bitbucket.org/ahmed_bilal_360factors/jira7-core
Java | 242 lines | 158 code | 33 blank | 51 comment | 0 complexity | fdb3e0b72de0ab7fc4db7da614406df6 MD5 | raw file
Possible License(s): Apache-2.0
  1. package com.atlassian.jira.license;
  2. import com.google.common.collect.ImmutableList;
  3. import org.junit.Before;
  4. import org.junit.Rule;
  5. import org.junit.Test;
  6. import org.mockito.Mock;
  7. import org.mockito.junit.MockitoJUnit;
  8. import org.mockito.junit.MockitoRule;
  9. import static org.hamcrest.MatcherAssert.assertThat;
  10. import static org.hamcrest.Matchers.is;
  11. import static org.mockito.Matchers.any;
  12. import static org.mockito.Mockito.never;
  13. import static org.mockito.Mockito.verify;
  14. import static org.mockito.Mockito.when;
  15. public class RenaissanceSwitchingMultiLicenseStoreTest {
  16. private static final ImmutableList<String> LEGACY_LICENSES = ImmutableList.of("legacy");
  17. private static final ImmutableList<String> PROD_LICENSES = ImmutableList.of("production");
  18. private static final String LEGACY_ID = "legacyId";
  19. private static final String PRODUCTION_ID = "productionId";
  20. @Rule
  21. public MockitoRule rule = MockitoJUnit.rule();
  22. @Mock
  23. private MultiLicenseStore production;
  24. @Mock
  25. private MultiLicenseStore legacy;
  26. private RenaissanceSwitchingMultiLicenseStore store;
  27. private RenaissanceMigrationStatus predicate = new MockRenaissanceMigrationStatus();
  28. @Before
  29. public void setUp() {
  30. when(legacy.retrieve()).thenReturn(LEGACY_LICENSES);
  31. when(production.retrieve()).thenReturn(PROD_LICENSES);
  32. when(legacy.retrieveServerId()).thenReturn(LEGACY_ID);
  33. when(production.retrieveServerId()).thenReturn(PRODUCTION_ID);
  34. store = new RenaissanceSwitchingMultiLicenseStore(legacy, production, predicate);
  35. }
  36. @Test
  37. public void retrieveUsesLegacyStoreWhenMigrationNotRun() {
  38. //when
  39. final Iterable<String> result = store.retrieve();
  40. //then
  41. assertThat(result, is(LEGACY_LICENSES));
  42. }
  43. @Test
  44. public void retrieveUsesProductStoreWhenMigrationHasRun() {
  45. //when
  46. final Iterable<String> resultLegacy = store.retrieve();
  47. //then
  48. assertThat(resultLegacy, is(LEGACY_LICENSES));
  49. //given
  50. predicate.markDone();
  51. //when
  52. final Iterable<String> resultProduction = store.retrieve();
  53. //then
  54. assertThat(resultProduction, is(PROD_LICENSES));
  55. }
  56. @Test
  57. public void storeUsesLegacyStoreWhenMigrationNotRun() {
  58. //when
  59. store.store(LEGACY_LICENSES);
  60. //then
  61. verify(legacy).store(LEGACY_LICENSES);
  62. verify(production, never()).store(any());
  63. }
  64. @Test
  65. public void storeUsesProductStoreWhenMigrationHasRun() {
  66. //given
  67. predicate.markDone();
  68. //when
  69. store.store(PROD_LICENSES);
  70. //then
  71. verify(production).store(PROD_LICENSES);
  72. verify(legacy, never()).store(any());
  73. }
  74. @Test
  75. public void retrieveServerIdUsesLegacyStoreWhenMigrationNotRun() {
  76. //when
  77. final String result = store.retrieveServerId();
  78. //then
  79. assertThat(result, is(LEGACY_ID));
  80. }
  81. @Test
  82. public void retrieveServerIdUsesProductStoreWhenMigrationHasRun() {
  83. //when
  84. final String resultLegacy = store.retrieveServerId();
  85. //then
  86. assertThat(resultLegacy, is(LEGACY_ID));
  87. //given
  88. predicate.markDone();
  89. //when
  90. final String result = store.retrieveServerId();
  91. //then
  92. assertThat(result, is(PRODUCTION_ID));
  93. }
  94. @Test
  95. public void storeServerIdUsesLegacyStoreWhenMigrationNotRun() {
  96. //when
  97. store.storeServerId(LEGACY_ID);
  98. //then
  99. verify(legacy).storeServerId(LEGACY_ID);
  100. verify(production, never()).storeServerId(any());
  101. }
  102. @Test
  103. public void storeServerIdUsesProductStoreWhenMigrationHasRun() {
  104. //given
  105. predicate.markDone();
  106. //when
  107. store.storeServerId(PRODUCTION_ID);
  108. //then
  109. verify(production).storeServerId(PRODUCTION_ID);
  110. verify(legacy, never()).storeServerId(any());
  111. }
  112. @Test
  113. public void storeServerIdUsesProductStoreInCloud() {
  114. //given
  115. predicate.markDone();
  116. //when
  117. store.storeServerId(PRODUCTION_ID);
  118. //then
  119. verify(production).storeServerId(PRODUCTION_ID);
  120. verify(legacy, never()).storeServerId(any());
  121. }
  122. @Test
  123. public void resetOldBuildConfirmationUsesLegacyStoreWhenMigrationNotRun() {
  124. //when
  125. store.resetOldBuildConfirmation();
  126. //then
  127. verify(legacy).resetOldBuildConfirmation();
  128. verify(production, never()).resetOldBuildConfirmation();
  129. }
  130. @Test
  131. public void resetOldBuildConfirmationUsesProductStoreWhenMigrationHasRun() {
  132. //given
  133. predicate.markDone();
  134. //when
  135. store.resetOldBuildConfirmation();
  136. //then
  137. verify(production).resetOldBuildConfirmation();
  138. verify(legacy, never()).resetOldBuildConfirmation();
  139. }
  140. @Test
  141. public void resetOldBuildConfirmationUsesProductStoreInCloud() {
  142. //given
  143. predicate.markDone();
  144. //when
  145. store.resetOldBuildConfirmation();
  146. //then
  147. verify(production).resetOldBuildConfirmation();
  148. verify(legacy, never()).resetOldBuildConfirmation();
  149. }
  150. @Test
  151. public void confirmProceedUnderEvaluationTermsUsesLegacyStoreWhenMigrationNotRun() {
  152. //when
  153. final String admin = "admin";
  154. store.confirmProceedUnderEvaluationTerms(admin);
  155. //then
  156. verify(legacy).confirmProceedUnderEvaluationTerms(admin);
  157. verify(production, never()).confirmProceedUnderEvaluationTerms(any());
  158. }
  159. @Test
  160. public void confirmProceedUnderEvaluationTermsUsesProductStoreWhenMigrationHasRun() {
  161. //given
  162. final String admin = "admin";
  163. predicate.markDone();
  164. //when
  165. store.confirmProceedUnderEvaluationTerms(admin);
  166. //then
  167. verify(production).confirmProceedUnderEvaluationTerms(admin);
  168. verify(legacy, never()).confirmProceedUnderEvaluationTerms(any());
  169. }
  170. @Test
  171. public void confirmProceedUnderEvaluationTermsUsesProductStoreInCloud() {
  172. //given
  173. final String admin = "admin";
  174. predicate.markDone();
  175. //when
  176. store.confirmProceedUnderEvaluationTerms(admin);
  177. //then
  178. verify(production).confirmProceedUnderEvaluationTerms(admin);
  179. verify(legacy, never()).confirmProceedUnderEvaluationTerms(any());
  180. }
  181. @Test
  182. public void clearUsesLegacyStoreWhenMigrationNotRun() {
  183. //when
  184. store.clear();
  185. //then
  186. verify(legacy).clear();
  187. verify(production, never()).clear();
  188. }
  189. @Test
  190. public void clearUsesProductStoreWhenMigrationHasRun() {
  191. //given
  192. predicate.markDone();
  193. //when
  194. store.clear();
  195. //then
  196. verify(production).clear();
  197. verify(legacy, never()).clear();
  198. }
  199. @Test
  200. public void clearUsesProductStoreInCloud() {
  201. //given
  202. predicate.markDone();
  203. //when
  204. store.clear();
  205. //then
  206. verify(production).clear();
  207. verify(legacy, never()).clear();
  208. }
  209. }