01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.tools.common;
19:
20: import java.io.ByteArrayOutputStream;
21: import java.io.File;
22: import java.io.PrintStream;
23:
24: import org.apache.cxf.helpers.FileUtils;
25: import org.junit.After;
26: import org.junit.Assert;
27: import org.junit.Before;
28:
29: public abstract class ToolTestBase extends Assert {
30:
31: protected PrintStream oldStdErr;
32: protected PrintStream oldStdOut;
33:
34: protected ByteArrayOutputStream errOut = new ByteArrayOutputStream();
35: protected ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
36:
37: @Before
38: public void setUp() {
39: oldStdErr = System.err;
40: oldStdOut = System.out;
41:
42: System.setErr(new PrintStream(errOut));
43: System.setOut(new PrintStream(stdOut));
44: }
45:
46: @After
47: public void tearDown() {
48:
49: System.setErr(oldStdErr);
50: System.setOut(oldStdOut);
51: }
52:
53: protected String getStdOut() {
54: return new String(stdOut.toByteArray());
55: }
56:
57: protected String getStdErr() {
58: return new String(errOut.toByteArray());
59: }
60:
61: protected String getLocation(String wsdlFile) throws Exception {
62: File output = new File(getClass().getResource(".").toURI());
63: output = new File(output, "resources");
64:
65: if (!output.exists()) {
66: FileUtils.mkDir(output);
67: }
68:
69: return new File(output, wsdlFile).toString();
70: }
71: }
|