1 18 19 package org.apache.beehive.netui.tools.testrecorder.client; 20 21 import org.apache.beehive.netui.tools.testrecorder.shared.Logger; 22 import org.apache.beehive.netui.tools.testrecorder.shared.Constants; 23 import org.apache.beehive.netui.tools.testrecorder.shared.config.TestDefinition; 24 import junit.framework.Assert; 25 import junit.framework.TestCase; 26 27 29 public class TestRecorderJUnitTest extends TestCase { 30 31 private static final Logger log = Logger.getInstance( TestRecorderJUnitTest.class ); 32 private TestDefinition test; 33 34 public TestRecorderJUnitTest( TestDefinition test ) { 35 this( test, test.getName() ); 36 this.test = test; 37 } 38 39 public TestRecorderJUnitTest( TestDefinition test, String name ) { 40 super( name ); 41 this.test = test; 42 } 43 44 protected void runTest() throws Throwable { 45 boolean outcome = execute(); 46 if ( !outcome ) { 47 String msg = "\nPlayback FAILED for test( " + getTest().getName() + " )\n"; 48 if ( log.isWarnEnabled() ) { 49 log.warn( msg ); 50 } 51 System.out.println( msg ); 52 Assert.fail( msg ); 53 } 54 } 55 56 private boolean execute() { 57 boolean outcome = false; 58 String testUser = System.getProperty( "user.name" ); 59 PlaybackExecutor exec = new PlaybackExecutor( getTest(), testUser, testUser ); 60 try { 61 outcome = exec.run(); 62 String msg = ( outcome == true ) ? Constants.PASS : Constants.FAIL ; 63 System.out.println( "Finished: '" + getTest().getName() + "': " + msg ); 64 if ( log.isWarnEnabled() ) { 65 log.warn( "Finished: '" + getTest().getName() + "': " + msg ); 66 } 67 } 68 catch ( Throwable ex ) { 69 outcome = false; 70 String msg = "ERROR: failed executing playback, exception( " + ex.getMessage() + " )"; 71 System.out.println( Logger.format( msg, ex ) ); 72 log.error( msg, ex ); 73 } 74 return outcome; 75 } 76 77 public TestDefinition getTest() { 78 return test; 79 } 80 } 81 | Popular Tags |