Commit e55b8041 authored by Paff's avatar Paff
Browse files

fix transformation

test for pretransformation
parent bbaae350
......@@ -209,7 +209,7 @@ public class MontiSecArcAnalysisVisitor extends CheckWorkflowClient {
try {
componentEntry = (SecComponentEntry) resolver.resolve(node.getType().getName(), ComponentEntry.KIND, getNameSpaceFor(node));
} catch (AmbigousException e) {
} catch (AmbigousException | NullPointerException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
......
......@@ -8,6 +8,8 @@ import interfaces2.resolvers.Resolver;
import java.util.List;
import java.util.Map;
import org.jgrapht.traverse.DepthFirstIterator;
import secarc.MontiSecArcConstants;
import secarc._ast.ASTSecArcCPE;
import secarc._ast.ASTSecArcConfiguration;
......@@ -19,21 +21,25 @@ import secarc._ast.ASTSecArcTrustlevelRelation;
import secarc._tool.MontiSecArcRoot;
import secarc.ets.entries.CPEEntry;
import secarc.ets.entries.ConfigurationEntry;
import secarc.ets.entries.IdentityEntry;
import secarc.ets.entries.PEPEntry;
import secarc.ets.entries.RoleEntry;
import secarc.ets.entries.SecComponentEntry;
import secarc.ets.entries.TrustlevelEntry;
import secarc.ets.entries.TrustlevelRelationEntry;
import secarc.ets.graph.ArchitectureGraph;
import secarc.ets.graph.ArchitectureGraphBuilder;
import secarc.ets.graph.Edge;
import secarc.ets.graph.Vertex;
import mc.MCG;
import mc.ast.ASTNode;
import mc.ast.ConcreteVisitor;
import mc.helper.NameHelper;
import mc.javadsl._ast.ASTQualifiedNameList;
import mc.types._ast.ASTQualifiedName;
import mc.umlp.arcd._ast.ASTArcComponent;
import mc.umlp.arcd._ast.ASTArcConnector;
import mc.umlp.arcd._ast.ASTArcPort;
import mc.umlp.arcd._ast.ASTArcSimpleConnector;
import mc.umlp.arcd._ast.ASTMCCompilationUnit;
import mc.umlp.arcd.ets.entries.ComponentEntry;
import mc.umlp.arcd.ets.entries.ConnectorEntry;
import mc.umlp.arcd.ets.entries.PortEntry;
......@@ -46,6 +52,11 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
protected Map<ASTNode, NameSpace> nodesToNameSpaces;
/**
* Architecture graph for analysis with identity links as edges
*/
private ArchitectureGraph graphIdentityEdges;
/**
*
* @param dslroot dsl root to use
......@@ -66,6 +77,27 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
this.entries = entries;
}
/**
* Visits compilation unit and builds the architecture graph
*
* @param node ast node to visit
*/
public void visit(ASTMCCompilationUnit node) {
SecComponentEntry componentEntry = null;
try {
componentEntry = (SecComponentEntry) resolver.resolve(node.getType().getName(), ComponentEntry.KIND, getNameSpaceFor(node));
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
//Create graph from ASTl
if(componentEntry != null) {
graphIdentityEdges = ArchitectureGraphBuilder.forArchitecture(componentEntry).buildGraphIdentityEdge();
}
}
public void visit(ASTSecArcRole node) {
try {
for(String role : node.getRoles()) {
......@@ -92,20 +124,6 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
}
}
public void visit(ASTSecArcIdentity node) {
try {
for(ASTQualifiedName target : node.getTargets()) {
IdentityEntry entry = (IdentityEntry) resolver.resolve(NameHelper.dotSeparatedStringFromList(target.getParts()), IdentityEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
}
}
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
}
public void visit(ASTSecArcPEP node) {
try {
PEPEntry entry = (PEPEntry) resolver.resolve(MontiSecArcConstants.PEP_NAME, PEPEntry.KIND, getNameSpaceFor(node));
......@@ -188,6 +206,20 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
if(entry != null && !this.entries.contains(entry)) {
node.delete();
}
//Delete Identity link, if the component is a target or source
Vertex<ComponentEntry> componentVertex = Vertex.of(entry);
//Check for target
DepthFirstIterator<Vertex<? extends STEntry>, Edge> iterator = new DepthFirstIterator<Vertex<? extends STEntry>, Edge>(graphIdentityEdges.getReversedRawGraph(), componentVertex);
if(iterator.hasNext()) {
iterator.next().getArchitectureElement().getNode().delete();
}
//Check for source
iterator = new DepthFirstIterator<Vertex<? extends STEntry>, Edge>(graphIdentityEdges.getRawGraph(), componentVertex);
if(iterator.hasNext()) {
iterator.next().getArchitectureElement().getNode().delete();
}
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
......
......@@ -35,12 +35,7 @@ public class PreAnalysisCriticalPortTransformationVisitor extends ConcreteVisito
*/
private ArchitectureGraph graphConnectorEdges;
/**
* Architecture graph for analysis with identity links as edges
*/
private ArchitectureGraph graphIdentityEdges;
private List<STEntry> entries;
private List<STEntry> entries = new ArrayList<STEntry>();
private Resolver resolver;
......@@ -83,7 +78,6 @@ public class PreAnalysisCriticalPortTransformationVisitor extends ConcreteVisito
//Create graph from ASTl
if(componentEntry != null) {
graphConnectorEdges = ArchitectureGraphBuilder.forArchitecture(componentEntry).buildGraphConnectorEdge();
graphIdentityEdges = ArchitectureGraphBuilder.forArchitecture(componentEntry).buildGraphIdentityEdge();
}
}
......@@ -123,9 +117,10 @@ public class PreAnalysisCriticalPortTransformationVisitor extends ConcreteVisito
while(iterator.hasNext()) {
pathEntry = iterator.next().getArchitectureElement();
if(pathEntry.equals(entry)) {
if(pathEntry.equals(entry) || !iterator.hasNext()) {
if(hasCriticalPort) {
this.entries.addAll(pathEntries);
this.entries.add(pathEntry);
}
pathEntries.clear();
hasCriticalPort = false;
......
......@@ -3,14 +3,13 @@ package secarc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import mc.ProblemReport;
import mc.ast.InheritanceVisitor;
import org.junit.Test;
import secarc.error.MontiSecArcAnalysisErrorCodes;
import secarc._tool.MontiSecArcRoot;
import secarc.ets.transform.criticalport.PreAnalysisCriticalPortTransformationVisitor;
public class MontiSecArcAnalysisWhatIfCiritcalPortTest extends TestWithSymtabAnalysis<MontiSecArcAnalysisTestTool> {
......@@ -22,24 +21,49 @@ public class MontiSecArcAnalysisWhatIfCiritcalPortTest extends TestWithSymtabAna
}
/**
* Test for configurations
* Test preTransformation without a critical port
*/
@Test
public void testConfiguration() {
public void testPreTranformationCriticalPortWithoutCriticalPort() {
//First File
// System.out.println("ConfigurationNotReviewed.secarc");
// MontiSecArcAnalysisTestTool tool = createTestToolWithoutJavaWhatIfCiritcalPort(new String[] { "src/test/resources/secarc/analysis/configuration/ConfigurationNotReviewed.secarc" });
// tool.init();
// assertTrue(tool.run());
//
// List<MontiSecArcAnalysisErrorCodes> errorCodes = new ArrayList<MontiSecArcAnalysisErrorCodes>();
// errorCodes.add(MontiSecArcAnalysisErrorCodes.ReviewedConfiguration);
// errorCodes.add(MontiSecArcAnalysisErrorCodes.ListThirdPartyComponents);
//
// assertEquals(2, handler.getWarnings().size());
// for(ProblemReport error : handler.getErrors()) {
// assertTrue(errorCodes.contains(error.getErrorcode()));
// }
System.out.println("ConfigurationNotReviewed.secarc");
MontiSecArcAnalysisTestTool tool = createTestToolWithoutJava(new String[] { "src/test/resources/secarc/analysis/configuration/ConfigurationNotReviewed.secarc" });
tool.init();
assertTrue(tool.run());
MontiSecArcRoot root= (MontiSecArcRoot) initSymtabForRoot(tool, "secarc.analysis.configuration.ConfigurationNotReviewed");
//Elements which are needed for analysis
PreAnalysisCriticalPortTransformationVisitor preVisitor = new PreAnalysisCriticalPortTransformationVisitor(root);
preVisitor.setResolver(resolver);
preVisitor.setNodesToNameSpaces(nodesToNameSpaces);
InheritanceVisitor.run(preVisitor, root.getAst());
assertEquals(0, preVisitor.getEntries().size());
}
/**
* Test preTransformation with a critical port
*/
@Test
public void testPreTranformationCriticalPortWithCriticalPort() {
//First File
System.out.println("CriticalPort.secarc");
MontiSecArcAnalysisTestTool tool = createTestToolWithoutJava(new String[] { "src/test/resources/secarc/analysis/criticalport/CriticalPort.secarc" });
tool.init();
assertTrue(tool.run());
MontiSecArcRoot root= (MontiSecArcRoot) initSymtabForRoot(tool, "secarc.analysis.criticalport.CriticalPort");
//Elements which are needed for analysis
PreAnalysisCriticalPortTransformationVisitor preVisitor = new PreAnalysisCriticalPortTransformationVisitor(root);
preVisitor.setResolver(resolver);
preVisitor.setNodesToNameSpaces(nodesToNameSpaces);
InheritanceVisitor.run(preVisitor, root.getAst());
assertEquals(4, preVisitor.getEntries().size());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment