diff options
author | Benoit Maggi | 2018-06-22 13:29:20 +0000 |
---|---|---|
committer | Benoit Maggi | 2018-06-25 11:50:22 +0000 |
commit | a1fb9d3bd28792386e25c71e89b16ad812b5da32 (patch) | |
tree | d3cbc902c1d0263ccc752ee1a816f98c989331e7 | |
parent | e6b916a145ba0c72e3c6c09b2548381ab0b701b6 (diff) | |
download | org.eclipse.papyrus-a1fb9d3bd28792386e25c71e89b16ad812b5da32.tar.gz org.eclipse.papyrus-a1fb9d3bd28792386e25c71e89b16ad812b5da32.tar.xz org.eclipse.papyrus-a1fb9d3bd28792386e25c71e89b16ad812b5da32.zip |
Bug 536183 - [AFViewpoints] NPE in Policychecker
- fix NPE in PolicyChecker.isInViewpoint
- add unit test for PolicyChecker
- add test in infra Test suite (to be executed in build)
- quality fix in policy plugin
- remove remaining pom of a deleted plugin
Change-Id: I532ef62dcccbfcd11f8ceda5d190705fffa36c36
Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
17 files changed, 102 insertions, 54 deletions
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF index 4a6119408ca..85e4bb88406 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF @@ -3,6 +3,7 @@ Export-Package: org.eclipse.papyrus.infra.viewpoints.configuration, org.eclipse.papyrus.infra.viewpoints.configuration.impl, org.eclipse.papyrus.infra.viewpoints.configuration.util, org.eclipse.papyrus.infra.viewpoints.policy, + org.eclipse.papyrus.infra.viewpoints.policy.providers, org.eclipse.papyrus.infra.viewpoints.policy.query, org.eclipse.papyrus.infra.viewpoints.style, org.eclipse.papyrus.infra.viewpoints.style.impl, diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelAddData.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelAddData.java index 2b4d148b5cf..d0911f8459c 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelAddData.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelAddData.java @@ -75,7 +75,7 @@ public class ModelAddData { public ModelAddData(boolean permit, EList<PathElement> insertionPath) { this.permit = permit; if (insertionPath != null && !insertionPath.isEmpty()) { - this.path = new ArrayList<EReference>(insertionPath.size()); + this.path = new ArrayList<>(insertionPath.size()); for (int i = 0; i != insertionPath.size(); i++) { path.add(insertionPath.get(i).getFeature()); } diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelRuleConstraintEngine.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelRuleConstraintEngine.java index b4f38600bab..882d538a8f7 100644 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelRuleConstraintEngine.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelRuleConstraintEngine.java @@ -35,7 +35,7 @@ import org.eclipse.papyrus.infra.architecture.representation.ModelRule; */ public class ModelRuleConstraintEngine extends DefaultConstraintEngine<ModelRule> { - protected final Map<ModelRule, List<Constraint>> modelRule2Constraints = new HashMap<ModelRule, List<Constraint>>(); + protected final Map<ModelRule, List<Constraint>> modelRule2Constraints = new HashMap<>(); /** singleton instance */ private static ModelRuleConstraintEngine instance; @@ -62,7 +62,7 @@ public class ModelRuleConstraintEngine extends DefaultConstraintEngine<ModelRule public boolean matchesRule(ModelRule rule, EObject element) { Collection<EObject> selection = Collections.singletonList(element); List<Constraint> constraints = getConstraintsFor(rule); - if (constraints == null || constraints.size() == 0) { + if (constraints == null || constraints.isEmpty()) { return true; } for (Constraint c : constraints) { @@ -103,11 +103,11 @@ public class ModelRuleConstraintEngine extends DefaultConstraintEngine<ModelRule */ protected List<Constraint> initializeConstraints(ModelRule rule) { List<ConstraintDescriptor> descriptors = rule.getConstraints(); - if (descriptors == null || descriptors.size() == 0) { + if (descriptors == null || descriptors.isEmpty()) { return Collections.emptyList(); } - List<Constraint> constraints = new ArrayList<Constraint>(); + List<Constraint> constraints = new ArrayList<>(); for (ConstraintDescriptor descriptor : descriptors) { try { Constraint constraint = ConstraintFactory.getInstance().createFromModel(descriptor); diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/NotationUtils.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/NotationUtils.java index 5dc2f91b291..4948648d28c 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/NotationUtils.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/NotationUtils.java @@ -116,7 +116,7 @@ public class NotationUtils { } IAdaptable input = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getInput(); if (input != null) { - EObject obj = (EObject) input.getAdapter(EObject.class); + EObject obj = input.getAdapter(EObject.class); return tryGetNotationResources(obj); } return null; @@ -177,6 +177,7 @@ public class NotationUtils { return result; } + @Override public void remove() { throw new UnsupportedOperationException(); } diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java index 0e2d531e6d0..408e3c76ac8 100644 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java @@ -311,14 +311,9 @@ public class PolicyChecker { * @since 2.0 */ public boolean isInViewpoint(PapyrusRepresentationKind kind) { - for (MergedArchitectureViewpoint viewpoint : getViewpoints()) { - for (RepresentationKind aKind : viewpoint.getRepresentationKinds()) { - if (aKind.getQualifiedName().equals(kind.getQualifiedName())) { - return true; - } - } - } - return false; + return kind!=null && getViewpoints().stream() + .flatMap(viewpoint -> viewpoint.getRepresentationKinds().stream()) + .anyMatch(representationKinds -> representationKinds.getQualifiedName().equals(kind.getQualifiedName())); } /** @@ -327,7 +322,7 @@ public class PolicyChecker { * @return A collection of view prototypes */ public Collection<ViewPrototype> getAllPrototypes() { - Collection<ViewPrototype> result = new ArrayList<ViewPrototype>(); + Collection<ViewPrototype> result = new ArrayList<>(); for (MergedArchitectureViewpoint viewpoint : getViewpoints()) { for (RepresentationKind kind : viewpoint.getRepresentationKinds()) { PapyrusRepresentationKind view = (PapyrusRepresentationKind) kind; @@ -348,7 +343,7 @@ public class PolicyChecker { * @return A list of the prototypes that can be instantiated */ public Collection<ViewPrototype> getPrototypesFor(EObject element) { - Collection<ViewPrototype> result = new LinkedHashSet<ViewPrototype>(); + Collection<ViewPrototype> result = new LinkedHashSet<>(); Collection<EPackage> profiles = profileHelper.getAppliedProfiles(element); Collection<EClass> stereotypes = profileHelper.getAppliedStereotypes(element); for (MergedArchitectureViewpoint viewpoint : getViewpoints()) { @@ -397,8 +392,7 @@ public class PolicyChecker { public OwningRule getOwningRuleFor(ViewPrototype prototype, EObject owner) { Collection<EClass> stereotypes = profileHelper.getAppliedStereotypes(owner); int count = prototype.getOwnedViewCount(owner); - OwningRule rule = matchesCreationOwner(prototype.representationKind, owner, stereotypes, count); - return rule; + return matchesCreationOwner(prototype.representationKind, owner, stereotypes, count); } /** diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ProfileUtils.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ProfileUtils.java index 082307e1dca..93664c93b23 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ProfileUtils.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ProfileUtils.java @@ -84,14 +84,14 @@ public class ProfileUtils { * @see org.eclipse.papyrus.infra.viewpoints.policy.IProfileHelper#getAppliedProfiles(org.eclipse.emf.ecore.EObject) */ public Collection<EPackage> getAppliedProfiles(EObject model) { - return new ArrayList<EPackage>(0); + return new ArrayList<>(0); } /** * @see org.eclipse.papyrus.infra.viewpoints.policy.IProfileHelper#getAppliedStereotypes(org.eclipse.emf.ecore.EObject) */ public Collection<EClass> getAppliedStereotypes(EObject object) { - return new ArrayList<EClass>(0); + return new ArrayList<>(0); } } } diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/RuleConstraintManager.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/RuleConstraintManager.java index 34a249dcabd..a6a60955b56 100644 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/RuleConstraintManager.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/RuleConstraintManager.java @@ -39,7 +39,7 @@ public class RuleConstraintManager { public boolean matchRule(ModelRule rule, EObject element) { // if no rule, return true List<ConstraintDescriptor> constraintDescriptors = rule.getConstraints(); - if (constraintDescriptors == null || constraintDescriptors.size() == 0) { + if (constraintDescriptors == null || constraintDescriptors.isEmpty()) { return true; } diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java index b7ac8b6b91c..917ba0f0a64 100644 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java @@ -81,7 +81,7 @@ public abstract class ViewPrototype { // Sort by priority Collections.sort(elements, helperConfigComparator()); - Collection<IViewTypeHelper> result = new ArrayList<IViewTypeHelper>(); + Collection<IViewTypeHelper> result = new ArrayList<>(); for (IConfigurationElement element : elements) { try { IViewTypeHelper instance = (IViewTypeHelper) element.createExecutableExtension("class"); @@ -371,7 +371,7 @@ public abstract class ViewPrototype { * @author Laurent Wouters */ public static class Comp implements Comparator<ViewPrototype> { - private static final Map<Class<? extends PapyrusRepresentationKind>, Integer> priorities = new HashMap<Class<? extends PapyrusRepresentationKind>, Integer>(); + private static final Map<Class<? extends PapyrusRepresentationKind>, Integer> priorities = new HashMap<>(); { priorities.put(PapyrusDiagram.class, 1); priorities.put(PapyrusTable.class, 2); diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewpointExplorer.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewpointExplorer.java index 06d9951d47d..e2dd28f92e7 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewpointExplorer.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewpointExplorer.java @@ -33,7 +33,6 @@ import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.papyrus.infra.architecture.ArchitectureDescriptionUtils; -import org.eclipse.papyrus.infra.core.architecture.RepresentationKind; import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureContext; import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureDescriptionLanguage; import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureFramework; @@ -96,16 +95,12 @@ public class ViewpointExplorer extends ViewPart { contentProvider = new AdapterFactoryContentProvider(adapterFactory); labelProvider = new AdapterFactoryLabelProvider(adapterFactory); editingDomain = new AdapterFactoryEditingDomain(adapterFactory, null, new HashMap<Resource, Boolean>()) { - public boolean isReadOnly(Resource resource) { + @Override + public boolean isReadOnly(Resource resource) { return true; // to make the editing domain non-editable } }; } - - @Override - public void init(IViewSite site) throws PartInitException { - super.init(site); - } /* * (non-Javadoc) @@ -285,7 +280,7 @@ public class ViewpointExplorer extends ViewPart { * @since 3.0 */ public Object[] getPropertySources(Object[] objects) { - ArrayList<Object> propertySources = new ArrayList<Object>(); + ArrayList<Object> propertySources = new ArrayList<>(); for (Object object : objects) { propertySources.add(getPropertySource(object)); } diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/query/IsContainedByProfileQuery.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/query/IsContainedByProfileQuery.java index eb58c6e3087..2d92dc1663b 100644 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/query/IsContainedByProfileQuery.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/query/IsContainedByProfileQuery.java @@ -63,11 +63,7 @@ public class IsContainedByProfileQuery implements JavaQuery { } String eclassName = eclass.getName(); - if ("Profile".equals(eclassName)) { - return true; - } - return false; - + return "Profile".equals(eclassName); } } diff --git a/tests/junit/plugins/infra/org.eclipse.papyrus.infra.suite.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/infra/org.eclipse.papyrus.infra.suite.tests/META-INF/MANIFEST.MF index 9a8c28bb44a..cbdcd05c25d 100755 --- a/tests/junit/plugins/infra/org.eclipse.papyrus.infra.suite.tests/META-INF/MANIFEST.MF +++ b/tests/junit/plugins/infra/org.eclipse.papyrus.infra.suite.tests/META-INF/MANIFEST.MF @@ -38,5 +38,6 @@ Require-Bundle: org.eclipse.ui, org.eclipse.papyrus.infra.gmfdiag.menu.tests;bundle-version="[1.2.0,2.0.0)", org.eclipse.papyrus.infra.gmfdiag.css.tests;bundle-version="[1.2.0,2.0.0)", org.eclipse.papyrus.infra.emf.expressions.tests;bundle-version="[1.0.0,2.0.0)", - org.eclipse.papyrus.infra.internationalization.tests;bundle-version="[1.0.0,2.0.0)" + org.eclipse.papyrus.infra.internationalization.tests;bundle-version="[1.0.0,2.0.0)", + org.eclipse.papyrus.infra.viewpoints.policy.tests;bundle-version="1.2.0" Automatic-Module-Name: org.eclipse.papyrus.infra.suite.tests diff --git a/tests/junit/plugins/infra/org.eclipse.papyrus.infra.suite.tests/test/org/eclipse/papyrus/infra/suite/tests/AllTests.java b/tests/junit/plugins/infra/org.eclipse.papyrus.infra.suite.tests/test/org/eclipse/papyrus/infra/suite/tests/AllTests.java index 777e484f0a1..7ea7a8607c4 100755 --- a/tests/junit/plugins/infra/org.eclipse.papyrus.infra.suite.tests/test/org/eclipse/papyrus/infra/suite/tests/AllTests.java +++ b/tests/junit/plugins/infra/org.eclipse.papyrus.infra.suite.tests/test/org/eclipse/papyrus/infra/suite/tests/AllTests.java @@ -72,6 +72,10 @@ public class AllTests { suiteClasses.add(new PluginTestSuiteClass(org.eclipse.papyrus.infra.internationalization.tests.tests.AllTests.class)); + suiteClasses.add(new PluginTestSuiteClass(org.eclipse.papyrus.infra.viewpoints.policy.tests.AllTests.class)); + + + // end } diff --git a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.tests/pom.xml b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.tests/pom.xml deleted file mode 100644 index 0a16904426a..00000000000 --- a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.tests/pom.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.eclipse.papyrus.tests</groupId> - <artifactId>org.eclipse.papyrus.infra.viewpoints.tests.releng</artifactId> - <version>1.2.0-SNAPSHOT</version> - </parent> - <groupId>org.eclipse.papyrus.tests</groupId> - <artifactId>org.eclipse.papyrus.infra.viewpoints.configuration.tests</artifactId> - <packaging>eclipse-test-plugin</packaging> -</project>
\ No newline at end of file diff --git a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/META-INF/MANIFEST.MF index c38b0d1f1df..27940e5c96b 100644 --- a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/META-INF/MANIFEST.MF +++ b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/META-INF/MANIFEST.MF @@ -6,7 +6,10 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.11.0", org.junit;bundle-version="4.11.0";visibility:=reexport, org.eclipse.gmf.runtime.emf.type.core;bundle-version="1.9.0", org.eclipse.papyrus.junit.utils;bundle-version="[2.0.0,3.0.0)", - org.eclipse.uml2.uml;bundle-version="[5.3.0,6.0.0)" + org.eclipse.uml2.uml;bundle-version="[5.3.0,6.0.0)", + org.eclipse.papyrus.infra.architecture;bundle-version="2.0.0", + org.eclipse.papyrus.infra.architecture.representation;bundle-version="2.0.0", + org.eclipse.papyrus.infra.gmfdiag.representation;bundle-version="2.0.0" Bundle-Vendor: %providerName Bundle-ActivationPolicy: lazy Bundle-ClassPath: . diff --git a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/pom.xml b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/pom.xml index e25dc9dc643..33d4237bd6d 100644 --- a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/pom.xml +++ b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/pom.xml @@ -7,7 +7,6 @@ <artifactId>org.eclipse.papyrus.infra.viewpoints.tests.releng</artifactId> <version>1.2.0-SNAPSHOT</version> </parent> - <groupId>org.eclipse.papyrus.tests</groupId> <artifactId>org.eclipse.papyrus.infra.viewpoints.policy.tests</artifactId> <packaging>eclipse-test-plugin</packaging> </project>
\ No newline at end of file diff --git a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/policy/tests/AllTests.java b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/policy/tests/AllTests.java index fd0f7ff75a9..bd0f1cec02b 100644 --- a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/policy/tests/AllTests.java +++ b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/policy/tests/AllTests.java @@ -22,8 +22,10 @@ import org.junit.runners.Suite.SuiteClasses; * The master test suite for the plug-in. */ @RunWith(ClassificationSuite.class) -@SuiteClasses(ViewPrototypeTest.class) +@SuiteClasses({ + ViewPrototypeTest.class, + PolicyCheckerTest.class + }) @Headless public class AllTests { - // Nothing required } diff --git a/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/policy/tests/PolicyCheckerTest.java b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/policy/tests/PolicyCheckerTest.java new file mode 100644 index 00000000000..ff38c5f34e0 --- /dev/null +++ b/tests/junit/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy.tests/src/org/eclipse/papyrus/infra/viewpoints/policy/tests/PolicyCheckerTest.java @@ -0,0 +1,65 @@ +/***************************************************************************** + * Copyright (c) 2018 CEA LIST 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.infra.viewpoints.policy.tests; + +import java.util.Collection; + +import org.eclipse.papyrus.infra.core.architecture.ArchitectureDescriptionLanguage; +import org.eclipse.papyrus.infra.core.architecture.ArchitectureDomain; +import org.eclipse.papyrus.infra.core.architecture.ArchitectureFactory; +import org.eclipse.papyrus.infra.core.architecture.ArchitectureViewpoint; +import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureContext; +import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureDomain; +import org.eclipse.papyrus.infra.gmfdiag.representation.PapyrusDiagram; +import org.eclipse.papyrus.infra.gmfdiag.representation.RepresentationFactory; +import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker; +import org.junit.Assert; +import org.junit.Test; + +/** + * + */ +@SuppressWarnings("nls") +public class PolicyCheckerTest { + + @Test + public void testIsInViewpoint() { + + ArchitectureDomain architectureDomain = ArchitectureFactory.eINSTANCE.createArchitectureDomain(); + ArchitectureDescriptionLanguage architectureDescriptionLanguage = ArchitectureFactory.eINSTANCE.createArchitectureDescriptionLanguage(); + architectureDescriptionLanguage.setDomain(architectureDomain); + ArchitectureViewpoint architectureViewpoint = ArchitectureFactory.eINSTANCE.createArchitectureViewpoint(); + architectureDescriptionLanguage.getViewpoints().add(architectureViewpoint); + + PapyrusDiagram knownDiagram = RepresentationFactory.eINSTANCE.createPapyrusDiagram(); + knownDiagram.setName("knownDiagram"); + architectureViewpoint.getRepresentationKinds().add(knownDiagram); + + PapyrusDiagram unknownDiagram = RepresentationFactory.eINSTANCE.createPapyrusDiagram(); + unknownDiagram.setName("unknownDiagram"); + + MergedArchitectureDomain mergedArchitectureDomain = new MergedArchitectureDomain(); + mergedArchitectureDomain.merge(architectureDomain); + + Collection<MergedArchitectureContext> contexts = mergedArchitectureDomain.getContexts(); + MergedArchitectureContext next = contexts.iterator().next(); + PolicyChecker policyChecker = PolicyChecker.getFor(next); + Assert.assertTrue(policyChecker.isInViewpoint(knownDiagram)); + Assert.assertFalse(policyChecker.isInViewpoint(unknownDiagram)); + Assert.assertFalse(policyChecker.isInViewpoint(null)); + } + + + + +} |