001 package nl.cwi.sen1.visbase.factbrowser;
002
003 import nl.cwi.sen1.tunit.TUnitTestCase;
004 import nl.cwi.sen1.tunit.ToolComValidator;
005 import aterm.ATerm;
006 import aterm.pure.PureFactory;
007
008 /**
009 * This test case tests the Fact Browser Interface Toolbus script.
010 *
011 * @author Raymond Bergen
012 * @author Srinivasan Tharmarajah
013 */
014 public class FBITBTest extends TUnitTestCase{
015
016 /**
017 * The function that contains executes all the test cases.
018 */
019 public void testFBI(){
020 MSDialogTool msDialogTool = new MSDialogTool(this, "msdialogstub", true);
021 FactBrowserTool factBrowserTool = new FactBrowserTool(this, "factbrowser", true);
022 FBMPTool fbmpTool = new FBMPTool(this, "fbmpstub", true);
023
024 Thread msDialogToolExecutor = new Thread(msDialogTool);
025 msDialogToolExecutor.setDaemon(true);
026 msDialogToolExecutor.start();
027 Thread factBrowserToolExecutor = new Thread(factBrowserTool);
028 factBrowserToolExecutor.setDaemon(true);
029 factBrowserToolExecutor.start();
030 Thread fbmpToolExecutor = new Thread(fbmpTool);
031 fbmpToolExecutor.setDaemon(true);
032 fbmpToolExecutor.start();
033
034 toolbus.waitTillShutdown();
035
036 if(hasFailed()) fail();
037
038 System.out.println("Test Passed");
039 }
040
041 protected void setUp() {
042 try{
043 startToolbus("./tbscript/", "./tbscript/init.tb");
044 }catch (Exception ex){
045 ex.printStackTrace();
046 stopToolbus();
047 fail(ex.toString());
048 }
049 }
050
051 protected void tearDown() {
052 stopToolbus();
053 }
054
055 public static class MSDialogTool extends ToolComValidator{
056 private static PureFactory factory = getFactory();
057 private final TUnitTestCase testCase;
058
059 public MSDialogTool(TUnitTestCase testCase, String name, boolean verbose){
060 super(testCase, name, verbose);
061
062 this.testCase = testCase;
063 }
064
065 public void run(){
066 try{
067 testCase.connectToolComValidator(this);
068
069 loadRstore();
070 }catch(Exception ex){
071 ex.printStackTrace();
072 }finally{
073 disconnect();
074 }
075 }
076
077 private void loadRstore(){
078 ATerm askForFileRecieved = factory.make("ask-for-file-recieved");
079 registerForDo(askForFileRecieved);
080 expectAction();
081 }
082 }
083
084 public static class FactBrowserTool extends ToolComValidator{
085 private static PureFactory factory = getFactory();
086 private final TUnitTestCase testCase;
087
088 public FactBrowserTool(TUnitTestCase testCase, String name, boolean verbose){
089 super(testCase, name, verbose);
090
091 this.testCase = testCase;
092 }
093
094 public void run(){
095 try{
096 testCase.connectToolComValidator(this);
097
098 loadRStore();
099 selectFacts();
100 selectVisualization();
101 unloadRStore();
102 }catch(Exception ex){
103 ex.printStackTrace();
104 }finally{
105 disconnect();
106 }
107 }
108
109 private void loadRStore(){
110 ATerm fbLoadRstore = factory.make("fb-load-rstore()");
111 sendEvent(fbLoadRstore);
112
113 ATerm fbShowRstoreFacts = factory.make("fb-show-rstore-facts(<str>, <int>, <list>)", "rstoreTestName", 1, factory.makeList());
114 registerForDo(fbShowRstoreFacts);
115 expectAction();
116 }
117
118 private void selectFacts(){
119 ATerm fbTypeSelected = factory.make("fb-type-selected(<term>)", factory.make("rType"));
120 sendEvent(fbTypeSelected);
121
122 ATerm fbAddVisualizationPlugin = factory.make("fb-add-visualization-plugin(<term>, <int>, <str>)", factory.make("rType"), 1, "pluginTestName");
123 registerForDo(fbAddVisualizationPlugin);
124 expectAction();
125 }
126
127 private void selectVisualization(){
128 ATerm fbVisualizationSelected = factory.make("fb-visualization-selected(<int>,<int>,<int>)", 1, 1, 1);
129 sendEvent(fbVisualizationSelected);
130 }
131
132 private void unloadRStore(){
133 int rstoreId = 5;
134 ATerm fbRStoreUnloaded = factory.make("fb-rstore-unloaded(<int>)", rstoreId);
135 registerForDo(fbRStoreUnloaded);
136 expectAction();
137 }
138 }
139
140 public static class FBMPTool extends ToolComValidator{
141 private static PureFactory factory = getFactory();
142 private final TUnitTestCase testCase;
143
144 public FBMPTool(TUnitTestCase testCase, String name, boolean verbose){
145 super(testCase, name, verbose);
146
147 this.testCase = testCase;
148 }
149
150 public void run(){
151 try{
152 testCase.connectToolComValidator(this);
153
154 loadRStore();
155 selectFacts();
156 selectVisualization();
157 unloadRStore();
158 }catch(Exception ex){
159 ex.printStackTrace();
160 }finally{
161 disconnect();
162 }
163 }
164
165 private void loadRStore(){
166 ATerm fbRstoreLoaded = factory.make("fb-rstore-loaded");
167 registerForDo(fbRstoreLoaded);
168 expectAction();
169 }
170
171 private void selectFacts(){
172 ATerm fbTypeSelectedRecieved = factory.make("fb-type-selected-recieved");
173 registerForDo(fbTypeSelectedRecieved);
174 expectAction();
175 }
176
177 private void selectVisualization(){
178 ATerm fbVisualizationSelectedRecieved = factory.make("fb-visualization-selected-recieved");
179 registerForDo(fbVisualizationSelectedRecieved);
180 expectAction();
181 }
182
183 private void unloadRStore(){
184 int rstoreId = 5;
185 ATerm fbUnloadRstore = factory.make("fb-unload-rstore(<int>)", rstoreId);
186 sendEvent(fbUnloadRstore);
187 registerForDo(fbUnloadRstore);
188 expectAction();
189 }
190 }
191 }