aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszarnekow2009-04-28 11:41:19 (EDT)
committersefftinge2009-04-28 11:41:19 (EDT)
commit7f68d9f3eed1a34ed6da234f647811666084f75e (patch)
tree15f2f792502791319f9117e7522c981f470f167f
parent7437216e34afd276ebb0519f85ae547448e27588 (diff)
downloadorg.eclipse.xtext-7f68d9f3eed1a34ed6da234f647811666084f75e.zip
org.eclipse.xtext-7f68d9f3eed1a34ed6da234f647811666084f75e.tar.gz
org.eclipse.xtext-7f68d9f3eed1a34ed6da234f647811666084f75e.tar.bz2
Fix: https://bugs.eclipse.org/bugs/show_bug.cgi?id=272200
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java4
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/validator/CompositeValidatorTest.java197
2 files changed, 201 insertions, 0 deletions
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java
index 5bb02b1..7a4df2f 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java
@@ -89,6 +89,10 @@ public class PluginTestSuite {
suite.addTestSuite(org.eclipse.xtext.xtext.ecoreInference.TypeHierarchyHelperTests.class);
suite.addTestSuite(org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformerTest.class);
suite.addTestSuite(org.eclipse.xtext.xtext.ecoreInference.UnassignedRuleCallTest.class);
+ suite.addTestSuite(org.eclipse.xtext.validator.AbstractDeclarativeValidatorTest.class);
+ suite.addTestSuite(org.eclipse.xtext.validator.ConcurrentValidationTest.class);
+ suite.addTestSuite(org.eclipse.xtext.validator.CompositeValidatorTest.WithEObjectValidator.class);
+ suite.addTestSuite(org.eclipse.xtext.validator.CompositeValidatorTest.WithoutEObjectValidator.class);
suite.addTestSuite(org.eclipse.xtext.valueconverter.Bug250313.Antlr.class);
suite.addTestSuite(org.eclipse.xtext.valueconverter.Bug250313.Packrat.class);
suite.addTestSuite(org.eclipse.xtext.xtext.ExceptionTest.class);
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/validator/CompositeValidatorTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/validator/CompositeValidatorTest.java
new file mode 100644
index 0000000..b850572
--- /dev/null
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/validator/CompositeValidatorTest.java
@@ -0,0 +1,197 @@
+/*******************************************************************************
+ * Copyright (c) 2009 itemis AG (http://www.itemis.eu) 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
+ *******************************************************************************/
+package org.eclipse.xtext.validator;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.util.DiagnosticChain;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EValidator;
+import org.eclipse.xtext.enumrules.EnumRulesTestLanguageCheckValidator;
+import org.eclipse.xtext.enumrules.EnumRulesTestLanguageStandaloneSetup;
+import org.eclipse.xtext.enumrules.enumRulesTestLanguage.EnumRulesTestLanguagePackage;
+import org.eclipse.xtext.junit.AbstractXtextTests;
+import org.eclipse.xtext.validator.CompositeEValidator.EValidatorEqualitySupport;
+
+import com.google.inject.Binder;
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.name.Names;
+
+/**
+ * @author Sebastian Zarnekow - Initial contribution and API
+ */
+public abstract class CompositeValidatorTest extends AbstractXtextTests {
+
+ protected EValidator.Registry registry;
+ protected EnumRulesTestLanguagePackage pack;
+ private First first;
+ private Second second;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ with(createStandaloneSetup());
+ registry = get(EValidator.Registry.class);
+ pack = get(EnumRulesTestLanguagePackage.class);
+ first = get(First.class);
+ second = get(Second.class);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ registry = null;
+ pack = null;
+ first = null;
+ second = null;
+ super.tearDown();
+ }
+
+ protected abstract EnumRulesTestLanguageStandaloneSetup createStandaloneSetup();
+
+ public static class First extends AbstractInjectableValidator {
+ private final EnumRulesTestLanguagePackage pack;
+
+ public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ return true;
+ }
+
+ @Inject
+ public First(EnumRulesTestLanguagePackage pack) {
+ this.pack = pack;
+ }
+
+ @Override
+ protected List<? extends EPackage> getEPackages() {
+ return Collections.singletonList(pack);
+ }
+ }
+
+ public static class Second extends AbstractInjectableValidator {
+ private final EnumRulesTestLanguagePackage pack;
+
+ public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ return true;
+ }
+
+ @Inject
+ public Second(EnumRulesTestLanguagePackage pack) {
+ this.pack = pack;
+ }
+
+ @Override
+ protected List<? extends EPackage> getEPackages() {
+ return Collections.singletonList(pack);
+ }
+ }
+
+ public void testSetup() {
+ assertNotNull("registry", registry);
+ }
+
+ public void testFirstAndSecond() {
+ EValidator validator = registry.getEValidator(pack);
+ assertNotNull(validator);
+ assertTrue(validator instanceof CompositeEValidator);
+ CompositeEValidator composite = (CompositeEValidator) validator;
+ Collection<EValidatorEqualitySupport> contents = composite.getContents();
+ EValidatorEqualitySupport equalitySupport = get(EValidatorEqualitySupport.class);
+ equalitySupport.setDelegate(first);
+ assertTrue(contents.contains(equalitySupport));
+ equalitySupport.setDelegate(second);
+ assertTrue(contents.contains(equalitySupport));
+ }
+
+ public abstract void testContentsSize();
+
+ public static class WithEObjectValidator extends CompositeValidatorTest {
+
+ @Override
+ protected EnumRulesTestLanguageStandaloneSetup createStandaloneSetup() {
+ return new EnumRulesTestLanguageStandaloneSetup() {
+ @Override
+ public Injector createInjector() {
+ return Guice.createInjector(new org.eclipse.xtext.enumrules.EnumRulesTestLanguageRuntimeModule() {
+
+ @Override
+ public void configure(Binder binder) {
+ super.configure(binder);
+ binder.bind(boolean.class).annotatedWith(
+ Names.named(CompositeEValidator.USE_EOBJECT_VALIDATOR)).toInstance(true);
+ binder.bind(EnumRulesTestLanguagePackage.class).toInstance(EnumRulesTestLanguagePackage.eINSTANCE);
+ }
+
+ @Override
+ public Class<? extends EnumRulesTestLanguageCheckValidator> bindEnumRulesTestLanguageCheckValidator() {
+ return null;
+ }
+
+ });
+ }
+
+ };
+ }
+
+ @Override
+ public void testContentsSize() {
+ EValidator validator = registry.getEValidator(pack);
+ assertNotNull(validator);
+ assertTrue(validator instanceof CompositeEValidator);
+ CompositeEValidator composite = (CompositeEValidator) validator;
+ Collection<EValidatorEqualitySupport> contents = composite.getContents();
+ assertEquals(3, contents.size());
+ }
+
+ }
+
+ public static class WithoutEObjectValidator extends CompositeValidatorTest {
+
+ @Override
+ protected EnumRulesTestLanguageStandaloneSetup createStandaloneSetup() {
+ return new EnumRulesTestLanguageStandaloneSetup() {
+ @Override
+ public Injector createInjector() {
+ return Guice.createInjector(new org.eclipse.xtext.enumrules.EnumRulesTestLanguageRuntimeModule() {
+
+ @Override
+ public void configure(Binder binder) {
+ super.configure(binder);
+ binder.bind(boolean.class).annotatedWith(
+ Names.named(CompositeEValidator.USE_EOBJECT_VALIDATOR)).toInstance(false);
+ binder.bind(EnumRulesTestLanguagePackage.class).toInstance(EnumRulesTestLanguagePackage.eINSTANCE);
+ }
+
+ @Override
+ public Class<? extends EnumRulesTestLanguageCheckValidator> bindEnumRulesTestLanguageCheckValidator() {
+ return null;
+ }
+
+ });
+ }
+
+ };
+ }
+
+ @Override
+ public void testContentsSize() {
+ EValidator validator = registry.getEValidator(pack);
+ assertNotNull(validator);
+ assertTrue(validator instanceof CompositeEValidator);
+ CompositeEValidator composite = (CompositeEValidator) validator;
+ Collection<EValidatorEqualitySupport> contents = composite.getContents();
+ assertEquals(2, contents.size());
+ }
+
+ }
+}