Commit 8517e505 authored by Jonathan Shahen's avatar Jonathan Shahen

Skeleton code for Timeinterval Reduction

Changed Commandline Options to a ENUM for better organization and to make sure that strings aren't misspelt
parent 8715e660
......@@ -17,7 +17,8 @@ import mohawk.converter.logging.MohawkConsoleFormatter;
import mohawk.converter.logging.MohawkTiming;
import mohawk.converter.to.asaptime.ConvertToASAPTimeNSA;
import mohawk.converter.to.mohawk.ConvertToMohawk;
import mohawk.converter.to.tred.ConvertToTRedRule;
import mohawk.converter.to.tred.ConvertToTRule;
import mohawk.global.pieces.MohawkT;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
......@@ -44,6 +45,25 @@ public class ConverterInstance {
public SpecHelper specHelper = new SpecHelper();
public MohawkTiming timing = new MohawkTiming();
public enum OptionString {
HELP("help"), AUTHORS("authors"), VERSION("version"), CHECKNUSMV("checknusmv"), LOGLEVEL("loglevel"), LOGFILE(
"logfile"), LOGFOLDER("logfolder"), NOHEADER("noheader"), RESULTSFILE("output"), MAXW("maxw"), LINESTR(
"linstr"), SPECFILE("input"), SPECEXT("specext"), BULK("bulk"), TO_ASAPTIME_NSA("to_asaptime_nsa"), TO_ASAPTIME_SA(
"to_asaptime_sa"), TO_TROLE("to_trole"), TO_TRULE("to_trule"), TO_MOHAWK("to_mohawk"), TO_MOHAWK_T(
"to_mohawk_t"), TO_ALL("to_all");
private String _str;
private OptionString(String s) {
_str = s;
}
@Override
public String toString() {
return _str;
}
}
public int run(String[] args) {
try {
Options options = new Options();
......@@ -83,6 +103,8 @@ public class ConverterInstance {
MohawkTARBACParser parser = specHelper.parseSpecFile(specFile);
/* Timing */timing.stopTimer("parseFile (" + i + ")");
MohawkT m = parser.mohawkT;
if (specHelper.error.errorFound) {
logger.warning("[PARSING ERROR] Skipping this file due to a parsing error");
continue;
......@@ -90,12 +112,13 @@ public class ConverterInstance {
logger.info("No errors found while parsing file, continuing on to converting");
}
if (cmd.hasOption("to_ranise") || cmd.hasOption("to_all")) {
if (cmd.hasOption(OptionString.TO_ASAPTIME_NSA.toString())
|| cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to Rainse...");
/* Timing */timing.startTimer("convertToRanise (" + i + ")");
ConvertToASAPTimeNSA toRanise = new ConvertToASAPTimeNSA();
String raniseStr = toRanise.convert(parser, specFile, true);
String raniseStr = toRanise.convert(m, specFile, true);
if (toRanise.lastError == null) {
logger.info("[SUCCESS] Successfully converted to Ranise's Input Format");
......@@ -110,13 +133,13 @@ public class ConverterInstance {
logger.info("[SKIP] Skipping converting to Ranise");
}
if (cmd.hasOption("to_uzun") || cmd.hasOption("to_all")) {
if (cmd.hasOption(OptionString.TO_TROLE.toString()) || cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to Uzun...");
/* Timing */timing.startTimer("convertToUzun (" + i + ")");
// TODO: Convert imported spec files to Uzun format
ConvertToTRedRule toUzun = new ConvertToTRedRule();
String uzunStr = toUzun.convert(parser, specFile, true);
ConvertToTRule toUzun = new ConvertToTRule();
String uzunStr = toUzun.convert(m, specFile, true);
if (toUzun.lastError == null) {
logger.info("[SUCCESS] Successfully converted to Uzun's Input Format");
......@@ -131,13 +154,13 @@ public class ConverterInstance {
logger.info("[SKIP] Skipping converting to Uzun");
}
if (cmd.hasOption("to_mohawk") || cmd.hasOption("to_all")) {
if (cmd.hasOption(OptionString.TO_MOHAWK.toString()) || cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to Mohawk...");
/* Timing */timing.startTimer("convertToMohawk (" + i + ")");
// TODO: Convert imported spec files to Mohawk format
ConvertToMohawk toMohawk = new ConvertToMohawk();
String mohawkStr = toMohawk.convert(parser, specFile, true);
String mohawkStr = toMohawk.convert(m, specFile, true);
if (toMohawk.lastError == null) {
logger.info("[SUCCESS] Successfully converted to Mohawk's Input Format");
......@@ -192,10 +215,10 @@ public class ConverterInstance {
@SuppressWarnings("static-access")
public void setupOptions(Options options) {
// Add Information Options
options.addOption("help", false, "Print this message");
options.addOption("authors", false, "Prints the authors");
options.addOption("version", false, "Prints the version (" + VERSION + ") information");
options.addOption("checknusmv", false,
options.addOption(OptionString.HELP.toString(), false, "Print this message");
options.addOption(OptionString.AUTHORS.toString(), false, "Prints the authors");
options.addOption(OptionString.VERSION.toString(), false, "Prints the version (" + VERSION + ") information");
options.addOption(OptionString.CHECKNUSMV.toString(), false,
"Checks that NuSMV is on the system and displays which version is installed");
// Add Logging Level Options
......@@ -204,7 +227,7 @@ public class ConverterInstance {
.withDescription(
"Be extra quiet only errors are shown; " + "Show debugging information; "
+ "extra information is given for Verbose; " + "default is warning level").hasArg()
.create("loglevel"));
.create(OptionString.LOGLEVEL.toString()));
options.addOption(OptionBuilder
.withArgName("logfile|'n'|'u'")
.withDescription(
......@@ -212,38 +235,54 @@ public class ConverterInstance {
+ "No file will be created when equal to 'n'; "
+ "A unique filename will be created when equal to 'u'; "
+ "default it creates a log called '" + Logger_filepath + "'").hasArg()
.create("output"));
options.addOption("noheader", false, "Does not write the CSV file header to the output log");
.create(OptionString.LOGFILE.toString()));
options.addOption(OptionBuilder
.withArgName("folder path")
.withDescription(
"The path to the location that the logs should be placed, "
+ "default it puts the logs in the folder '" + Logger_folderpath + "'").hasArg()
.create(OptionString.LOGFOLDER.toString()));
options.addOption(OptionString.NOHEADER.toString(), false,
"Does not write the CSV file header to the output log");
options.addOption(OptionBuilder.withArgName("csvfile")
.withDescription("The file where the result should be stored").hasArg().create("results"));
.withDescription("The file where the result should be stored").hasArg()
.create(OptionString.RESULTSFILE.toString()));
// custom Console Logging Options
options.addOption(OptionBuilder.withArgName("num")
.withDescription("The maximum width of the console (default 120)").hasArg().create("maxw"));
.withDescription("The maximum width of the console (default 120)").hasArg()
.create(OptionString.MAXW.toString()));
options.addOption(OptionBuilder.withArgName("string")
.withDescription("The new line string when wrapping a long line (default '\\n ')").hasArg()
.create("linestr"));
.create(OptionString.LINESTR.toString()));
// Add File IO Options
options.addOption(OptionBuilder.withArgName("file|folder")
.withDescription("Path to the RBAC Spec file or Folder if the 'bulk' option is set").hasArg()
.create("rbacspec"));
.withDescription("Path to the Mohawk-T Spec File, or Folder if the 'bulk' option is set").hasArg()
.create(OptionString.SPECFILE.toString()));
options.addOption(OptionBuilder
.withArgName("extension")
.withDescription(
"File extention used when searching for SPEC files when the 'bulk' option is used. Default:'"
+ specHelper.specFileExt + "'").hasArg().create("specext"));
+ specHelper.specFileExt + "'").hasArg().create(OptionString.SPECEXT.toString()));
// Add Functional Options
options.addOption("bulk", false, "Use the folder that rbacspec points to and run against all *.spec");
options.addOption("to_ranise", false, "Convert input SPEC file to Ranise's format");
options.addOption("to_uzun", false, "Convert input SPEC file to Uzun's format");
options.addOption("to_mohawk", false, "Convert input SPEC file to Mohawk's RBAC format");
options.addOption("to_all", false, "Convert input SPEC file to All formats (Mohawk, Ranise, Uzun)");
options.addOption(OptionString.BULK.toString(), false,
"Use the folder that rbacspec points to and run against all *.spec");
options.addOption(OptionString.TO_ASAPTIME_NSA.toString(), false,
"Convert input SPEC file to ASAPTime NSA format");
options.addOption(OptionString.TO_ASAPTIME_SA.toString(), false,
"Convert input SPEC file to ASAPTime SA format");
options.addOption(OptionString.TO_TROLE.toString(), false, "Convert input SPEC file to TRole format");
options.addOption(OptionString.TO_TRULE.toString(), false, "Convert input SPEC file to TRule format");
options.addOption(OptionString.TO_MOHAWK.toString(), false, "Convert input SPEC file to Mohawk's ARBAC format");
options.addOption(OptionString.TO_MOHAWK_T.toString(), false,
"Convert input SPEC file to Mohawk-T's ATRBAC format");
options.addOption(OptionString.TO_ALL.toString(), false,
"Convert input SPEC file to All formats except Mohawk-T (Mohawk, ASAPTime NSA, ASAPTime SA, TRole, TRule)");
}
public Level getLoggerLevel() {
......@@ -258,9 +297,9 @@ public class ConverterInstance {
// Logging Level
logger.setUseParentHandlers(false);
consoleHandler.setFormatter(new MohawkConsoleFormatter());
setLoggerLevel(Level.WARNING); // Default Level
if (cmd.hasOption("loglevel")) {
String loglevel = cmd.getOptionValue("loglevel");
setLoggerLevel(Level.INFO); // Default Level
if (cmd.hasOption(OptionString.LOGLEVEL.toString())) {
String loglevel = cmd.getOptionValue(OptionString.LOGLEVEL.toString());
if (loglevel.equalsIgnoreCase("quiet")) {
setLoggerLevel(Level.SEVERE);
} else if (loglevel.equalsIgnoreCase("debug")) {
......@@ -275,38 +314,29 @@ public class ConverterInstance {
logger.addHandler(consoleHandler);
// Add CSV File Headers
if (cmd.hasOption("noheader")) {
if (cmd.hasOption(OptionString.NOHEADER.toString())) {
WriteCSVFileHeader = false;
}
// Set Logger Folder
if (cmd.hasOption("logfolder")) {
File logfile = new File(cmd.getOptionValue("logfolder"));
if (!logfile.exists()) {
logfile.mkdir();
}
if (logfile.isDirectory()) {
Logger_folderpath = cmd.getOptionValue("logfolder");
} else {
logger.severe("logfolder did not contain a folder that exists or that could be created!");
}
if (cmd.hasOption(OptionString.LOGFOLDER.toString())) {
Logger_folderpath = cmd.getOptionValue(OptionString.LOGFOLDER.toString());
}
// Set File Logger
if (cmd.hasOption("logfile")) {
if (cmd.hasOption(OptionString.LOGFILE.toString())) {
// Check if no log file was requested
if (cmd.getOptionValue("logfile").equals("n")) {
if (cmd.getOptionValue(OptionString.LOGFILE.toString()).equals("n")) {
// Create no log file
Logger_filepath = "";
} else if (cmd.getOptionValue("logfile").equals("u")) {
} else if (cmd.getOptionValue(OptionString.LOGFILE.toString()).equals("u")) {
// Create a unique log file
Logger_filepath = "mohawk-log.%u.%g.txt";
} else {
try {
// Create a log file with a specific name
File logfile = new File(Logger_folderpath + File.separator + cmd.getOptionValue("logfile"));
File logfile = new File(Logger_folderpath + File.separator
+ cmd.getOptionValue(OptionString.LOGFILE.toString()));
if (!logfile.exists()) {
logfile.createNewFile();
......@@ -328,6 +358,14 @@ public class ConverterInstance {
}
// Add Logger File Handler
if (!Logger_filepath.isEmpty()) {
File logfile = new File(cmd.getOptionValue(OptionString.LOGFOLDER.toString()));
logfile.mkdirs();
if (logfile.isDirectory()) {
Logger_folderpath = cmd.getOptionValue(OptionString.LOGFOLDER.toString());
} else {
logger.severe("logfolder did not contain a folder that exists or that could be created!");
}
fileHandler = new FileHandler(Logger_folderpath + File.separator + Logger_filepath);
fileHandler.setLevel(getLoggerLevel());
fileHandler.setFormatter(new MohawkCSVFileFormatter());
......@@ -336,18 +374,18 @@ public class ConverterInstance {
}
private Boolean setupReturnImmediatelyOptions(CommandLine cmd, Options options) throws Exception {
if (cmd.hasOption("help") == true || cmd.getOptions().length == 0) {
if (cmd.hasOption(OptionString.HELP.toString()) == true || cmd.getOptions().length == 0) {
printHelp(cmd, options);
return true;
}
if (cmd.hasOption("version")) {
if (cmd.hasOption(OptionString.VERSION.toString())) {
// keep it as simple as possible for the version
System.out.println(VERSION);
return true;
}
if (cmd.hasOption("authors")) {
if (cmd.hasOption(OptionString.AUTHORS.toString())) {
// keep it as simple as possible for the version
System.out.println(AUTHORS);
return true;
......@@ -358,22 +396,23 @@ public class ConverterInstance {
private void setupSpecOptions(CommandLine cmd, Options options) {
// Grab the SPEC file
if (cmd.hasOption("rbacspec")) {
logger.fine("[OPTION] Using a specific SPEC File: " + cmd.getOptionValue("rbacspec"));
specHelper.specFile = cmd.getOptionValue("rbacspec");
if (cmd.hasOption(OptionString.SPECFILE.toString())) {
logger.fine("[OPTION] Using a specific SPEC File: " + cmd.getOptionValue(OptionString.SPECFILE.toString()));
specHelper.specFile = cmd.getOptionValue(OptionString.SPECFILE.toString());
} else {
logger.fine("[OPTION] No Spec File included");
}
if (cmd.hasOption("specext")) {
logger.fine("[OPTION] Using a specific SPEC File Extension: " + cmd.getOptionValue("specext"));
specHelper.specFileExt = cmd.getOptionValue("specext");
if (cmd.hasOption(OptionString.SPECEXT.toString())) {
logger.fine("[OPTION] Using a specific SPEC File Extension: "
+ cmd.getOptionValue(OptionString.SPECEXT.toString()));
specHelper.specFileExt = cmd.getOptionValue(OptionString.SPECEXT.toString());
} else {
logger.fine("[OPTION] Using the default SPEC File Extension: " + specHelper.specFileExt);
}
// Load more than one file from the SPEC File?
if (cmd.hasOption("bulk")) {
if (cmd.hasOption(OptionString.BULK.toString())) {
logger.fine("[OPTION] Bulk SPEC File inclusion: Enabled");
specHelper.bulk = true;
} else {
......@@ -383,11 +422,11 @@ public class ConverterInstance {
private void setupUserPreferenceOptions(CommandLine cmd, Options options) {
// Set the Console's Max Width
if (cmd.hasOption("maxw")) {
if (cmd.hasOption(OptionString.MAXW.toString())) {
logger.fine("[OPTION] Setting the console's maximum width");
String maxw = "";
try {
maxw = cmd.getOptionValue("maxw");
maxw = cmd.getOptionValue(OptionString.MAXW.toString());
((MohawkConsoleFormatter) consoleHandler.getFormatter()).maxWidth = Integer.decode(maxw);
} catch (NumberFormatException e) {
logger.severe("[ERROR] Could not decode 'maxw': " + maxw + ";\n" + e.getMessage());
......@@ -397,9 +436,10 @@ public class ConverterInstance {
}
// Set the Console's Wrap String
if (cmd.hasOption("linestr")) {
if (cmd.hasOption(OptionString.LINESTR.toString())) {
logger.fine("[OPTION] Setting the console's new line string");
((MohawkConsoleFormatter) consoleHandler.getFormatter()).newLineStr = cmd.getOptionValue("linestr");
((MohawkConsoleFormatter) consoleHandler.getFormatter()).newLineStr = cmd
.getOptionValue(OptionString.LINESTR.toString());
} else {
logger.fine("[OPTION] Default Line String Used");
}
......@@ -407,7 +447,7 @@ public class ConverterInstance {
}
private void setupResultOptions(CommandLine cmd, Options options) {
if (cmd.hasOption("results")) {
if (cmd.hasOption(OptionString.RESULTSFILE.toString())) {
logger.fine("[OPTION] Changing the results file");
resultsFile = cmd.getOptionValue("results");
}
......
......@@ -28,17 +28,7 @@ import mohawk.global.helper.*;
int tabsize = 1;
/* Global States */
public RoleHelper roleHelper = new RoleHelper();
public TimeIntervalHelper timeIntervalHelper = new TimeIntervalHelper();
/* Blocks */
public CanAssign canAssign = new CanAssign();
public CanRevoke canRevoke = new CanRevoke();
public CanEnable canEnable = new CanEnable();
public CanDisable canDisable = new CanDisable();
public Query query = new Query();
public ExpectedResult expectedResult = ExpectedResult.UNKNOWN;
public MohawkT mohawkT = new MohawkT("Mohawk Converter");
private void logmsg(String msg) {
......@@ -98,7 +88,7 @@ canassign
(
myrule [RuleType.ASSIGN]
{
canAssign.addRule($myrule.r);
mohawkT.canAssign.addRule($myrule.r);
}
)* RightBrace
......@@ -114,7 +104,7 @@ canrevoke
(
myrule [RuleType.REVOKE]
{
canRevoke.addRule($myrule.r);
mohawkT.canRevoke.addRule($myrule.r);
}
)* RightBrace
......@@ -130,7 +120,7 @@ canenable
(
myrule [RuleType.ENABLE]
{
canEnable.addRule($myrule.r);
mohawkT.canEnable.addRule($myrule.r);
}
)* RightBrace
......@@ -146,7 +136,7 @@ candisable
(
myrule [RuleType.DISABLE]
{
canDisable.addRule($myrule.r);
mohawkT.canDisable.addRule($myrule.r);
}
)* RightBrace
......@@ -158,8 +148,8 @@ query
:
Query Colon t = timeslot Comma ra = roleArray
{
query._timeslot = new TimeSlot($t.val);
query._roles = $ra.r;
mohawkT.query._timeslot = new TimeSlot($t.val);
mohawkT.query._roles = $ra.r;
}
;
......@@ -169,13 +159,13 @@ expected
Expected Colon
(
Reachable
{expectedResult = ExpectedResult.REACHABLE;}
{mohawkT.expectedResult = ExpectedResult.REACHABLE;}
| Unreachable
{expectedResult = ExpectedResult.UNREACHABLE;}
{mohawkT.expectedResult = ExpectedResult.UNREACHABLE;}
| Unknown
{expectedResult = ExpectedResult.UNKNOWN;}
{mohawkT.expectedResult = ExpectedResult.UNKNOWN;}
)
;
......@@ -290,7 +280,7 @@ timeslot returns [Integer val]
Timeslot
{
$val = new Integer($Timeslot.text.substring(1));
timeIntervalHelper.add(new TimeInterval($val));
mohawkT.timeIntervalHelper.add(new TimeInterval($val));
}
;
......@@ -301,7 +291,7 @@ myrole returns [String rolet, Role role]
{
$rolet = $MyRole.getText();
$role = new Role($rolet);
roleHelper.add($role);
mohawkT.roleHelper.add($role);
}
;
......
......@@ -15,6 +15,7 @@ import java.util.logging.Logger;
import mohawk.converter.generated.MohawkTARBACLexer;
import mohawk.converter.generated.MohawkTARBACParser;
import mohawk.global.FileExtensions;
import mohawk.global.pieces.MohawkT;
import mohawk.global.pieces.Rule;
import mohawk.global.pieces.TimeInterval;
......@@ -51,22 +52,23 @@ public class ConverterRegressionTests {
error.errorFound = false;
MohawkTARBACParser parser = loadfile(file);
MohawkT m = parser.mohawkT;
// Check for Parsing errors
assertFalse("Errors were found!", error.errorFound);
// Correct number of rules per block
assertEquals("Not the correct number of Rule in CanAssign Block", 2, parser.canAssign.size());
assertEquals("Not the correct number of Rule in CanRevoke Block", 0, parser.canRevoke.size());
assertEquals("Not the correct number of Rule in CanEnable Block", 0, parser.canEnable.size());
assertEquals("Not the correct number of Rule in CanDisable Block", 0, parser.canDisable.size());
assertEquals("Not the correct number of Rule in CanAssign Block", 2, m.canAssign.size());
assertEquals("Not the correct number of Rule in CanRevoke Block", 0, m.canRevoke.size());
assertEquals("Not the correct number of Rule in CanEnable Block", 0, m.canEnable.size());
assertEquals("Not the correct number of Rule in CanDisable Block", 0, m.canDisable.size());
// Correct number of roles and timeslots
assertEquals("Incorrect number of Roles", new Integer(4), parser.roleHelper.size());
assertEquals("Incorrect number of Roles", new Integer(4), m.roleHelper.size());
// t0, t1, t2, t5
assertEquals("Incorrect number of Timeslots", new Integer(4), parser.timeIntervalHelper.size());
assertEquals("Incorrect number of Timeslots", new Integer(4), m.timeIntervalHelper.size());
// t0, t1, t2, t5
assertEquals("Incorrect max Timeslot", new Integer(5), parser.timeIntervalHelper.maxTimeSlot);
assertEquals("Incorrect max Timeslot", new Integer(5), m.timeIntervalHelper.maxTimeSlot);
}
@Test
......@@ -76,22 +78,23 @@ public class ConverterRegressionTests {
error.errorFound = false;
MohawkTARBACParser parser = loadfile(file);
MohawkT m = parser.mohawkT;
// Check for Parsing errors
assertFalse("Errors were found!", error.errorFound);
// Correct number of rules per block
assertEquals("Not the correct number of Rule in CanAssign Block", 2, parser.canAssign.size());
assertEquals("Not the correct number of Rule in CanRevoke Block", 0, parser.canRevoke.size());
assertEquals("Not the correct number of Rule in CanEnable Block", 2, parser.canEnable.size());
assertEquals("Not the correct number of Rule in CanDisable Block", 2, parser.canDisable.size());
assertEquals("Not the correct number of Rule in CanAssign Block", 2, m.canAssign.size());
assertEquals("Not the correct number of Rule in CanRevoke Block", 0, m.canRevoke.size());
assertEquals("Not the correct number of Rule in CanEnable Block", 2, m.canEnable.size());
assertEquals("Not the correct number of Rule in CanDisable Block", 2, m.canDisable.size());
// Correct number of roles and timeslots
assertEquals("Incorrect number of Roles", new Integer(5), parser.roleHelper.size()); //
assertEquals("Incorrect number of Roles", new Integer(5), m.roleHelper.size()); //
// t0, t1, t2, t5
assertEquals("Incorrect number of Timeslots", new Integer(4), parser.timeIntervalHelper.size());
assertEquals("Incorrect number of Timeslots", new Integer(4), m.timeIntervalHelper.size());
// t0, t1, t2, t5
assertEquals("Incorrect max Timeslot", new Integer(5), parser.timeIntervalHelper.maxTimeSlot);
assertEquals("Incorrect max Timeslot", new Integer(5), m.timeIntervalHelper.maxTimeSlot);
}
@Test
......@@ -101,22 +104,23 @@ public class ConverterRegressionTests {
error.errorFound = false;
MohawkTARBACParser parser = loadfile(file);
MohawkT m = parser.mohawkT;
// Check for Parsing errors
assertFalse("Errors were found!", error.errorFound);
// Correct number of rules per block
assertEquals("Not the correct number of Rule in CanAssign Block", 3, parser.canAssign.size());
assertEquals("Not the correct number of Rule in CanRevoke Block", 0, parser.canRevoke.size());
assertEquals("Not the correct number of Rule in CanEnable Block", 2, parser.canEnable.size());
assertEquals("Not the correct number of Rule in CanDisable Block", 2, parser.canDisable.size());
assertEquals("Not the correct number of Rule in CanAssign Block", 3, m.canAssign.size());
assertEquals("Not the correct number of Rule in CanRevoke Block", 0, m.canRevoke.size());
assertEquals("Not the correct number of Rule in CanEnable Block", 2, m.canEnable.size());
assertEquals("Not the correct number of Rule in CanDisable Block", 2, m.canDisable.size());
// Correct number of roles and timeslots
assertEquals("Incorrect number of Roles", new Integer(6), parser.roleHelper.size()); //
assertEquals("Incorrect number of Roles", new Integer(6), m.roleHelper.size()); //
// t0, t1, t2, t5
assertEquals("Incorrect number of Timeslots", new Integer(4), parser.timeIntervalHelper.size());
assertEquals("Incorrect number of Timeslots", new Integer(4), m.timeIntervalHelper.size());
// t0, t1, t2, t5
assertEquals("Incorrect max Timeslot", new Integer(5), parser.timeIntervalHelper.maxTimeSlot);
assertEquals("Incorrect max Timeslot", new Integer(5), m.timeIntervalHelper.maxTimeSlot);
}
@Test
......@@ -126,10 +130,11 @@ public class ConverterRegressionTests {
error.errorFound = false;
MohawkTARBACParser parser = loadfile(file);
MohawkT m = parser.mohawkT;
// Check for Parsing errors
assertFalse("Errors were found!", error.errorFound);
ArrayList<Rule> rules = parser.canAssign.getRules();
ArrayList<Rule> rules = m.canAssign.getRules();
assertEquals("Time interval not the same for full style", new TimeInterval(0, 5),
rules.get(0)._adminTimeInterval);
......@@ -204,15 +209,17 @@ public class ConverterRegressionTests {
parser.addErrorListener(errorListener);
parser.init();
System.out.println("Roles: " + parser.roleHelper);
System.out.println("Timeslots: " + parser.timeIntervalHelper);
System.out.println("Max Timeslot: " + parser.timeIntervalHelper.maxTimeSlot);
System.out.println(parser.query.toString());
System.out.println(parser.expectedResult.toString());
System.out.println(parser.canAssign.toString());
System.out.println(parser.canDisable.toString());
System.out.println(parser.canEnable.toString());
System.out.println(parser.canRevoke.toString());
MohawkT m = parser.mohawkT;
System.out.println("Roles: " + m.roleHelper);
System.out.println("Timeslots: " + m.timeIntervalHelper);
System.out.println("Max Timeslot: " + m.timeIntervalHelper.maxTimeSlot);
System.out.println(m.query.toString());
System.out.println(m.expectedResult.toString());
System.out.println(m.canAssign.toString());
System.out.println(m.canDisable.toString());
System.out.println(m.canEnable.toString());
System.out.println(m.canRevoke.toString());
return parser;
}
......
......@@ -8,13 +8,13 @@ import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import mohawk.converter.generated.MohawkTARBACParser;
import mohawk.global.pieces.MohawkT;
public class ConvertTo {
public String convertedStr = null;
public String lastError = null;
public String convert(MohawkTARBACParser p, File f, Boolean writeToFile) {
public String convert(MohawkT m, File f, Boolean writeToFile) {
return null;
}
......
......@@ -4,4 +4,4 @@ CONFIG <numRoles> <numTimeslots>
GOAL <goalRole> <goalTimeslot>
<! can_revoke 3 , t3 , true ; t5 , 14 !>
</