KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tools > testrecorder > client > TestRecorderJUnitTest


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

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 /**
28  */

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 JavaDoc name ) {
40         super( name );
41         this.test = test;
42     }
43
44     protected void runTest() throws Throwable JavaDoc {
45         boolean outcome = execute();
46         if ( !outcome ) {
47             String JavaDoc 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 JavaDoc testUser = System.getProperty( "user.name" );
59         PlaybackExecutor exec = new PlaybackExecutor( getTest(), testUser, testUser );
60         try {
61             outcome = exec.run();
62             String JavaDoc 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 JavaDoc ex ) {
69             outcome = false;
70             String JavaDoc 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