001: /*
002: * $Id: Tomcat5xTestSetup.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts.apps;
022:
023: import java.io.File;
024: import java.net.URL;
025:
026: import junit.extensions.TestSetup;
027: import junit.framework.Test;
028:
029: import org.codehaus.cargo.container.ContainerType;
030: import org.codehaus.cargo.container.InstalledLocalContainer;
031: import org.codehaus.cargo.container.installer.Installer;
032: import org.codehaus.cargo.container.installer.ZipURLInstaller;
033: import org.codehaus.cargo.container.configuration.ConfigurationType;
034: import org.codehaus.cargo.container.configuration.LocalConfiguration;
035: import org.codehaus.cargo.container.deployable.WAR;
036: import org.codehaus.cargo.container.property.ServletPropertySet;
037: import org.codehaus.cargo.generic.DefaultContainerFactory;
038: import org.codehaus.cargo.generic.configuration.DefaultConfigurationFactory;
039:
040: /**
041: * Set up to run tests with Tomcat 5.x. If the 'cargo.tomcat5x.home'
042: * System property is not set, Tomcat 5.0.30 will be downloaded from ibiblio.
043: */
044: public class Tomcat5xTestSetup extends TestSetup {
045:
046: InstalledLocalContainer container;
047: String version;
048: String port;
049: String localRepository;
050:
051: public Tomcat5xTestSetup(Test test) {
052: super (test);
053: }
054:
055: /**
056: * Required until MSUREFIRE-119 is fixed.
057: */
058: public String getName() {
059: return "Tomcat5xTestSetup";
060: }
061:
062: protected void setUp() throws Exception {
063: version = System.getProperty("version");
064: port = System.getProperty("cargo.servlet.port");
065: localRepository = System.getProperty("localRepository");
066:
067: // (1) Find the locally installed container. This System property may
068: // be set in settings.xml, or on the command line with
069: // -Dcargo.tomcat5x.home=c:/java/apache-tomcat-5.5.17
070: String tomcat5x = System.getProperty("cargo.tomcat5x.home");
071:
072: File tomcatHome;
073: if (tomcat5x == null || tomcat5x.startsWith("$")) {
074: //System.out.println("INFO: Downloading Tomcat 5.0 from a mirror");
075: Installer installer = new ZipURLInstaller(
076: new URL(
077: "http://mirrors.ibiblio.org/pub/mirrors/apache"
078: + "/tomcat/tomcat-5/v5.0.30/bin/jakarta-tomcat-5.0.30.zip"));
079: installer.install();
080: tomcatHome = installer.getHome();
081: } else {
082: tomcatHome = new File(tomcat5x);
083: }
084: //System.out.println("INFO: Tomcat home is " + tomcatHome);
085:
086: // (2) Create the Cargo Container instance wrapping our physical container
087: LocalConfiguration configuration = (LocalConfiguration) new DefaultConfigurationFactory()
088: .createConfiguration("tomcat5x",
089: ConfigurationType.STANDALONE);
090: container = (InstalledLocalContainer) new DefaultContainerFactory()
091: .createContainer("tomcat5x", ContainerType.INSTALLED,
092: configuration);
093: container.setHome(tomcatHome);
094:
095: // (3) Statically deploy WAR(s)
096: configuration.addDeployable(getWAR("struts-blank"));
097: configuration.addDeployable(getWAR("struts-cookbook"));
098: configuration.addDeployable(getWAR("struts-examples"));
099: configuration.addDeployable(getWAR("struts-faces-example1"));
100: configuration.addDeployable(getWAR("struts-faces-example2"));
101: configuration.addDeployable(getWAR("struts-mailreader"));
102: configuration
103: .addDeployable(getWAR("struts-scripting-mailreader"));
104: configuration.addDeployable(getWAR("struts-el-example"));
105:
106: configuration.setProperty(ServletPropertySet.PORT, port);
107:
108: // (4) Start the container
109: container.start();
110: }
111:
112: protected void tearDown() throws Exception {
113: // (6) Stop the container
114: container.stop();
115: }
116:
117: private WAR getWAR(String context) {
118: return new WAR(localRepository + "/org/apache/struts/"
119: + context + "/" + version + "/" + context + "-"
120: + version + ".war");
121: }
122:
123: }
|