Commit bd7155c0 authored by Paff's avatar Paff
Browse files

testsuit

wrapper for terminal with loop
filter in workflows without analysis
parent ad10bbac
......@@ -14,6 +14,9 @@ import interfaces2.workflows.PrepareCheckWorkflow;
import mc.DSLRootFactory;
import mc.IErrorDelegator;
import mc.IModelInfrastructureProvider;
import mc.umlp.arcd.ToolConstants;
import mc.umlp.arcd._tool.ArchitectureDiagramRoot;
import mc.umlp.arcd.prettyprint.ArchitectureDiagramPrettyPrintWorkflow;
import secarc._tool.MontiSecArcParsingWorkflow;
import secarc._tool.MontiSecArcRoot;
import secarc._tool.MontiSecArcRootFactory;
......@@ -22,6 +25,7 @@ import secarc.ets.check.MontiSecArcAnalysisWorkflow;
import secarc.ets.transform.PreCoCoCheckMontiSecArcTransformationWorkflow;
import secarc.ets.transform.criticalport.AnalysisCriticalPortTransformationWorkflow;
import secarc.ets.transform.trustlevel.AnalysisTrustlevelTransformationWorkflow;
import secarc.prettyprint.MontiSecArcPrettyPrintWorkflow;
/**
* As subclass of {@link ModelingLanguage}, this class configures the technical
......@@ -81,8 +85,11 @@ public final class MontiSecArcAnalysis extends MontiSecArc {
//Workflow for analysis with critical ports
this.addFilterCriticalPortWorkflow(analysisConfPath);
//Workflow for analysis
//Workflow for analysis
this.addAnalysisWorkflow(analysisConfPath, analysisParameter);
// PrettyPrinter (can be called by "print" on the command line)
addExecutionUnit(ToolConstants.WF_PRETTY_PRINT, new MontiSecArcPrettyPrintWorkflow(LANGUAGE_ROOT));
}
/**
......
......@@ -49,7 +49,6 @@ public class MontiSecArcAnalysisTool extends ETSTool {
*/
protected static String getAnalysisConfPath(String[] arguments) {
boolean confpathExists = false;
for(String argument : arguments) {
if(argument.equals(MontiSecArcConstants.ARG_ANALYSISCONFPATH)) {
confpathExists = true;
......@@ -73,7 +72,7 @@ public class MontiSecArcAnalysisTool extends ETSTool {
List<String> analysisParameter = new ArrayList<String>();
for(String argument : arguments) {
//Search for beginning of parameters
if(argument.equals(MontiSecArcConstants.ANALYSIS_WORKFLOW_BEGINNERS) || argument.equals(MontiSecArcConstants.ANALYSIS_WORKFLOW_ADVANCED)) {
if(argument.equals(MontiSecArcConstants.FILTER_TRUSTLEVEL)) {
isAnalysisParameter = true;
continue;
}
......@@ -101,8 +100,8 @@ public class MontiSecArcAnalysisTool extends ETSTool {
List<String> cleanedArguments = new ArrayList<String>();
boolean isAnalysisParameter = false;
boolean isAnalysisConfPath = false;
for(String argument : arguments) {
if(argument.equals(MontiSecArcConstants.ANALYSIS_WORKFLOW_BEGINNERS) || argument.equals(MontiSecArcConstants.ANALYSIS_WORKFLOW_ADVANCED)) {
for(String argument : arguments) {
if(argument.equals(MontiSecArcConstants.FILTER_TRUSTLEVEL)) {
isAnalysisParameter = true;
cleanedArguments.add(argument);
continue;
......
......@@ -23,7 +23,6 @@ import java.util.List;
import mc.MCG;
import mc.Parameters;
import mc.ProblemReport.Type;
/**
* Tool for {@link MontiSecArcAnalysis}.
......@@ -119,7 +118,6 @@ public class WrapperMontiSecArcAnalysisTool extends MontiSecArcAnalysisTool {
Constructor<WrapperMontiSecArcAnalysisTool> constructor = toolClass.getConstructor(String[].class);
args = argsAsList.toArray(new String[argsAsList.size()]);
tool = constructor.newInstance((Object) args);
tool.setErrorLevel(Type.WARNING);
}
catch (Exception e) {
e.printStackTrace();
......
......@@ -86,6 +86,7 @@ public class AnalysisCriticalPortTransformationWorkflow<T extends MontiSecArcRoo
//Delete all nodes which are not needed
for(UMLPNode node : visitorTransform.getRemoveNodes()) {
node.delete();
// resolver.resolve(node.get, expectedKind, nsp)
}
}
......
package secarc;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ MontiSecArcAnalysisTest.class,
MontiSecArcAnalysisTransformationCriticalPortTest.class,
MontiSecArcAnalysisTransformationTrustlevelTest.class,
MontiSecArcAnalysisWhatIfCiritcalPortTest.class,
MontiSecArcAnalysisWhatIfCiritcalPortTrustlevelTest.class,
MontiSecArcAnalysisWhatIfTrustlevelTest.class })
public class AllTests {
}
......@@ -14,7 +14,6 @@ import mc.ProblemReport;
import org.junit.Test;
import secarc.error.MontiSecArcAnalysisErrorCodes;
import secarc.ets.check.MontiSecArcContextConditionConstants;
/**
......
......@@ -58,10 +58,10 @@ public class MontiSecArcAnalysisTransformationTrustlevelTest extends TestWithSym
if(entry != null) {
assertEquals(true, ((SecComponentEntry) entry).getTrustlevel().isPresent());
assertEquals(1, ((SecComponentEntry) entry).getTrustlevel().get().getValue());
assertEquals(true, ((SecComponentEntry) entry).getTrustlevel().get().isPositive());
assertEquals(false, ((SecComponentEntry) entry).getTrustlevel().get().isPositive());
}
assertEquals(5, handler.getWarnings().size());
assertEquals(6, handler.getWarnings().size());
}
/**
......@@ -90,7 +90,9 @@ public class MontiSecArcAnalysisTransformationTrustlevelTest extends TestWithSym
}
}
if(entry != null) {
assertEquals(false, ((SecComponentEntry) entry).getTrustlevel().isPresent());
assertEquals(true, ((SecComponentEntry) entry).getTrustlevel().isPresent());
assertEquals(1, ((SecComponentEntry) entry).getTrustlevel().get().getValue());
assertEquals(false, ((SecComponentEntry) entry).getTrustlevel().get().isPositive());
}
assertEquals(2, handler.getWarnings().size());
......@@ -213,7 +215,7 @@ public class MontiSecArcAnalysisTransformationTrustlevelTest extends TestWithSym
}
assertEquals(null, entry);
assertEquals(5, handler.getWarnings().size());
assertEquals(6, handler.getWarnings().size());
}
protected ComponentEntry existComponent(String parameter, NameSpace np) throws AmbigousException {
......
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._tool.MontiSecArcRoot;
import secarc.error.MontiSecArcAnalysisErrorCodes;
import secarc.ets.transform.criticalport.PreAnalysisCriticalPortTransformationVisitor;
public class MontiSecArcAnalysisWhatIfCiritcalPortTrustlevelTest extends TestWithSymtabAnalysis<MontiSecArcAnalysisTestTool> {
/**
*
*/
public MontiSecArcAnalysisWhatIfCiritcalPortTrustlevelTest() {
super(MontiSecArcAnalysisTestTool.class, new String[] { "gen/conv" });
}
/**
* Tests for Connetors
*/
@Test
public void testConnectorWhatIf() {
//First file
System.out.println("EncryptedPathEndInLowTrustlevel.secarc");
MontiSecArcAnalysisTestTool tool = createTestToolWithoutJavaWhatIfCiritcalPortTrustlevel(new String[] { "src/test/resources/secarc/analysis/connector/EncryptedPathEndInLowTrustlevel.secarc" }, "secarc.analysis.connector.EncryptedPathEndInLowTrustlevel.TargetHelp");
tool.init();
assertTrue(tool.run());
List<MontiSecArcAnalysisErrorCodes> errorCodes = new ArrayList<MontiSecArcAnalysisErrorCodes>();
errorCodes.add(MontiSecArcAnalysisErrorCodes.ListIncomingtPorts);
errorCodes.add(MontiSecArcAnalysisErrorCodes.EncryptedPathEndInLowTrustlevel);
errorCodes.add(MontiSecArcAnalysisErrorCodes.ListThirdPartyComponents);
errorCodes.add(MontiSecArcAnalysisErrorCodes.ReasonDifferingTrustlevel);
errorCodes.add(MontiSecArcAnalysisErrorCodes.TaintTracking);
assertEquals(1, handler.getWarnings().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
}
/**
* Test preTransformation with a critical port
*/
@Test
public void testPreTranformationCriticalPortWithCriticalPort() {
//First File
System.out.println("CriticalPort.secarc");
MontiSecArcAnalysisTestTool tool = createTestToolWithoutJavaWhatIfCiritcalPortTrustlevel(new String[] { "src/test/resources/secarc/analysis/criticalport/CriticalPort.secarc" }, "secarc.analysis.criticalport.CriticalPort");
tool.init();
assertTrue(tool.run());
MontiSecArcRoot root= (MontiSecArcRoot) initSymtabForRoot(tool, "secarc.analysis.criticalport.CriticalPort");
//Elements which are needed for analysis
PreAnalysisCriticalPortTransformationVisitor preVisitor = new PreAnalysisCriticalPortTransformationVisitor();
preVisitor.setResolver(resolver);
preVisitor.setNodesToNameSpaces(nodesToNameSpaces);
InheritanceVisitor.run(preVisitor, root.getAst());
assertEquals(4, preVisitor.getEntries().size());
}
}
......@@ -38,7 +38,7 @@ public class MontiSecArcAnalysisWhatIfTrustlevelTest extends TestWithSymtabAnaly
errorCodes.add(MontiSecArcAnalysisErrorCodes.ReasonDifferingTrustlevel);
errorCodes.add(MontiSecArcAnalysisErrorCodes.TaintTracking);
assertEquals(5, handler.getWarnings().size());
assertEquals(6, handler.getWarnings().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
......@@ -51,7 +51,7 @@ public class MontiSecArcAnalysisWhatIfTrustlevelTest extends TestWithSymtabAnaly
tool.init();
assertTrue(tool.run());
assertEquals(3, handler.getWarnings().size());
assertEquals(4, handler.getWarnings().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
......@@ -64,7 +64,7 @@ public class MontiSecArcAnalysisWhatIfTrustlevelTest extends TestWithSymtabAnaly
tool.init();
assertTrue(tool.run());
assertEquals(6, handler.getWarnings().size());
assertEquals(7, handler.getWarnings().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
......@@ -77,7 +77,7 @@ public class MontiSecArcAnalysisWhatIfTrustlevelTest extends TestWithSymtabAnaly
tool.init();
assertTrue(tool.run());
assertEquals(3, handler.getWarnings().size());
assertEquals(4, handler.getWarnings().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
......@@ -113,7 +113,7 @@ public class MontiSecArcAnalysisWhatIfTrustlevelTest extends TestWithSymtabAnaly
tool.init();
assertTrue(tool.run());
assertEquals(2, handler.getWarnings().size());
assertEquals(3, handler.getWarnings().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
......@@ -175,7 +175,7 @@ public class MontiSecArcAnalysisWhatIfTrustlevelTest extends TestWithSymtabAnaly
errorCodes.add(MontiSecArcAnalysisErrorCodes.RoleAccess);
errorCodes.add(MontiSecArcAnalysisErrorCodes.ListThirdPartyComponents);
assertEquals(11, handler.getWarnings().size());
assertEquals(13, handler.getWarnings().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
......@@ -246,7 +246,7 @@ public class MontiSecArcAnalysisWhatIfTrustlevelTest extends TestWithSymtabAnaly
errorCodes.add(MontiSecArcAnalysisErrorCodes.DerivedRolesPort);
errorCodes.add(MontiSecArcAnalysisErrorCodes.RoleAccess);
assertEquals(5, handler.getWarnings().size());
assertEquals(6, handler.getWarnings().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
......@@ -272,7 +272,7 @@ public class MontiSecArcAnalysisWhatIfTrustlevelTest extends TestWithSymtabAnaly
tool.init();
assertTrue(tool.run());
assertEquals(2, handler.getWarnings().size());
assertEquals(3, handler.getWarnings().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
......@@ -331,7 +331,7 @@ public class MontiSecArcAnalysisWhatIfTrustlevelTest extends TestWithSymtabAnaly
errorCodes.add(MontiSecArcAnalysisErrorCodes.TrustlevelForTrustlevelrelation);
errorCodes.add(MontiSecArcAnalysisErrorCodes.DerivedTrustlevel);
assertEquals(4, handler.getWarnings().size());
assertEquals(5, handler.getWarnings().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
......
......@@ -22,6 +22,7 @@ import interfaces2.language.ETSTool;
import mc.Parameters;
import mc.ProblemReport.Type;
import mc.umlp.arcd.TestWithSymtab;
import mc.umlp.arcd.ToolConstants;
/**
* Helper class to setup tests with a symbol table.
......@@ -100,7 +101,7 @@ public class TestWithSymtabAnalysis<T extends ETSTool> extends
ARG_SYNTHESIS, Parameters.ALL, WF_RUN_CHECK,
//Uses analysis workflow
MontiSecArcConstants.ARG_ANALYSISCONFPATH, "/home/user/workspace/MA-Paff/03.Implementierung/montiSecArcAnalysis/src/main/conf/Analysis_Conf.txt",
ARG_SYNTHESIS, "secarc", MontiSecArcConstants.FILTER_TRUSTLEVEL,
ARG_SYNTHESIS, "secarc", MontiSecArcConstants.FILTER_TRUSTLEVEL, whatIfElement,
ARG_SYNTHESIS, "secarc", MontiSecArcConstants.ANALYSIS_WORKFLOW_BEGINNERS,};
List<String> argsAsList = new LinkedList<String>();
argsAsList.addAll(Arrays.asList(args));
......@@ -162,5 +163,46 @@ public class TestWithSymtabAnalysis<T extends ETSTool> extends
}
return tool;
}
protected T createTestToolWithoutJavaWhatIfCiritcalPortTrustlevel(String[] files, String whatIfElement, String... additionalModelPath) {
String[] args = new String[] {
ARG_MODELPATH, "src/main/java",
ARG_CONF, "mc-test.cfg",
ARG_OUT, OUTPUT_TEST_FOLDER,
ARG_SYMTABDIR, SYMTAB_FOLDER,
ARG_ANALYSIS, Parameters.ALL, WF_PARSE,
ARG_ANALYSIS, Parameters.ALL, WF_INIT_SYMTAB,
ARG_ANALYSIS, Parameters.ALL, WF_CREATE_SYMTAB,
ARG_SYNTHESIS, Parameters.ALL, WF_INIT_CHECK,
ARG_SYNTHESIS, "arcd", WF_PRE_CHECK_TRAFO,
ARG_SYNTHESIS, Parameters.ALL, WF_RUN_CHECK,
//Uses analysis workflow
MontiSecArcConstants.ARG_ANALYSISCONFPATH, "/home/user/workspace/MA-Paff/03.Implementierung/montiSecArcAnalysis/src/main/conf/Analysis_Conf.txt",
ARG_SYNTHESIS, "secarc", MontiSecArcConstants.FILTER_TRUSTLEVEL, whatIfElement,
ARG_SYNTHESIS, "secarc", MontiSecArcConstants.FILTER_CRITICAL_PORT,
ARG_SYNTHESIS, "secarc", MontiSecArcConstants.ANALYSIS_WORKFLOW_BEGINNERS,
ARG_SYNTHESIS, "secarc", ToolConstants.WF_PRETTY_PRINT,};
List<String> argsAsList = new LinkedList<String>();
argsAsList.addAll(Arrays.asList(args));
for (String mp : additionalModelPath) {
argsAsList.add(ARG_MODELPATH);
argsAsList.add(mp);
}
for (String file : files) {
argsAsList.add(file);
}
T tool = null;
try {
Constructor<T> constructor = toolClass.getConstructor(String[].class);
args = argsAsList.toArray(new String[argsAsList.size()]);
tool = constructor.newInstance((Object) args);
tool.setErrorLevel(Type.WARNING);
}
catch (Exception e) {
e.printStackTrace();
}
return tool;
}
}
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