Package com.consol.citrus.xml

Examples of com.consol.citrus.xml.XsdSchemaRepository


                        + "<test>Hello TestFramework</test>"
                    + "</message>");
       
        DomXmlMessageValidator validator = new DomXmlMessageValidator();
       
        XsdSchemaRepository schemaRepository = new XsdSchemaRepository();
        Resource schemaResource = new ClassPathResource("com/consol/citrus/validation/test.xsd");
        SimpleXsdSchema schema = new SimpleXsdSchema(schemaResource);
        schema.afterPropertiesSet();
       
        schemaRepository.getSchemas().add(schema);
       
        validator.addSchemaRepository(schemaRepository);
       
        validator.validateXMLSchema(message, new XmlMessageValidationContext());
    }
View Full Code Here


                        + "<test>Hello TestFramework</test>"
                    + "</message>");
       
        DomXmlMessageValidator validator = new DomXmlMessageValidator();
       
        XsdSchemaRepository schemaRepository = new XsdSchemaRepository();
        schemaRepository.setBeanName("schemaRepository1");
        Resource schemaResource = new ClassPathResource("com/consol/citrus/validation/test.xsd");
        SimpleXsdSchema schema = new SimpleXsdSchema(schemaResource);
        schema.afterPropertiesSet();
       
        schemaRepository.getSchemas().add(schema);
       
        validator.addSchemaRepository(schemaRepository);
       
        XsdSchemaRepository schemaRepository2 = new XsdSchemaRepository();
        schemaRepository2.setBeanName("schemaRepository2");
        Resource schemaResource2 = new ClassPathResource("com/consol/citrus/validation/sample.xsd");
        SimpleXsdSchema schema2 = new SimpleXsdSchema(schemaResource2);
        schema2.afterPropertiesSet();

        schemaRepository2.getSchemas().add(schema2);

        validator.addSchemaRepository(schemaRepository2);
       
        validator.validateXMLSchema(message, new XmlMessageValidationContext());
View Full Code Here

                + "<test>Hello TestFramework</test>"
                + "</message>");

        DomXmlMessageValidator validator = new DomXmlMessageValidator();

        XsdSchemaRepository schemaRepository = new XsdSchemaRepository();
        schemaRepository.setBeanName("schemaRepository1");
        Resource schemaResource = new ClassPathResource("com/consol/citrus/validation/test.xsd");
        SimpleXsdSchema schema = new SimpleXsdSchema(schemaResource);
        schema.afterPropertiesSet();

        schemaRepository.getSchemas().add(schema);

        validator.addSchemaRepository(schemaRepository);

        XsdSchemaRepository schemaRepository2 = new XsdSchemaRepository();
        schemaRepository2.setBeanName("schemaRepository2");
        Resource schemaResource2 = new ClassPathResource("com/consol/citrus/validation/sample.xsd");
        SimpleXsdSchema schema2 = new SimpleXsdSchema(schemaResource2);
        schema2.afterPropertiesSet();

        schemaRepository2.getSchemas().add(schema2);

        validator.addSchemaRepository(schemaRepository2);

        try {
            validator.validateXMLSchema(message, new XmlMessageValidationContext());
View Full Code Here

                + "<test>Hello TestFramework</test>"
                + "</message>");

        DomXmlMessageValidator validator = new DomXmlMessageValidator();

        XsdSchemaRepository schemaRepository = new XsdSchemaRepository();
        schemaRepository.setBeanName("schemaRepository");
        Resource schemaResource = new ClassPathResource("com/consol/citrus/validation/test.xsd");
        SimpleXsdSchema schema = new SimpleXsdSchema(schemaResource);
        schema.afterPropertiesSet();
        Resource schemaResource2 = new ClassPathResource("com/consol/citrus/validation/sample.xsd");
        SimpleXsdSchema schema2 = new SimpleXsdSchema(schemaResource2);
        schema2.afterPropertiesSet();

        schemaRepository.getSchemas().add(schema);
        schemaRepository.getSchemas().add(schema2);

        validator.addSchemaRepository(schemaRepository);

        try {
            validator.validateXMLSchema(message, new XmlMessageValidationContext());
View Full Code Here

                        + "<wrongElement>totally wrong</wrongElement>"
                    + "</message>");
       
        DomXmlMessageValidator validator = new DomXmlMessageValidator();
       
        XsdSchemaRepository schemaRepository = new XsdSchemaRepository();
        Resource schemaResource = new ClassPathResource("com/consol/citrus/validation/test.xsd");
        SimpleXsdSchema schema = new SimpleXsdSchema(schemaResource);
        schema.afterPropertiesSet();
       
        schemaRepository.getSchemas().add(schema);
       
        validator.addSchemaRepository(schemaRepository);
       
        validator.validateXMLSchema(message, new XmlMessageValidationContext());
    }
View Full Code Here

            }

            log.info("Starting XML schema validation ...");

            XmlValidator validator = null;
            XsdSchemaRepository schemaRepository = null;
            if (validationContext.getSchema() != null) {
                validator = applicationContext.getBean(validationContext.getSchema(), XsdSchema.class).createValidator();
            } else if (validationContext.getSchemaRepository() != null) {
                schemaRepository = applicationContext.getBean(validationContext.getSchemaRepository(), XsdSchemaRepository.class);
            } else if (schemaRepositories.size() == 1) {
                schemaRepository = schemaRepositories.get(0);
            } else if (schemaRepositories.size() > 0) {
                for (XsdSchemaRepository repository : schemaRepositories) {
                    if (repository.canValidate(doc)) {
                        schemaRepository = repository;
                    }
                }
               
                if (schemaRepository == null) {
                    throw new CitrusRuntimeException(String.format("Failed to find proper schema repository in Spring bean context for validating element '%s(%s)'",
                            doc.getFirstChild().getLocalName(), doc.getFirstChild().getNamespaceURI()));
                }
            } else {
                log.warn("Neither schema instance nor schema repository defined - skipping XML schema validation");
                return;
            }
           
            if (schemaRepository != null) {
                if (!schemaRepository.canValidate(doc)) {
                    throw new CitrusRuntimeException(String.format("Unable to find proper XML schema definition for element '%s(%s)' in schema repository '%s'",
                            doc.getFirstChild().getLocalName(),
                            doc.getFirstChild().getNamespaceURI(),
                            schemaRepository.getName()));
                }

                List<Resource> schemas = new ArrayList<Resource>();

                for (XsdSchema xsdSchema : schemaRepository.getSchemas()) {
                    if (xsdSchema instanceof MultiResourceXsdSchema) {
                        for (Resource resource : ((MultiResourceXsdSchema) xsdSchema).getSchemas()) {
                            schemas.add(resource);
                        }                           
                    } else if (xsdSchema instanceof WsdlXsdSchema) {
View Full Code Here

        Map<String, XsdSchemaRepository> schemaRepositories = beanDefinitionContext.getBeansOfType(XsdSchemaRepository.class);
       
        Assert.assertEquals(schemaRepositories.size(), 3);
       
        // 1st schema repository
        XsdSchemaRepository schemaRepository = schemaRepositories.get("schemaRepository1");
        Assert.assertEquals(schemaRepository.getSchemaMappingStrategy().getClass(), TargetNamespaceSchemaMappingStrategy.class);
        Assert.assertNotNull(schemaRepository.getSchemas());
        Assert.assertEquals(schemaRepository.getSchemas().size(), 5);
        Assert.assertEquals(schemaRepository.getSchemas().get(0).getClass(), SimpleXsdSchema.class);
        Assert.assertEquals(schemaRepository.getSchemas().get(1).getClass(), SimpleXsdSchema.class);
        Assert.assertEquals(schemaRepository.getSchemas().get(2).getClass(), WsdlXsdSchema.class);
        Assert.assertEquals(schemaRepository.getSchemas().get(3).getClass(), WsdlXsdSchema.class);
        Assert.assertEquals(schemaRepository.getSchemas().get(4).getClass(), MultiResourceXsdSchema.class);
        Assert.assertNotNull(schemaRepository.getLocations());
        Assert.assertEquals(schemaRepository.getLocations().size(), 0);

        // 2nd schema repository
        schemaRepository = schemaRepositories.get("schemaRepository2");
        Assert.assertNotNull(schemaRepository.getSchemas());
        Assert.assertEquals(schemaRepository.getSchemas().size(), 2);
        Assert.assertEquals(schemaRepository.getSchemas().get(0).getClass(), SimpleXsdSchema.class);
        Assert.assertEquals(schemaRepository.getSchemas().get(1).getClass(), SimpleXsdSchema.class);
        Assert.assertNotNull(schemaRepository.getLocations());
        Assert.assertEquals(schemaRepository.getLocations().size(), 1);
        Assert.assertEquals(schemaRepository.getLocations().get(0), "classpath:com/consol/citrus/validation/*");

        // 3rd schema repository
        schemaRepository = schemaRepositories.get("schemaRepository3");
        Assert.assertEquals(schemaRepository.getSchemaMappingStrategy().getClass(), RootQNameSchemaMappingStrategy.class);

        Assert.assertTrue(beanDefinitionContext.containsBean("schema1"));
        Assert.assertTrue(beanDefinitionContext.containsBean("schema2"));
        Assert.assertTrue(beanDefinitionContext.containsBean("wsdl1"));
        Assert.assertTrue(beanDefinitionContext.containsBean("wsdl2"));
View Full Code Here

TOP

Related Classes of com.consol.citrus.xml.XsdSchemaRepository

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.