Skip to content

Commit

Permalink
[2041] Tests for MultiInstanceRole tools
Browse files Browse the repository at this point in the history
Change-Id: I88e6e0075a7cb59e759c0b4ff0a82c45879fb42a
Signed-off-by: Felix Dorner <felix.dorner@gmail.com>
  • Loading branch information
felixdo committed May 9, 2018
1 parent 933ba0d commit 17353ca
Show file tree
Hide file tree
Showing 6 changed files with 352 additions and 0 deletions.
Expand Up @@ -1498,4 +1498,11 @@ public interface IToolNameConstants {
String TABLE_TOOL_REQ_SFIR = "System Functional Interface Requirement"; //$NON-NLS-1$
String TABLE_TOOL_REQ_SNFR = "System Non Functional Requirement"; //$NON-NLS-1$
String TABLE_TOOL_REQ_SNFIR = "System Non Functional Interface Requirement"; //$NON-NLS-1$

/**
* Tool on IS, ES diagrams to create multiple instance roles for identical represented
*/
String TOOL_SCENARIO_MULTI_INSTANCEROLE_COMPONENT = "Add multiple lifelines for an existing Component"; //$NON-NLS-1$
String TOOL_SCENARIO_MULTI_INSTANCEROLE_ACTOR = "Add multiple lifelines for an existing Actor"; //$NON-NLS-1$
String TOOL_OES_MULTI_INSTANCEROLE_ENTITYACTOR = "Add multiple lifelines for an existing Entity / Actor"; //$NON-NLS-1$
}
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2018 THALES GLOBAL SERVICES.
* 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:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.test.diagram.common.ju.context;

import org.eclipse.sirius.diagram.DDiagram;
import org.polarsys.capella.core.model.helpers.BlockArchitectureExt;
import org.polarsys.capella.core.sirius.analysis.IDiagramNameConstants;
import org.polarsys.capella.test.diagram.common.ju.step.crud.CreateDiagramStep;
import org.polarsys.capella.test.diagram.common.ju.step.crud.OpenDiagramStep;
import org.polarsys.capella.test.framework.context.SessionContext;

public class ISDiagram extends DiagramContext {

public ISDiagram(SessionContext context, DDiagram diagram) {
super(context, diagram);
}

public static ISDiagram createDiagram(SessionContext executionContext, String targetIdentifier) {
String name = IDiagramNameConstants.INTERFACE_SCENARIO_DIAGRAM_NAME;
return (ISDiagram) new CreateDiagramStep(executionContext, targetIdentifier, name) {
@Override
public DiagramContext getResult() {
return new ISDiagram(getExecutionContext(), diagram);
}
}.run().open();
}

public static ISDiagram openDiagram(SessionContext executionContext, String name, final BlockArchitectureExt.Type type) {
return (ISDiagram) new OpenDiagramStep(executionContext, name) {
@Override
public DiagramContext getResult() {
return new ISDiagram(getExecutionContext(), diagram);
}
}.run().open();
}

}
@@ -0,0 +1,146 @@
/*******************************************************************************
* Copyright (c) 2018 THALES GLOBAL SERVICES.
* 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:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.test.diagram.common.ju.step.tools.sequence;

import static org.hamcrest.core.AnyOf.anyOf;
import static org.hamcrest.core.IsCollectionContaining.hasItem;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.sirius.diagram.DDiagramElement;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.hamcrest.Matcher;
import org.polarsys.capella.core.data.cs.AbstractActor;
import org.polarsys.capella.core.data.cs.BlockArchitecture;
import org.polarsys.capella.core.data.cs.Part;
import org.polarsys.capella.core.data.interaction.InstanceRole;
import org.polarsys.capella.core.data.oa.OaPackage;
import org.polarsys.capella.core.model.helpers.BlockArchitectureExt;
import org.polarsys.capella.core.sirius.analysis.IDiagramNameConstants;
import org.polarsys.capella.core.sirius.analysis.constants.IToolNameConstants;
import org.polarsys.capella.test.diagram.common.ju.context.DiagramContext;
import org.polarsys.capella.test.diagram.common.ju.headless.HeadlessResultOpProvider;
import org.polarsys.capella.test.diagram.common.ju.headless.IHeadlessResult;
import org.polarsys.capella.test.diagram.common.ju.step.tools.AbstractToolStep;
import org.polarsys.capella.test.diagram.common.ju.wrapper.utils.ArgumentType;

public final class MultiInstanceRoleTool extends AbstractToolStep<InstanceRole> {

private MultiInstanceRoleTool(DiagramContext context, String toolName, Part partToInsert) {
super(context, toolName);
this.partToInsert = partToInsert;
}

private Collection<DDiagramElement> preExecutionElements;
private Part partToInsert;
private InstanceRole result;

public static InstanceRole newInstanceRole(DiagramContext context, String representedPartId) {

EObject diagramTarget = ((DSemanticDecorator) context.getDiagram()).getTarget();
BlockArchitecture ba = BlockArchitectureExt.getRootBlockArchitecture(diagramTarget);
Part part = context.getSemanticElement(representedPartId);

String toolName = null;

/*
* Check that the tool is used on any of the supported diagram kinds (OES, IS, ES)
*/
Matcher<String> diagramDescriptionName = null;

if (ba.eClass() == OaPackage.Literals.OPERATIONAL_ANALYSIS) {
diagramDescriptionName = equalTo(IDiagramNameConstants.OPERATIONAL_INTERACTION_SCENARIO_DIAGRAM_NAME);
toolName = IToolNameConstants.TOOL_OES_MULTI_INSTANCEROLE_ENTITYACTOR;
} else {
diagramDescriptionName = anyOf(equalTo(IDiagramNameConstants.INTERFACE_SCENARIO), equalTo(IDiagramNameConstants.DATA_FLOW_SCENARIO_DIAGRAM_NAME));

if (part.getAbstractType() instanceof AbstractActor) {
toolName = IToolNameConstants.TOOL_SCENARIO_MULTI_INSTANCEROLE_ACTOR;
} else {
toolName = IToolNameConstants.TOOL_SCENARIO_MULTI_INSTANCEROLE_COMPONENT;
}

}

assertThat(context.getDiagram().getDescription().getName(), diagramDescriptionName);
MultiInstanceRoleTool tool = new MultiInstanceRoleTool(context, toolName, part);
return tool.run();

}

/**
* @see org.polarsys.capella.test.diagram.common.ju.steps.AbstractExecuteToolCmdStep.tool.AbstractExecuteToolCmdTest#initToolArguments()
*/
@Override
protected void initToolArguments() {
DSemanticDecorator containerView = getExecutionContext().getView(getExecutionContext().getDiagramId());
_toolWrapper.setArgumentValue(ArgumentType.CONTAINER, containerView.getTarget());
_toolWrapper.setArgumentValue(ArgumentType.CONTAINER_VIEW, containerView);
}


@Override
protected void postRunTest() {

List<DDiagramElement> now = new ArrayList<DDiagramElement>(getExecutionContext().getDiagram().getOwnedDiagramElements());
now.removeAll(preExecutionElements);

assertEquals(1, now.size());
DDiagramElement elem = now.get(0);

assertTrue(elem.getTarget() instanceof InstanceRole);
assertSame(partToInsert, ((InstanceRole) elem.getTarget()).getRepresentedInstance());
result = (InstanceRole) elem.getTarget();
}

/**
* @see org.polarsys.capella.test.diagram.common.ju.steps.AbstractExecuteToolCmdStep.tool.AbstractExecuteToolCmdTest#preTestRun()
*/
@Override
protected void preRunTest() {

// this auto-selects the part to be inserted from the selection dialog
HeadlessResultOpProvider.INSTANCE.setCurrentOp(createOperation());
preExecutionElements = new ArrayList<DDiagramElement>(getExecutionContext().getDiagram().getOwnedDiagramElements());
super.preRunTest();
}

/**
* @return
*/
protected IHeadlessResult createOperation() {
return new IHeadlessResult() {
@Override
public Object getResult(java.util.Collection<? extends EObject> selections, Map<String, Object> parameters) {
@SuppressWarnings("unchecked")
Iterable<? super Part> scope = (Iterable<? super Part>) parameters.get("scope"); //$NON-NLS-1$
assertThat(scope, hasItem(partToInsert));
return partToInsert;
}
};
}


@Override
public InstanceRole getResult() {
return result;
}

}
Expand Up @@ -2491,6 +2491,12 @@
<ownedCapabilities xsi:type="org.polarsys.capella.core.data.ctx:Capability"
id="4e6fa11e-933f-4aec-b4c0-621c8fb244e5" name="Provide Moving-Map Services"
description="[Wikipedia]&lt;br />&#xD;&#xA;A moving-map system is a real-time flight information video channel broadcast through to cabin project/video screens and&#xD;&#xA;personal televisions (PTVs). In addition to displaying a map that illustrates the position and direction of the plane, the&#xD;&#xA;system gives the altitude, airspeed, outside air temperature, distance to the destination, distance from the origination&#xD;&#xA;point, and local time. The moving-map system information is derived in real time from the aircraft's flight computer&#xD;&#xA;systems.">
<ownedScenarios xsi:type="org.polarsys.capella.core.data.interaction:Scenario"
id="c3d663a9-3a4c-4e36-ac88-d5163b11d3ff" name="[IS] Provide Moving-Map Services"
kind="INTERFACE">
<ownedInstanceRoles xsi:type="org.polarsys.capella.core.data.interaction:InstanceRole"
id="450ec410-5971-4e4d-a0c4-091950ffc101" name="IFE System" representedInstance="#cb4b8f2d-7663-4d35-bc44-20080a8d3133"/>
</ownedScenarios>
<ownedActorCapabilityInvolvements xsi:type="org.polarsys.capella.core.data.ctx:ActorCapabilityInvolvement"
id="b5e2ccdb-fd59-45fa-82df-d6befe26e3f2" involved="#c8b78c78-5b11-4fc0-87b7-3ca84622efea"/>
<ownedActorCapabilityInvolvements xsi:type="org.polarsys.capella.core.data.ctx:ActorCapabilityInvolvement"
Expand Down Expand Up @@ -8315,6 +8321,9 @@
</ownedCapabilityRealizations>
<ownedCapabilityRealizations xsi:type="org.polarsys.capella.core.data.la:CapabilityRealization"
id="36429bbc-57fd-4862-b59e-003a11f4b146" name="Provide Configuration Means">
<ownedScenarios xsi:type="org.polarsys.capella.core.data.interaction:Scenario"
id="5bf082b5-2050-438c-a203-f1eb03cbcecd" name="[IS] Provide Configuration Means"
kind="INTERFACE"/>
<ownedAbstractCapabilityRealizations xsi:type="org.polarsys.capella.core.data.interaction:AbstractCapabilityRealization"
id="57757338-f769-45a2-a54b-a360f1adbe89" targetElement="#a643f8af-0104-49c8-add7-525806988ccb"
sourceElement="#36429bbc-57fd-4862-b59e-003a11f4b146"/>
Expand Down Expand Up @@ -13257,12 +13266,18 @@
</ownedCapabilityRealizations>
<ownedCapabilityRealizations xsi:type="org.polarsys.capella.core.data.la:CapabilityRealization"
id="9bd26014-34ac-46c1-ac3c-7646941ada16" name="Provide Testing Interface">
<ownedScenarios xsi:type="org.polarsys.capella.core.data.interaction:Scenario"
id="7b2fa095-18cb-483f-87be-73f78c1cc88f" name="Provide Testing Interface"
kind="DATA_FLOW"/>
<ownedAbstractCapabilityRealizations xsi:type="org.polarsys.capella.core.data.interaction:AbstractCapabilityRealization"
id="3ea5aac1-1f67-4db8-bf34-35a4e57fa830" targetElement="#bd2a543a-d87b-4147-8ad4-7f77a110ced2"
sourceElement="#9bd26014-34ac-46c1-ac3c-7646941ada16"/>
</ownedCapabilityRealizations>
<ownedCapabilityRealizations xsi:type="org.polarsys.capella.core.data.la:CapabilityRealization"
id="ca3942df-c48d-461c-9cc2-de207cd35908" name="Provide Configuration Means">
<ownedScenarios xsi:type="org.polarsys.capella.core.data.interaction:Scenario"
id="9ef4fd22-b504-4013-9edb-fb9e7ed1d97d" name="[IS] Provide Configuration Means"
kind="INTERFACE"/>
<ownedAbstractCapabilityRealizations xsi:type="org.polarsys.capella.core.data.interaction:AbstractCapabilityRealization"
id="ee6e3530-547f-4af6-83ad-7cc8f373da64" targetElement="#36429bbc-57fd-4862-b59e-003a11f4b146"
sourceElement="#ca3942df-c48d-461c-9cc2-de207cd35908"/>
Expand Down
@@ -0,0 +1,137 @@
/*******************************************************************************
* Copyright (c) 2018 THALES GLOBAL SERVICES.
* 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:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.test.diagram.tools.ju.es;

import static org.polarsys.capella.test.diagram.common.ju.context.ESDiagram.createDiagram;
import static org.polarsys.capella.test.diagram.common.ju.step.tools.sequence.MultiInstanceRoleTool.newInstanceRole;

import org.eclipse.sirius.business.api.session.Session;
import org.polarsys.capella.test.diagram.common.ju.api.AbstractDiagramTestCase;
import org.polarsys.capella.test.diagram.common.ju.context.DiagramContext;
import org.polarsys.capella.test.diagram.common.ju.context.ESDiagram;
import org.polarsys.capella.test.diagram.common.ju.context.ISDiagram;
import org.polarsys.capella.test.framework.context.SessionContext;

import junit.framework.Test;

/**
* Test the Multi-InstanceRole Tool on IS, ES and OES diagrams
*/
public class MultiInstanceRoleTest extends AbstractDiagramTestCase {

protected SessionContext sc;
protected Session s;

private static final String OA_SCENARIO__FLIGHT_PHASES = "d04ae481-72c3-432e-b4e7-b2d66264d3b0"; //$NON-NLS-1$
private static final String CTX_SCENARIO__START_VOD_SERVICE = "58d8d80a-34ab-4e60-aee2-fb8eb885583a"; //$NON-NLS-1$
private static final String CTX_SCENARIO__PROVIDE_MOVING_MAP_SERVICES = "c3d663a9-3a4c-4e36-ac88-d5163b11d3ff"; //$NON-NLS-1$
private static final String LA_SCENARIO__PERFORM_AUDIO_ANNOUNCEMENT = "2c5abb7e-3281-4651-8458-39d383b9dcc0"; //$NON-NLS-1$
private static final String LA_SCENARIO__PROVIDE_CONFIGURATION_MEANS = "5bf082b5-2050-438c-a203-f1eb03cbcecd"; //$NON-NLS-1$
private static final String PA_SCENARIO__PROVIDE_TESTING_INTERFACE = "7b2fa095-18cb-483f-87be-73f78c1cc88f"; //$NON-NLS-1$
private static final String PA_SCENARIO__PROVIDE_CONFIGURATION_MEANS = "9ef4fd22-b504-4013-9edb-fb9e7ed1d97d";

// watch out, these IDs are part IDs
private static final String OA_ACTOR__GROUND_OPERATOR = "8dec32f0-0393-4da9-b9a1-1f1a3a9a8128"; //$NON-NLS-1$
private static final String OA_ENTITY__AIRCRAFT = "bb2375f0-8f2d-4f6d-b469-42b275f8795a"; //$NON-NLS-1$
private static final String CTX_ACTOR__PASSENGER = "e9c81b65-e5f7-4edd-be4d-4e6a08f5e825"; //$NON-NLS-1$
private static final String CTX_SYSTEM__IFE_SYSTEM = "cb4b8f2d-7663-4d35-bc44-20080a8d3133"; //$NON-NLS-1$
private static final String LA_ACTOR__CABIN_CREW = "0bbbd1de-dd06-4860-90a5-41a026de9601"; //$NON-NLS-1$
private static final String LA_COMPONENT__IFE_SYSTEM = "ce1400b3-f97e-4c62-8187-562b72134923"; //$NON-NLS-1$
private static final String LA_COMPONENT__CABIN_SCREEN ="bd03d965-9e76-4ec0-b298-c1b8f497f5a4"; //$NON-NLS-1$
private static final String PA_COMPONENT__AIRCRAFT_FRONT_SERVERS = "f3fc69a5-507d-43c5-a4a1-4a5fd9e6b347"; //$NON-NLS-1$
private static final String PA_COMPONENT__IFE_SYSTEM = "1371e1d0-8401-4b88-8d3a-cc72d34f1132"; //$NON-NLS-1$
private static final String PA_ACTOR__AIRCRAFT = "369cbf55-7250-4e93-9656-0f3cee9a5d0e"; //$NON-NLS-1$

private Session session;
private SessionContext context;

@Override
protected String getRequiredTestModel() {
return "In-Flight Entertainment System"; //$NON-NLS-1$
}


@Override
public void test() throws Exception {

session = getSession(getRequiredTestModel());
context = new SessionContext(session);

oaTest();
saTest();
laTest();
paTest();
}

private void oaTest() {
ESDiagram diagram = createDiagram(context, OA_SCENARIO__FLIGHT_PHASES);
newInstanceRole(diagram, OA_ACTOR__GROUND_OPERATOR);
newInstanceRole(diagram, OA_ACTOR__GROUND_OPERATOR);
newInstanceRole(diagram, OA_ENTITY__AIRCRAFT);
newInstanceRole(diagram, OA_ENTITY__AIRCRAFT);
}

private void saTest() {
DiagramContext diagram = ESDiagram.createDiagram(context, CTX_SCENARIO__START_VOD_SERVICE);
newInstanceRole(diagram, CTX_ACTOR__PASSENGER);
newInstanceRole(diagram, CTX_ACTOR__PASSENGER);
newInstanceRole(diagram, CTX_SYSTEM__IFE_SYSTEM);
newInstanceRole(diagram, CTX_SYSTEM__IFE_SYSTEM);

diagram = ISDiagram.createDiagram(context, CTX_SCENARIO__PROVIDE_MOVING_MAP_SERVICES);
newInstanceRole(diagram, CTX_ACTOR__PASSENGER);
newInstanceRole(diagram, CTX_ACTOR__PASSENGER);
newInstanceRole(diagram, CTX_SYSTEM__IFE_SYSTEM);
newInstanceRole(diagram, CTX_SYSTEM__IFE_SYSTEM);
}

private void laTest() {
DiagramContext diagram = ESDiagram.createDiagram(context, LA_SCENARIO__PERFORM_AUDIO_ANNOUNCEMENT);
newInstanceRole(diagram, LA_ACTOR__CABIN_CREW);
newInstanceRole(diagram, LA_ACTOR__CABIN_CREW);
newInstanceRole(diagram, LA_COMPONENT__CABIN_SCREEN);
newInstanceRole(diagram, LA_COMPONENT__CABIN_SCREEN);
newInstanceRole(diagram, LA_COMPONENT__IFE_SYSTEM);
newInstanceRole(diagram, LA_COMPONENT__IFE_SYSTEM);

diagram = ISDiagram.createDiagram(context, LA_SCENARIO__PROVIDE_CONFIGURATION_MEANS);
newInstanceRole(diagram, LA_ACTOR__CABIN_CREW);
newInstanceRole(diagram, LA_ACTOR__CABIN_CREW);
newInstanceRole(diagram, LA_COMPONENT__CABIN_SCREEN);
newInstanceRole(diagram, LA_COMPONENT__CABIN_SCREEN);
newInstanceRole(diagram, LA_COMPONENT__IFE_SYSTEM);
newInstanceRole(diagram, LA_COMPONENT__IFE_SYSTEM);

}

private void paTest() {
DiagramContext diagram = ESDiagram.createDiagram(context, PA_SCENARIO__PROVIDE_TESTING_INTERFACE);
newInstanceRole(diagram, PA_COMPONENT__IFE_SYSTEM);
newInstanceRole(diagram, PA_COMPONENT__IFE_SYSTEM);
newInstanceRole(diagram, PA_COMPONENT__AIRCRAFT_FRONT_SERVERS);
newInstanceRole(diagram, PA_COMPONENT__AIRCRAFT_FRONT_SERVERS);
newInstanceRole(diagram, PA_ACTOR__AIRCRAFT);
newInstanceRole(diagram, PA_ACTOR__AIRCRAFT);

diagram = ISDiagram.createDiagram(context, PA_SCENARIO__PROVIDE_CONFIGURATION_MEANS);
newInstanceRole(diagram, PA_COMPONENT__IFE_SYSTEM);
newInstanceRole(diagram, PA_COMPONENT__IFE_SYSTEM);
newInstanceRole(diagram, PA_COMPONENT__AIRCRAFT_FRONT_SERVERS);
newInstanceRole(diagram, PA_COMPONENT__AIRCRAFT_FRONT_SERVERS);
newInstanceRole(diagram, PA_ACTOR__AIRCRAFT);
newInstanceRole(diagram, PA_ACTOR__AIRCRAFT);

}

public static Test suite() {
return new MultiInstanceRoleTest();
}
}

0 comments on commit 17353ca

Please sign in to comment.