Skip to content

Commit

Permalink
#164 Fix issues in tests
Browse files Browse the repository at this point in the history
When created inside the executeCommand() body, createFunctionalExchange
doesn't create the GMF elements,
and createFunctionalChain cannot find it


More generally, any calls to diagram.createXXX should be done outside of an execute command

Change-Id: If512b3ee0bb8c504570d78db58a1c70a02c3c71f
Signed-off-by: Erwann Traisnel <erwann.traisnel@obeo.fr>
  • Loading branch information
etraisnel2 authored and pdulth committed Jan 4, 2024
1 parent c4a81a5 commit bfe5cef
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 128 deletions.
Expand Up @@ -24,7 +24,6 @@
import org.polarsys.capella.test.diagram.common.ju.context.OABDiagram;
import org.polarsys.capella.test.diagram.common.ju.step.crud.CreateDiagramStep;
import org.polarsys.capella.test.diagram.common.ju.step.tools.CreateContainerTool;
import org.polarsys.capella.test.diagram.common.ju.step.tools.CreatePathTool;
import org.polarsys.capella.test.diagram.common.ju.step.tools.InsertRemoveTool;
import org.polarsys.capella.test.framework.context.SessionContext;

Expand Down Expand Up @@ -66,11 +65,6 @@ public void removeThreat(Threat threat) {
new InsertRemoveTool(this, CybersecurityAnalysisConstants.TOOL_XAB_INSERT_THREAT).remove(threat.getId());
}

@Override
public void createFunctionalChain(String path, String... links) {
new CreatePathTool(this, IToolNameConstants.TOOL_OAIB_CREATE_OPERATIONAL_PROCESS, path, links).run();
}

public String createEntity(String id, String containerId) {
DDiagramElementContainer element = new CreateContainerTool(this, IToolNameConstants.TOOL_OAB_CREATE_OE, containerId,
id).run();
Expand Down
Expand Up @@ -88,7 +88,7 @@ protected void removePrimaryAsset(PrimaryAsset pa) {
protected void insertThreat(Threat threat) {
((CyberOABDiagram) diagram).insertThreat(threat);
}

@Override
protected void removeThreat(Threat threat) {
((CyberOABDiagram) diagram).removeThreat(threat);
Expand All @@ -98,39 +98,38 @@ protected void removeThreat(Threat threat) {
protected void step3() throws RollbackException, InterruptedException {
CyberOABDiagram diagram = (CyberOABDiagram) this.diagram;

executeCommand(() -> {
// create 2 entities in diagram
String entity1Id = diagram.createEntity("e1", diagram.getDiagramId());
String entity2Id = diagram.createEntity("e2", diagram.getDiagramId());
// create 2 entities in diagram
String entity1Id = diagram.createEntity("e1", diagram.getDiagramId());
String entity2Id = diagram.createEntity("e2", diagram.getDiagramId());

// create an untrusted actor and a trusted one inside the previous ones
String untrustedActorId = diagram.createActor("untrustedActor", entity1Id);
String trustedActorId = diagram.createActor("trustedActor", entity2Id);
// create an untrusted actor and a trusted one inside the previous ones
String untrustedActorId = diagram.createActor("untrustedActor", entity1Id);
String trustedActorId = diagram.createActor("trustedActor", entity2Id);

executeCommand(() -> {
AbstractType untrustedActor = ((Entity) diagram.getSemanticObjectMap().get("untrustedActor"));
TrustBoundaryStorage storage = CybersecurityFactory.eINSTANCE.createTrustBoundaryStorage();
storage.setTrusted(false);
untrustedActor.getOwnedExtensions().add(storage);
});
// create activities inside the actors and an interaction between them
String func1 = diagram.createFunction("func1", untrustedActorId);
String func2 = diagram.createFunction("func2", trustedActorId);
diagram.createFunctionalExchange(func1, func2, "functional exchange");
FunctionalExchange functionalExchange = (FunctionalExchange) diagram.getSemanticObjectMap()
.get("functional exchange");

// create activities inside the actors and an interaction between them
String func1 = diagram.createFunction("func1", untrustedActorId);
String func2 = diagram.createFunction("func2", trustedActorId);
diagram.createFunctionalExchange(func1, func2, "functional exchange");
FunctionalExchange functionalExchange = (FunctionalExchange) diagram.getSemanticObjectMap()
.get("functional exchange");

// create a communication mean between the 'container' entities
diagram.createComponentExchange(entity1Id, entity2Id, "component exchange");
ComponentExchange componentExchange = (ComponentExchange) diagram.getSemanticObjectMap()
.get("component exchange");
// create a communication mean between the 'container' entities
diagram.createComponentExchange(entity1Id, entity2Id, "component exchange");
ComponentExchange componentExchange = (ComponentExchange) diagram.getSemanticObjectMap().get("component exchange");

executeCommand(() -> {
// add an allocated functional exchange to the component exchange
Allocators.allocate(functionalExchange).on(componentExchange);

assertTrue(CybersecurityQueries.isTrustBoundary(functionalExchange));
assertTrue(CybersecurityQueries.isTrustBoundary(componentExchange));

});

assertTrue(CybersecurityQueries.isTrustBoundary(functionalExchange));
assertTrue(CybersecurityQueries.isTrustBoundary(componentExchange));
}

@Override
Expand Down

0 comments on commit bfe5cef

Please sign in to comment.