You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2005/02/05 22:14:00 UTC
cvs commit: ws-axis/java/test GenericLocalTest.java
dims 2005/02/05 13:14:00
Modified: java/test GenericLocalTest.java
Added: java/test/holders ArrayOfBook.java Book.java build.xml
PackageTests.java TestBook.java
java/test/holders/holders ArrayOfBookHolder.java
BookHolder.java
Log:
Checking in test case (working). Will break if the indexed methods in ArrayOfBook are removed.
[Basically if we have a bean that contains a field that is an array, but the bean does not provide indexed methods to set/get values, only java bean setter and getter (that take/return the entire array) then we fail.]
Revision Changes Path
1.1 ws-axis/java/test/holders/ArrayOfBook.java
Index: ArrayOfBook.java
===================================================================
package test.holders;
public class ArrayOfBook implements java.io.Serializable {
private test.holders.Book[] arrayOfBook;
public ArrayOfBook() {
}
public ArrayOfBook(
test.holders.Book[] arrayOfBook) {
this.arrayOfBook = arrayOfBook;
}
public test.holders.Book[] getArrayOfBook() {
return arrayOfBook;
}
public void setArrayOfBook(test.holders.Book[] arrayOfBook) {
this.arrayOfBook = arrayOfBook;
}
public test.holders.Book getArrayOfBook(int i) {
return this.arrayOfBook[i];
}
public void setArrayOfBook(int i, test.holders.Book _value) {
this.arrayOfBook[i] = _value;
}
}
1.1 ws-axis/java/test/holders/Book.java
Index: Book.java
===================================================================
package test.holders;
public class Book implements java.io.Serializable {
private java.lang.String author;
private java.lang.String title;
private int isbn;
public Book() {
}
public Book(
java.lang.String author,
int isbn,
java.lang.String title) {
this.author = author;
this.title = title;
this.isbn = isbn;
}
/**
* Gets the author value for this Book.
*
* @return author
*/
public java.lang.String getAuthor() {
return author;
}
/**
* Sets the author value for this Book.
*
* @param author
*/
public void setAuthor(java.lang.String author) {
this.author = author;
}
/**
* Gets the title value for this Book.
*
* @return title
*/
public java.lang.String getTitle() {
return title;
}
/**
* Sets the title value for this Book.
*
* @param title
*/
public void setTitle(java.lang.String title) {
this.title = title;
}
/**
* Gets the isbn value for this Book.
*
* @return isbn
*/
public int getIsbn() {
return isbn;
}
/**
* Sets the isbn value for this Book.
*
* @param isbn
*/
public void setIsbn(int isbn) {
this.isbn = isbn;
}
}
1.1 ws-axis/java/test/holders/build.xml
Index: build.xml
===================================================================
<?xml version="1.0" ?>
<!DOCTYPE project [
<!ENTITY properties SYSTEM "file:../../xmls/properties.xml">
<!ENTITY paths SYSTEM "file:../../xmls/path_refs.xml">
<!ENTITY taskdefs SYSTEM "file:../../xmls/taskdefs.xml">
<!ENTITY taskdefs_post_compile SYSTEM "file:../../xmls/taskdefs_post_compile.xml">
<!ENTITY targets SYSTEM "file:../../xmls/targets.xml">
]>
<!-- ===================================================================
<description>
Test/Sample Component file for Axis
Notes:
This is a build file for use with the Jakarta Ant build tool.
Prerequisites:
jakarta-ant from http://jakarta.apache.org
Build Instructions:
To compile
ant compile
To execute
ant run
Author:
Matt Seibert mseibert@us.ibm.com
Copyright:
Copyright (c) 2002-2003 Apache Software Foundation.
</description>
==================================================================== -->
<project default="compile">
<property name="axis.home" location="../../"/>
<property name="componentName" value="test/holders"/>
&properties;
&paths;
&taskdefs;
&taskdefs_post_compile;
&targets;
<target name="clean">
<echo message="Removing ${build.dir}/classes/${componentName} and ${build.dir}/work/${componentName}"/>
<delete dir="${build.dir}/classes/${componentName}"/>
<delete dir="${build.dir}/work/${componentName}"/>
</target>
<target name="copy" depends="setenv"/>
<target name="compile" depends="copy">
<echo message="Compiling ${componentName}"/>
<javac srcdir="${axis.home}" destdir="${build.dest}" debug="${debug}"
nowarn="${nowarn}" source="${source}" fork="${javac.fork}">
<classpath>
<path refid="classpath"/>
</classpath>
<include name="${componentName}/**/*.java"/>
</javac>
</target>
<target name="run">
<antcall target="execute-Component-noServer"/>
</target>
</project>
1.1 ws-axis/java/test/holders/PackageTests.java
Index: PackageTests.java
===================================================================
/*
* Copyright 2002-2004 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 test.holders;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class PackageTests extends TestCase {
public PackageTests(String name) {
super(name);
}
public static Test suite() throws Exception {
TestSuite suite = new TestSuite();
suite.addTestSuite(TestBook.class);
return suite;
}
}
1.1 ws-axis/java/test/holders/TestBook.java
Index: TestBook.java
===================================================================
/*
* Copyright 2002-2004 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 test.holders;
import org.apache.axis.client.Call;
import org.apache.axis.encoding.TypeMapping;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
import org.apache.axis.enum.Style;
import org.apache.axis.enum.Use;
import test.GenericLocalTest;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import java.rmi.RemoteException;
import java.util.List;
/**
* Confirm that faults using beans work
*/
public class TestBook extends GenericLocalTest {
private QName TYPE_ARRAY_OF_BOOK =
new QName("http://holdertest.org/xsd", "ArrayOfBook");
private QName TYPE_BOOK = new QName("http://holdertest.org/xsd", "Book");
public TestBook() {
super("service");
}
public TestBook(String s) {
super(s);
}
protected void setUp() throws Exception {
super.setUp(false); // don't deploy here
TypeMapping tm = (TypeMapping)config.getTypeMappingRegistry().
getDefaultTypeMapping();
tm.register(Book.class, TYPE_BOOK,
new BeanSerializerFactory(Book.class, TYPE_BOOK),
new BeanDeserializerFactory(Book.class, TYPE_BOOK));
tm.register(ArrayOfBook.class, TYPE_ARRAY_OF_BOOK,
new BeanSerializerFactory(ArrayOfBook.class,
TYPE_ARRAY_OF_BOOK),
new BeanDeserializerFactory(ArrayOfBook.class,
TYPE_ARRAY_OF_BOOK));
deploy("service", this.getClass(), Style.RPC, Use.LITERAL);
}
public void testInOutBook() throws Exception {
Call call = getCall();
call.setOperationStyle("rpc");
call.setOperationUse("literal");
call.setEncodingStyle("");
call.registerTypeMapping(Book.class, TYPE_BOOK,
new BeanSerializerFactory(Book.class, TYPE_BOOK),
new BeanDeserializerFactory(Book.class, TYPE_BOOK));
call.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);
call.addParameter("varBook", TYPE_BOOK, ParameterMode.INOUT);
Book data = new Book();
data.setAuthor("author1");
data.setTitle("title1");
data.setIsbn(1);
call.invoke("echoInOutBook", new Object []{data});
List l = call.getOutputValues();
assertEquals(1, l.size());
assertEquals("author2", ((Book)l.get(0)).getAuthor());
assertEquals("title2", ((Book)l.get(0)).getTitle());
assertEquals(2, ((Book)l.get(0)).getIsbn());
}
public void testInOutBookArray() throws Exception {
Call call = getCall();
call.setOperationStyle("rpc");
call.setOperationUse("literal");
call.setEncodingStyle("");
call.registerTypeMapping(ArrayOfBook.class, TYPE_ARRAY_OF_BOOK,
new BeanSerializerFactory(ArrayOfBook.class,
TYPE_ARRAY_OF_BOOK),
new BeanDeserializerFactory(ArrayOfBook.class,
TYPE_ARRAY_OF_BOOK));
call.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);
call.addParameter("varBook", TYPE_ARRAY_OF_BOOK, ParameterMode.INOUT);
Book b0 = new Book();
b0.setAuthor("author0");
b0.setTitle("title0");
b0.setIsbn(0);
Book b1 = new Book();
b1.setAuthor("author1");
b1.setTitle("title1");
b1.setIsbn(1);
Book b[] = new Book[2];
b[0] = b0;
b[1] = b1;
ArrayOfBook aob = new ArrayOfBook();
aob.setArrayOfBook(b);
call.invoke("echoInOutBookArray", new Object []{aob});
List l = call.getOutputValues();
assertEquals(1, l.size());
ArrayOfBook aob2 = (ArrayOfBook)l.get(0);
Book b2[] = aob2.getArrayOfBook();
assertEquals(2, b2.length);
assertEquals(b2[0].getAuthor(), b[1].getAuthor());
assertEquals(b2[1].getTitle(), b[0].getTitle());
}
public void echoInOutBook(test.holders.holders.BookHolder varBook)
throws java.rmi.RemoteException {
Book b = varBook.value;
b.setAuthor("author2");
b.setTitle("title2");
b.setIsbn(2);
varBook.value = b;
}
public void echoInOutBookArray(test.holders.holders.ArrayOfBookHolder varBook)
throws java.rmi.RemoteException {
ArrayOfBook v = varBook.value;
Book[] b = v.getArrayOfBook();
if (b.length != 2) throw new RemoteException("array size not 2");
String author = b[0].getAuthor();
String title = b[0].getTitle();
int isbn = b[0].getIsbn();
b[0].setAuthor(b[1].getAuthor());
b[0].setTitle(b[1].getTitle());
b[0].setIsbn(b[1].getIsbn());
b[1].setAuthor(author);
b[1].setTitle(title);
b[1].setIsbn(isbn);
v.setArrayOfBook(b);
varBook.value = v;
}
}
1.1 ws-axis/java/test/holders/holders/ArrayOfBookHolder.java
Index: ArrayOfBookHolder.java
===================================================================
package test.holders.holders;
public final class ArrayOfBookHolder implements javax.xml.rpc.holders.Holder {
public test.holders.ArrayOfBook value;
public ArrayOfBookHolder() {
}
public ArrayOfBookHolder(test.holders.ArrayOfBook value) {
this.value = value;
}
}
1.1 ws-axis/java/test/holders/holders/BookHolder.java
Index: BookHolder.java
===================================================================
package test.holders.holders;
public final class BookHolder implements javax.xml.rpc.holders.Holder {
public test.holders.Book value;
public BookHolder() {
}
public BookHolder(test.holders.Book value) {
this.value = value;
}
}
1.7 +14 -0 ws-axis/java/test/GenericLocalTest.java
Index: GenericLocalTest.java
===================================================================
RCS file: /home/cvs/ws-axis/java/test/GenericLocalTest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- GenericLocalTest.java 25 Feb 2004 14:02:53 -0000 1.6
+++ GenericLocalTest.java 5 Feb 2005 21:14:00 -0000 1.7
@@ -21,6 +21,7 @@
import org.apache.axis.configuration.BasicServerConfig;
import org.apache.axis.configuration.SimpleProvider;
import org.apache.axis.enum.Style;
+import org.apache.axis.enum.Use;
import org.apache.axis.handlers.soap.SOAPService;
import org.apache.axis.providers.java.RPCProvider;
import org.apache.axis.server.AxisServer;
@@ -121,6 +122,19 @@
transport.setRemoteService(serviceName);
}
+ public void deploy(String serviceName, Class target, Style style, Use use) {
+ String className = target.getName();
+
+ service = new SOAPService(new RPCProvider());
+ service.setStyle(style);
+ service.setUse(use);
+
+ service.setOption("className", className);
+ service.setOption("allowedMethods", "*");
+
+ config.deployService(serviceName, service);
+ transport.setRemoteService(serviceName);
+ }
/**
* Deploy a service to the local server we've set up, using a
* Handler we provide as the pivot.