Index: fedd/abac-src/rbtm/test/TestEngine.java
===================================================================
--- fedd/abac-src/rbtm/test/TestEngine.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/test/TestEngine.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,223 @@
+package edu.stanford.peer.rbtm.test;
+
+import java.io.*;
+import java.util.*;
+
+import edu.stanford.peer.rbtm.RBTMConstants;
+import edu.stanford.peer.rbtm.engine.*;
+import edu.stanford.peer.rbtm.credential.*;
+import edu.stanford.peer.rbtm.util.*;
+
+public class TestEngine implements RBTMConstants {
+
+    static HashSet credSet;
+
+    static GraphEngine mgr, oppoEngine, sensEngine, simpEngine;
+
+    static PrintStream out, oppoOut, sensOut, simpOut;
+
+    static String outPrefix = "frontier";
+
+    static void createOutput(String prefix) {
+	if(prefix == null || prefix.length() == 0) 
+	    prefix = outPrefix;
+	try {
+	    out = new PrintStream(new FileOutputStream(prefix + "-cred.txt"));
+	oppoOut = new PrintStream(new FileOutputStream(prefix + "-oppo.txt"));
+	sensOut = new PrintStream(new FileOutputStream(prefix + "-sens.txt"));
+	simpOut = new PrintStream(new FileOutputStream(prefix + "-simp.txt"));
+	}
+	catch(Exception ex) {
+	    ex.printStackTrace();
+	}
+    }
+
+    static void parseSection(BufferedReader in, HashMap conf) 
+	throws Exception {
+	HashSet set = new HashSet();
+	String name = null;
+	try {
+	    String heading = in.readLine();
+	    while(heading.startsWith("#")) {
+		System.out.println("Skipping over: " + heading);
+		heading = in.readLine();
+	    }
+	    StringTokenizer st = new StringTokenizer(heading, "[]");
+	    name = st.nextToken().trim();
+	    System.out.println("Processing section " + name);
+	    conf.put(name, set);
+	    while(true) {
+		String line = in.readLine().trim();
+		if(line.length() < 1)
+		    return;
+		if(!line.startsWith("#")) {
+		    System.out.println("line = '" + line + "'");
+		    set.add(line);
+		}
+	    }
+	}
+	catch(EOFException eof) {
+	    conf.put(name, set);
+	    throw eof;
+	}
+	catch(Exception ex) {
+	    //ex.printStackTrace();
+	    throw(ex);
+	}
+    }
+
+    public static HashMap loadConfiguration(String name) {
+	HashMap confMap = new HashMap(6);
+	try {
+	    BufferedReader in = new BufferedReader(new FileReader(name));
+	    while(true) {
+		parseSection(in, confMap);
+	    }
+	}
+	catch(Exception ex) {
+	    //ex.printStackTrace();
+	    return confMap;
+	}
+    }
+
+
+    static HashSet loadCredentials(HashMap confs) {
+	HashSet credSet = new HashSet();
+
+	try {
+	    Iterator i = ((HashSet)confs.get("credentials")).iterator();
+	    while(i.hasNext()) {
+		credSet.add(new StaticCredential((String)i.next()));
+	    }
+	}
+	catch(Exception ex) {
+	    //ex.printStackTrace();
+	    return credSet;
+	}
+	return credSet;
+    }
+    
+    static HashSet loadTraceable(HashMap conf) {
+	HashSet names = new HashSet();
+
+	try {
+	    Iterator i = ((HashSet)conf.get("traceable")).iterator();
+	    while(i.hasNext()) {
+		names.add(new SimpleRoleName((String)i.next()));
+	    }
+	}
+	catch(Exception ex) {
+	    ex.printStackTrace();
+	    return names;
+	}
+	System.out.println("traceable: " + names);
+	return names;
+    }
+
+    static HashSet loadSensitive(HashMap conf) {
+	HashSet sens = new HashSet();
+
+	try {
+	    Iterator i = ((HashSet)conf.get("sensitive")).iterator();
+	    while(i.hasNext()) {
+		sens.add(StaticCredential.getRole((String)i.next()));
+	    }
+	}
+	catch(Exception ex) {
+	    ex.printStackTrace();
+	    return sens;
+	}
+	System.out.println("sensitive: " + sens);
+	return sens;
+    }
+
+
+    static void createEngines(HashMap conf) {
+	Oppo oppo = new Oppo(new Vector(loadTraceable(conf)));
+	Sens sens = new Sens(new Vector(loadSensitive(conf)));
+	Simp simp = new Simp();
+	int track = TRACK_ALL;
+
+	System.out.println("------> Credential Graph");
+	mgr = new GraphEngine(credSet, track, null, null);
+	System.out.println("------> Opponent Graph");
+	oppoEngine = new GraphEngine(credSet, track, null, oppo);
+	System.out.println("------> Sensitive Graph");
+	sensEngine = new GraphEngine(credSet, track, null, sens);
+	System.out.println("------> Simple Graph");
+	simpEngine = new GraphEngine(credSet, track, null, simp);
+     }
+
+    static void searchExpression
+        (EntityExpression child, GraphEngine graph, PrintStream out) {
+        ResultEvidenceMap map = graph.backwardSearch(child);
+        Iterator i = map.resultSet().iterator();
+        while(i.hasNext()) {
+            EntityExpression ancestor = (EntityExpression)i.next();
+            HashSet chain = graph.getChain(child, ancestor);
+            Iterator credentials = chain.iterator();
+
+            out.println("Credential chain for" + child + "<--" + ancestor );
+            while(credentials.hasNext()) {
+                out.print("\t");
+                out.println(credentials.next());
+            }
+        }
+    }
+
+    static void searchExpression(EntityExpression expr) {
+	System.out.println("[cred for " + expr + "]");
+	out.println("Credential Graph of  " + expr + " = " +
+				   mgr.backwardSearch(expr));
+    searchExpression(expr, mgr, out);
+	System.out.println("[oppo for " + expr + "]");
+	oppoOut.println("Oppo Frontier of  " + expr + " = " +
+				   oppoEngine.backwardSearch(expr));
+	oppoOut.println("[oppo chains for " + expr + "]");
+    searchExpression(expr, oppoEngine, oppoOut);
+	System.out.println("[sens for " + expr + "]");
+	sensOut.println("Sens Frontier of  " + expr + " = " +
+				   sensEngine.backwardSearch(expr));
+	sensOut.println("[sens chains for " + expr + "]");
+    searchExpression(expr, sensEngine, sensOut);
+	System.out.println("[simp for " + expr + "]");
+	simpOut.println("Simp Frontier of  " + expr + " = " +
+				   simpEngine.backwardSearch(expr));
+	simpOut.println("[simp chains for " + expr + "]");
+    searchExpression(expr, sensEngine, sensOut);
+    }
+
+    static void performSearches(HashMap conf) {
+	String line;
+	EntityExpression expr;
+	
+	try {
+	    Iterator i = ((HashSet)conf.get("searches")).iterator();
+	    while(i.hasNext()) {
+		expr = StaticCredential.getEntityExpression
+		    (((String)i.next()).trim());
+		searchExpression(expr);
+	    }
+	}
+	catch(Exception ex) {
+	    ex.printStackTrace();
+	}
+	
+    }
+
+
+
+
+    public static void main(String arg[]) {
+	HashMap conf = loadConfiguration((arg.length > 0)?arg[0]:"abac.conf");
+	credSet = loadCredentials(conf);
+
+	createEngines(conf);
+	createOutput("frontier");
+	performSearches(conf);
+    }
+
+}
+ 
+
+
