|
|
Axis 2 example source code file (TestClassTemplate.xsl)
This example Axis 2 source code file (TestClassTemplate.xsl) is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.
The Axis 2 TestClassTemplate.xsl source code
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you 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.
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<!-- Incldue the test object creation template -->
<xsl:include href="testObject"/>
<xsl:template match="/class">
<xsl:variable name="interfaceName">
<xsl:variable name="package">
<xsl:variable name="callbackname">
<xsl:variable name="stubname">
<xsl:variable name="isSync">
<xsl:variable name="isAsync">
<xsl:variable name="isbackcompatible" select="@isbackcompatible"/>
/**
* <xsl:value-of select="@name"/>.java
*
* This file was auto-generated from WSDL
* by the Apache Axis2 version: #axisVersion# #today#
*/
package <xsl:value-of select="$package"/>;
/*
* <xsl:value-of select="@name"/> Junit test case
*/
public class <xsl:value-of select="@name"/> extends junit.framework.TestCase{
<xsl:for-each select="method">
<xsl:if test="@mep='12'">
<xsl:variable name="outputtype">
<xsl:variable name="outParamType" select="output/param[@location='body']/@type">
<xsl:variable name="outParamComplexType" select="output/param[@location='body']/@complextype">
<xsl:variable name="outParamCount" select="count(output/param[@location='body']/param)">
<xsl:if test="$isSync='1'">
/**
* Auto generated test method
*/
public void test<xsl:value-of select="@name"/>() throws java.lang.Exception{
<xsl:value-of select="$package"/>. stub =
new <xsl:value-of select="$package"/>.();//the default implementation should point to the right endpoint
<xsl:choose>
<xsl:when test="count(input/param)>0">
<xsl:for-each select="input/param[@type!='']">
<xsl:value-of select="@type"/> =
</xsl:text>()getTestObject(.class);
// TODO : Fill in the <xsl:value-of select="@name"/> here
</xsl:for-each>
<xsl:choose>
<xsl:when test="$outputtype=''">
<!-- for now think there is only one input element -->
//There is no output to be tested!
stub.<xsl:value-of select="@name"/>(
<xsl:for-each select="input/param[@type!='']">
<xsl:variable name="opname" select="@opname"/>
<xsl:variable name="paramname" select="@name"/>
<xsl:variable name="complexType" select="@complextype"/>
<xsl:variable name="paramcount" select="count(param[@type!='' and @opname=$opname])"/>
<xsl:choose>
<xsl:when test="($isbackcompatible='true') and string-length(normalize-space($complexType)) > 0">
<xsl:if test="@type!=''">,get()
</xsl:when>
<xsl:when test="($paramcount > 0) and not($isbackcompatible='true')">
<xsl:for-each select="param[@type!='' and @opname=$opname]">
<xsl:if test="position()>1">,get()
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:if test="@type!=''">,
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>);
</xsl:when>
<xsl:otherwise>
assertNotNull(stub.<xsl:value-of select="@name"/>(
<xsl:for-each select="input/param[@type!='']">
<xsl:variable name="opname" select="@opname"/>
<xsl:variable name="paramname" select="@name"/>
<xsl:variable name="complexType" select="@complextype"/>
<xsl:variable name="paramcount" select="count(param[@type!='' and @opname=$opname])"/>
<xsl:choose>
<xsl:when test="($isbackcompatible='true') and string-length(normalize-space($complexType)) > 0">
<xsl:if test="@type!=''">,get()
</xsl:when>
<xsl:when test="($paramcount > 0) and not($isbackcompatible='true')">
<xsl:for-each select="param[@type!='' and @opname=$opname]">
<xsl:if test="position()>1">,get()
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:if test="@type!=''">,
</xsl:otherwise>
</xsl:choose>
<!-- if the input/param element contain any attributes then we have to unwrap them-->
</xsl:for-each>));
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$outputtype=''">
//There is no output to be tested!
stub.<xsl:value-of select="@name"/>();
</xsl:when>
<xsl:otherwise>
assertNotNull(stub.<xsl:value-of select="@name"/>());
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
}
</xsl:if>
<xsl:if test="$isAsync='1'">
<xsl:variable name="tempCallbackName">tempCallback
/**
* Auto generated test method
*/
public void testStart<xsl:value-of select="@name"/>() throws java.lang.Exception{
<xsl:value-of select="$package"/>. stub = new .();
<xsl:choose>
<xsl:when test="count(input/param)>0">
<xsl:for-each select="input/param[@type!='']">
<xsl:value-of select="@type"/> =
</xsl:text>()getTestObject(.class);
// TODO : Fill in the <xsl:value-of select="@name"/> here
</xsl:for-each>
stub.start<xsl:value-of select="@name"/>(
<xsl:for-each select="input/param[@type!='']">
<xsl:variable name="opname" select="@opname"/>
<xsl:variable name="paramname" select="@name"/>
<xsl:variable name="paramcount" select="count(param[@type!='' and @opname=$opname])"/>
<xsl:choose>
<xsl:when test="$paramcount > 0">
<xsl:for-each select="param[@type!='' and @opname=$opname]">
<xsl:if test="position()>1">,get()
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:if test="@type!=''">,
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>,
new <xsl:value-of select="$tempCallbackName"/>()
);
</xsl:when>
<xsl:otherwise>
stub.start<xsl:value-of select="@name"/>(
new <xsl:value-of select="$tempCallbackName"/>()
);
</xsl:otherwise>
</xsl:choose>
}
private class <xsl:value-of select="$tempCallbackName"/> extends .{
public <xsl:value-of select="$tempCallbackName"/>(){ super(null);}
public void receiveResult<xsl:value-of select="@name"/>(
<xsl:choose>
<xsl:when test="$outParamCount=1">
<xsl:value-of select="output/param[@location='body']/param/@type"/> result
</xsl:when>
<xsl:when test="string-length(normalize-space($outParamComplexType)) > 0">
<xsl:value-of select="$outParamComplexType"/> result
</xsl:when>
<xsl:when test="string-length(normalize-space($outParamType)) > 0">
<xsl:value-of select="$outParamType"/> result
</xsl:when>
</xsl:choose>) {
}
public void receiveError<xsl:value-of select="@name"/>(java.lang.Exception e) {
fail();
}
}
</xsl:if>
<!-- end of in-out mep -->
</xsl:if>
<!-- start of in-only mep-->
<xsl:if test="@mep='10' or @mep='11'">
/**
* Auto generated test method
*/
public void test<xsl:value-of select="@name"/>() throws java.lang.Exception{
<xsl:value-of select="$package"/>. stub =
new <xsl:value-of select="$package"/>.();//the default implementation should point to the right endpoint
<xsl:choose>
<xsl:when test="count(input/param)>0">
<xsl:for-each select="input/param[@type!='']">
<xsl:value-of select="@type"/> =
</xsl:text>()getTestObject(.class);
// TODO : Fill in the <xsl:value-of select="@name"/> here
</xsl:for-each>
//There is no output to be tested!
stub.<xsl:value-of select="@name"/>(
<xsl:for-each select="input/param[@type!='']">
<xsl:variable name="opname" select="@opname"/>
<xsl:variable name="paramname" select="@name"/>
<xsl:variable name="paramcount" select="count(param[@type!='' and @opname=$opname])"/>
<xsl:variable name="shorttype" select="@shorttype"/>
<xsl:choose>
<xsl:when test="$paramcount > 0">
<xsl:for-each select="param[@type!='' and @opname=$opname]">
<xsl:if test="position()>1">,get()
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:if test="@type!=''">,
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>);
</xsl:when>
<xsl:otherwise>
//There is no output to be tested!
stub.<xsl:value-of select="@name"/>();
</xsl:otherwise>
</xsl:choose>
}
</xsl:if>
</xsl:for-each>
<!-- generate the test object -->
<xsl:apply-templates/>
}
</xsl:template>
</xsl:stylesheet>
Other Axis 2 examples (source code examples)
Here is a short list of links related to this Axis 2 TestClassTemplate.xsl source code file:
|