001: package org.objectweb.celtix.systest.schema_validation;
002:
003: import java.io.Serializable;
004: import java.net.URL;
005: import java.util.List;
006:
007: import javax.xml.namespace.QName;
008: import javax.xml.ws.ProtocolException;
009:
010: import junit.framework.Test;
011: import junit.framework.TestSuite;
012:
013: import org.objectweb.celtix.systest.common.ClientServerSetupBase;
014: import org.objectweb.celtix.systest.common.ClientServerTestBase;
015: import org.objectweb.schema_validation.SchemaValidation;
016: import org.objectweb.schema_validation.SchemaValidationService;
017: import org.objectweb.schema_validation.types.ComplexStruct;
018: import org.objectweb.schema_validation.types.OccuringStruct;
019:
020: public class ValidationClientServerTest extends ClientServerTestBase {
021:
022: private final QName serviceName = new QName(
023: "http://objectweb.org/schema_validation",
024: "SchemaValidationService");
025: private final QName portName = new QName(
026: "http://objectweb.org/schema_validation", "SoapPort");
027:
028: public static Test suite() throws Exception {
029: TestSuite suite = new TestSuite(
030: ValidationClientServerTest.class);
031: return new ClientServerSetupBase(suite) {
032: public void startServers() throws Exception {
033: assertTrue("server did not launch correctly",
034: launchServer(ValidationServer.class));
035: }
036:
037: public void setUp() throws Exception {
038: // set up configuration to enable schema validation
039: URL url = getClass().getResource("celtix-config.xml");
040: assertNotNull("cannot find test resource", url);
041: configFileName = url.toString();
042: super .setUp();
043: }
044: };
045: }
046:
047: // TODO : Change this test so that we test the combinations of
048: // client and server with schema validation enabled/disabled...
049: public void testSchemaValidation() throws Exception {
050: URL wsdl = getClass().getResource(
051: "/wsdl/schema_validation.wsdl");
052: assertNotNull(wsdl);
053:
054: SchemaValidationService service = new SchemaValidationService(
055: wsdl, serviceName);
056: assertNotNull(service);
057:
058: SchemaValidation validation = service.getPort(portName,
059: SchemaValidation.class);
060:
061: ComplexStruct complexStruct = new ComplexStruct();
062: complexStruct.setElem1("one");
063: // Don't initialize a member of the structure. Validation should throw
064: // an exception.
065: // complexStruct.setElem2("two");
066: complexStruct.setElem3(3);
067: try {
068: /*boolean result =*/validation
069: .setComplexStruct(complexStruct);
070: fail("Set ComplexStruct hould have thrown ProtocolException");
071: } catch (ProtocolException e) {
072: //System.out.println(e.getMessage());
073: }
074:
075: OccuringStruct occuringStruct = new OccuringStruct();
076: // Populate the list in the wrong order. Validation should throw
077: // an exception.
078: List<Serializable> floatIntStringList = occuringStruct
079: .getVarFloatAndVarIntAndVarString();
080: floatIntStringList.add(new Integer(42));
081: floatIntStringList.add(new Float(4.2f));
082: floatIntStringList.add("Goofus and Gallant");
083: try {
084: /*boolean result =*/validation
085: .setOccuringStruct(occuringStruct);
086: fail("Set OccuringStruct hould have thrown ProtocolException");
087: } catch (ProtocolException e) {
088: //System.out.println(e.getMessage());
089: }
090:
091: try {
092: // The server will attempt to return an invalid ComplexStruct
093: /*complexStruct =*/validation.getComplexStruct("Hello");
094: // This would throw an exception if validation is disabled on
095: // the server and enabled on the client.
096: //fail("Get ComplexStruct should have thrown ProtocolException");
097: } catch (ProtocolException e) {
098: //System.out.println(e.getMessage());
099: }
100:
101: try {
102: // The server will attempt to return an invalid OccuringStruct
103: /*occuringStruct =*/validation.getOccuringStruct("World");
104: // This would throw an exception if validation is disabled on
105: // the server and enabled on the client.
106: //fail("Get OccuringStruct should have thrown ProtocolException");
107: } catch (ProtocolException e) {
108: //System.out.println(e.getMessage());
109: }
110: }
111:
112: public static void main(String[] args) {
113: junit.textui.TestRunner.run(ValidationClientServerTest.class);
114: }
115:
116: }
|