Package org.apache.schema_validation

Examples of org.apache.schema_validation.SchemaValidation


        assertNotNull(wsdl);

        SchemaValidationService service = new SchemaValidationService(wsdl, serviceName);
        assertNotNull(service);

        SchemaValidation validation = service.getPort(portName, SchemaValidation.class);
        updateAddressPort(validation, PORT);
        ((BindingProvider)validation).getRequestContext()
            .put(Message.SCHEMA_VALIDATION_ENABLED, 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);
        }
        ((BindingProvider)validation).getRequestContext()
            .put(Message.SCHEMA_VALIDATION_ENABLED, 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);
        }

        ((BindingProvider)validation).getRequestContext()
            .put(Message.SCHEMA_VALIDATION_ENABLED, 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);
        }
View Full Code Here


    @Test
    public void testSchemaValidationProviderMessage() throws Exception {
        doProviderTest("MProvider");
    }
    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";
View Full Code Here

        ((java.io.Closeable)validation).close();
    }
   
    @Test
    public void testSchemaValidationServer() throws Exception {
        SchemaValidation validation = createService(Boolean.FALSE, "SoapPortValidate");
        runSchemaValidationTest(validation);
        ((java.io.Closeable)validation).close();
    }
View Full Code Here

        runSchemaValidationTest(validation);
        ((java.io.Closeable)validation).close();
    }
    @Test
    public void testSchemaValidationClient() throws Exception {
        SchemaValidation validation = createService(Boolean.TRUE, "SoapPort");
        runSchemaValidationTest(validation);
        ((java.io.Closeable)validation).close();
    }
View Full Code Here

        request.setId(id);
        return service.doSomething(request);
    }
   
    private void assertFailureResponseValidation(Object validationConfig) throws Exception {
        SchemaValidation service = createService(validationConfig);
       
        SomeResponse response = execute(service, "1111111111"); // valid request
        assertEquals(response.getTransactionId(), "aaaaaaaaaa");
       
        try {
View Full Code Here

       
        ((java.io.Closeable)service).close();
    }
   
    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();
View Full Code Here

        assertEquals(response.getTransactionId(), "aaaaaaaaaa");
        ((java.io.Closeable)service).close();
    }
   
    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();
View Full Code Here

        assertEquals(response.getTransactionId(), "aaaaaaaaaaxxx");
        ((java.io.Closeable)service).close();
    }
   
    private void assertFailedRequestValidation(Object validationConfig) throws Exception {
        SchemaValidation service = createService(validationConfig);
       
        SomeResponse response = execute(service, "1111111111");
        assertEquals(response.getTransactionId(), "aaaaaaaaaa");
       
        try {
View Full Code Here

        assertNotNull(wsdl);

        SchemaValidationService service = new SchemaValidationService(wsdl, serviceName);
        assertNotNull(service);

        SchemaValidation validation = service.getPort(portName, SchemaValidation.class);
        setAddress(validation, "http://localhost:" + PORT + "/SoapContext/" + postfix);
       
        ((BindingProvider)validation).getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, validationConfig);
        ((BindingProvider)validation).getResponseContext().put(Message.SCHEMA_VALIDATION_ENABLED, validationConfig);
        new LoggingFeature().initialize(ClientProxy.getClient(validation), getBus());
View Full Code Here

        assertNotNull(wsdl);

        SchemaValidationService service = new SchemaValidationService(wsdl, serviceName);
        assertNotNull(service);

        SchemaValidation validation = service.getPort(portName, SchemaValidation.class);

        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 hould have thrown ProtocolException");
        } catch (WebServiceException e) {
            assertTrue(e.getCause() instanceof Fault);
            String expected = "'{\"http://apache.org/schema_validation/types\":elem2}' is expected.";
            assertTrue(e.getCause().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 hould have thrown ProtocolException");
        } catch (WebServiceException e) {
            assertTrue(e.getCause() instanceof Fault);
            String expected = "'{\"http://apache.org/schema_validation/types\":varFloat}' is expected.";
            assertTrue(e.getCause().getMessage().indexOf(expected) != -1);
        }

        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) {
            assertTrue(e.getCause() instanceof Fault);
            String expected = "'{\"http://apache.org/schema_validation/types\":elem2}' is expected.";
            assertTrue(e.getCause().getMessage().indexOf(expected) != -1);
        }

        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) {
            assertTrue(e.getCause() instanceof Fault);
            String expected = "'{\"http://apache.org/schema_validation/types\":varFloat}' is expected.";
            assertTrue(e.getCause().getMessage().indexOf(expected) != -1);
View Full Code Here

TOP

Related Classes of org.apache.schema_validation.SchemaValidation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.