001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Vitaly A. Provodin
021: * @version $Revision: 1.5 $
022: */
023:
024: /**
025: * Created on 01.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.share;
027:
028: import org.apache.harmony.jpda.tests.framework.TestErrorException;
029: import org.apache.harmony.jpda.tests.share.JPDALogWriter;
030: import org.apache.harmony.jpda.tests.share.JPDATestOptions;
031:
032: import junit.framework.TestCase;
033:
034: /**
035: * Basic class for all JDWP unit tests based on <code>JUnit</code> framework.
036: * <p>
037: * This class extends JUnit interface <code>TestCase</code> and implements
038: * <code>setUp()</code> and <code>tearDown()</code> being common for all
039: * JDWP tests.
040: * <p>
041: * It also introduces <code>internalSetUp()</code> and
042: * <code>internalTearDown()</code> that can be implemented to supply safe
043: * start up and shut down of debuggee.
044: */
045: public abstract class JDWPRawTestCase extends TestCase {
046:
047: /** Where to print log messages. */
048: protected JPDALogWriter logWriter;
049:
050: /** Test run options. */
051: protected JPDATestOptions settings;
052:
053: /**
054: * This method should be overridden in derived classes to return full name
055: * for debuggee class.
056: *
057: * @return full debuggee class name
058: */
059: protected abstract String getDebuggeeClassName();
060:
061: /**
062: * This method will be invoked before starting each test.
063: *
064: * @throws Exception
065: * if any error occurs
066: */
067: protected void internalSetUp() throws Exception {
068: }
069:
070: /**
071: * This method will be invoked after each test completed or any error
072: * occurred.
073: */
074: protected void internalTearDown() {
075: }
076:
077: /**
078: * Overrides inherited JUnit method to provide initialization and invocation
079: * of internalSetUp() and internalTearDown() methods.
080: */
081: protected void setUp() throws Exception {
082: super .setUp();
083:
084: settings = createTestOptions();
085: settings.setDebuggeeClassName(getDebuggeeClassName());
086:
087: logWriter = new JPDALogWriter(System.out, null, settings
088: .isVerbose());
089:
090: logWriter.println("\n=====================================>>>");
091: logWriter.println("Run: " + getClass().getName() + "."
092: + getName());
093: logWriter.println("----------------------------------------");
094:
095: try {
096: internalSetUp();
097: logWriter
098: .println("----------------------------------------");
099: } catch (Throwable e) {
100: logWriter.printError(e);
101: logWriter
102: .println("----------------------------------------");
103: internalTearDown();
104: throw new TestErrorException(e);
105: }
106: }
107:
108: /**
109: * Creates wrapper object for accessing test options;
110: */
111: protected JPDATestOptions createTestOptions() {
112: return new JPDATestOptions();
113: }
114:
115: /**
116: * Overrides inherited JUnit method to provide cleanup and invocation of
117: * internalTearDown() method.
118: */
119: protected void tearDown() throws Exception {
120: logWriter.println("----------------------------------------");
121: internalTearDown();
122: logWriter.println("<<<=====================================\n");
123:
124: super.tearDown();
125: }
126: }
|