// TODO : Change this test so that we test the combinations of
// client and server with schema validation enabled/disabled...
// Only tests client side validation enabled/server side disabled.
@Test
public void testSchemaValidation() throws Exception {
SchemaValidation validation = createService(Boolean.TRUE);
ComplexStruct complexStruct = new ComplexStruct();
complexStruct.setElem1("one");
// Don't initialize a member of the structure.
// Client side validation should throw an exception.
// complexStruct.setElem2("two");
complexStruct.setElem3(3);
try {
/*boolean result =*/
validation.setComplexStruct(complexStruct);
fail("Set ComplexStruct should have thrown ProtocolException");
} catch (WebServiceException e) {
String expected = "'{\"http://apache.org/schema_validation/types\":elem2}' is expected.";
assertTrue(e.getMessage(), e.getMessage().indexOf(expected) != -1);
}
OccuringStruct occuringStruct = new OccuringStruct();
// Populate the list in the wrong order.
// Client side validation should throw an exception.
List<Serializable> floatIntStringList = occuringStruct.getVarFloatAndVarIntAndVarString();
floatIntStringList.add(new Integer(42));
floatIntStringList.add(new Float(4.2f));
floatIntStringList.add("Goofus and Gallant");
try {
/*boolean result =*/
validation.setOccuringStruct(occuringStruct);
fail("Set OccuringStruct should have thrown ProtocolException");
} catch (WebServiceException e) {
String expected = "'{\"http://apache.org/schema_validation/types\":varFloat}' is expected.";
assertTrue(e.getMessage().indexOf(expected) != -1);
}
validation = createService(Boolean.FALSE);
try {
// The server will attempt to return an invalid ComplexStruct
// When validation is disabled on the server side, we'll get the
// exception while unmarshalling the invalid response.
/*complexStruct =*/
validation.getComplexStruct("Hello");
fail("Get ComplexStruct should have thrown ProtocolException");
} catch (WebServiceException e) {
String expected = "'{\"http://apache.org/schema_validation/types\":elem2}' is expected.";
assertTrue("Found message " + e.getMessage(),
e.getMessage().indexOf(expected) != -1);
}
validation = createService(Boolean.TRUE);
try {
// The server will attempt to return an invalid OccuringStruct
// When validation is disabled on the server side, we'll get the
// exception while unmarshalling the invalid response.
/*occuringStruct =*/
validation.getOccuringStruct("World");
fail("Get OccuringStruct should have thrown ProtocolException");
} catch (WebServiceException e) {
String expected = "'{\"http://apache.org/schema_validation/types\":varFloat}' is expected.";
assertTrue(e.getMessage().indexOf(expected) != -1);
}