KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > sandesha > AbstractTestCase


1 /*
2  * Copyright 2001-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
17 package org.apache.sandesha;
18
19 import junit.framework.TestCase;
20 import org.apache.axis.Message;
21 import org.apache.axis.MessageContext;
22 import org.apache.axis.message.SOAPEnvelope;
23
24 import java.io.File JavaDoc;
25 import java.io.FileInputStream JavaDoc;
26
27 /**
28  * Abstract base class for test cases.
29  */

30 public abstract class AbstractTestCase
31         extends TestCase {
32     protected String JavaDoc testDir = "test";
33     //protected String sampleDir = "src/samples/";
34
//protected String outDir = "target/generated/samples/";
35
//protected String tempDir = "target/generated/temp";
36
protected String JavaDoc testResourceDir = "test-resources";
37
38
39     /**
40      * Basedir for all file I/O. Important when running tests from
41      * the reactor.
42      */

43     public String JavaDoc basedir = System.getProperty("basedir");
44
45     /**
46      * Constructor.
47      */

48     public AbstractTestCase(String JavaDoc testName) {
49         super(testName);
50         if (basedir == null) {
51             basedir = new File JavaDoc(".").getAbsolutePath();
52         }
53         testDir = new File JavaDoc(basedir, testDir).getAbsolutePath();
54         //sampleDir = new File(basedir,sampleDir).getAbsolutePath();
55
//outDir = new File(basedir,outDir).getAbsolutePath();
56
//tempDir = new File(basedir,tempDir).getAbsolutePath();
57
testResourceDir = new File JavaDoc(basedir, testResourceDir).getAbsolutePath();
58     }
59
60
61     public File JavaDoc getTestResourceFile(String JavaDoc relativePath) {
62         return new File JavaDoc(testResourceDir, relativePath);
63     }
64
65     public RMMessageContext getRMMessageContext(String JavaDoc relativePath) throws Exception JavaDoc {
66
67         FileInputStream JavaDoc fin = new FileInputStream JavaDoc(getTestResourceFile(relativePath));
68         SOAPEnvelope sEnv = new SOAPEnvelope(fin);
69         MessageContext msgCtx = new MessageContext(null);
70         msgCtx.setRequestMessage(new Message(sEnv));
71         msgCtx.setResponseMessage(new Message(new SOAPEnvelope()));
72         RMMessageContext rmMsgCtx = new RMMessageContext();
73         rmMsgCtx.setMsgContext(msgCtx);
74         return rmMsgCtx;
75     }
76
77
78 }
79
80
Popular Tags