KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > systest > schema_validation > ValidationClientServerTest


1 package org.objectweb.celtix.systest.schema_validation;
2
3 import java.io.Serializable JavaDoc;
4 import java.net.URL JavaDoc;
5 import java.util.List JavaDoc;
6
7 import javax.xml.namespace.QName JavaDoc;
8 import javax.xml.ws.ProtocolException;
9
10 import junit.framework.Test;
11 import junit.framework.TestSuite;
12
13 import org.objectweb.celtix.systest.common.ClientServerSetupBase;
14 import org.objectweb.celtix.systest.common.ClientServerTestBase;
15 import org.objectweb.schema_validation.SchemaValidation;
16 import org.objectweb.schema_validation.SchemaValidationService;
17 import org.objectweb.schema_validation.types.ComplexStruct;
18 import org.objectweb.schema_validation.types.OccuringStruct;
19
20 public class ValidationClientServerTest extends ClientServerTestBase {
21
22     private final QName JavaDoc serviceName = new QName JavaDoc("http://objectweb.org/schema_validation",
23                                                 "SchemaValidationService");
24     private final QName JavaDoc portName = new QName JavaDoc("http://objectweb.org/schema_validation",
25                                              "SoapPort");
26
27     public static Test suite() throws Exception JavaDoc {
28         TestSuite suite = new TestSuite(ValidationClientServerTest.class);
29         return new ClientServerSetupBase(suite) {
30             public void startServers() throws Exception JavaDoc {
31                 assertTrue("server did not launch correctly", launchServer(ValidationServer.class));
32             }
33             
34             public void setUp() throws Exception JavaDoc {
35                 // set up configuration to enable schema validation
36
URL JavaDoc url = getClass().getResource("celtix-config.xml");
37                 assertNotNull("cannot find test resource", url);
38                 configFileName = url.toString();
39                 super.setUp();
40             }
41         };
42     }
43
44     // TODO : Change this test so that we test the combinations of
45
// client and server with schema validation enabled/disabled...
46
public void testSchemaValidation() throws Exception JavaDoc {
47         URL JavaDoc wsdl = getClass().getResource("/wsdl/schema_validation.wsdl");
48         assertNotNull(wsdl);
49         
50         SchemaValidationService service = new SchemaValidationService(wsdl, serviceName);
51         assertNotNull(service);
52         
53         SchemaValidation validation = service.getPort(portName, SchemaValidation.class);
54
55         ComplexStruct complexStruct = new ComplexStruct();
56         complexStruct.setElem1("one");
57         // Don't initialize a member of the structure. Validation should throw
58
// an exception.
59
// complexStruct.setElem2("two");
60
complexStruct.setElem3(3);
61         try {
62             /*boolean result =*/ validation.setComplexStruct(complexStruct);
63             fail("Set ComplexStruct hould have thrown ProtocolException");
64         } catch (ProtocolException e) {
65             //System.out.println(e.getMessage());
66
}
67
68         OccuringStruct occuringStruct = new OccuringStruct();
69         // Populate the list in the wrong order. Validation should throw
70
// an exception.
71
List JavaDoc<Serializable JavaDoc> floatIntStringList = occuringStruct.getVarFloatAndVarIntAndVarString();
72         floatIntStringList.add(new Integer JavaDoc(42));
73         floatIntStringList.add(new Float JavaDoc(4.2f));
74         floatIntStringList.add("Goofus and Gallant");
75         try {
76             /*boolean result =*/ validation.setOccuringStruct(occuringStruct);
77             fail("Set OccuringStruct hould have thrown ProtocolException");
78         } catch (ProtocolException e) {
79             //System.out.println(e.getMessage());
80
}
81
82         try {
83             // The server will attempt to return an invalid ComplexStruct
84
/*complexStruct =*/ validation.getComplexStruct("Hello");
85             // This would throw an exception if validation is disabled on
86
// the server and enabled on the client.
87
//fail("Get ComplexStruct should have thrown ProtocolException");
88
} catch (ProtocolException e) {
89             //System.out.println(e.getMessage());
90
}
91         
92         try {
93             // The server will attempt to return an invalid OccuringStruct
94
/*occuringStruct =*/ validation.getOccuringStruct("World");
95             // This would throw an exception if validation is disabled on
96
// the server and enabled on the client.
97
//fail("Get OccuringStruct should have thrown ProtocolException");
98
} catch (ProtocolException e) {
99             //System.out.println(e.getMessage());
100
}
101     }
102
103     public static void main(String JavaDoc[] args) {
104         junit.textui.TestRunner.run(ValidationClientServerTest.class);
105     }
106     
107 }
108
Popular Tags