diff options
author | Christian W. Damus | 2021-04-21 14:29:12 +0000 |
---|---|---|
committer | Patrick Tessier | 2021-04-30 13:16:18 +0000 |
commit | 86f984acefa80ba08d53cb623fb6ba116d468a4f (patch) | |
tree | 4c939f9e027d349d488005c39548ca5435b08307 /tests/junit | |
parent | 43f64c4a1e2628473f007b1b9d8885a036039cdf (diff) | |
download | org.eclipse.papyrus-86f984acefa80ba08d53cb623fb6ba116d468a4f.tar.gz org.eclipse.papyrus-86f984acefa80ba08d53cb623fb6ba116d468a4f.tar.xz org.eclipse.papyrus-86f984acefa80ba08d53cb623fb6ba116d468a4f.zip |
Bug 572677: [Toolsmiths] Duplicate extensions for "Missing oepu.extensionpoints.UMLProfile" quickfix
- in the case of generating a new element, only add it to the plug-in
model after configuring it
- fix up some method signatures for methods that access markers
to let them throw CoreException
- add JUnit test coverage for affected quick fixes
- while we're at it, add all of the validation builder tests to the
Toolsmiths test suite
- and fix the UML Profile validation build test failures
- fix case mismatch in file name in ModelDependenciesCheckerTest
Change-Id: Ifcf9bf83cbc282cf7898df6c819ade02c36c0c6e
Signed-off-by: Christian W. Damus <give.a.damus@gmail.com>
Diffstat (limited to 'tests/junit')
12 files changed, 394 insertions, 63 deletions
diff --git a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ProjectFixture.java b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ProjectFixture.java index 22bf311ecf4..182a1c31f3a 100644 --- a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ProjectFixture.java +++ b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ProjectFixture.java @@ -399,21 +399,23 @@ public class ProjectFixture implements TestRule { try { project.refreshLocal(IResource.DEPTH_INFINITE, null); - // Make sure that we can delete everything - project.accept(new IResourceVisitor() { - - @Override - public boolean visit(IResource resource) throws CoreException { - switch (resource.getType()) { - case IResource.FILE: - case IResource.FOLDER: - ensureWritable(resource); - break; + if (project.isAccessible()) { + // Make sure that we can delete everything + project.accept(new IResourceVisitor() { + + @Override + public boolean visit(IResource resource) throws CoreException { + switch (resource.getType()) { + case IResource.FILE: + case IResource.FOLDER: + ensureWritable(resource); + break; + } + + return true; } - - return true; - } - }); + }); + } project.delete(true, null); } catch (CoreException e) { diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.suite.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.suite.tests/META-INF/MANIFEST.MF index ce486a958a6..cf366559e02 100755 --- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.suite.tests/META-INF/MANIFEST.MF +++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.suite.tests/META-INF/MANIFEST.MF @@ -14,6 +14,10 @@ Require-Bundle: org.eclipse.emf.edit.ui;bundle-version="[2.18.0,3.0.0)", org.eclipse.papyrus.junit.framework;bundle-version="[2.0.0,3.0.0)", org.eclipse.papyrus.junit.utils;bundle-version="[3.0.0,4.0.0)", org.eclipse.papyrus.toolsmiths.profilemigration.tests;bundle-version="[1.0.0,2.0.0)", + org.eclipse.papyrus.toolsmiths.validation.common.tests;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.toolsmiths.validation.architecture.tests;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.toolsmiths.validation.elementtypes.tests;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.toolsmiths.validation.profile.tests;bundle-version="[2.0.0,3.0.0)", org.eclipse.ui.views.properties.tabbed;bundle-version="[3.8.0,4.0.0)", org.junit;bundle-version="[4.13.0,5.0.0)" Export-Package: org.eclipse.papyrus.toolsmiths.suite.tests diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.suite.tests/Papyrus Toolsmiths ALL tests.launch b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.suite.tests/Papyrus Toolsmiths ALL tests.launch index e742aa4d156..dff5b05bc32 100755 --- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.suite.tests/Papyrus Toolsmiths ALL tests.launch +++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.suite.tests/Papyrus Toolsmiths ALL tests.launch @@ -1,44 +1,46 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <launchConfiguration type="org.eclipse.pde.ui.JunitLaunchConfig"> -<booleanAttribute key="askclear" value="false"/> -<booleanAttribute key="automaticAdd" value="true"/> -<booleanAttribute key="automaticValidate" value="false"/> -<stringAttribute key="bootstrap" value=""/> -<stringAttribute key="checked" value="[NONE]"/> -<booleanAttribute key="clearConfig" value="true"/> -<booleanAttribute key="clearws" value="true"/> -<booleanAttribute key="clearwslog" value="false"/> -<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/Papyrus Toolsmiths ALL tests"/> -<booleanAttribute key="default" value="true"/> -<booleanAttribute key="includeOptional" value="true"/> -<stringAttribute key="location" value="${workspace_loc}/../junit-all-workspace"/> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> -<listEntry value="/org.eclipse.papyrus.toolsmiths.suite.tests/test/org/eclipse/papyrus/toolsmiths/suite/tests/AllTests.java"/> -</listAttribute> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> -<listEntry value="1"/> -</listAttribute> -<mapAttribute key="org.eclipse.debug.core.environmentVariables"> -<mapEntry key="skip.long.junit.tests" value="false"/> -</mapAttribute> -<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/> -<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> -<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> -<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/> -<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> -<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/><stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.papyrus.toolsmiths.suite.tests.AllTests"/> -<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/> -<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.papyrus.toolsmiths.suite.tests"/> -<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/> -<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms512m -Xmx1024m -DsuppressRawWhenUnchecked=true -XX:SoftRefLRUPolicyMSPerMB=100 -Doomph.setup.skip=true -Doomph.setup.questionnaire.skip=true"/> -<stringAttribute key="pde.version" value="3.3"/> -<stringAttribute key="product" value="org.eclipse.platform.ide"/> -<booleanAttribute key="run_in_ui_thread" value="true"/> -<booleanAttribute key="show_selected_only" value="false"/> -<booleanAttribute key="tracing" value="true"/> -<booleanAttribute key="useCustomFeatures" value="false"/> -<booleanAttribute key="useDefaultConfig" value="true"/> -<booleanAttribute key="useDefaultConfigArea" value="true"/> -<booleanAttribute key="useProduct" value="true"/> -<stringAttribute key="yk-options" value=" additional-options2=onexit\=snapshot "/> + <booleanAttribute key="askclear" value="false"/> + <booleanAttribute key="automaticAdd" value="true"/> + <booleanAttribute key="automaticValidate" value="false"/> + <stringAttribute key="bootstrap" value=""/> + <stringAttribute key="checked" value="[NONE]"/> + <booleanAttribute key="clearConfig" value="true"/> + <booleanAttribute key="clearws" value="true"/> + <booleanAttribute key="clearwslog" value="false"/> + <stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/Papyrus Toolsmiths ALL tests"/> + <booleanAttribute key="default" value="true"/> + <booleanAttribute key="includeOptional" value="true"/> + <stringAttribute key="location" value="${workspace_loc}/../junit-all-workspace"/> + <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> + <listEntry value="/org.eclipse.papyrus.toolsmiths.suite.tests/test/org/eclipse/papyrus/toolsmiths/suite/tests/AllTests.java"/> + </listAttribute> + <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> + <listEntry value="1"/> + </listAttribute> + <mapAttribute key="org.eclipse.debug.core.environmentVariables"> + <mapEntry key="skip.long.junit.tests" value="false"/> + </mapAttribute> + <stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/> + <booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> + <stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> + <stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/> + <booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/> + <booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> + <stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/> + <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.papyrus.toolsmiths.suite.tests.AllTests"/> + <stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/> + <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.papyrus.toolsmiths.suite.tests"/> + <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/> + <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms512m -Xmx1024m -DsuppressRawWhenUnchecked=true -XX:SoftRefLRUPolicyMSPerMB=100 -Doomph.setup.skip=true -Doomph.setup.questionnaire.skip=true"/> + <stringAttribute key="pde.version" value="3.3"/> + <stringAttribute key="product" value="org.eclipse.platform.ide"/> + <booleanAttribute key="run_in_ui_thread" value="true"/> + <booleanAttribute key="show_selected_only" value="false"/> + <booleanAttribute key="tracing" value="true"/> + <booleanAttribute key="useCustomFeatures" value="false"/> + <booleanAttribute key="useDefaultConfig" value="true"/> + <booleanAttribute key="useDefaultConfigArea" value="true"/> + <booleanAttribute key="useProduct" value="true"/> + <stringAttribute key="yk-options" value=" additional-options2=onexit\=snapshot "/> </launchConfiguration> diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.suite.tests/test/org/eclipse/papyrus/toolsmiths/suite/tests/AllTests.java b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.suite.tests/test/org/eclipse/papyrus/toolsmiths/suite/tests/AllTests.java index bb7c8e705f3..cec0f399a65 100755..100644 --- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.suite.tests/test/org/eclipse/papyrus/toolsmiths/suite/tests/AllTests.java +++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.suite.tests/test/org/eclipse/papyrus/toolsmiths/suite/tests/AllTests.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2017 CEA LIST. + * Copyright (c) 2017, 2021 CEA LIST, Christian W. Damus, and others. * * * All rights reserved. This program and the accompanying materials @@ -11,6 +11,7 @@ * * Contributors: * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * Christian W. Damus - bug 572677 * *****************************************************************************/ package org.eclipse.papyrus.toolsmiths.suite.tests; @@ -39,6 +40,10 @@ public class AllTests { /* **************** plugins *********************** */ suiteClasses.add(new PluginTestSuiteClass(org.eclipse.papyrus.toolsmiths.profilemigration.tests.AllTests.class)); + suiteClasses.add(new PluginTestSuiteClass(org.eclipse.papyrus.toolsmiths.validation.common.tests.AllTests.class)); + suiteClasses.add(new PluginTestSuiteClass(org.eclipse.papyrus.toolsmiths.validation.architecture.tests.AllTests.class)); + suiteClasses.add(new PluginTestSuiteClass(org.eclipse.papyrus.toolsmiths.validation.elementtypes.tests.AllTests.class)); + suiteClasses.add(new PluginTestSuiteClass(org.eclipse.papyrus.toolsmiths.validation.profile.tests.AllTests.class)); // end diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/META-INF/MANIFEST.MF index 6e01bd86432..5540c45c23d 100644 --- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/META-INF/MANIFEST.MF +++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/META-INF/MANIFEST.MF @@ -14,8 +14,11 @@ Require-Bundle: org.eclipse.gmf.runtime.emf.type.core;bundle-version="[1.9.0,2.0 org.eclipse.jface;bundle-version="[3.22.0,4.0.0)", org.eclipse.ui;bundle-version="[3.118.100,4.0.0)", org.eclipse.papyrus.infra.core;bundle-version="[4.0.0,5.0.0)", - org.eclipse.papyrus.infra.architecture;bundle-version="[3.0.0,4.0.0)" -Export-Package: org.eclipse.papyrus.toolsmiths.validation.common.tests.rules + org.eclipse.papyrus.infra.architecture;bundle-version="[3.0.0,4.0.0)", + org.eclipse.pde.core;bundle-version="[3.13.0,4.0.0)", + org.eclipse.ui.ide;bundle-version="[3.18.0,4.0.0)" +Export-Package: org.eclipse.papyrus.toolsmiths.validation.common.tests, + org.eclipse.papyrus.toolsmiths.validation.common.tests.rules Automatic-Module-Name: org.eclipse.papyrus.toolsmiths.validation.common.tests Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/bug572677/plugin.xml b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/bug572677/plugin.xml new file mode 100644 index 00000000000..1d89a635e79 --- /dev/null +++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/bug572677/plugin.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> +<plugin> + <extension + point="org.eclipse.papyrus.uml.extensionpoints.UMLProfile"> + <profile + path="resources/MyTest.profile.uml"> + </profile> + </extension> +</plugin> diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/AbstractMissingAttributeMarkerResolutionTest.java b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/AbstractMissingAttributeMarkerResolutionTest.java new file mode 100644 index 00000000000..9a232d1e1a3 --- /dev/null +++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/AbstractMissingAttributeMarkerResolutionTest.java @@ -0,0 +1,104 @@ +/***************************************************************************** + * Copyright (c) 2021 Christian W. Damus, CEA LIST, and others. + * + * All rights reserved. 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 + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Christian W. Damus - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.toolsmiths.validation.common.tests; + +import static org.eclipse.papyrus.junit.matchers.MoreMatchers.regexContains; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.Map; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.papyrus.toolsmiths.validation.common.checkers.CommonProblemConstants; +import org.eclipse.papyrus.toolsmiths.validation.common.quickfix.AbstractMissingAttributeMarkerResolution; +import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.Build; +import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.OverlayFile; +import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.TestProject; +import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.TestProjectFixture; +import org.junit.Rule; +import org.junit.Test; + +/** + * Specific test cases for the {@link AbstractMissingAttributeMarkerResolution} class. + */ +@TestProject("org.eclipse.papyrus.toolsmiths.validation.common.example") +@Build(false) +public class AbstractMissingAttributeMarkerResolutionTest { + + @SuppressWarnings("restriction") + private static final String ATTR_LOCATION_PATH = org.eclipse.pde.internal.core.builders.PDEMarkerFactory.MPK_LOCATION_PATH; + private static final String ATTR_NAME = "attrName"; + private static final String ATTR_VALUE = "attrValue"; + private static final String NAME = "name"; + + @Rule + public final TestProjectFixture project = new TestProjectFixture(); + + /** + * Verify that the marker resolution generates the expected attribute content in the <tt>plugin.xml</tt>. + */ + @Test + @OverlayFile(value = "bug572677/plugin.xml", path = "plugin.xml") + public void addMissingAttribute() { + IFile pluginXML = project.getFile("plugin.xml"); + + IMarker marker = project.mockMarker(pluginXML, Map.of(ATTR_NAME, NAME, + ATTR_VALUE, "MyTest", + ATTR_LOCATION_PATH, "(0)plugin>(0)extension>(0)profile@name")); + + AbstractMissingAttributeMarkerResolution fix = new TestMarkerResolution(); + fix.run(marker); + + String fileContent = project.getContent(pluginXML); + assertThat(fileContent, regexContains( + "(?ms)<extension\\s+" + + " point=\"org.eclipse.papyrus.uml.extensionpoints.UMLProfile\">\\s+" + + " <profile\\s+" + + " name=\"MyTest\"\\s+" + + " path=\"resources/MyTest.profile.uml\">\\s+" + + " </profile>\\s+" + + " </extension>")); + } + + // + // Test framework + // + + private static final class TestMarkerResolution extends AbstractMissingAttributeMarkerResolution { + + TestMarkerResolution() { + super(CommonProblemConstants.MAX_PROBLEM_ID, NAME); + } + + @Override + protected String getAttributeValue(IMarker marker) throws CoreException { + return marker.getAttribute(ATTR_VALUE, ""); + } + + @Override + public String getDescription() { + return "This is a quick fix in a test."; + } + + @Override + public String getLabel() { + return "Test Fix"; + } + + } + +} diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/AbstractMissingExtensionMarkerResolutionTest.java b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/AbstractMissingExtensionMarkerResolutionTest.java new file mode 100644 index 00000000000..ec91ccf77cf --- /dev/null +++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/AbstractMissingExtensionMarkerResolutionTest.java @@ -0,0 +1,141 @@ +/***************************************************************************** + * Copyright (c) 2021 Christian W. Damus, CEA LIST, and others. + * + * All rights reserved. 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 + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Christian W. Damus - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.toolsmiths.validation.common.tests; + +import static org.eclipse.papyrus.junit.matchers.MoreMatchers.regexContains; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.Map; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.papyrus.toolsmiths.validation.common.checkers.CommonProblemConstants; +import org.eclipse.papyrus.toolsmiths.validation.common.quickfix.AbstractMissingExtensionMarkerResolution; +import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.Build; +import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.TestProject; +import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.TestProjectFixture; +import org.eclipse.pde.core.plugin.IPluginElement; +import org.eclipse.pde.core.plugin.IPluginExtension; +import org.junit.Rule; +import org.junit.Test; + +/** + * Specific test cases for the {@link AbstractMissingExtensionMarkerResolution} class. + */ +@TestProject("org.eclipse.papyrus.toolsmiths.validation.common.example") +@Build(false) +public class AbstractMissingExtensionMarkerResolutionTest { + + private static final String ATTR_EXT_PT = "extensionPoint"; + private static final String ATTR_ELEMENT_NAME = "elementName"; + private static final String ATTR_ATTRIBUTE_NAME_PREFIX = "attrName"; + private static final String ATTR_ATTRIBUTE_VALUE_PREFIX = "attrValue"; + + @Rule + public final TestProjectFixture project = new TestProjectFixture(); + + /** + * Verify that the marker resolution generates the expected extension content in the <tt>plugin.xml</tt>. + */ + @Test + public void addMissingExtension() { + IFile pluginXML = project.getFile("plugin.xml"); + + IMarker marker = project.mockMarker(pluginXML, Map.of(ATTR_EXT_PT, "my.extension.for.testing", + ATTR_ELEMENT_NAME, "thing", + ATTR_ATTRIBUTE_NAME_PREFIX + 1, "color", + ATTR_ATTRIBUTE_VALUE_PREFIX + 1, "green")); + + AbstractMissingExtensionMarkerResolution fix = new TestMarkerResolution(); + fix.run(marker); + + String fileContent = project.getContent(pluginXML); + assertThat(fileContent, regexContains( + "(?ms)<extension\\s+point=\"my.extension.for.testing\">\\s+" + + "<thing\\s+color=\"green\">\\s+" + + "</thing>\\s+" + + "</extension>")); + } + + /** + * Verify that the marker resolution does not generate all of the intermediate states of the + * configuration of a new extension in the <tt>plugin.xml</tt>. + * + * @see <a href="https://eclip.se/572677">bug 572677<a> + */ + @Test + public void noIntermediateExtensionPointConfigurations() { + IFile pluginXML = project.getFile("plugin.xml"); + + IMarker marker = project.mockMarker(pluginXML, Map.of(ATTR_EXT_PT, "my.extension.for.testing", + ATTR_ELEMENT_NAME, "thing", + ATTR_ATTRIBUTE_NAME_PREFIX + 1, "color", + ATTR_ATTRIBUTE_VALUE_PREFIX + 1, "green")); + + AbstractMissingExtensionMarkerResolution fix = new TestMarkerResolution(); + fix.run(marker); + + String fileContent = project.getContent(pluginXML); + assertThat(fileContent, not(containsString("<thing></thing>"))); + } + + // + // Test framework + // + + private static final class TestMarkerResolution extends AbstractMissingExtensionMarkerResolution { + + TestMarkerResolution() { + super(CommonProblemConstants.MAX_PROBLEM_ID); + } + + @Override + protected String getExtensionPoint(IMarker marker) throws CoreException { + return marker.getAttribute(ATTR_EXT_PT, ""); + } + + @Override + protected void configureExtension(IPluginExtension extension, IMarker marker) throws CoreException { + String elementName = marker.getAttribute(ATTR_ELEMENT_NAME, ""); + + IPluginElement element = createElement(extension, elementName); + + for (int i = 1;; i = i + 1) { + String attrName = marker.getAttribute(ATTR_ATTRIBUTE_NAME_PREFIX + i, ""); + if (attrName.isBlank()) { + break; + } + String attrValue = marker.getAttribute(ATTR_ATTRIBUTE_VALUE_PREFIX + i, ""); + setAttribute(element, attrName, attrValue); + } + } + + @Override + public String getDescription() { + return "This is a quick fix in a test."; + } + + @Override + public String getLabel() { + return "Test Fix"; + } + + } + +} diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/AllTests.java b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/AllTests.java index 24e7cb5e454..41a72e83375 100644 --- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/AllTests.java +++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/AllTests.java @@ -26,6 +26,8 @@ import org.junit.runners.Suite.SuiteClasses; @SuiteClasses({ ModelDependenciesCheckerTest.class, ProjectManagementUtilsTest.class, + AbstractMissingExtensionMarkerResolutionTest.class, + AbstractMissingAttributeMarkerResolutionTest.class, }) public class AllTests { // Suite is specified in annotations diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/ModelDependenciesCheckerTest.java b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/ModelDependenciesCheckerTest.java index 4dabb495c0b..96382e08b1c 100644 --- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/ModelDependenciesCheckerTest.java +++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/ModelDependenciesCheckerTest.java @@ -77,7 +77,7 @@ public class ModelDependenciesCheckerTest { * not imply a bundle name, even if the authority looks like one. */ @Test - @OverlayFile(value = "bug569357/Bookstore-weirdHREF.profile.uml", path = BOOKSTORE_PROFILE) + @OverlayFile(value = "bug569357/BookStore-weirdHREF.profile.uml", path = BOOKSTORE_PROFILE) public void unresolvedNonBundleDeployedURI() { List<Diagnostic> diagnostics = checkModel(BOOKSTORE_PROFILE, // Pre-resolve the HREF that doesn't imply bundle deployment diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/rules/TestProjectFixture.java b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/rules/TestProjectFixture.java index 64a28eaf453..811c7a04081 100644 --- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/rules/TestProjectFixture.java +++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/rules/TestProjectFixture.java @@ -22,7 +22,11 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.lang.reflect.Proxy; import java.net.URL; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -63,6 +67,8 @@ import org.eclipse.papyrus.toolsmiths.validation.common.utils.ModelResourceMappe import org.junit.runner.Description; import org.junit.runners.model.Statement; +import junit.framework.AssertionFailedError; + /** * <p> * A project fixture that copies initial content into the project and ensures that the project name @@ -354,6 +360,55 @@ public class TestProjectFixture extends ProjectFixture { } } + /** + * Get the contents of a {@code file} as a string. + * + * @param file + * a file + * @return its contents + */ + public final String getContent(IFile file) { + try { + return Files.readString(Paths.get(file.getLocationURI()), Charset.forName("UTF-8")); + } catch (IOException e) { + e.printStackTrace(); + throw new AssertionFailedError("Failed to read contents of test file: " + e.getMessage()); + } + } + + /** + * Create a mock marker with string-valued {@code attributes}. + * + * @param resource + * the marker owner + * @param attributes + * the marker attributes + * @return a mock marker that knows how to answer {@link IMarker#getResource()}, + * {@link IMarker#getAttribute(String)}, and {@link IMarker#getAttribute(String, String)}. + */ + public IMarker mockMarker(IResource resource, Map<String, String> attributes) { + return (IMarker) Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] { IMarker.class }, + (proxy, method, args) -> { + switch (method.getName()) { + case "getResource": //$NON-NLS-1$ + return resource; + case "getAttribute": //$NON-NLS-1$ + if (method.getReturnType() == String.class && args.length == 2) { + String result = attributes.get(args[0]); + if (result == null) { + result = (String) args[1]; + } + return result; + } + if (args.length == 1) { + return attributes.get(args[0]); + } + break; + } + return null; + }); + } + // // Nested types // diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.profile.tests/src/org/eclipse/papyrus/toolsmiths/validation/profile/tests/ProfilePluginValidationTest.java b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.profile.tests/src/org/eclipse/papyrus/toolsmiths/validation/profile/tests/ProfilePluginValidationTest.java index 63378aab03f..880a461356f 100644 --- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.profile.tests/src/org/eclipse/papyrus/toolsmiths/validation/profile/tests/ProfilePluginValidationTest.java +++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.profile.tests/src/org/eclipse/papyrus/toolsmiths/validation/profile/tests/ProfilePluginValidationTest.java @@ -10,13 +10,14 @@ * * Contributors: * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation - * Christian W. Damus - bug 571125 + * Christian W. Damus - bugs 571125, 572677 * *****************************************************************************/ package org.eclipse.papyrus.toolsmiths.validation.profile.tests; import static org.eclipse.papyrus.junit.matchers.MoreMatchers.greaterThan; import static org.eclipse.papyrus.junit.matchers.MoreMatchers.greaterThanOrEqual; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.util.Arrays; @@ -88,7 +89,7 @@ public class ProfilePluginValidationTest extends AbstractPapyrusTest { // Now check the markers Assert.assertNotNull("The markers have to be found", markers); //$NON-NLS-1$ - MatcherAssert.assertThat("The number of markers is not correct", markers.size(), greaterThanOrEqual(6)); //$NON-NLS-1$ + assertThat("The number of markers is not correct", markers.size(), greaterThanOrEqual(6)); //$NON-NLS-1$ // Check the profile.uml markers final List<IMarker> profileFileMarkers = markers.stream().filter(marker -> marker.getResource().getFullPath().toString().endsWith("bookstore.profile.uml")).collect(Collectors.toList()); //$NON-NLS-1$ @@ -99,12 +100,14 @@ public class ProfilePluginValidationTest extends AbstractPapyrusTest { final List<IMarker> manifestMarkers = markers.stream().filter(marker -> marker.getResource().getFullPath().toString().endsWith("MANIFEST.MF")).collect(Collectors.toList()); //$NON-NLS-1$ Assert.assertNotNull("Dependencies markers are not found", manifestMarkers); //$NON-NLS-1$ Assert.assertEquals("The number of markers for dependencies is not correct", 4, manifestMarkers.size()); //$NON-NLS-1$ - Assert.assertTrue("The severity of profile marker is not correct", isMarkerSeverity(manifestMarkers.get(0), IMarker.SEVERITY_WARNING)); //$NON-NLS-1$ + IMarker manifestWarning = manifestMarkers.stream().filter(m -> isMarkerSeverity(m, IMarker.SEVERITY_WARNING)).findAny().orElse(null); + Assert.assertNotNull("The severity of profile marker is not correct", manifestWarning); //$NON-NLS-1$ // Check the build markers. The profile and genmodel need to be included in the binary build final List<IMarker> buildMarkers = markers.stream().filter(marker -> marker.getResource().getFullPath().toString().endsWith("build.properties")).collect(Collectors.toList()); //$NON-NLS-1$ Assert.assertNotNull("Build markers are not found", buildMarkers); //$NON-NLS-1$ - MatcherAssert.assertThat("The number of markers for build is not correct", buildMarkers.size(), greaterThan(0)); //$NON-NLS-1$ + final List<IMarker> errorBuildMarkers = buildMarkers.stream().filter(marker -> isMarkerSeverity(marker, IMarker.SEVERITY_ERROR)).collect(Collectors.toList()); + assertThat("The number of error markers for build is not correct", errorBuildMarkers.size(), greaterThanOrEqual(1)); //$NON-NLS-1$ // Check the extensions markers final List<IMarker> extensionsMarkers = markers.stream().filter(marker -> marker.getResource().getFullPath().toString().endsWith("plugin.xml")).collect(Collectors.toList()); //$NON-NLS-1$ |