beehive-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeremiah Johnson" <jerjo...@bea.com>
Subject possible WSM tests
Date Thu, 16 Jun 2005 13:00:43 GMT
I have some tests that I wrote to check the WSDL produced after a JWS has been compiled and
deployed.  I wrote these tests because I was interested in checking some pieces of the WSDL
based on the annotations in the JSR 181 spec.  In some cases (i.e. namespace issues), they
can serve as regression tests, but in others (i.e. @Oneway) they don’t have much value.
 A major problem with these tests is that they currently require a Web container.

I can create a Jira issue and attach my full diff - just wanted to bring up the type of test
to see if you see value in it.  Please take a look at the info below and let me know if you
have questions or doubts.

Since the WSM tests don’t currently have any tests (that I know of) that require a Web container,
I modified the build scripts in WSM a little.  Here is an overview of what I did:

Added some main properties:
<property name="wsm.test.webapp.name" value="wsmWeb"/>
<property name="server.root.url" value="http://localhost:8080"/>
<property name="webapp.waitfor.url" value="${server.root.url}/${wsm.test.webapp.name}”/>

Increased the work of build.webapp:
<target name="build.webapp">
    <deploy-wsm webappDir="${webapp.dir}"/>
    <build-webapp webappDir="${webapp.dir}"/>
    <build-webservices srcdir="${webapp.dir}/WEB-INF/src-ws"
        destdir="${webapp.dir}/WEB-INF/classes"
        tempdir="${webapp.dir}/WEB-INF/temp"
        classpathref="drt.classpath"/>
    <copy overwrite="true" todir="${build.dir}/${wsm.test.webapp.name}">
        <fileset dir="${webapp.dir}">
            <exclude name="WEB-INF/src/**"/>
            <exclude name="WEB-INF/src-ws/**"/>
            <exclude name="WEB-INF/temp/**"/>
        </fileset>
    </copy>
</target>

Added the in-container section to drt:
        <echo message="** in-container tests starting **"/>
        <parallel>
            <start-server shmem="false" javaOptions=""/>
            <sequential>
                <antcall target="ensure.deployed"/>
                <junit failureproperty="wsmdrtfailed" printsummary="on"
                    tempdir="${build.dir}" fork="yes">
                    <classpath>
                        <pathelement location="${build.tests}"/>
                        <pathelement location="${build.gen-tests}"/>
                        <path refid="drt.classpath"/>
                    </classpath>
                    <sysproperty key="base.url"
                        value="${server.root.url}/${wsm.test.webapp.name}"/>
                    <formatter type="plain"/>
<test name="org.apache.beehive.wsm.jsr181.wsdl.WebServiceTargetNamespace"
  todir="${drt.logs}"/>
                </junit>
                <antcall target="undeploy"/>
                <echo message="stopping Web container"/>
                <stop-server />
            </sequential>
        </parallel>

Here is an example case that I think adds value:
/*
 * Copyright 2005 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.
 */
package org.apache.beehive.wsm.jsr181.wsdl;

import javax.wsdl.Definition;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;

import junit.framework.TestCase;

/**
 * Unit tests around the WebService targetNamespace attribute.
 * <p>
 * This test currently requires a running instance of a Web container.  The
 * root URL of the server is determined by the value of BASE_URL.
 * </p>
 */
public class WebServiceTargetNamespace extends TestCase {

    /**
     * The root URL of the server to hit for the Web service; defaults to
     * http://localhsot:8080/wsmTest but can be overridden by setting the
     * base.url system property.
     */
    private static final String BASE_URL =
        System.getProperty( "base.url", "http://localhost:8080/wsmTest" );

    /**
     * Instance of the WSDL Reader used in the test methods; this is (re)set
     * in the set up method.
     */
    private WSDLReader reader;

    /**
     * Prepare for testing by creating a new reader instance.
     */
    public void setUp() {
        try {
            reader = WSDLFactory.newInstance().newWSDLReader();
        } catch( Exception e ) {
            e.printStackTrace();
            fail( "failed to prepare WSDL reader for tests: " + e );
        }
    }

    /**
     * When the targetNamespace attribute is used but empty, the
     * targetNamespace in the WSDL should default to http://{package};
     * in this case it should be http://webservice.
     */
    public void testEmpty() throws Exception {
        Definition wsdl = reader.readWSDL( null,
            BASE_URL + "/webservice/TargetNamespaceEmpty.jws?wsdl" );
        assertEquals( "http://webservice", wsdl.getTargetNamespace() );
    }

    /**
     * When the targetNamespace attribute is used but empty, the
     * targetNamespace in the WSDL should default to the http://{package}.
     * <p>
     * If there is no package, then it defaults to http://{classname}; in
     * this case, it should be http://TargetNamespaceEmpty.
     * </p>
     */
    public void testEmptyNoPackage() throws Exception {
        Definition wsdl = reader.readWSDL( null,
            BASE_URL + "/WebServiceTargetNamespaceEmpty.jws?wsdl" );
        assertEquals( "http://WebServiceTargetNamespaceEmpty",
            wsdl.getTargetNamespace() );
    }

    /**
     * When the targetNamespace attribute is not used, the targetNamespace in
     * the WSDL should default to http://{package}; in this case it should be
     * http://webservice.
     */
    public void testNotUsed() throws Exception {
        Definition wsdl = reader.readWSDL( null,
            BASE_URL + "/webservice/TargetNamespaceNotUsed.jws?wsdl" );
        assertEquals( "http://webservice", wsdl.getTargetNamespace() );
    }

    /**
     * When the targetNamespace attribute is not used, the targetNamespace in
     * the WSDL should default to the package name of the Web service.
     * <p>
     * If there is no package, then the targetNamespace defaults to
     * http://{classname}; in this case it would be
     * http://WebServiceTargetNamespaceNotUsed.
     * </p>
     */
    public void testNotUsedNoPackage() throws Exception {
        Definition wsdl = reader.readWSDL( null,
            BASE_URL + "/WebServiceTargetNamespaceNotUsed.jws?wsdl" );
        assertEquals( "http://WebServiceTargetNamespaceNotUsed",
            wsdl.getTargetNamespace() );
    }

    /**
     * When the name attribute is used, the portType should be the name set
     * in the attribute; in this case, the targetNamespace should be
     * urn:jsr181-webservice.
     */
    public void testUsed() throws Exception {
        Definition wsdl = reader.readWSDL( null,
            BASE_URL + "/webservice/TargetNamespaceUsed.jws?wsdl" );
        assertEquals( "urn:jsr181-webservice", wsdl.getTargetNamespace() );
    }

}

Here is the example case that I don’t think adds much value:
/*
 * Copyright 2005 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.
 */
package org.apache.beehive.wsm.jsr181.wsdl;

import java.util.List;
import java.util.Map;
import javax.wsdl.Definition;
import javax.wsdl.Operation;
import javax.wsdl.Port;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;

import junit.framework.TestCase;

/**
 * Unit tests around the Oneway annotation.
 */
public class Oneway extends TestCase {

    /**
     * The root URL of the server to hit for the Web service; defaults to
     * http://localhsot:8080/wsmTest but can be overridden by setting the
     * base.url system property.
     */
    private static final String BASE_URL =
        System.getProperty( "base.url", "http://localhost:8080/wsmTest" );

    /**
     * Instance of the WSDL Reader used in the test methods; this is (re)set
     * in the set up method.
     */
    private WSDLReader reader;

    /**
     * Prepare for testing by creating a new reader instance.
     */
    public void setUp() {
        try {
            reader = WSDLFactory.newInstance().newWSDLReader();
        } catch( Exception e ) {
            e.printStackTrace();
            fail( "failed to prepare WSDL reader for tests: " + e );
        }
    }

    /**
     * When the Oneway annotation is not used, the operation will have an
     * output element even if the return on the actual method signature is
     * void.
     */
    public void testNotUsed() throws Exception {
        Definition wsdl =
            reader.readWSDL( null, BASE_URL + "OnewayNotUsed.jws?wsdl" );
        assertOperationOutput( wsdl, true );
    }

    /**
     * When the Oneway annotation is used, the operation will not have an
     * output element.
     */
    public void testUsed() throws Exception {
        Definition wsdl =
            reader.readWSDL( null, BASE_URL + "OnewayUsed.jws?wsdl" );
        assertOperationOutput( wsdl, false );
    }

    /**
     * Assuming one service, port, and operation for the given WSDL, this
     * verifies that the operation does or doesn't have an output element.
     */
    private static void assertOperationOutput( Definition wsdl,
        boolean output ) {
        Map services = wsdl.getServices();
        assertNotNull( "services", services );
        assertEquals( 1, services.size() );
        Service service = (Service) services.values().toArray()[0];

        Map ports = service.getPorts();
        assertNotNull( "ports", ports );
        assertEquals( 1, ports.size() );
        PortType portType =
            ((Port) ports.values().toArray()[0]).getBinding().getPortType();

        List<Operation> operations = portType.getOperations();
        assertNotNull( "operations", operations );
        assertEquals( 1, operations.size() );

        assertNotNull( "input", operations.get(0).getInput() );
        if( output ) {
            assertNotNull( "output expected", operations.get(0).getOutput() );
        } else {
            assertNull( "output not expected", operations.get(0).getOutput() );
        }
    }

}

Here is the full diff of the wsm build.xml, in case you are interested:
Index: wsm/drt/build.xml
===================================================================
--- wsm/drt/build.xml   (revision 190820)
+++ wsm/drt/build.xml   (working copy)
@@ -5,6 +5,10 @@
     <import file="../../beehive-imports.xml"/>
     <import file="../../ant/beehive-tools.xml"/>

+    <property name="wsm.test.webapp.name" value="wsmWeb"/>
+    <property name="server.root.url" value="http://localhost:8080"/>
+    <property name="webapp.waitfor.url" value="${server.root.url}/${wsm.test.we
bapp.name}"/>
+
     <property name="drt.root" location="${basedir}"/>
     <property name="build.dir" location="${drt.root}/build"/>
     <property name="drt.logs" location="${build.dir}/logs"/>
@@ -43,6 +47,12 @@
         <fileset refid="axis.jars"/>
     </path>

+    <condition property="do.start.appserver" value="true">
+        <not>
+            <isset property="start.appserver"/>
+        </not>
+    </condition>
+
     <target name="usage">
         <echo message=""/>
         <echo message=""/>
@@ -111,11 +121,24 @@
     <target name="build.webapp">
         <deploy-wsm webappDir="${webapp.dir}"/>
         <build-webapp webappDir="${webapp.dir}"/>
+        <build-webservices srcdir="${webapp.dir}/WEB-INF/src-ws"
+            destdir="${webapp.dir}/WEB-INF/classes"
+            tempdir="${webapp.dir}/WEB-INF/temp"
+            classpathref="drt.classpath"/>
+        <copy overwrite="true" todir="${build.dir}/${wsm.test.webapp.name}">
+            <fileset dir="${webapp.dir}">
+                <exclude name="WEB-INF/src/**"/>
+                <exclude name="WEB-INF/src-ws/**"/>
+                <exclude name="WEB-INF/temp/**"/>
+            </fileset>
+        </copy>
     </target>

     <target name="clean.webapp">
         <clean-webapp webappDir="${webapp.dir}"/>
         <delete dir="${webapp.dir}/WEB-INF/lib"/>
+        <delete dir="${webapp.dir}/WEB-INF/temp"/>
+        <delete dir="${webapp.dir}/WEB-INF/classes"/>
     </target>

     <target name="xbean">
@@ -148,7 +171,8 @@

     <target name="run.drt">
         <echo message="** junit logfiles written to ${drt.logs} **"/>
-        <junit failureproperty="wsmdrtfailed" printsummary="on" tempdir="${buil
d.dir}" fork="yes">
+        <junit failureproperty="wsmdrtfailed" printsummary="on"
+            tempdir="${build.dir}" fork="yes">
             <classpath>
                 <pathelement location="${build.tests}"/>
                 <pathelement location="${build.gen-tests}"/>
@@ -162,7 +186,110 @@
                 </fileset>
             </batchtest>
         </junit>
-        <fail if="wsmdrtfailed" message="One or more tests in the WSM DRT faile
d."/>
+
+        <echo message="** in-container tests starting **"/>
+        <parallel>
+            <start-server shmem="false" javaOptions=""/>
+            <sequential>
+                <antcall target="ensure.deployed"/>
+                <junit failureproperty="wsmdrtfailed" printsummary="on"
+                    tempdir="${build.dir}" fork="yes">
+                    <classpath>
+                        <pathelement location="${build.tests}"/>
+                        <pathelement location="${build.gen-tests}"/>
+                        <path refid="drt.classpath"/>
+                    </classpath>
+                    <sysproperty key="base.url"
+                        value="${server.root.url}/${wsm.test.webapp.name}"/>
+                    <formatter type="plain"/>
+<test name="org.apache.beehive.wsm.jsr181.wsdl.WebServiceTargetNamespace"
+  todir="${drt.logs}"/>
+                </junit>
+                <antcall target="undeploy"/>
+                <echo message="stopping Web container"/>
+                <stop-server />
+            </sequential>
+        </parallel>
+
+        <fail if="wsmtemp" message="One or more tests in the WSM DRT failed."/>

     </target>

+    <!-- ================================================================ -->
+    <!--                                                                  -->
+    <!-- Targets for deploying the webapp on a server                     -->
+    <!--                                                                  -->
+    <!-- ================================================================ -->
+    <target name="deploy" description="Deploy webapp">
+        <deploy-webapp webappDir="${webapp.dir}" contextPath="${wsm.test.webapp
.name}"/>
+    </target>
+
+    <target name="undeploy" description="Undeploy webapp">
+        <undeploy-webapp contextPath="${wsm.test.webapp.name}"/>
+    </target>
+
+    <target name="redeploy" description="Redeploy webapp">
+        <undeploy-webapp contextPath="${wsm.test.webapp.name}"/>
+    </target>
+
+    <!-- ================================================================ -->
+    <!--                                                                  -->
+    <!-- Targets for starting / stopping a server                         -->
+    <!--                                                                  -->
+    <!-- ================================================================ -->
+    <target name="start" description="Start server">
+        <start-server shmem="false" javaOptions=""/>
+    </target>
+
+    <target name="start.with.shmem" description="Start server">
+        <start-server shmem="true" javaOptions=""/>
+    </target>
+
+    <target name="start.with.asserts" description="Start server with asserts en
abled for org.apache.beehive.netui">
+        <start-server shmem="false" javaOptions="-ea:org.apache.beehive.netui..
."/>
+    </target>
+
+    <target name="start.with.shmem.asserts" description="Start server with asse
rts enabled for org.apache.beehive.wsm">
+        <start-server shmem="true" javaOptions="-ea:org.apache.beehive.wsm..."/
>
+    </target>
+
+    <target name="stop" description="Stop server">
+        <stop-server/>
+    </target>
+
+    <target name="ensure.deployed" description="Deploy Web services webapp">
+        <echo>Ensuring that the webapp ${wsm.test.webapp.name} is deployed on a
 running server at the url ${webapp.waitfor.url}</echo>
+
+        <waitfor maxwait="5" maxwaitunit="second" timeoutproperty="unavailable"
>
+            <http url="${webapp.waitfor.url}"/>
+        </waitfor>
+        <antcall target="do.deploy"/>
+        <antcall target="do.redeploy"/>
+        <fail if="still.unavailable" message="Couldn't find webapp with path ${
webapp.waitfor.url}"/>
+    </target>
+
+    <target name="do.deploy" if="unavailable">
+        <echo>Webapp is not deployed; deploying</echo>
+
+        <antcall target="deploy"/>
+        <echo>...deploy complete</echo>
+
+        <waitfor maxwait="120" maxwaitunit="second" timeoutproperty="still.unav
ailable">
+            <http url="${webapp.waitfor.url}"/>
+        </waitfor>
+    </target>
+
+    <target name="do.redeploy" unless="unavailable">
+        <echo>Webapp is deployed; undeploy and redeploy</echo>
+
+        <antcall target="undeploy"/>
+        <echo>...undeploy complete</echo>
+
+        <antcall target="deploy"/>
+        <echo>...deploy complete</echo>
+
+        <waitfor maxwait="120" maxwaitunit="second" timeoutproperty="still.unav
ailable">
+            <http url="${webapp.waitfor.url}"/>
+        </waitfor>
+    </target>
+
 </project>

I wanted this email to be a little longer, but that is all I have to say :)

- jeremiah

Mime
View raw message