StrutsAppsTest

HomePage | RecentChanges | Preferences


package org.apache.struts.apps;

import junit.extensions.TestSetup;
import junit.framework.Test;
import org.codehaus.cargo.container.InstalledLocalContainer;
import org.codehaus.cargo.container.ContainerType;
import org.codehaus.cargo.container.property.ServletPropertySet;
import org.codehaus.cargo.container.installer.Installer;
import org.codehaus.cargo.container.installer.ZipURLInstaller;
import org.codehaus.cargo.container.configuration.ConfigurationType;
import org.codehaus.cargo.container.configuration.LocalConfiguration;
import org.codehaus.cargo.container.deployable.WAR;
import org.codehaus.cargo.generic.DefaultContainerFactory;
import org.codehaus.cargo.generic.configuration.DefaultConfigurationFactory;

import java.io.File;
import java.net.URL;

public class Tomcat5xTestSetup extends TestSetup {

    InstalledLocalContainer container;
    String version;
    String port;
    String localRepository;

    public Tomcat5xTestSetup(Test test) {
        super(test);
    }

    protected void setUp() throws Exception {

        version = System.getProperty("version");
        port = System.getProperty("cargo.servlet.port");
        localRepository = System.getProperty("localRepository");

        // (1) Find the locally installed container.  This System property may
        //     be set in settings.xml, or on the command line with
        //     -Dcargo.tomcat5x.home=...
        String tomcat5x = System.getProperty("cargo.tomcat5x.home");

        File tomcatHome;
        if (tomcat5x == null || tomcat5x.startsWith("$")) {
            System.out.println("INFO: Downloading Tomcat 5.0 from a mirror");
            Installer installer = new ZipURLInstaller(
                    new URL("http://mirrors.ibiblio.org/pub/mirrors/apache"
                            + "/tomcat/tomcat-5/v5.0.30/bin/jakarta-tomcat-5.0.30.zip"));
            installer.install();
            tomcatHome = installer.getHome();
        } else {
            tomcatHome = new File(tomcat5x);
        }
        System.out.println("INFO: Tomcat home is " + tomcatHome);

        // (2) Create the Cargo Container instance wrapping our physical container
        LocalConfiguration configuration = (LocalConfiguration)
                new DefaultConfigurationFactory().createConfiguration(
                        "tomcat5x", ConfigurationType.STANDALONE);
        container = (InstalledLocalContainer)
                new DefaultContainerFactory().createContainer(
                        "tomcat5x", ContainerType.INSTALLED, configuration);
        container.setHome(tomcatHome);

        // (3) Statically deploy WAR(s)
        configuration.addDeployable(getWAR("struts-blank"));
        configuration.addDeployable(getWAR("struts-cookbook"));
        configuration.addDeployable(getWAR("struts-examples"));
        //configuration.addDeployable(getWAR("struts-faces-example1"));
        //configuration.addDeployable(getWAR("struts-faces-example2"));
        configuration.addDeployable(getWAR("struts-mailreader"));
        configuration.addDeployable(getWAR("struts-scripting-mailreader"));
        configuration.addDeployable(getWAR("strutsel-exercise-taglib"));

        configuration.setProperty(ServletPropertySet.PORT, port);

        // (4) Start the container
        container.start();
    }

    protected void tearDown() throws Exception {
        // (6) Stop the container
        container.stop();
    }

    private WAR getWAR(String context) {
        return new WAR(localRepository + "/org/apache/struts/action/"
                + context + "/" + version + "/" + context + "-" + version + ".war");
    }

}

package org.apache.struts.apps;

import java.net.URL;

import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.WebClient;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * Verify that each of the example apps starts and displays its
 * default page.
 */
public class AppsTest extends TestCase {

    private String version;
    private String port;

    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public AppsTest(String testName) {
        super(testName);
    }

    public void setUp() throws Exception {
        super.setUp();
        version = System.getProperty("version");
        port = System.getProperty("cargo.servlet.port");
    }

    /**
     * @return the suite of tests being tested
     */
    public static Test suite() {
        TestSuite suite = new TestSuite(AppsTest.class);
        return new Tomcat5xTestSetup(suite);
    }

    /**
     * Verify that the Struts Blank app has started
     */
    public void testStrutsBlank() throws Exception {

        WebClient webClient = new WebClient();
        URL url = new URL("http://localhost:"
                + port + "/struts-blank-" + version);
        HtmlPage page = (HtmlPage) webClient.getPage(url);

        assertEquals("Struts Blank Application", page.getTitleText());
    }

    /**
     * Verify that the Struts Cookbook app has started
     */
    public void testStrutsCookbook() throws Exception {

        WebClient webClient = new WebClient();
        URL url = new URL("http://localhost:"
                + port + "/struts-cookbook-" + version);
        HtmlPage page = (HtmlPage) webClient.getPage(url);

        assertEquals("Struts Cookbook", page.getTitleText());
    }

    /**
     * Verify that the Struts Examples app has started
     */
    public void testStrutsExamples() throws Exception {

        WebClient webClient = new WebClient();
        URL url = new URL("http://localhost:"
                + port + "/struts-examples-" + version);
        HtmlPage page = (HtmlPage) webClient.getPage(url);

        assertEquals("Struts Examples", page.getTitleText());
    }


    /**
     * Verify that the Struts Mailreader app has started
     */
    public void testStrutsMailreader() throws Exception {

        WebClient webClient = new WebClient();
        URL url = new URL("http://localhost:"
                + port + "/struts-mailreader-" + version);
        HtmlPage page = (HtmlPage) webClient.getPage(url);

        assertEquals("MailReader Demonstration Application",
                page.getTitleText());
    }

    /**
     * Verify that the Struts Scripting Mailreader app has started
     */
    public void testStrutsScriptingMailreader() throws Exception {

        WebClient webClient = new WebClient();
        URL url = new URL("http://localhost:" + port
                + "/struts-scripting-mailreader-" + version);
        HtmlPage page = (HtmlPage) webClient.getPage(url);

        assertEquals("MailReader Demonstration Application",
                page.getTitleText());
    }

    /**
     * Verify that the Struts EL Exercise Taglib app has started
     */
    public void testStrutsELExcerciseTaglib() throws Exception {

        WebClient webClient = new WebClient();
        URL url = new URL("http://localhost:" + port
                + "/strutsel-exercise-taglib-" + version);
        HtmlPage page = (HtmlPage) webClient.getPage(url);

        assertEquals("Struts-EL Test Application", page.getTitleText());
    }

    /**
     * Verify that the Struts Faces Example 1 app has started
     */
    public void xtestStrutsFacesExample1() throws Exception {

        WebClient webClient = new WebClient();
        URL url = new URL("http://localhost:" + port
                + "/struts-faces-example1-" + version);
        HtmlPage page = (HtmlPage) webClient.getPage(url);

        assertEquals("?", page.getTitleText());
    }

    /**
     * Verify that the Struts Faces Example 2 app has started
     */
    public void xtestStrutsFacesExample2() throws Exception {

        WebClient webClient = new WebClient();
        URL url = new URL("http://localhost:" + port
                + "/struts-faces-example2-" + version);
        HtmlPage page = (HtmlPage) webClient.getPage(url);

        assertEquals("?", page.getTitleText());
    }

}

<?xml version="1.0"?>
<!--
/*
 * Copyright 2005-2006 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * $Id: pom.xml 393684 2006-04-13 02:13:56Z wsmoak $
 */
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

   <parent>
      <groupId>org.apache.struts.action</groupId>
      <artifactId>struts-action-it</artifactId>
      <version>1.3.2-SNAPSHOT</version>
   </parent>

  <modelVersion>4.0.0</modelVersion>
  <groupId>org.apache.struts.action</groupId>
  <artifactId>struts-action-it-apps</artifactId>
  <packaging>pom</packaging>
  <name>Struts Action - Integration - Taglib Tests</name>
  <url>http://maven.apache.org</url>

    <dependencies>
       <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
       </dependency>
        <dependency>
           <groupId>htmlunit</groupId>
           <artifactId>htmlunit</artifactId>
           <version>1.8</version>
           <exclusions>
              <exclusion>
                 <groupId>javax.xml</groupId>
                 <artifactId>jsr173</artifactId>
              </exclusion>
           </exclusions>
        </dependency>
       <dependency>
          <groupId>org.codehaus.cargo</groupId>
          <artifactId>cargo-core-uberjar</artifactId>
          <version>0.8</version>
          <scope>test</scope>
       </dependency>
       <dependency>
          <groupId>org.codehaus.cargo</groupId>
          <artifactId>cargo-ant</artifactId>
          <version>0.8</version>
          <scope>test</scope>
       </dependency>
    </dependencies>

    <profiles>
    <profile>
    <id>perform-itest</id>
    <build>
       <plugins>
          <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-compiler-plugin</artifactId>
             <executions>
                <execution>
                   <id>compiler-for-tests</id>
                   <phase>test-compile</phase>
                   <goals>
                      <goal>testCompile</goal>
                   </goals>
                </execution>
             </executions>
          </plugin>
          <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-surefire-plugin</artifactId>
             <configuration>
                <systemProperties>
                   <property>
                      <name>cargo.tomcat5x.home</name>
                      <value>${cargo.tomcat5x.home}</value>
                   </property>
                   <property>
                       <name>cargo.servlet.port</name>
                       <value>8080</value>
                   </property>
                   <property>
                      <name>version</name>
                      <value>${version}</value>
                   </property>
                </systemProperties>
             </configuration>
             <executions>
                <execution>
                   <id>surefire-it</id>
                   <phase>integration-test</phase>
                   <goals>
                      <goal>test</goal>
                   </goals>
                </execution>
             </executions>
          </plugin>
       </plugins>
    </build>
    </profile>
    </profiles>

</project>


HomePage | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited April 13, 2006 10:36 pm by WendySmoak (diff)
Search: