| 1 |
/* |
| 2 |
* Copyright 2002-2004 The Apache Software Foundation. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
package test.holders; |
| 17 |
|
| 18 |
import org.apache.axis.client.Call; |
| 19 |
import org.apache.axis.encoding.TypeMapping; |
| 20 |
import org.apache.axis.encoding.ser.BeanDeserializerFactory; |
| 21 |
import org.apache.axis.encoding.ser.BeanSerializerFactory; |
| 22 |
import org.apache.axis.constants.Style; |
| 23 |
import org.apache.axis.constants.Use; |
| 24 |
import test.GenericLocalTest; |
| 25 |
|
| 26 |
import javax.xml.namespace.QName; |
| 27 |
import javax.xml.rpc.ParameterMode; |
| 28 |
import java.rmi.RemoteException; |
| 29 |
import java.util.List; |
| 30 |
|
| 31 |
/** |
| 32 |
* Confirm that faults using beans work |
| 33 |
*/ |
| 34 |
public class TestBook extends GenericLocalTest { |
| 35 |
private QName TYPE_ARRAY_OF_BOOK = |
| 36 |
new QName("http://holdertest.org/xsd", "ArrayOfBook"); |
| 37 |
private QName TYPE_BOOK = new QName("http://holdertest.org/xsd", "Book"); |
| 38 |
|
| 39 |
public TestBook() { |
| 40 |
super("service"); |
| 41 |
} |
| 42 |
|
| 43 |
public TestBook(String s) { |
| 44 |
super(s); |
| 45 |
} |
| 46 |
|
| 47 |
protected void setUp() throws Exception { |
| 48 |
super.setUp(false); // don't deploy here |
| 49 |
TypeMapping tm = (TypeMapping)config.getTypeMappingRegistry(). |
| 50 |
getDefaultTypeMapping(); |
| 51 |
tm.register(Book.class, TYPE_BOOK, |
| 52 |
new BeanSerializerFactory(Book.class, TYPE_BOOK), |
| 53 |
new BeanDeserializerFactory(Book.class, TYPE_BOOK)); |
| 54 |
tm.register(ArrayOfBook.class, TYPE_ARRAY_OF_BOOK, |
| 55 |
new BeanSerializerFactory(ArrayOfBook.class, |
| 56 |
TYPE_ARRAY_OF_BOOK), |
| 57 |
new BeanDeserializerFactory(ArrayOfBook.class, |
| 58 |
TYPE_ARRAY_OF_BOOK)); |
| 59 |
deploy("service", this.getClass(), Style.RPC, Use.LITERAL); |
| 60 |
} |
| 61 |
|
| 62 |
public void testInOutBook() throws Exception { |
| 63 |
Call call = getCall(); |
| 64 |
call.setOperationStyle("rpc"); |
| 65 |
call.setOperationUse("literal"); |
| 66 |
call.setEncodingStyle(""); |
| 67 |
call.registerTypeMapping(Book.class, TYPE_BOOK, |
| 68 |
new BeanSerializerFactory(Book.class, TYPE_BOOK), |
| 69 |
new BeanDeserializerFactory(Book.class, TYPE_BOOK)); |
| 70 |
call.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID); |
| 71 |
call.addParameter("varBook", TYPE_BOOK, ParameterMode.INOUT); |
| 72 |
Book data = new Book(); |
| 73 |
data.setAuthor("author1"); |
| 74 |
data.setTitle("title1"); |
| 75 |
data.setIsbn(1); |
| 76 |
call.invoke("echoInOutBook", new Object []{data}); |
| 77 |
List l = call.getOutputValues(); |
| 78 |
assertEquals(1, l.size()); |
| 79 |
assertEquals("author2", ((Book)l.get(0)).getAuthor()); |
| 80 |
assertEquals("title2", ((Book)l.get(0)).getTitle()); |
| 81 |
assertEquals(2, ((Book)l.get(0)).getIsbn()); |
| 82 |
} |
| 83 |
|
| 84 |
public void testInOutBookArray() throws Exception { |
| 85 |
Call call = getCall(); |
| 86 |
call.setOperationStyle("rpc"); |
| 87 |
call.setOperationUse("literal"); |
| 88 |
call.setEncodingStyle(""); |
| 89 |
call.registerTypeMapping(ArrayOfBook.class, TYPE_ARRAY_OF_BOOK, |
| 90 |
new BeanSerializerFactory(ArrayOfBook.class, |
| 91 |
TYPE_ARRAY_OF_BOOK), |
| 92 |
new BeanDeserializerFactory(ArrayOfBook.class, |
| 93 |
TYPE_ARRAY_OF_BOOK)); |
| 94 |
call.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID); |
| 95 |
call.addParameter("varBook", TYPE_ARRAY_OF_BOOK, ParameterMode.INOUT); |
| 96 |
Book b0 = new Book(); |
| 97 |
b0.setAuthor("author0"); |
| 98 |
b0.setTitle("title0"); |
| 99 |
b0.setIsbn(0); |
| 100 |
Book b1 = new Book(); |
| 101 |
b1.setAuthor("author1"); |
| 102 |
b1.setTitle("title1"); |
| 103 |
b1.setIsbn(1); |
| 104 |
Book b[] = new Book[2]; |
| 105 |
b[0] = b0; |
| 106 |
b[1] = b1; |
| 107 |
ArrayOfBook aob = new ArrayOfBook(); |
| 108 |
aob.setArrayOfBook(b); |
| 109 |
call.invoke("echoInOutBookArray", new Object []{aob}); |
| 110 |
List l = call.getOutputValues(); |
| 111 |
assertEquals(1, l.size()); |
| 112 |
ArrayOfBook aob2 = (ArrayOfBook)l.get(0); |
| 113 |
Book b2[] = aob2.getArrayOfBook(); |
| 114 |
assertEquals(2, b2.length); |
| 115 |
assertEquals(b2[0].getAuthor(), b[1].getAuthor()); |
| 116 |
assertEquals(b2[1].getTitle(), b[0].getTitle()); |
| 117 |
} |
| 118 |
|
| 119 |
public void echoInOutBook(test.holders.holders.BookHolder varBook) |
| 120 |
throws java.rmi.RemoteException { |
| 121 |
Book b = varBook.value; |
| 122 |
b.setAuthor("author2"); |
| 123 |
b.setTitle("title2"); |
| 124 |
b.setIsbn(2); |
| 125 |
varBook.value = b; |
| 126 |
} |
| 127 |
|
| 128 |
public void echoInOutBookArray(test.holders.holders.ArrayOfBookHolder varBook) |
| 129 |
throws java.rmi.RemoteException { |
| 130 |
ArrayOfBook v = varBook.value; |
| 131 |
Book[] b = v.getArrayOfBook(); |
| 132 |
if (b.length != 2) throw new RemoteException("array size not 2"); |
| 133 |
String author = b[0].getAuthor(); |
| 134 |
String title = b[0].getTitle(); |
| 135 |
int isbn = b[0].getIsbn(); |
| 136 |
b[0].setAuthor(b[1].getAuthor()); |
| 137 |
b[0].setTitle(b[1].getTitle()); |
| 138 |
b[0].setIsbn(b[1].getIsbn()); |
| 139 |
b[1].setAuthor(author); |
| 140 |
b[1].setTitle(title); |
| 141 |
b[1].setIsbn(isbn); |
| 142 |
v.setArrayOfBook(b); |
| 143 |
varBook.value = v; |
| 144 |
} |
| 145 |
} |