Skip to content

Commit

Permalink
Merge AllPDEMinimalTests into AllPDETests and merge minimal tests
Browse files Browse the repository at this point in the history
This prevents (and resolves already existing) discrepancies between the
tests run in the verification-builds and I-builds. All tests executed in
verification builds should also run in I-builds.
Only those that cannot succeed in verification builds are dynamically
disable using JUnit-Assume.

With that just the AllPDETests test-suite can be executed.
  • Loading branch information
HannesWell committed Sep 17, 2023
1 parent ba4fde8 commit dfcd3a7
Show file tree
Hide file tree
Showing 15 changed files with 1,506 additions and 1,811 deletions.
2 changes: 1 addition & 1 deletion ui/org.eclipse.pde.ui.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<code.ignoredWarnings>-warn:-discouraged</code.ignoredWarnings>
<defaultSigning-excludeInnerJars>true</defaultSigning-excludeInnerJars>
<testSuite>${project.artifactId}</testSuite>
<testClass>org.eclipse.pde.ui.tests.AllPDEMinimalTests</testClass>
<testClass>org.eclipse.pde.ui.tests.AllPDETests</testClass>
</properties>

<build>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005,2021 IBM Corporation and others.
* Copyright (c) 2005, 2023 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,6 +15,8 @@

import org.eclipse.pde.core.tests.internal.AllPDECoreTests;
import org.eclipse.pde.core.tests.internal.classpath.ClasspathResolutionTest;
import org.eclipse.pde.core.tests.internal.core.builders.BundleErrorReporterTest;
import org.eclipse.pde.core.tests.internal.util.PDESchemaHelperTest;
import org.eclipse.pde.ui.tests.build.properties.AllValidatorTests;
import org.eclipse.pde.ui.tests.classpathcontributor.ClasspathContributorTest;
import org.eclipse.pde.ui.tests.classpathresolver.ClasspathResolverTest;
Expand All @@ -38,27 +40,29 @@
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({
AllTargetTests.class,
AllNewProjectTests.class,
AllPreferenceTests.class,
AllImportTests.class,
AllBundleModelTests.class,
AllXMLModelTests.class,
AllValidatorTests.class,
AllNLSTests.class,
AllPDERuntimeTests.class,
ExportBundleTests.class,
AllLauncherTests.class,
AllLogViewTests.class,
ProjectCreationTests.class,
BundleRootTests.class,
PluginRegistryTests.class,
ClasspathResolverTest.class,
ClasspathContributorTest.class,
DynamicPluginProjectReferencesTest.class,
ClasspathResolutionTest.class,
AllPDECoreTests.class
@SuiteClasses({ //
AllTargetTests.class, //
AllNewProjectTests.class, //
AllPreferenceTests.class, //
AllImportTests.class, //
AllBundleModelTests.class, //
AllXMLModelTests.class, //
AllValidatorTests.class, //
AllNLSTests.class, //
AllPDERuntimeTests.class, //
ExportBundleTests.class, //
AllLauncherTests.class, //
AllLogViewTests.class, //
ProjectCreationTests.class, //
BundleRootTests.class, //
PluginRegistryTests.class, //
ClasspathResolverTest.class, //
PDESchemaHelperTest.class, //
ClasspathContributorTest.class, //
DynamicPluginProjectReferencesTest.class, //
ClasspathResolutionTest.class, //
BundleErrorReporterTest.class, //
AllPDECoreTests.class //
})
public class AllPDETests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
package org.eclipse.pde.ui.tests;

import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;

import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
Expand All @@ -22,6 +28,7 @@
import org.eclipse.core.runtime.ICoreRunnable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
Expand Down Expand Up @@ -131,4 +138,15 @@ private static void closeIntro(final IWorkbench wb) {
}
}
}

public static void assumeRunningInStandaloneEclipseSDK() {
try {
Path location = Path.of(Platform.getInstallLocation().getURL().toURI());
for (String directory : List.of("plugins", "features")) {
assumeTrue("Not running in a standalone Eclipse SDK", Files.isDirectory(location.resolve(directory)));
}
} catch (URISyntaxException e) {
throw new IllegalStateException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.pde.core.plugin.IMatchRules;
import org.eclipse.pde.core.plugin.IPluginBase;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.core.plugin.PluginRegistry.PluginFilter;
import org.eclipse.pde.core.project.IBundleProjectDescription;
import org.junit.Test;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.Version;
Expand All @@ -28,16 +38,183 @@
*
* @since 3.6
*/
public class PluginRegistryTests extends PluginRegistryTestsMinimal {
public class PluginRegistryTests {

@Test
public void testMatchNone() {
IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", null, IMatchRules.NONE, null);
assertNotNull(model);
assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId());
}

@Test
public void testMatchGreaterOrEqual() {
IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", "3.0.0",
IMatchRules.GREATER_OR_EQUAL, null);
assertNotNull(model);
assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId());
}

@Test
public void testMatchPerfect() {
IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", "3.0.0", IMatchRules.PERFECT, null);
assertNull(model);
}

@Test
public void testMatchCompatible() {
IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", "3.6.0", IMatchRules.COMPATIBLE,
null);
assertNotNull(model);
assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId());
}

@Test
public void testMatchCompatibleNone() {
IPluginModelBase model = PluginRegistry.findModel("org.eclipse.pde.core", "2.6.0", IMatchRules.COMPATIBLE,
null);
assertNull(model);
}

@Test
public void testMatchPrefix() {
IPluginModelBase model = PluginRegistry.findModel("org.eclipse", "3.6.0", IMatchRules.PREFIX, null);
// prefix rule is not supported by this API, should return null
assertNull(model);
}

@Test
public void testRangeNone() {
IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", null, null);
assertNotNull(model);
assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId());
}

@Test
public void testOverlapRange() {
IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", new VersionRange("[2.0.0,4.0.0)"),
null);
assertNotNull(model);
assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId());
}

@Test
public void testMinRange() {
IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", new VersionRange("3.0.0"), null);
assertNotNull(model);
assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId());
}

@Test
public void testUnmatchedRange() {
IPluginModelBase model = PluginRegistry.findModel("org.eclipse.pde.core", new VersionRange("[1.0.0,2.0.0)"),
null);
assertNull(model);
}

@Test
public void testRangeWithFilterMatch() {
PluginFilter filter = new PluginFilter() {
@Override
public boolean accept(IPluginModelBase model) {
IPluginBase base = model.getPluginBase();
if (base != null) {
String id = base.getId();
if (id != null) {
return id.startsWith("org.eclipse");
}
}
return false;
}
};
IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", new VersionRange("[2.0.0,4.0.0)"),
filter);
assertNotNull(model);
assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId());
}

@Test
public void testRangeWithFilterNoMatch() {
PluginFilter filter = new PluginFilter() {
@Override
public boolean accept(IPluginModelBase model) {
IPluginBase base = model.getPluginBase();
if (base != null) {
String id = base.getId();
if (id != null) {
return id.startsWith("xyz");
}
}
return false;
}
};
IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", new VersionRange("[2.0.0,4.0.0)"),
filter);
assertNull(model);
}

@Test
public void testSingleRangeMatch() {
IPluginModelBase[] models = PluginRegistry.findModels("org.eclipse.jdt.debug",
new VersionRange("[1.0.0,4.0.0)"), null);
assertNotNull(models);
assertEquals(1, models.length);
assertEquals("org.eclipse.jdt.debug", models[0].getPluginBase().getId());
}

@Test
public void testWorkspaceOverTarget() throws CoreException {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("org.junit");
try {
IBundleProjectDescription description = ProjectCreationTests.getBundleProjectService()
.getDescription(project);
description.setSymbolicName("org.junit");
description.setBundleVersion(new Version("4.3.2"));
description.setBundleVendor("bogus");
description.apply(null);

waitForBuild();

IPluginModelBase[] models = PluginRegistry.findModels("org.junit", new VersionRange("[3.8.2,4.8.2]"), null);
assertNotNull(models);
assertEquals(1, models.length);
assertEquals("org.junit", models[0].getPluginBase().getId());
assertEquals(project, models[0].getUnderlyingResource().getProject());

} finally {
if (project.exists()) {
project.delete(true, null);
waitForBuild();
}
}
}

@Test
public void testMatchEquivalent() {
Version testsVersion = FrameworkUtil.getBundle(getClass()).getVersion();
Version testsVersion = FrameworkUtil.getBundle(PluginRegistryTests.class).getVersion();
IPluginModelBase model = PluginRegistry.findModel("org.eclipse.pde.ui.tests",
String.format("%s.%s.%s", testsVersion.getMajor(), testsVersion.getMinor(), testsVersion.getMicro()),
IMatchRules.EQUIVALENT,
null);
assertNotNull("NOTE: This test might also fail because the version of the bundle got changed.", model);
assertEquals("org.eclipse.pde.ui.tests", model.getPluginBase().getId());
}

/**
* Wait for builds to complete
*/
public static void waitForBuild() {
boolean wasInterrupted = false;
do {
try {
Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_BUILD, null);
wasInterrupted = false;
} catch (OperationCanceledException e) {
e.printStackTrace();
} catch (InterruptedException e) {
wasInterrupted = true;
}
} while (wasInterrupted);
}
}
Loading

0 comments on commit dfcd3a7

Please sign in to comment.