diff options
Diffstat (limited to 'tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite')
2 files changed, 81 insertions, 1 deletions
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/AllTests.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/AllTests.java index 7dee471098c..41624e37db8 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/AllTests.java +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/AllTests.java @@ -18,6 +18,7 @@ import org.eclipse.papyrus.junit.framework.classification.ClassificationSuite; import org.eclipse.papyrus.junit.framework.classification.ClassificationSuite.DynamicClasses; import org.eclipse.papyrus.uml.diagram.composite.test.canonical.AllCanonicalTests; import org.eclipse.papyrus.uml.diagram.composite.test.model.AllModelTests; +import org.eclipse.papyrus.uml.diagram.composite.test.resources.ModelValidationTest; import org.eclipse.papyrus.uml.diagram.composite.tests.copyPaste.ConstraintCopyPasteTest; import org.junit.runner.RunWith; import org.junit.runners.Suite.SuiteClasses; @@ -31,7 +32,8 @@ import org.junit.runners.Suite.SuiteClasses; AllCanonicalTests.class, RoundedCompartmentTest.class, AllModelTests.class, - ConstraintCopyPasteTest.class + ConstraintCopyPasteTest.class, + ModelValidationTest.class }) @DynamicClasses("org.eclipse.papyrus.uml.diagram.composite.test.AllGenTests") public class AllTests { diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/resources/ModelValidationTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/resources/ModelValidationTest.java new file mode 100644 index 00000000000..23ff62430e0 --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/resources/ModelValidationTest.java @@ -0,0 +1,78 @@ +/***************************************************************************** + * Copyright (c) 2018 CEA 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: + * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.composite.test.resources; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import org.eclipse.emf.common.util.Diagnostic; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.util.Diagnostician; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * This is a parameterized test to validate all model in the plugin + * + * @author Benoit Maggi + */ +@SuppressWarnings("nls") +@RunWith(Parameterized.class) +public class ModelValidationTest { + + @Parameters + public static Collection<Object[]> data() { + return Arrays.asList(new Object[][] { + {"/model/CompositeStructure.paletteconfiguration"}, + {"/model/compositediagram.elementtypesconfigurations"}, + {"/model/compositediagram.gmfgen"}, + }); + } + + private String modelPath; + + public ModelValidationTest(String modelPath) { + this.modelPath = modelPath; + } + + /** + * Validate the model with the rules defined in the meta-model tooling + */ + @Test + public void validateModel() { + String fullPath = "org.eclipse.papyrus.uml.diagram.composite"+ this.modelPath; + URI modelPlatformURI = URI.createPlatformPluginURI(fullPath, true); + Resource resource = new ResourceSetImpl().getResource(modelPlatformURI, true); + Diagnostic diagnostic = Diagnostician.INSTANCE.validate(resource.getContents().get(0)); + Assert.assertEquals("The "+modelPath+" model is invalid "+print(diagnostic), Diagnostic.OK, diagnostic.getSeverity()); + } + + // FIXME : Something should exist in API to do that + private String print(Diagnostic diagnostic) { + List<Diagnostic> children = diagnostic.getChildren(); + StringBuilder stringBuilder = new StringBuilder(diagnostic.getMessage()); + for (Diagnostic diagnosticChildren : children) { + stringBuilder.append("\n"); //$NON-NLS-1$ + stringBuilder.append(diagnosticChildren.getMessage()); + } + return stringBuilder.toString(); + } + +} |