Search in sources :

Example 1 with SchemaValidation

use of org.apache.schema_validation.SchemaValidation in project cxf by apache.

the class ValidationClientServerTest method assertIgnoredResponseValidation.

private void assertIgnoredResponseValidation(Object validationConfig) throws Exception {
    SchemaValidation service = createService(validationConfig);
    // the request will result in invalid response but validation is turned off
    SomeResponse response = execute(service, "1234567890");
    assertEquals(response.getTransactionId(), "aaaaaaaaaaxxx");
    ((java.io.Closeable) service).close();
}
Also used : SomeResponse(org.apache.schema_validation.types.SomeResponse) SchemaValidation(org.apache.schema_validation.SchemaValidation)

Example 2 with SchemaValidation

use of org.apache.schema_validation.SchemaValidation in project cxf by apache.

the class ValidationClientServerTest method assertIgnoredRequestValidation.

private void assertIgnoredRequestValidation(Object validationConfig) throws Exception {
    SchemaValidation service = createService(validationConfig);
    // this is an invalid request but validation is turned off.
    SomeResponse response = execute(service, "1234567890aaaa");
    assertEquals(response.getTransactionId(), "aaaaaaaaaa");
    ((java.io.Closeable) service).close();
}
Also used : SomeResponse(org.apache.schema_validation.types.SomeResponse) SchemaValidation(org.apache.schema_validation.SchemaValidation)

Example 3 with SchemaValidation

use of org.apache.schema_validation.SchemaValidation in project cxf by apache.

the class ValidationClientServerTest method assertFailureResponseValidation.

private void assertFailureResponseValidation(Object validationConfig) throws Exception {
    SchemaValidation service = createService(validationConfig);
    // valid request
    SomeResponse response = execute(service, "1111111111");
    assertEquals(response.getTransactionId(), "aaaaaaaaaa");
    try {
        // valid request, but will result in invalid response
        execute(service, "1234567890");
        fail("should catch marshall exception as the invalid incoming message per schema");
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("Unmarshalling Error"));
        assertTrue(e.getMessage().contains("is not facet-valid with respect to pattern"));
    }
    ((java.io.Closeable) service).close();
}
Also used : SomeResponse(org.apache.schema_validation.types.SomeResponse) SchemaValidation(org.apache.schema_validation.SchemaValidation) WebServiceException(javax.xml.ws.WebServiceException)

Example 4 with SchemaValidation

use of org.apache.schema_validation.SchemaValidation in project cxf by apache.

the class ValidationClientServerTest method testSchemaValidationServerForMethod.

@Test
public void testSchemaValidationServerForMethod() throws Exception {
    SchemaValidation validation = createService(Boolean.FALSE, "SoapPortMethodValidate");
    ComplexStruct complexStruct = new ComplexStruct();
    complexStruct.setElem1("one");
    complexStruct.setElem3(3);
    try {
        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);
    }
    SchemaValidation novlidation = createService(Boolean.FALSE, "SoapPort");
    try {
        novlidation.setComplexStruct(complexStruct);
    } catch (WebServiceException e) {
        fail("Exception is not expected :" + e);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) ComplexStruct(org.apache.schema_validation.types.ComplexStruct) SchemaValidation(org.apache.schema_validation.SchemaValidation) Test(org.junit.Test)

Example 5 with SchemaValidation

use of org.apache.schema_validation.SchemaValidation in project cxf by apache.

the class ValidationClientServerTest method doProviderTest.

private void doProviderTest(String postfix) throws Exception {
    SchemaValidation validation = createService(Boolean.FALSE, postfix);
    SomeRequest req = new SomeRequest();
    req.setId("9999999999");
    try {
        validation.doSomething(req);
        fail("Should have faulted");
    } catch (DoSomethingFault e) {
        assertEquals("1234", e.getFaultInfo().getErrorCode());
    }
    req.setId("8888888888");
    try {
        validation.doSomething(req);
        fail("Should have faulted");
    } catch (DoSomethingFault e) {
        fail("Should not have happened");
    } catch (WebServiceException e) {
        String expected = "Value '1' is not facet-valid";
        assertTrue(e.getMessage().indexOf(expected) != -1);
    }
    ((java.io.Closeable) validation).close();
}
Also used : DoSomethingFault(org.apache.schema_validation.DoSomethingFault) SomeRequest(org.apache.schema_validation.types.SomeRequest) WebServiceException(javax.xml.ws.WebServiceException) SchemaValidation(org.apache.schema_validation.SchemaValidation)

Aggregations

SchemaValidation (org.apache.schema_validation.SchemaValidation)9 WebServiceException (javax.xml.ws.WebServiceException)4 SomeResponse (org.apache.schema_validation.types.SomeResponse)4 Test (org.junit.Test)3 URL (java.net.URL)1 LoggingFeature (org.apache.cxf.ext.logging.LoggingFeature)1 DoSomethingFault (org.apache.schema_validation.DoSomethingFault)1 SchemaValidationService (org.apache.schema_validation.SchemaValidationService)1 ComplexStruct (org.apache.schema_validation.types.ComplexStruct)1 SomeRequest (org.apache.schema_validation.types.SomeRequest)1