| /***************************************************************************** |
| * Copyright (c) 2021 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: |
| * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation |
| * |
| *****************************************************************************/ |
| |
| package org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml16.odt.architecture.tests; |
| |
| import org.eclipse.emf.transaction.TransactionalEditingDomain; |
| import org.eclipse.gmf.runtime.common.core.command.ICommand; |
| import org.eclipse.osgi.util.NLS; |
| import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; |
| import org.eclipse.papyrus.junit.utils.rules.ModelSetFixture; |
| import org.eclipse.papyrus.junit.utils.rules.PluginResource; |
| import org.eclipse.papyrus.model2doc.integration.ieee.requirements.documentation.IEEEFunctionalRequirements; |
| import org.eclipse.papyrus.model2doc.integration.ieee.requirements.documentation.IEEERequirementCategory; |
| import org.eclipse.papyrus.model2doc.integration.ieee.requirements.documentation.IEEERequirements; |
| import org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml16.odt.architecture.internal.commands.CreateIEEERequirementsStructureForSysML16Command; |
| import org.eclipse.papyrus.model2doc.integration.ieee.requirements.utils.IEEERequirementsConstants; |
| import org.eclipse.uml2.uml.NamedElement; |
| import org.eclipse.uml2.uml.Package; |
| import org.eclipse.uml2.uml.util.UMLUtil; |
| import org.junit.Assert; |
| import org.junit.Rule; |
| import org.junit.Test; |
| |
| /** |
| * This test check the creation of the required IEEE packages in the user model |
| */ |
| @SuppressWarnings("nls") |
| @PluginResource("resources/IEEEPackagesCreation/IEEEPackagesCreation.di") |
| public class IEEEPackagesCreationTest { |
| |
| @Rule |
| public final ModelSetFixture fixture = new ModelSetFixture(); |
| |
| @Test |
| public void createIEEEPackage_Test1() { |
| final org.eclipse.uml2.uml.Package rootPackage = fixture.getModel(); |
| // the initial model contents 2 Package Import and 10 applied profile |
| final int expectedInitialOwnedElementNumber = 2 + 10; |
| final int expectedInitialAppliedProfileNumber = 10; |
| // some check on the input model |
| Assert.assertEquals("The initial input model has changed.", expectedInitialOwnedElementNumber, rootPackage.getOwnedElements().size()); |
| Assert.assertEquals("The initial input model doesn't have the expected number of required profiles.", expectedInitialAppliedProfileNumber, rootPackage.getAllAppliedProfiles().size()); |
| Assert.assertTrue("The IEEE Profile must not be applied on the input model", rootPackage.getAppliedProfile(IEEERequirementsConstants.IEEE_PROFILE_NAME) == null); |
| |
| |
| final ICommand cmd = new CreateIEEERequirementsStructureForSysML16Command(fixture.getEditingDomain(), rootPackage); |
| Assert.assertTrue("The command to create the IEEE Requirements Packages must be executable", cmd.canExecute()); |
| |
| final TransactionalEditingDomain domain = fixture.getEditingDomain(); |
| domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(cmd)); |
| |
| |
| Assert.assertTrue("The IEEE Profile has not been applied", rootPackage.getAppliedProfile(IEEERequirementsConstants.IEEE_PROFILE_NAME) != null); |
| |
| // check the creation of the IEEE Package |
| |
| checkCreatedPackages(rootPackage, IEEERequirementsConstants.EXTERNAl_INTERFACES_PACKAGE, IEEERequirementCategory.EXTERNAL_INTERFACES_REQUIREMENTS); |
| final Package externalInterfacesPackage = (Package) rootPackage.getPackagedElement(IEEERequirementsConstants.EXTERNAl_INTERFACES_PACKAGE); |
| checkCreatedPackages(externalInterfacesPackage, IEEERequirementsConstants.USER_INTERFACES_PACKAGE, IEEERequirementCategory.USER_INTERFACES); |
| checkCreatedPackages(externalInterfacesPackage, IEEERequirementsConstants.HW_INTERFACES_PACKAGE, IEEERequirementCategory.HARDWARE_INTERFACES); |
| checkCreatedPackages(externalInterfacesPackage, IEEERequirementsConstants.SW_INTERFACES_PACKAGE, IEEERequirementCategory.SOFTWARE_INTERFACES); |
| checkCreatedPackages(externalInterfacesPackage, IEEERequirementsConstants.COMMUNICATION_INTERFACES_PACKAGE, IEEERequirementCategory.COMMUNICATION_INTERFACES); |
| |
| |
| checkCreatedPackages(rootPackage, IEEERequirementsConstants.FUNCTIONAL_REQUIREMENTS_ROOT_PACKAGE, IEEERequirementCategory.FUNCTIONAL_REQUIREMENTS); |
| // this package contains subPackage |
| final Package functionalRequirements = (Package) rootPackage.getPackagedElement(IEEERequirementsConstants.FUNCTIONAL_REQUIREMENTS_ROOT_PACKAGE); |
| checkCreatedFunctionRequirementsPackage(functionalRequirements, IEEERequirementsConstants.FUNCTIONAL_REQUIREMENTS_MODE_1, 1); |
| checkCreatedFunctionRequirementsPackage(functionalRequirements, IEEERequirementsConstants.FUNCTIONAL_REQUIREMENTS_MODE_2, 2); |
| checkCreatedFunctionRequirementsPackage(functionalRequirements, IEEERequirementsConstants.FUNCTIONAL_REQUIREMENTS_MODE_3, 3); |
| |
| checkCreatedPackages(rootPackage, IEEERequirementsConstants.PERFORMANCE_REQUIREMENTS_PACKAGE, IEEERequirementCategory.PERFORMANCE_REQUIREMENTS); |
| checkCreatedPackages(rootPackage, IEEERequirementsConstants.DESIGN_CONSTRAINTS_REQUIREMENTS_PACKAGE, IEEERequirementCategory.DESIGN_CONSTRAINTS); |
| checkCreatedPackages(rootPackage, IEEERequirementsConstants.SOFTWARE_SYSTEM_ATTRIBUTE_REQUIREMENTS_PACKAGE, IEEERequirementCategory.SOFTWARE_SYSTEM_ATTRIBUTES); |
| checkCreatedPackages(rootPackage, IEEERequirementsConstants.OTHER_REQUIREMENTS_PACKAGE, IEEERequirementCategory.OTHER_REQUIREMENTS); |
| } |
| |
| private void checkCreatedPackages(final Package parentPackage, final String packName, final org.eclipse.papyrus.model2doc.integration.ieee.requirements.documentation.IEEERequirementCategory category) { |
| final NamedElement namedElement = parentPackage.getPackagedElement(packName); |
| Assert.assertTrue(namedElement instanceof Package); |
| Assert.assertNotNull(NLS.bind("The package named {0} can't be found", packName), namedElement); |
| final IEEERequirements req = UMLUtil.getStereotypeApplication(namedElement, org.eclipse.papyrus.model2doc.integration.ieee.requirements.documentation.IEEERequirements.class); |
| Assert.assertNotNull(NLS.bind("The stereotype IEEERequirements is not applied on {0}", packName), req); |
| Assert.assertEquals(NLS.bind("The requirement category for the package {0} is not the expected one.", packName), category, req.getCategory()); |
| } |
| |
| private void checkCreatedFunctionRequirementsPackage(final Package parentPackage, final String packName, final int expectedMode) { |
| final NamedElement namedElement = parentPackage.getPackagedElement(packName); |
| Assert.assertTrue(namedElement instanceof Package); |
| Assert.assertNotNull(NLS.bind("The package named {0} can't be found", packName), namedElement); |
| final IEEEFunctionalRequirements req = UMLUtil.getStereotypeApplication(namedElement, org.eclipse.papyrus.model2doc.integration.ieee.requirements.documentation.IEEEFunctionalRequirements.class); |
| Assert.assertNotNull(NLS.bind("The stereotype IEEEFunctionalRequirements is not applied on {0}", packName), req); |
| Assert.assertEquals(NLS.bind("The requirement category for the package {0} is not the expected one.", packName), IEEERequirementCategory.FUNCTIONAL_REQUIREMENTS, req.getCategory()); |
| Assert.assertEquals(NLS.bind("The mode for the for package {0} is not the expected one", packName), expectedMode, req.getMode()); |
| } |
| } |