From b01e2c4bffc42b5aecfe6479fffd6dd9c2495f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Fri, 15 Sep 2023 19:24:13 +0300 Subject: [PATCH] Rewrite smartimport test as plain JUnit test This removes RedDeer dependency which has been announced to drop from simrel. --- .../META-INF/MANIFEST.MF | 13 +- .../build.properties | 1 - .../pom.xml | 2 +- .../ui/tests/smartimport/AllTests.java | 4 +- .../smartimport/EclipseJavaProjectTest.java | 41 +---- .../tests/smartimport/FeatureProjectTest.java | 37 +--- .../smartimport/PlainEclipseProjectTest.java | 38 +--- .../smartimport/PlainJavaProjectTest.java | 38 +--- .../smartimport/ProjectTestTemplate.java | 162 +++++------------- .../smartimport/plugins/ImportedProject.java | 71 -------- .../smartimport/plugins/ProjectProposal.java | 65 ------- .../plugins/SmartImportRootWizardPage.java | 106 ------------ .../plugins/SmartImportWizard.java | 26 --- 13 files changed, 85 insertions(+), 519 deletions(-) delete mode 100644 ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/ImportedProject.java delete mode 100644 ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/ProjectProposal.java delete mode 100644 ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/SmartImportRootWizardPage.java delete mode 100644 ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/SmartImportWizard.java diff --git a/ui/org.eclipse.pde.ui.tests.smartimport/META-INF/MANIFEST.MF b/ui/org.eclipse.pde.ui.tests.smartimport/META-INF/MANIFEST.MF index 15249210cc..9639b9e775 100644 --- a/ui/org.eclipse.pde.ui.tests.smartimport/META-INF/MANIFEST.MF +++ b/ui/org.eclipse.pde.ui.tests.smartimport/META-INF/MANIFEST.MF @@ -8,23 +8,14 @@ Export-Package: org.eclipse.ui.tests.smartimport Require-Bundle: org.eclipse.core.resources, org.eclipse.core.runtime, org.eclipse.jface, - org.eclipse.reddeer.core;bundle-version="[3.0.0,5.0.0)", - org.eclipse.reddeer.common;bundle-version="[3.0.0,5.0.0)", - org.eclipse.reddeer.eclipse;bundle-version="[3.0.0,5.0.0)", - org.eclipse.reddeer.jface;bundle-version="[3.0.0,5.0.0)", - org.eclipse.reddeer.junit;bundle-version="[3.0.0,5.0.0)", - org.eclipse.reddeer.junit.extension;bundle-version="[3.0.0,5.0.0)", - org.eclipse.reddeer.swt;bundle-version="[3.0.0,5.0.0)", - org.eclipse.reddeer.workbench;bundle-version="[3.0.0,5.0.0)", - org.eclipse.reddeer.workbench.core;bundle-version="[3.0.0,5.0.0)", org.eclipse.swt, + org.eclipse.ui.ide, org.eclipse.jdt.ui, org.eclipse.pde.ui Bundle-ActivationPolicy: lazy Eclipse-BundleShape: dir Bundle-RequiredExecutionEnvironment: JavaSE-17 Automatic-Module-Name: org.eclipse.pde.ui.tests.smartimport -Import-Package: org.hamcrest, - org.junit, +Import-Package: org.junit, org.junit.runner, org.junit.runners diff --git a/ui/org.eclipse.pde.ui.tests.smartimport/build.properties b/ui/org.eclipse.pde.ui.tests.smartimport/build.properties index d01fd19891..38c2fd6175 100644 --- a/ui/org.eclipse.pde.ui.tests.smartimport/build.properties +++ b/ui/org.eclipse.pde.ui.tests.smartimport/build.properties @@ -13,5 +13,4 @@ bin.includes = about.html,\ test.xml,\ META-INF/ src.includes = about.html -jars.compile.order = browser.jar source.. = src/ diff --git a/ui/org.eclipse.pde.ui.tests.smartimport/pom.xml b/ui/org.eclipse.pde.ui.tests.smartimport/pom.xml index 6350deeb72..2601569976 100644 --- a/ui/org.eclipse.pde.ui.tests.smartimport/pom.xml +++ b/ui/org.eclipse.pde.ui.tests.smartimport/pom.xml @@ -37,7 +37,7 @@ org.eclipse.ui.tests.smartimport org.eclipse.ui.tests.smartimport.AllTests - ${tycho.test.jvmArgs} ${platformSystemProperties} -Drd.logLevel=off + ${tycho.test.jvmArgs} ${platformSystemProperties} **/*Test.class diff --git a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/AllTests.java b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/AllTests.java index fd4b66670d..71aa06b763 100644 --- a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/AllTests.java +++ b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/AllTests.java @@ -13,11 +13,11 @@ ******************************************************************************/ package org.eclipse.ui.tests.smartimport; -import org.eclipse.reddeer.junit.runner.RedDeerSuite; import org.junit.runner.RunWith; +import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -@RunWith(RedDeerSuite.class) +@RunWith(Suite.class) @SuiteClasses({ PlainJavaProjectTest.class, PlainEclipseProjectTest.class, diff --git a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/EclipseJavaProjectTest.java b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/EclipseJavaProjectTest.java index 29793335c4..4269ae595d 100644 --- a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/EclipseJavaProjectTest.java +++ b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/EclipseJavaProjectTest.java @@ -14,55 +14,32 @@ package org.eclipse.ui.tests.smartimport; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; import java.io.File; -import java.util.ArrayList; -import java.util.List; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import org.eclipse.ui.tests.smartimport.plugins.ImportedProject; -import org.eclipse.ui.tests.smartimport.plugins.ProjectProposal; public class EclipseJavaProjectTest extends ProjectTestTemplate { + private static final String JAVA_ECLIPSE_PROJECT = "JavaEclipseProject"; + @Override File getProjectPath() { return new File("target/resources/JavaEclipseProject"); } @Override - List getExpectedProposals() { - ArrayList returnList = new ArrayList<>(); - ProjectProposal projectProposal = new ProjectProposal("JavaEclipseProject"); - projectProposal.addImportAs("Eclipse project"); - returnList.add(projectProposal); - return returnList; - } - - @Override - List getExpectedImportedProjects() { - ArrayList returnList = new ArrayList<>(); - ImportedProject project = new ImportedProject("JavaEclipseProject", ""); - project.addImportedAs("Eclipse project"); - returnList.add(project); - return returnList; + void checkImportedProject() throws CoreException { + IProject project = getProject(); + String[] natureIds = project.getDescription().getNatureIds(); + assertEquals("Project should have exactly 1 nature", 1, natureIds.length); + assertEquals("Project should have java nature", "org.eclipse.jdt.core.javanature", natureIds[0]); } - @Override - void checkImportedProject() { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("JavaEclipseProject"); - String[] natureIds = {}; - try { - natureIds = project.getDescription().getNatureIds(); - } catch (CoreException e) { - e.printStackTrace(); - fail(); - } - assertEquals("Project should have exactly 1 nature", 1, natureIds.length); - assertEquals("Project should have java nature", "org.eclipse.jdt.core.javanature", natureIds[0]); + IProject getProject() { + return ResourcesPlugin.getWorkspace().getRoot().getProject(JAVA_ECLIPSE_PROJECT); } } diff --git a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/FeatureProjectTest.java b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/FeatureProjectTest.java index b27addd2d7..ada330d8a4 100644 --- a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/FeatureProjectTest.java +++ b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/FeatureProjectTest.java @@ -14,17 +14,12 @@ package org.eclipse.ui.tests.smartimport; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; import java.io.File; -import java.util.ArrayList; -import java.util.List; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import org.eclipse.ui.tests.smartimport.plugins.ImportedProject; -import org.eclipse.ui.tests.smartimport.plugins.ProjectProposal; public class FeatureProjectTest extends ProjectTestTemplate { @@ -36,34 +31,16 @@ File getProjectPath() { } @Override - List getExpectedProposals() { - ArrayList returnList = new ArrayList<>(); - ProjectProposal projectProposal = new ProjectProposal(PROJECT_NAME); - returnList.add(projectProposal); - return returnList; - } - - @Override - List getExpectedImportedProjects() { - ArrayList returnList = new ArrayList<>(); - ImportedProject project = new ImportedProject(PROJECT_NAME, ""); - project.addImportedAs("Eclipse Feature"); - returnList.add(project); - return returnList; + void checkImportedProject() throws CoreException { + IProject project = getProject(); + String[] natureIds = project.getDescription().getNatureIds(); + assertEquals("Project should have exactly 1 nature", 1, natureIds.length); + assertEquals("Project should have feature nature", "org.eclipse.pde.FeatureNature", natureIds[0]); } @Override - void checkImportedProject() { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME); - String[] natureIds = {}; - try { - natureIds = project.getDescription().getNatureIds(); - } catch (CoreException e) { - e.printStackTrace(); - fail(); - } - assertEquals("Project should have exactly 1 nature", 1, natureIds.length); - assertEquals("Project should have feature nature", "org.eclipse.pde.FeatureNature", natureIds[0]); + IProject getProject() { + return ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME); } } diff --git a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/PlainEclipseProjectTest.java b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/PlainEclipseProjectTest.java index e4e3cf1f01..704a1bbbb6 100644 --- a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/PlainEclipseProjectTest.java +++ b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/PlainEclipseProjectTest.java @@ -14,53 +14,31 @@ package org.eclipse.ui.tests.smartimport; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; import java.io.File; -import java.util.ArrayList; -import java.util.List; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import org.eclipse.ui.tests.smartimport.plugins.ImportedProject; -import org.eclipse.ui.tests.smartimport.plugins.ProjectProposal; public class PlainEclipseProjectTest extends ProjectTestTemplate { + private static final String PLAIN_ECLIPSE_PROJECT = "PlainEclipseProject"; + @Override File getProjectPath() { return new File("target/resources/PlainEclipseProject"); } @Override - List getExpectedProposals() { - ArrayList returnList = new ArrayList<>(); - ProjectProposal projectProposal = new ProjectProposal("PlainEclipseProject"); - projectProposal.addImportAs("Eclipse project"); - returnList.add(projectProposal); - return returnList; + IProject getProject() { + return ResourcesPlugin.getWorkspace().getRoot().getProject(PLAIN_ECLIPSE_PROJECT); } @Override - List getExpectedImportedProjects() { - ArrayList returnList = new ArrayList<>(); - ImportedProject project = new ImportedProject("PlainEclipseProject", ""); - project.addImportedAs("Eclipse project"); - returnList.add(project); - return returnList; + void checkImportedProject() throws CoreException { + IProject project = getProject(); + String[] natureIds = project.getDescription().getNatureIds(); + assertEquals("This project should not have any nature", 0, natureIds.length); } - - @Override - void checkImportedProject() { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("PlainEclipseProject"); - try { - String[] natureIds = project.getDescription().getNatureIds(); - assertEquals("This project should not have any nature", 0, natureIds.length); - } catch (CoreException e) { - e.printStackTrace(); - fail(); - } - } - } diff --git a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/PlainJavaProjectTest.java b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/PlainJavaProjectTest.java index 8d08464a5b..626d813317 100644 --- a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/PlainJavaProjectTest.java +++ b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/PlainJavaProjectTest.java @@ -14,53 +14,33 @@ package org.eclipse.ui.tests.smartimport; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; import java.io.File; -import java.util.ArrayList; -import java.util.List; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import org.eclipse.ui.tests.smartimport.plugins.ImportedProject; -import org.eclipse.ui.tests.smartimport.plugins.ProjectProposal; public class PlainJavaProjectTest extends ProjectTestTemplate { + private static final String PLAIN_JAVA_PROJECT = "PlainJavaProject"; + @Override public File getProjectPath() { return new File("target/resources/PlainJavaProject"); } - @Override - List getExpectedProposals() { - ArrayList returnList = new ArrayList<>(); - ProjectProposal projectProposal = new ProjectProposal("PlainJavaProject"); - returnList.add(projectProposal); - return returnList; - } @Override - List getExpectedImportedProjects() { - ArrayList returnList = new ArrayList<>(); - ImportedProject project = new ImportedProject("PlainJavaProject", ""); - project.addImportedAs("Java"); - returnList.add(project); - return returnList; + void checkImportedProject() throws CoreException { + IProject project = getProject(); + String[] natureIds = project.getDescription().getNatureIds(); + assertEquals("Project should have exactly 1 nature", 1, natureIds.length); + assertEquals("Project should have java nature", "org.eclipse.jdt.core.javanature", natureIds[0]); } @Override - void checkImportedProject() { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("PlainJavaProject"); - String[] natureIds = {}; - try { - natureIds = project.getDescription().getNatureIds(); - } catch (CoreException e) { - e.printStackTrace(); - fail(); - } - assertEquals("Project should have exactly 1 nature", 1, natureIds.length); - assertEquals("Project should have java nature", "org.eclipse.jdt.core.javanature", natureIds[0]); + IProject getProject() { + return ResourcesPlugin.getWorkspace().getRoot().getProject(PLAIN_JAVA_PROJECT); } } diff --git a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/ProjectTestTemplate.java b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/ProjectTestTemplate.java index a2d1757c8c..0c24ebe383 100644 --- a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/ProjectTestTemplate.java +++ b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/ProjectTestTemplate.java @@ -13,111 +13,59 @@ ******************************************************************************/ package org.eclipse.ui.tests.smartimport; -import static java.util.Collections.emptyList; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.File; -import java.util.Iterator; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import org.eclipse.reddeer.common.logging.Logger; -import org.eclipse.reddeer.common.matcher.RegexMatcher; -import org.eclipse.reddeer.common.wait.AbstractWait; -import org.eclipse.reddeer.common.wait.TimePeriod; -import org.eclipse.reddeer.common.wait.WaitUntil; -import org.eclipse.reddeer.eclipse.core.resources.DefaultProject; -import org.eclipse.reddeer.eclipse.core.resources.Project; -import org.eclipse.reddeer.eclipse.ui.navigator.resources.ProjectExplorer; -import org.eclipse.reddeer.eclipse.ui.problems.Problem; -import org.eclipse.reddeer.eclipse.ui.views.log.LogMessage; -import org.eclipse.reddeer.eclipse.ui.views.log.LogView; -import org.eclipse.reddeer.eclipse.ui.views.markers.ProblemsView; -import org.eclipse.reddeer.eclipse.ui.views.markers.ProblemsView.ProblemType; -import org.eclipse.reddeer.swt.condition.ControlIsEnabled; -import org.eclipse.reddeer.swt.impl.button.FinishButton; -import org.eclipse.reddeer.workbench.handler.WorkbenchShellHandler; -import org.eclipse.ui.tests.smartimport.plugins.ImportedProject; -import org.eclipse.ui.tests.smartimport.plugins.ProjectProposal; -import org.eclipse.ui.tests.smartimport.plugins.SmartImportRootWizardPage; -import org.eclipse.ui.tests.smartimport.plugins.SmartImportWizard; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Platform; +import org.eclipse.ui.internal.wizards.datatransfer.SmartImportJob; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; public abstract class ProjectTestTemplate { - public static final String IGNORED_ERRORS_PROPERTY = "ignored.errors.regexp"; - private static final Logger LOG = new Logger(ProjectTestTemplate.class); - - private String ignoredErrorsRegExp = "Current Eclipse instance does not support software installation."; - public ProjectTestTemplate() { - String extraPattern = System.getProperty(IGNORED_ERRORS_PROPERTY); - - if (extraPattern != null && !extraPattern.isEmpty()) { - ignoredErrorsRegExp = ignoredErrorsRegExp + "|" + extraPattern; - } } @After - public void cleanup() { - WorkbenchShellHandler.getInstance().closeAllNonWorbenchShells(); - for (Project p : getProjects()) { - p.delete(false); + public void cleanup() throws CoreException, FileNotFoundException, IOException { + for (IProject p : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { + p.delete(true, new NullProgressMonitor()); } // empty error log - - LogView logView = new LogView(); - logView.open(); - logView.deleteLog(); - } - - private List getProjects() { - try { - ProjectExplorer explorer = new ProjectExplorer(); - explorer.open(); - return explorer.getProjects(); - } catch (NullPointerException e) { - // TODO: remove workaround when - // https://github.com/eclipse/reddeer/issues/2005 is fixed - LOG.error("https://github.com/eclipse/reddeer/issues/2005", e); - return emptyList(); - } + new FileWriter(Platform.getLogFileLocation().toFile(), false).close(); } @BeforeClass public static void setupClass() { - AbstractWait.sleep(TimePeriod.DEFAULT); - LogView logView = new LogView(); - logView.open(); - logView.deleteLog(); + // empty error log + try { + new FileWriter(Platform.getLogFileLocation().toFile(), false).close(); + } catch (IOException e) { + // ignore + } } @Test - public void testImport() { - SmartImportWizard easymportWizard = new SmartImportWizard(); - easymportWizard.open(); - SmartImportRootWizardPage selectImportRootWizardPage = new SmartImportRootWizardPage(easymportWizard); - String path = getProjectPath().getAbsolutePath(); - selectImportRootWizardPage.selectDirectory(path); - selectImportRootWizardPage.setSearchForNestedProjects(true); - selectImportRootWizardPage.setDetectAndConfigureNatures(true); - new WaitUntil(new ControlIsEnabled(new FinishButton()), TimePeriod.LONG); - - // check proposals - List allProjectProposals = selectImportRootWizardPage.getAllProjectProposals(); - List expectedProposals = getExpectedProposals(); - assertEquals(expectedProposals.size(), allProjectProposals.size()); - for (ProjectProposal projectProposal : allProjectProposals) { - if (!expectedProposals.contains(projectProposal)) { - fail("Expected proposals: " + expectedProposals.toString() + ", actual proposals: " - + allProjectProposals.toString()); - } - } - easymportWizard.finish(); + @SuppressWarnings("restriction") + public void testImport() throws CoreException, InterruptedException, IOException { + SmartImportJob job = new SmartImportJob(getProjectPath(), null, true, false); + job.run(new NullProgressMonitor()); + job.join(); // check imported project checkErrorLog(); @@ -126,52 +74,36 @@ public void testImport() { checkImportedProject(); } - private void checkErrorLog() { - LogView logView = new LogView(); - logView.open(); - List errorMessages = logView.getErrorMessages(); - - RegexMatcher matcher = new RegexMatcher(ignoredErrorsRegExp); - int ignoredErrors = 0; - - Iterator iterator = errorMessages.iterator(); - - while (iterator.hasNext()) { - LogMessage logMessage = iterator.next(); - - if (matcher.matches(logMessage.getMessage())) { - LOG.info("Ignoring error message: " + logMessage.getMessage()); - iterator.remove(); - // Increase exceptedErrors if log contains error which can be - // ignored. - ignoredErrors++; - } - } - - assertTrue("There are unexpected errors in error log: " + errorMessages, - ((errorMessages.size() - ignoredErrors) <= 0)); + private void checkErrorLog() throws IOException { + String log = Files.readString(Platform.getLogFileLocation().toFile().toPath()); + assertTrue(log.isEmpty()); } - private void checkProblemsView() { - ProblemsView problemsView = new ProblemsView(); - problemsView.open(); - List problems = problemsView.getProblems(ProblemType.ERROR); - assertTrue("There should be no errors in imported project: " + System.lineSeparator() - + problems.stream().map(String::valueOf).collect(Collectors.joining(System.lineSeparator())), - problems.isEmpty()); + private void checkProblemsView() throws CoreException { + IProject project = getProject(); + IMarker[] problems = project.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); + List errorMarkers = Arrays.asList(problems).stream().filter(m -> { + try { + return m.getAttribute(IMarker.SEVERITY).equals(IMarker.SEVERITY_ERROR); + } catch (CoreException e) { + return false; + } + }).toList(); + assertTrue( + "There should be no errors in imported project: " + System.lineSeparator() + errorMarkers.stream() + .map(String::valueOf).collect(Collectors.joining(System.lineSeparator())), + errorMarkers.isEmpty()); } abstract File getProjectPath(); - abstract List getExpectedProposals(); - - abstract List getExpectedImportedProjects(); + abstract IProject getProject(); /** * Checks whether the project was imported correctly. * */ - abstract void checkImportedProject(); + abstract void checkImportedProject() throws CoreException; } diff --git a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/ImportedProject.java b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/ImportedProject.java deleted file mode 100644 index 9d49cd5e5f..0000000000 --- a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/ImportedProject.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2018 Red Hat, Inc. and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributor: - * Red Hat, Inc. - initial API and implementation - ******************************************************************************/ -package org.eclipse.ui.tests.smartimport.plugins; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -/** - * This class represents imported project as it is displayed after import in {@link EasymportJobReportDialog}. - */ -public class ImportedProject { - - private final String projectName; - private final List importedAs; - private final String relativePath; - - public ImportedProject(String projectName, String relativePath) { - this.projectName = projectName; - this.relativePath = relativePath; - importedAs = new ArrayList<>(); - } - - public void addImportedAs(String type){ - importedAs.add(type); - } - - public String getProjectName() { - return projectName; - } - - public List getImportedAsList() { - return importedAs; - } - - public String getRelativePath() { - return relativePath; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof ImportedProject){ - ImportedProject project = (ImportedProject) obj; - if (project.getProjectName().equals(projectName) && project.getRelativePath().equals(relativePath)){ - return project.getImportedAsList().equals(this.getImportedAsList()); - } - } - return false; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("ProjectName: "+projectName+", "); - sb.append("relative path: \""+relativePath+"\", "); - sb.append(importedAs.stream().collect(Collectors.joining(","))); - return sb.toString(); - } - -} diff --git a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/ProjectProposal.java b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/ProjectProposal.java deleted file mode 100644 index ea1ea6c4a9..0000000000 --- a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/ProjectProposal.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2018 Red Hat, Inc. and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributor: - * Red Hat, Inc. - initial API and implementation - ******************************************************************************/ -package org.eclipse.ui.tests.smartimport.plugins; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -public class ProjectProposal { - - private String folder; - private final List importAsList; - - public ProjectProposal(String folder) { - this.folder = folder; - this.importAsList = new ArrayList<>(); - } - - public String getFolder() { - return folder; - } - - public void setFolder(String folder) { - this.folder = folder; - } - - public List getImportAsList() { - return importAsList; - } - - public void addImportAs(String importType){ - importAsList.add(importType); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof ProjectProposal){ - ProjectProposal proposal = (ProjectProposal) obj; - if (proposal.getFolder().equals(folder)){ - return proposal.getImportAsList().equals(this.getImportAsList()); - } - } - return false; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("Folder: "+folder+", "); - sb.append(importAsList.stream().collect(Collectors.joining(","))); - return sb.toString(); - } - -} diff --git a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/SmartImportRootWizardPage.java b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/SmartImportRootWizardPage.java deleted file mode 100644 index 57623bf441..0000000000 --- a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/SmartImportRootWizardPage.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2018 Red Hat, Inc. and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributor: - * Red Hat, Inc. - initial API and implementation - ******************************************************************************/ -package org.eclipse.ui.tests.smartimport.plugins; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.reddeer.common.logging.Logger; -import org.eclipse.reddeer.common.wait.WaitWhile; -import org.eclipse.reddeer.core.reference.ReferencedComposite; -import org.eclipse.reddeer.eclipse.ui.wizards.datatransfer.WizardProjectsImportPage; -import org.eclipse.reddeer.jface.wizard.WizardPage; -import org.eclipse.reddeer.swt.api.Combo; -import org.eclipse.reddeer.swt.api.Shell; -import org.eclipse.reddeer.swt.api.TreeItem; -import org.eclipse.reddeer.swt.condition.ShellIsAvailable; -import org.eclipse.reddeer.swt.impl.button.CheckBox; -import org.eclipse.reddeer.swt.impl.button.OkButton; -import org.eclipse.reddeer.swt.impl.combo.LabeledCombo; -import org.eclipse.reddeer.swt.impl.label.DefaultLabel; -import org.eclipse.reddeer.swt.impl.link.DefaultLink; -import org.eclipse.reddeer.swt.impl.shell.DefaultShell; -import org.eclipse.reddeer.swt.impl.tree.DefaultTree; - -public class SmartImportRootWizardPage extends WizardPage { - - private static final Logger log = Logger.getLogger(WizardProjectsImportPage.class); - - public SmartImportRootWizardPage(ReferencedComposite referencedComposite) { - super(referencedComposite); - } - - public void selectDirectory(String path){ - log.info("Selecting directory \""+path+"\" in SelectImportRootWizardPage."); - Combo selectDirText = new LabeledCombo(this, "Import source:"); - selectDirText.setText(path); - } - - - public List getDetectors(){ - List resultList = new ArrayList<>(); - new DefaultLink(this, "installed project configurators").click(); - Shell configuratorsShell = new DefaultShell("Installed project configuratos"); - String labelText = new DefaultLabel(configuratorsShell, 1).getText(); - String[] split = labelText.split("\n"); - for (String row: split) { - if (row.startsWith("*")){ - resultList.add(row.substring(2)); - } - } - new OkButton(configuratorsShell).click(); - new WaitWhile(new ShellIsAvailable(configuratorsShell)); - return resultList; - } - - public void setSearchForNestedProjects(boolean value){ - new CheckBox(this, "Search for nested projects").toggle(value); - } - - public void setDetectAndConfigureNatures(boolean value){ - new CheckBox(this, "Detect and configure project natures").toggle(value); - } - - public void setHideOpenProjects(boolean value){ - new CheckBox(this, "Hide already open projects").toggle(value); - } - - public List getAllProjectProposals() { - - DefaultTree tree = new DefaultTree(this); - List returnList = parseTree(tree); - return returnList; - } - - private List parseTree(DefaultTree tree) { - List returnList = new ArrayList<>(); - for (TreeItem treeItem : tree.getAllItems()) { - ProjectProposal projectProposal = new ProjectProposal(treeItem.getCell(0)); - returnList.add(fillProjectProposal(projectProposal, treeItem)); - } - return returnList; - } - - private ProjectProposal fillProjectProposal(ProjectProposal projectProposal, TreeItem treeItem) { - String cell = treeItem.getCell(1); - String[] split = cell.split(","); - for (String type : split) { - if (!type.equals("")) { - projectProposal.addImportAs(type); - } - } - return projectProposal; - } - -} diff --git a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/SmartImportWizard.java b/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/SmartImportWizard.java deleted file mode 100644 index ffd3df6a14..0000000000 --- a/ui/org.eclipse.pde.ui.tests.smartimport/src/org/eclipse/ui/tests/smartimport/plugins/SmartImportWizard.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2018 Red Hat, Inc. and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributor: - * Red Hat, Inc. - initial API and implementation - ******************************************************************************/ -package org.eclipse.ui.tests.smartimport.plugins; - -import org.eclipse.reddeer.workbench.workbenchmenu.WorkbenchMenuWizardDialog; - -/** - * Represents SmartImport Wizard (File -> Open Projects from File System...). - */ -public class SmartImportWizard extends WorkbenchMenuWizardDialog { - - public SmartImportWizard() { - super("Import Projects from File System or Archive", "File", "Open Projects from File System..."); - } -}