1 | import java.io.*; |
---|
2 | import java.util.*; |
---|
3 | |
---|
4 | import net.deterlab.abac.*; |
---|
5 | import net.deterlab.abac.regression.*; |
---|
6 | |
---|
7 | |
---|
8 | /** |
---|
9 | * Simple test of the native Java implementation of ABAC. Loads credentials |
---|
10 | * from an rt0 file and runs a query against them. |
---|
11 | */ |
---|
12 | public class Regression { |
---|
13 | |
---|
14 | static RegressionTest[] tests = new RegressionTest[] { |
---|
15 | new WriteCreds("net.deterlab.abac.GENICredential"), |
---|
16 | new WriteCreds("net.deterlab.abac.X509Credential"), |
---|
17 | }; |
---|
18 | |
---|
19 | public static void fatal(String s) { |
---|
20 | if (s != null ) |
---|
21 | System.err.println(s); |
---|
22 | System.exit(20); |
---|
23 | } |
---|
24 | |
---|
25 | public static boolean clearDir(File d) { |
---|
26 | for (String fn: d.list() ) { |
---|
27 | File f = new File(d, fn); |
---|
28 | |
---|
29 | if ( f.isDirectory() ) |
---|
30 | if ( !clearDir(f) ) return false; |
---|
31 | if ( !f.delete() ) return false; |
---|
32 | } |
---|
33 | return true; |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | public static void main(String[] args) throws IOException { |
---|
38 | if (args.length < 2 ) |
---|
39 | fatal("Usage Regression regression_data_dir scratch"); |
---|
40 | |
---|
41 | File data = new File(args[0]); |
---|
42 | File scratch = new File(args[1]); |
---|
43 | |
---|
44 | if ( !data.isDirectory() ) |
---|
45 | fatal(data + " is not a directory"); |
---|
46 | if ( !scratch.isDirectory() ) |
---|
47 | fatal(scratch + " is not a directory"); |
---|
48 | |
---|
49 | for (RegressionTest test: tests) { |
---|
50 | if (!clearDir(scratch) ) |
---|
51 | fatal("Could not clear " + scratch); |
---|
52 | |
---|
53 | if ( test.runTest(data, scratch)) |
---|
54 | System.out.println(test.getName() + " Passed."); |
---|
55 | else |
---|
56 | fatal(test.getName() + " Failed: " + test.getReason()); |
---|
57 | } |
---|
58 | System.exit(0); |
---|
59 | } |
---|
60 | } |
---|