blob: 6425976f197cb3be99e24840050f07508c97b62e [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.ws.tests;
import java.io.IOException;
import java.net.URL;
import junit.framework.TestCase;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.etools.common.test.apitools.ProjectUnzipUtil;
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jst.ws.tests.plugin.TestsPlugin;
import org.eclipse.jst.ws.tests.unittest.WSJUnitConstants;
import org.eclipse.jst.ws.tests.util.JUnitUtils;
import org.eclipse.wst.command.internal.env.context.PersistentResourceContext;
import org.eclipse.wst.command.internal.env.eclipse.EclipseEnvironment;
import org.eclipse.wst.command.internal.env.ui.eclipse.EclipseStatusHandler;
import org.eclipse.wst.common.environment.IEnvironment;
import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IServer;
public abstract class WSWizardTest extends TestCase implements WSJUnitConstants
{
protected IEnvironment env_;
protected IRuntime serverRuntime_;
protected IServer server_;
protected IStructuredSelection initialSelection_;
public String defaultURL_ = "http://localhost:8080/";
/**
* Set up the workspace for the Web Service Wizard JUnit test. Setup consists of the following steps:
* 1) Obtain an instance of the environment.
* 2) Install the server runtime.
* 3) Install the input data. This may include projects, source files etc.
* 4) Install an instance of the server if required. This may also include configuration of the input data on the server.
* 5) Initialize the J2EE, Web Service Runtime and Server type defaults for the Web Service wizard to use.
* 6) Initialize the initial selection object to set the context for the Web Service wizard.
* @throws Exception
*/
protected void setUp() throws Exception
{
// Get an instance of the default environment with the AccumulateStatusHandler to minimize UI dialog blocks.
PersistentResourceContext resourceContext = PersistentResourceContext.getInstance();
EclipseStatusHandler handler = new EclipseStatusHandler();
EclipseEnvironment environment = new EclipseEnvironment( null, resourceContext, handler );
env_ = environment;
assertTrue(env_ != null);
server_ = null;
JUnitUtils.hideActionDialogs();
installServerRuntime();
installServer();
// unzip pre-configured workspace projects
if (!ProjectUtilities.getProject(WSJUnitConstants.BU_PROJECT_NAME).exists())
createProjects();
installInputData();
initJ2EEWSRuntimeServerDefaults();
initInitialSelection();
}
/**
* Install the server runtime.
* @throws Exception
*/
protected abstract void installServerRuntime() throws Exception;
/**
* Installs the input data from an aggregator. This ensures that the environment, runtime
* and server are correctly set on the aggregate since its lifecycle methods are not necessarily
* called.
* @param env
* @param serverRuntime
* @param server
* @throws Exception
*/
public void installInputData(IEnvironment env,IRuntime serverRuntime,IServer server) throws Exception
{
env_ = env;
serverRuntime_ = serverRuntime;
server_ = server;
//installInputData();
}
// Creates projects from the provided ZIP file.
public static boolean createProjects() {
IPath localZipPath = getLocalPath();
ProjectUnzipUtil util = new ProjectUnzipUtil(localZipPath, perf_projectNames);
return util.createProjects();
}
private static IPath getLocalPath() {
URL url = TestsPlugin.getDefault().find(perf_zipFilePath);
try {
url = Platform.asLocalURL(url);
} catch (IOException e) {
e.printStackTrace();
}
return new Path(url.getPath());
}
/**
* Install the input data for the test. This may include projects, source files etc.
* @throws Exception
*/
protected abstract void installInputData() throws Exception;
/**
* Install an instance of the server. This may also configure input data on the server.
* @throws Exception
*/
protected abstract void installServer() throws Exception;
/**
* Initialize the J2EE level, Web Service runtime type and Server defaults for the test case.
* @throws Exception
*/
protected abstract void initJ2EEWSRuntimeServerDefaults() throws Exception;
/**
* Initialize the initial selection which drives the Web Service wizard. This could include source Java files,
* WSDL URLs and even EJBs.
* @throws Exception
*/
protected abstract void initInitialSelection() throws Exception;
/**
* Clean up the workspace. Cleanup consists of the following steps:
* 1) Delete the input data. This should include removal of configuration data on the server if necessary.
* 2) Stop the server.
* 3) Delete the server.
* 4) Delete the server runtime.
*/
protected void tearDown() throws Exception
{
stopServer();
// deleteServer();
// deleteInputData();
// deleteServerRuntime();
}
/**
* Delete the input data. This should include removal of projects, src files etc. as well as removal of any server configured data.
* @throws Exception
*/
protected abstract void deleteInputData() throws Exception;
/**
* Stop the server if it is running.
* @throws Exception
*/
protected void stopServer() throws Exception
{
if (server_ != null && server_.getServerState() == IServer.STATE_STARTED)
server_.stop(true);
assertTrue(server_.getServerState() == IServer.STATE_STOPPED);
}
/**
* Delete the server.
* @throws Exception
*/
protected void deleteServer() throws Exception
{
if (server_ != null)
server_.delete();
}
/**
* Delete the server runtime.
* @throws Exception
*/
protected void deleteServerRuntime() throws Exception
{
if (serverRuntime_ != null)
serverRuntime_.delete();
}
/**
* Get the default URL in the form of: http://localhost:9080/<contextRoot>/<path>
* @param path - a file or URL relative path.
* @param contextRoot - the context root of the Web module for this URL.
* @return
*/
protected String getDefaultURL(String path,String contextRoot)
{
StringBuffer url = new StringBuffer(defaultURL_);
url.append(contextRoot);
url.append('/');
url.append(path);
return url.toString();
}
}