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 * The FBMP Toolbus test case for toolbus testing.
010 *
011 * @author Bas Basten
012 * @author Anton Lycklama a Nijeholt
013 *
014 */
015 public class FBMPTBTest extends TUnitTestCase {
016
017 /**
018 * Test the all the toolbus scenarios.
019 */
020 public void testFBMP() {
021 FBMPTool fbmpTool = new FBMPTool(this, "fbmp-test-tool", true);
022
023 Thread fbmpToolExecutor = new Thread(fbmpTool);
024 fbmpToolExecutor.setDaemon(true);
025 fbmpToolExecutor.start();
026
027 toolbus.waitTillShutdown();
028
029 if(hasFailed()) fail();
030
031 System.out.println("Test Passed");
032 }
033
034 protected void setUp() {
035 try{
036 startToolbus("./tbscript/", "./tbscript/fbmp_test_init.tb");
037 }catch (Exception ex){
038 ex.printStackTrace();
039 stopToolbus();
040 fail(ex.toString());
041 }
042 }
043
044 protected void tearDown() {
045 stopToolbus();
046 }
047
048 public static class FBMPTool extends ToolComValidator{
049 private final TUnitTestCase testCase;
050
051 public FBMPTool(TUnitTestCase testCase, String name, boolean verbose){
052 super(testCase, name, verbose);
053
054 this.testCase = testCase;
055 }
056
057 public void run(){
058 try{
059 testCase.connectToolComValidator(this);
060
061 PureFactory factory = getFactory();
062
063 for(int i = 1; i <= 6; i++){
064 ATerm scenarioStart = factory.make("start-scenario(<int>)", i);
065 sendEvent(scenarioStart);
066
067 ATerm scenarioResult = factory.make("scenario-successful(<int>)", i);
068 registerForDo(scenarioResult);
069 expectAction();
070
071 waitForCompletion();
072 }
073 }catch(Exception ex){
074 ex.printStackTrace();
075 }finally{
076 disconnect();
077 }
078 }
079 }
080 }