PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/jira-project/jira-functional-tests/jira-func-tests-legacy/src/main/java/com/atlassian/jira/webtests/ztests/imports/project/AbstractProjectImportTestCase.java

https://bitbucket.org/ahmed_bilal_360factors/jira7-core
Java | 196 lines | 89 code | 25 blank | 82 comment | 5 complexity | 1d8e8406c968624e963443ecf656043a MD5 | raw file
Possible License(s): Apache-2.0
  1. package com.atlassian.jira.webtests.ztests.imports.project;
  2. import com.atlassian.jira.functest.framework.FuncTestCase;
  3. import com.atlassian.jira.functest.framework.Navigation;
  4. import com.atlassian.jira.functest.framework.admin.ProjectImportTypeFix;
  5. import org.apache.commons.io.FileUtils;
  6. import org.apache.commons.io.FilenameUtils;
  7. import org.junit.Assert;
  8. import java.io.File;
  9. import java.io.IOException;
  10. /**
  11. * Has some base methods for testing ProjectImport.
  12. *
  13. * @since v3.13
  14. * @deprecated use {@link BaseJiraProjectImportFuncTest}
  15. * for junit4 support.
  16. */
  17. @Deprecated
  18. //DEBT-170: this should be moven to jira-func-tests-legacy in a long run
  19. public abstract class AbstractProjectImportTestCase extends FuncTestCase {
  20. public void advanceThroughWaitingPage() {
  21. int count = 0;
  22. while (tester.getDialog().getResponseText().contains("Project Import: Progress")) {
  23. // We need to click the refresh which should take us to the next page
  24. tester.submit("Refresh");
  25. // OK - we are still in progress. Wait a little while before we try again.
  26. try {
  27. Thread.sleep(100);
  28. } catch (InterruptedException e) {
  29. // Not expected.
  30. throw new RuntimeException(e);
  31. }
  32. // Safety net to make sure that we don't get in an infinite loop.
  33. count++;
  34. if (count >= 100) {
  35. Assert.fail("Our project import backup selection has taken too long!");
  36. }
  37. }
  38. }
  39. /**
  40. * Takes two XML paths and runs the Project Import up to the summary screen.
  41. * The first backup file is imported and then exported to the temp directory.
  42. * We need to do this to migrate the file to the latest version of JIRA.
  43. * Then we import the second file. (This will usually have some config changes that will show errors and/or warnings
  44. * on the Summary Screen.)
  45. * <p>
  46. * This method then kicks off a project import on the MKY project and takes it up to the Summary page.
  47. * </p>
  48. *
  49. * @param backupFileName The File that we project import.
  50. * @param currentSystemXML The "current system" state.
  51. * @return The temp file, which should be deleted by the calling test.
  52. */
  53. public File doProjectImport(String backupFileName, String currentSystemXML) {
  54. return doProjectImport(backupFileName, currentSystemXML, false);
  55. }
  56. /**
  57. * Takes two XML paths and runs the Project Import up to the summary screen.
  58. * The first backup file is imported and then exported to the temp directory.
  59. * We need to do this to migrate the file to the latest version of JIRA.
  60. * Then we import the second file. (This will usually have some config changes that will show errors and/or warnings
  61. * on the Summary Screen.)
  62. * <p>
  63. * This method then kicks off a project import on the MKY project and takes it up to the Summary page.
  64. * </p>
  65. *
  66. * @param backupFileName The File that we project import.
  67. * @param currentSystemXML The "current system" state.
  68. * @param projectName Name of project to import.
  69. * @return The temp file, which should be deleted by the calling test.
  70. */
  71. public File doProjectImport(String backupFileName, String currentSystemXML, String projectName) {
  72. return doProjectImport(backupFileName, currentSystemXML, projectName, false);
  73. }
  74. /**
  75. * Takes two XML paths and runs the Project Import up to the summary screen.
  76. * The first backup file is imported and then exported to the temp directory.
  77. * We need to do this to migrate the file to the latest version of JIRA.
  78. * Then we import the second file. (This will usually have some config changes that will show errors and/or warnings
  79. * on the Summary Screen.)
  80. * <p>
  81. * This method then kicks off a project import on the MKY project and takes it up to the Summary page.
  82. * </p>
  83. *
  84. * @param backupFileName The File that we project import.
  85. * @param currentSystemXML The "current system" state.
  86. * @param projectName Name of project to import.
  87. * @param doPluginsRefresh specify <code>true</code> if you are testing plugins and need JIRA to do a full refresh
  88. * on data import; if testing core JIRA then a quick import should suffice.
  89. * @return The temp file, which should be deleted by the calling test.
  90. */
  91. public File doProjectImport(String backupFileName, String currentSystemXML, String projectName, final boolean doPluginsRefresh) {
  92. File tempFile = importAndExportBackupAndSetupCurrentInstance(backupFileName, currentSystemXML, doPluginsRefresh);
  93. importToPreImportSummaryPage(tempFile, projectName);
  94. return tempFile;
  95. }
  96. /**
  97. * Takes two XML paths and runs the Project Import up to the summary screen.
  98. * The first backup file is imported and then exported to the temp directory.
  99. * We need to do this to migrate the file to the latest version of JIRA.
  100. * Then we import the second file. (This will usually have some config changes that will show errors and/or warnings
  101. * on the Summary Screen.)
  102. * <p>
  103. * This method then kicks off a project import on the MKY project and takes it up to the Summary page.
  104. * </p>
  105. *
  106. * @param backupFileName The File that we project import.
  107. * @param currentSystemXML The "current system" state.
  108. * @param doPluginsRefresh specify <code>true</code> if you are testing plugins and need JIRA to do a full refresh
  109. * on data import; if testing core JIRA then a quick import should suffice.
  110. * @return The temp file, which should be deleted by the calling test.
  111. */
  112. public File doProjectImport(String backupFileName, String currentSystemXML, final boolean doPluginsRefresh) {
  113. File tempFile = importAndExportBackupAndSetupCurrentInstance(backupFileName, currentSystemXML, doPluginsRefresh);
  114. importToPreImportSummaryPage(tempFile);
  115. return tempFile;
  116. }
  117. protected File copyFileToJiraImportDirectory(final File file) {
  118. File jiraImportDirectory = new File(administration.getJiraHomeDirectory(), "import");
  119. if (file.getParentFile().equals(jiraImportDirectory)) {
  120. //File already in the import directory, no need to copy
  121. return file;
  122. }
  123. try {
  124. FileUtils.copyFileToDirectory(file, jiraImportDirectory);
  125. } catch (IOException e) {
  126. throw new RuntimeException("Could not copy file " + file.getAbsolutePath() + " to the import directory in jira home " + jiraImportDirectory, e);
  127. }
  128. return new File(jiraImportDirectory, file.getName());
  129. }
  130. public void importToPreImportSummaryPage(final File tempFile) {
  131. importToPreImportSummaryPage(tempFile, "monkey");
  132. }
  133. public void importToPreImportSummaryPage(final File tempFile, final String projectName) {
  134. copyFileToJiraImportDirectory(tempFile);
  135. // Lets try our import
  136. this.navigation.gotoAdminSection(Navigation.AdminSection.PROJECT_IMPORT);
  137. // Get to the project select page
  138. tester.setWorkingForm("project-import");
  139. tester.assertTextPresent("Project Import: Select Backup File");
  140. tester.setFormElement("backupPath", tempFile.getName());
  141. tester.submit();
  142. advanceThroughWaitingPage();
  143. tester.assertTextPresent("Project Import: Select Project to Import");
  144. // Choose the MKY project
  145. tester.selectOption("projectKey", projectName);
  146. tester.submit("Next");
  147. advanceThroughWaitingPage();
  148. }
  149. public File importAndExportBackupAndSetupCurrentInstance(final String backupFileName, final String currentSystemXML) {
  150. return importAndExportBackupAndSetupCurrentInstance(backupFileName, currentSystemXML, false);
  151. }
  152. public File importAndExportBackupAndSetupCurrentInstance(final String backupFileName, final String currentSystemXML, final boolean doPluginsRefresh) {
  153. // We always need to restore the data and write it out to a tmp file whos path we know
  154. if (doPluginsRefresh) {
  155. this.administration.restoreDataSlowOldWay(backupFileName);
  156. } else {
  157. backdoor.restoreDataFromResource(backupFileName);
  158. }
  159. // We don't need to delete the file, as the export will handle overwrite. It might help us stay unique.
  160. File backupFile = this.administration.exportDataToFile(FilenameUtils.removeExtension(backupFileName) + "_out.xml");
  161. final ProjectImportTypeFix fix = new ProjectImportTypeFix(backdoor);
  162. fix.rewriteProjectTypes(backupFile);
  163. // Now do the test
  164. backupFile = copyFileToJiraImportDirectory(backupFile);
  165. // Import the data that has the project data missing and it is ready to be imported
  166. backdoor.restoreDataFromResource(currentSystemXML);
  167. fix.updateAllProjectsToBusinessType();
  168. this.administration.attachments().enable();
  169. return backupFile;
  170. }
  171. }