001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.testutil.common;
019:
020: import java.io.IOException;
021: import java.util.ArrayList;
022: import java.util.List;
023: import java.util.Map;
024:
025: import org.junit.AfterClass;
026: import org.junit.Assert;
027:
028: public abstract class AbstractClientServerTestBase extends Assert {
029: private static List<ServerLauncher> launchers = new ArrayList<ServerLauncher>();
030:
031: @AfterClass
032: public static void stopAllServers() throws Exception {
033: boolean passed = true;
034: for (ServerLauncher sl : launchers) {
035: try {
036: sl.signalStop();
037: } catch (IOException ex) {
038: ex.printStackTrace();
039: }
040: }
041: for (ServerLauncher sl : launchers) {
042: try {
043: passed = passed && sl.stopServer();
044: } catch (IOException ex) {
045: ex.printStackTrace();
046: }
047: }
048: launchers.clear();
049: System.gc();
050: assertTrue("server failed", passed);
051: }
052:
053: public static boolean launchServer(Class<?> clz) {
054: boolean ok = false;
055: try {
056: ServerLauncher sl = new ServerLauncher(clz.getName());
057: ok = sl.launchServer();
058: assertTrue("server failed to launch", ok);
059: launchers.add(sl);
060: } catch (IOException ex) {
061: ex.printStackTrace();
062: fail("failed to launch server " + clz);
063: }
064:
065: return ok;
066: }
067:
068: public static boolean launchServer(Class<?> clz, boolean inProcess) {
069: boolean ok = false;
070: try {
071: ServerLauncher sl = new ServerLauncher(clz.getName(),
072: inProcess);
073: ok = sl.launchServer();
074: assertTrue("server failed to launch", ok);
075: launchers.add(sl);
076: } catch (IOException ex) {
077: ex.printStackTrace();
078: fail("failed to launch server " + clz);
079: }
080:
081: return ok;
082: }
083:
084: public static boolean launchServer(Class<?> clz,
085: Map<String, String> props, String[] args) {
086: return launchServer(clz, props, args, false);
087: }
088:
089: public static boolean launchServer(Class<?> clz,
090: Map<String, String> props, String[] args, boolean inProcess) {
091: boolean ok = false;
092: try {
093: ServerLauncher sl = new ServerLauncher(clz.getName(),
094: props, args, inProcess);
095: ok = sl.launchServer();
096: assertTrue("server failed to launch", ok);
097: launchers.add(sl);
098: } catch (IOException ex) {
099: ex.printStackTrace();
100: fail("failed to launch server " + clz);
101: }
102:
103: return ok;
104: }
105: }
|