KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > systest > ScenarioTestCase


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

18 package org.apache.activemq.systest;
19
20 import junit.framework.AssertionFailedError;
21 import junit.framework.Test;
22 import junit.framework.TestResult;
23
24 /**
25  * A JUnit {@link Test} for running a Scenario in a JUnit test suite.
26  *
27  * @version $Revision: 1.1 $
28  */

29 public class ScenarioTestCase implements Test {
30
31     private Scenario scenario;
32     private String JavaDoc description;
33
34     public ScenarioTestCase(Scenario scenario, String JavaDoc description) {
35         this.scenario = scenario;
36         this.description = description;
37     }
38
39     public int countTestCases() {
40         return 1;
41     }
42
43     public void run(TestResult result) {
44         result.startTest(this);
45         try {
46             scenario.start();
47             scenario.run();
48             scenario.stop();
49             result.endTest(this);
50         }
51         catch (AssertionFailedError e) {
52             result.addFailure(this, e);
53         }
54         catch (Throwable JavaDoc e) {
55             System.out.println("Failed to run test: " + e);
56             e.printStackTrace();
57             result.addError(this, e);
58         }
59         finally {
60             try {
61                 scenario.stop();
62                 scenario = null;
63             }
64             catch (Exception JavaDoc e) {
65                 System.out.println("Failed to close down test: " + e);
66                 e.printStackTrace();
67             }
68         }
69     }
70
71     public String JavaDoc toString() {
72         return description;
73     }
74 }
75
Popular Tags