-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2041] Tests for MultiInstanceRole tools
Change-Id: I88e6e0075a7cb59e759c0b4ff0a82c45879fb42a Signed-off-by: Felix Dorner <felix.dorner@gmail.com>
- Loading branch information
Showing
6 changed files
with
352 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
....diagram.common.ju/src/org/polarsys/capella/test/diagram/common/ju/context/ISDiagram.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
146 changes: 146 additions & 0 deletions
146
...rg/polarsys/capella/test/diagram/common/ju/step/tools/sequence/MultiInstanceRoleTool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
...ram.tools.ju/src/org/polarsys/capella/test/diagram/tools/ju/es/MultiInstanceRoleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
Oops, something went wrong.