diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/META-INF/MANIFEST.MF b/com.avaloq.tools.ddk.checkcfg.core.test/META-INF/MANIFEST.MF index 5de06d4e47..93cb16f69c 100644 --- a/com.avaloq.tools.ddk.checkcfg.core.test/META-INF/MANIFEST.MF +++ b/com.avaloq.tools.ddk.checkcfg.core.test/META-INF/MANIFEST.MF @@ -18,13 +18,12 @@ Require-Bundle: com.avaloq.tools.ddk.test.core, org.eclipse.core.runtime, org.eclipse.xtend.lib, org.eclipse.xtext.ui.testing, - org.junit, org.eclipse.xtext.xbase.lib, org.eclipse.ui.workbench;resolution:=optional, org.objectweb.asm;resolution:=optional, junit-jupiter-api, junit-jupiter-engine, - junit-vintage-engine + junit-platform-suite-api Import-Package: org.hamcrest.core, org.junit.runner;version="4.5.0", org.junit.runner.manipulation;version="4.5.0", diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/contentassist/CheckCfgContentAssistTest.xtend b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/contentassist/CheckCfgContentAssistTest.xtend index e9985f811a..4fd894c04e 100644 --- a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/contentassist/CheckCfgContentAssistTest.xtend +++ b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/contentassist/CheckCfgContentAssistTest.xtend @@ -11,12 +11,9 @@ package com.avaloq.tools.ddk.checkcfg.contentassist -import com.avaloq.tools.ddk.checkcfg.util.CheckCfgTestUtil import com.avaloq.tools.ddk.test.checkcfg.TestPropertySpecificationWithExpectedValues import com.avaloq.tools.ddk.test.checkcfg.TestPropertySpecificationWithOutExpectedValues -import com.avaloq.tools.ddk.xtext.test.contentassist.AbstractAcfContentAssistTest import com.google.common.collect.Lists -import org.junit.Test import static com.avaloq.tools.ddk.checkcfg.CheckCfgConstants.PROPERTY_EXECUTABLE_EXTENSION_ATTRIBUTE import static com.avaloq.tools.ddk.checkcfg.CheckCfgConstants.PROPERTY_EXTENSION_POINT @@ -25,7 +22,16 @@ import static extension com.avaloq.tools.ddk.test.core.mock.ExtensionRegistryMoc import static extension com.avaloq.tools.ddk.test.core.mock.ExtensionRegistryMock.mockExecutableExtension import static extension com.avaloq.tools.ddk.test.core.mock.ExtensionRegistryMock.unMock import com.avaloq.tools.ddk.test.core.BugTest +import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractAcfContentAssistTest +import org.junit.jupiter.api.Test +import com.avaloq.tools.ddk.checkcfg.util.CheckCfgTestUtil +import org.junit.jupiter.api.^extension.ExtendWith +import org.eclipse.xtext.testing.extensions.InjectionExtension +import com.avaloq.tools.ddk.checkcfg.CheckCfgUiInjectorProvider +import org.eclipse.xtext.testing.InjectWith +@ExtendWith(InjectionExtension) +@InjectWith(CheckCfgUiInjectorProvider) class CheckCfgContentAssistTest extends AbstractAcfContentAssistTest { override protected getXtextTestUtil() { diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/scoping/CheckCfgScopeProviderTest.xtend b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/scoping/CheckCfgScopeProviderTest.xtend index dd8e62f977..783111d937 100644 --- a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/scoping/CheckCfgScopeProviderTest.xtend +++ b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/scoping/CheckCfgScopeProviderTest.xtend @@ -14,9 +14,8 @@ package com.avaloq.tools.ddk.checkcfg.scoping import com.avaloq.tools.ddk.test.core.BugTest import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckcfgPackage import com.avaloq.tools.ddk.checkcfg.util.CheckCfgTestUtil -import com.avaloq.tools.ddk.xtext.test.scoping.AbstractScopingTest - -import static org.junit.Assert.assertArrayEquals +import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractScopingTest +import static org.junit.jupiter.api.Assertions.assertArrayEquals final class CheckCfgScopeProviderTest extends AbstractScopingTest { @@ -72,7 +71,7 @@ final class CheckCfgScopeProviderTest extends AbstractScopingTest { // Check catalog has the correct fully-qualified package name val actualName = element.name.segments; val actualPackageName = actualName.take(EXP_PACKAGE_NAME_PREFIX.size); - assertArrayEquals("Catalog must have the correct fully-qualified package name", EXP_PACKAGE_NAME_PREFIX, actualPackageName); + assertArrayEquals(EXP_PACKAGE_NAME_PREFIX, actualPackageName, "Catalog must have the correct fully-qualified package name"); ] } } diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/syntax/CheckCfgSyntaxTest.xtend b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/syntax/CheckCfgSyntaxTest.xtend index 978c127b60..7349296e2c 100644 --- a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/syntax/CheckCfgSyntaxTest.xtend +++ b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/syntax/CheckCfgSyntaxTest.xtend @@ -12,10 +12,11 @@ package com.avaloq.tools.ddk.checkcfg.syntax import com.avaloq.tools.ddk.checkcfg.util.CheckCfgTestUtil -import com.avaloq.tools.ddk.xtext.test.validation.AbstractValidationTest +import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractValidationTest import java.util.LinkedList import org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil -import org.junit.Test +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.BeforeAll class CheckCfgSyntaxTest extends AbstractValidationTest { @@ -26,9 +27,9 @@ class CheckCfgSyntaxTest extends AbstractValidationTest { override protected getRequiredSourceFileNames() { new LinkedList } - - @Test - def void testSyntax() { + + @BeforeAll + def void setup() { val checkSource = ''' package checkcfgtest @@ -49,7 +50,11 @@ class CheckCfgSyntaxTest extends AbstractValidationTest { ''' addCustomerSourceToWorkspace("customer$sca_testchecks.check", checkSource) IResourcesSetupUtil.waitForBuild + } + + @Test + def void testSyntax() { val checkcfgSource = ''' check configuration checkconfiguration { catalog checkcfgtest.CheckCfgTestChecks { diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/test/CheckCfgTestSuite.java b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/test/CheckCfgTestSuite.java index 0ad5ba197a..17b83cf1f6 100644 --- a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/test/CheckCfgTestSuite.java +++ b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/test/CheckCfgTestSuite.java @@ -10,8 +10,8 @@ *******************************************************************************/ package com.avaloq.tools.ddk.checkcfg.test; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; import com.avaloq.tools.ddk.checkcfg.contentassist.CheckCfgContentAssistTest; import com.avaloq.tools.ddk.checkcfg.scoping.CheckCfgScopeProviderTest; @@ -22,10 +22,10 @@ /** - * Empty class serving only as holder for JUnit4 annotations. + * Empty class serving only as holder for JUnit5 annotations. */ -@RunWith(Suite.class) -@Suite.SuiteClasses({ +@Suite +@SelectClasses({ // @Format-Off CheckCfgConfiguredParameterValidationsTest.class, CheckCfgContentAssistTest.class, diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgTestUtil.xtend b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgTestUtil.xtend index 349d67ea20..9e82cc1f0d 100644 --- a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgTestUtil.xtend +++ b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/util/CheckCfgTestUtil.xtend @@ -11,10 +11,10 @@ package com.avaloq.tools.ddk.checkcfg.util -import com.avaloq.tools.ddk.xtext.test.AbstractXtextTestUtil import com.avaloq.tools.ddk.xtext.test.PluginTestProjectManager import com.avaloq.tools.ddk.xtext.test.ITestProjectManager import com.avaloq.tools.ddk.checkcfg.ui.internal.CheckcfgActivator +import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractXtextTestUtil class CheckCfgTestUtil extends AbstractXtextTestUtil{ diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgConfiguredParameterValidationsTest.xtend b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgConfiguredParameterValidationsTest.xtend index 015a28f1c4..32b1f4b56c 100644 --- a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgConfiguredParameterValidationsTest.xtend +++ b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgConfiguredParameterValidationsTest.xtend @@ -14,9 +14,7 @@ package com.avaloq.tools.ddk.checkcfg.validation import com.avaloq.tools.ddk.checkcfg.util.CheckCfgTestUtil import com.avaloq.tools.ddk.test.checkcfg.TestPropertySpecificationWithExpectedValues import com.avaloq.tools.ddk.test.checkcfg.TestPropertySpecificationWithOutExpectedValues -import com.avaloq.tools.ddk.xtext.test.validation.AbstractValidationTest import com.google.common.collect.Lists -import org.junit.Test import static com.avaloq.tools.ddk.checkcfg.CheckCfgConstants.PROPERTY_EXECUTABLE_EXTENSION_ATTRIBUTE import static com.avaloq.tools.ddk.checkcfg.CheckCfgConstants.PROPERTY_EXTENSION_POINT @@ -24,6 +22,8 @@ import static com.avaloq.tools.ddk.checkcfg.CheckCfgConstants.PROPERTY_EXTENSION import static extension com.avaloq.tools.ddk.test.core.mock.ExtensionRegistryMock.mockConfigurationElement import static extension com.avaloq.tools.ddk.test.core.mock.ExtensionRegistryMock.mockExecutableExtension import static extension com.avaloq.tools.ddk.test.core.mock.ExtensionRegistryMock.unMock +import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractValidationTest +import org.junit.jupiter.api.Test class CheckCfgConfiguredParameterValidationsTest extends AbstractValidationTest { diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgTest.xtend b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgTest.xtend index b3e3b4ca3d..58b57e1764 100644 --- a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgTest.xtend +++ b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgTest.xtend @@ -13,18 +13,17 @@ package com.avaloq.tools.ddk.checkcfg.validation import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckcfgPackage import com.google.inject.Inject -import junit.framework.TestCase -import org.eclipse.xtext.testing.XtextRunner import org.eclipse.xtext.testing.util.ParseHelper import org.eclipse.xtext.testing.validation.ValidationTestHelper -import org.junit.Test -import org.junit.runner.RunWith import org.eclipse.xtext.testing.InjectWith import com.avaloq.tools.ddk.checkcfg.CheckCfgUiInjectorProvider +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.^extension.ExtendWith +import org.eclipse.xtext.testing.extensions.InjectionExtension @InjectWith(typeof(CheckCfgUiInjectorProvider)) -@RunWith(XtextRunner) -class CheckCfgTest extends TestCase { +@ExtendWith(InjectionExtension) +class CheckCfgTest { @Inject diff --git a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgValidationTest.java b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgValidationTest.java index 2c771b7175..e78117de6b 100644 --- a/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgValidationTest.java +++ b/com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgValidationTest.java @@ -11,11 +11,11 @@ package com.avaloq.tools.ddk.checkcfg.validation; import org.eclipse.xtext.testing.InjectWith; -import org.eclipse.xtext.testing.XtextRunner; +import org.eclipse.xtext.testing.extensions.InjectionExtension; import org.eclipse.xtext.testing.util.ParseHelper; import org.eclipse.xtext.testing.validation.ValidationTestHelper; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import com.avaloq.tools.ddk.checkcfg.CheckCfgUiInjectorProvider; import com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration; @@ -23,15 +23,13 @@ import com.avaloq.tools.ddk.checkcfg.util.CheckCfgModelUtil; import com.google.inject.Inject; -import junit.framework.TestCase; - /** * Performs validations on Check Configuration models. */ @InjectWith(CheckCfgUiInjectorProvider.class) -@RunWith(XtextRunner.class) -public class CheckCfgValidationTest extends TestCase { +@ExtendWith(InjectionExtension.class) +public class CheckCfgValidationTest { @Inject private ValidationTestHelper helper; diff --git a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/jupiter/AbstractAcfContentAssistTest.java b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/jupiter/AbstractAcfContentAssistTest.java new file mode 100644 index 0000000000..af1c607e5c --- /dev/null +++ b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/jupiter/AbstractAcfContentAssistTest.java @@ -0,0 +1,357 @@ +/******************************************************************************* + * Copyright (c) 2025 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ +package com.avaloq.tools.ddk.xtext.test.jupiter; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.fail; + +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.eclipse.emf.common.util.WrappedException; +import org.eclipse.jface.text.contentassist.ICompletionProposal; + +import com.avaloq.tools.ddk.xtext.test.AcfContentAssistProcessorTestBuilder; +import com.avaloq.tools.ddk.xtext.test.TagCompilationParticipant; +import com.google.common.collect.Maps; +import com.google.inject.Injector; + + +/** + * The Class AcfContentAssistTest provides utility operations for non-UI content assist + * tests. It allows testing content assist on non-complete models step by step, as a user + * would also use it when defining a new model in the corresponding editor. + */ +// CHECKSTYLE:OFF +@SuppressWarnings("nls") +public abstract class AbstractAcfContentAssistTest extends AbstractXtextMarkerBasedTest { + private final AcfContentAssistMarkerTagsInfo acfContentAssistMarkerTagInfo = new AcfContentAssistMarkerTagsInfo(); + private static final String AT_LEAST_ONE_PROPOSAL_WAS_PROVIDED = "At least one proposal was provided"; + private static final String EXPECTED_PROPOSALS_NOT_SET = "No expected proposals provided to check against actual proposals."; + // CHECKSTYLE:ON + private static final String SEPARATOR = ", "; + + /** + * Creates a new completion proposal builder. + * + * @return the content assist processor test builder + */ + protected AcfContentAssistProcessorTestBuilder newBuilder() { + try { + return new AcfContentAssistProcessorTestBuilder(getXtextTestUtil().get(Injector.class), getTestUtil()); + // CHECKSTYLE:OFF + } catch (Exception e) { + // CHECKSTYLE:ON + throw new WrappedException("Could not create ContentAssistProcessorTestBuilder.", e); + } + } + + /** + * Gets the completion proposal display strings. + * + * @param computedProposals + * the computed proposals + * @return the completion proposal display strings + */ + private String getCompletionProposalDisplayStrings(final ICompletionProposal... computedProposals) { + String result = ""; + for (ICompletionProposal p : computedProposals) { + result += p.getDisplayString() + SEPARATOR; // NOPMD + } + if (result != null && result.length() > SEPARATOR.length()) { + return result.substring(0, result.length() - SEPARATOR.length()); + } + return null; + } + + /** + * Iterate over given computed completion proposals and compare resulting display string with each expected proposal text. Fail if one or more expected + * proposals not found. + * + * @param computedProposals + * the computed proposals + * @param positiveTest + * indicates the type of test. + * TRUE: the test is positive and must fail if proposals not found. + * FALSE: the test is negative and must fail if proposals found. + * @param proposals + * the expected proposals as display strings + */ + private void assertCompletionProposal(final ICompletionProposal[] computedProposals, final boolean positiveTest, final String... proposals) { + assertNotEquals(AT_LEAST_ONE_PROPOSAL_WAS_PROVIDED, proposals.length, 0); + for (final String s : proposals) { + boolean foundProposal = false; + for (ICompletionProposal p : computedProposals) { + if (s.equals(p.getDisplayString())) { + foundProposal = true; + break; + } + } + if (positiveTest && !foundProposal) { + fail(MessageFormat.format("Expected to find proposal \"{0}\" but could only find \"{1}\"", s, getCompletionProposalDisplayStrings(computedProposals))); + } else if (!positiveTest && foundProposal) { + fail(MessageFormat.format("Not expected to find proposal \"{0}\" but found \"{1}\"", s, getCompletionProposalDisplayStrings(computedProposals))); + } + } + } + + /** + * Iterate over given computed completion proposals and compare resulting display string with each expected proposal text. Fail if one or more expected + * proposals not found. + * + * @param computedProposals + * the computed proposals + * @param expectedProposals + * the expected proposals as display strings + */ + protected void assertCompletionProposal(final ICompletionProposal[] computedProposals, final String... expectedProposals) { + assertCompletionProposal(computedProposals, true, expectedProposals); + } + + /** + * Iterate over given computed completion proposals and compare resulting display string with each expected proposal text. Fail if one or more expected + * proposals not found. + * + * @param cursorPosition + * the cursor position within the main test source + * @param expectedProposals + * the expected proposals as display strings + */ + protected void assertCompletionProposal(final int cursorPosition, final String... expectedProposals) { + assertCompletionProposal(newBuilder().computeCompletionProposals(getTestSource(), cursorPosition), expectedProposals); + } + + /** + * Iterate over given computed completion proposals and compare resulting display string with each expected proposal text. Fail if one or more not expected + * proposals found. + * + * @param computedProposals + * the computed proposals + * @param expectedProposals + * the not expected proposals as display strings + */ + protected void assertNotCompletionProposal(final ICompletionProposal[] computedProposals, final String... expectedProposals) { + assertCompletionProposal(computedProposals, false, expectedProposals); + } + + /** + * Ensures that the list of expected proposals corresponds exactly the list of computed proposals. + * + * @param computedProposals + * the computed proposals + * @param expectedProposals + * the expected proposals as display strings + */ + protected void assertExactlyCompletionProposal(final ICompletionProposal[] computedProposals, final String... expectedProposals) { + assertNotEquals(AT_LEAST_ONE_PROPOSAL_WAS_PROVIDED, expectedProposals.length, 0); + + Set computedProposalsAsSet = new HashSet(); + for (ICompletionProposal p : computedProposals) { + computedProposalsAsSet.add(p.getDisplayString()); + } + + Set expectedProposalsAsSet = new HashSet(); + expectedProposalsAsSet.addAll(Arrays.asList(expectedProposals)); + + if (computedProposalsAsSet.size() != expectedProposalsAsSet.size()) { + // Calculate missing templates + Set missing = new HashSet(expectedProposalsAsSet); + missing.removeAll(computedProposalsAsSet); + if (!missing.isEmpty()) { + fail(MessageFormat.format("Proposals not found: \"{0}\".", missing.toString())); + } + // Calculate false positives + Set notExpected = new HashSet(computedProposalsAsSet); + notExpected.removeAll(expectedProposalsAsSet); + if (!notExpected.isEmpty()) { + fail(MessageFormat.format("Not expected: \"{0}\".", notExpected.toString())); + } + } + } + + /** + * Asserts the expected valid and invalid proposals based on the given registered source filename. + * + * @param sourceFileName + * the filename of the test source that the proposals were to be computed from, must not be {@code null} + */ + @SuppressWarnings("restriction") + private void assertSourceProposals(final String sourceFileName) { + try { + AcfContentAssistProcessorTestBuilder builder = newBuilder().append(getTestSource(sourceFileName).getContent()); + assertFalse(EXPECTED_PROPOSALS_NOT_SET, (acfContentAssistMarkerTagInfo.expectedProposalMap.isEmpty() + && acfContentAssistMarkerTagInfo.notExpectedProposalMap.isEmpty() && acfContentAssistMarkerTagInfo.expectedExactlyProposalMap.isEmpty())); + for (int markerId : getUsedTagsItems()) { + final ICompletionProposal[] proposals = builder.computeCompletionProposals(getOffsetForTag(markerId)); + if (acfContentAssistMarkerTagInfo.expectedProposalMap.containsKey(markerId)) { + assertCompletionProposal(proposals, acfContentAssistMarkerTagInfo.expectedProposalMap.get(markerId)); + } + if (acfContentAssistMarkerTagInfo.notExpectedProposalMap.containsKey(markerId)) { + assertNotCompletionProposal(proposals, acfContentAssistMarkerTagInfo.notExpectedProposalMap.get(markerId)); + } + if (acfContentAssistMarkerTagInfo.expectedExactlyProposalMap.containsKey(markerId)) { + assertExactlyCompletionProposal(proposals, acfContentAssistMarkerTagInfo.expectedExactlyProposalMap.get(markerId)); + } + } + // CHECKSTYLE:OFF + } catch (Exception e) { + // CHECKSTYLE:ON + throw new WrappedException("Could not assert the expected valid and invalid proposals.", e); + } + } + + /** + * Asserts the proposals for the given kernel test filename and content. + * + * @param sourceFileName + * the filename of the test source that the proposals were to be computed from, must not be {@code null} + * @param sourceContent + * the content of the test source, must not be {@code null} + */ + protected void assertKernelSourceProposals(final String sourceFileName, final CharSequence sourceContent) { + addKernelSourceToWorkspace(sourceFileName, sourceContent); + assertSourceProposals(sourceFileName); + } + + /** + * Asserts the proposals for the given customer test filename and content. + * + * @param sourceFileName + * the filename of the test source that the proposals were to be computed from, must not be {@code null} + * @param sourceContent + * the content of the test source, must not be {@code null} + */ + protected void assertCustomerSourceProposals(final String sourceFileName, final CharSequence sourceContent) { + addCustomerSourceToWorkspace(sourceFileName, sourceContent); + assertSourceProposals(sourceFileName); + } + + /** + * Registers the marker with the given proposals. Each of the expected proposal must have a match with the computed proposals on the marked position. + * + * @param proposals + * the expected proposals, must not be {@code null} + * @return mark text to be inserted in the source file, never {@code null} + */ + protected String expected(final String... proposals) { + Integer markerId = getTag(); + acfContentAssistMarkerTagInfo.expectedProposalMap.put(markerId, proposals); + return mark(markerId); + } + + /** + * Registers the marker with the given proposals. The expected proposals must EXACTLY match the computed proposals on the marked position. + * + * @param proposals + * the exact expected proposals, must not be {@code null} + * @return mark text to be inserted in the source file, never {@code null} + */ + protected String expectedExactly(final String... proposals) { + Integer markerId = getTag(); + acfContentAssistMarkerTagInfo.expectedExactlyProposalMap.put(markerId, proposals); + return mark(markerId); + } + + /** + * Registers the marker with the given proposals. Each of the expected proposal must NOT match with any of the computed proposals on the marked position. + * + * @param proposals + * the expected invalid proposals, must not be {@code null} + * @return mark text to be inserted in the source file, never {@code null} + */ + protected String notExpected(final String... proposals) { + Integer markerId = getTag(); + acfContentAssistMarkerTagInfo.notExpectedProposalMap.put(markerId, proposals); + return mark(markerId); + } + + /** + * Stores the valid proposals in a corresponding map using the given marker id. + * This method will return the marker id that will be used to {@link #mark()} the position in + * which the valid proposals are expected. + * Use {@link #getTag()} for the marker id when accessing locally. For global declarations, use @Tag annotation for marker id. + * + * @param markerId + * the unique marker id, must not be {@code null}} + * @param proposals + * the expected valid proposals, must not be {@code null} + * @return the marker id, never {@code null} + */ + protected int expected(final int markerId, final String... proposals) { + acfContentAssistMarkerTagInfo.expectedProposalMap.put(markerId, proposals); + return markerId; + } + + /** + * Stores the invalid proposals in a corresponding map using the given marker id. + * This method will return the marker id that will be used to {@link #mark()} the position in which the proposals are not expected. + * Use {@link #getTag()} for the marker id when accessing locally. For global declarations, use @Tag annotation for marker id. + * + * @param markerId + * the unique marker id, must not be {@code null}} + * @param proposals + * the expected invalid proposals, must not be {@code null} + * @return the marker id, never {@code null} + */ + protected int notExpected(final int markerId, final String... proposals) { + acfContentAssistMarkerTagInfo.notExpectedProposalMap.put(markerId, proposals); + return markerId; + } + + /** + * Stores the exact valid proposals in a corresponding map using the given marker id. + * This method will return the marker id that will be used to {@link #mark()} the position in which the exact proposals are expected. + * Use {@link #getTag()} for the marker id when accessing locally. For global declarations, use @Tag annotation for marker id. + * + * @param markerId + * the unique marker id, must not be {@code null}} + * @param proposals + * the expected exact proposals, must not be {@code null} + * @return the marker id, never {@code null} + */ + protected int expectedExactly(final int markerId, final String... proposals) { + acfContentAssistMarkerTagInfo.expectedExactlyProposalMap.put(markerId, proposals); + return markerId; + } + + /** + * This class preserves information about tags in the sources for all tests within + * a content assist test class. + */ + private final class AcfContentAssistMarkerTagsInfo extends MarkerTagsInfo { + private final Map expectedProposalMap = Maps.newHashMap(); + private final Map notExpectedProposalMap = Maps.newHashMap(); + private final Map expectedExactlyProposalMap = Maps.newHashMap(); + + @Override + public void clearTags(final long maxId) { + super.clearTags(maxId); + expectedProposalMap.entrySet().removeIf(entry -> entry.getKey() < TagCompilationParticipant.COUNTER_BASE); + notExpectedProposalMap.entrySet().removeIf(entry -> entry.getKey() < TagCompilationParticipant.COUNTER_BASE); + expectedExactlyProposalMap.entrySet().removeIf(entry -> entry.getKey() < TagCompilationParticipant.COUNTER_BASE); + } + } + + @Override + protected AcfContentAssistMarkerTagsInfo getMarkerTagsInfo() { + AcfContentAssistMarkerTagsInfo info = (AcfContentAssistMarkerTagsInfo) getTestInformation().getTestObject(AcfContentAssistMarkerTagsInfo.class); + if (info == null) { + info = acfContentAssistMarkerTagInfo; + getTestInformation().putTestObject(AcfContentAssistMarkerTagsInfo.class, acfContentAssistMarkerTagInfo); + } + return info; + } + +} diff --git a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/jupiter/AbstractXtextMarkerBasedTest.java b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/jupiter/AbstractXtextMarkerBasedTest.java index fd3febe873..e4bccc5a69 100644 --- a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/jupiter/AbstractXtextMarkerBasedTest.java +++ b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/jupiter/AbstractXtextMarkerBasedTest.java @@ -375,7 +375,7 @@ protected void processErrorsFound(final String sourceWithoutMarkers) { sb.append(SPLITTING_LINE); sb.append("List of all found diagnostics:\n"); sb.append(getAdditionalErrorMessageInformation()); - assertEquals("Errors found. Consider compare view.", sourceWithoutMarkers, sb.toString()); + assertEquals(sourceWithoutMarkers, sb.toString(), "Errors found. Consider compare view."); } }