How to use parse method of com.consol.citrus.config.xml.SchemaParser class

Best Citrus code snippet using com.consol.citrus.config.xml.SchemaParser.parse

Source:SchemaRepositoryParser.java Github

copy

Full Screen

...29import java.util.List;30import java.util.Objects;31import java.util.stream.Collectors;32/**33 * Bean definition parser for schema-repository configuration.34 *35 * @author Martin.Maher@consol.de36 * @since 1.3.137 */38public class SchemaRepositoryParser implements BeanDefinitionParser {39 private static final String LOCATION = "location";40 private static final String LOCATIONS = "locations";41 private static final String SCHEMA = "schema";42 private static final String SCHEMAS = "schemas";43 private static final String ID = "id";44 private final SchemaParser schemaParser = new SchemaParser();45 @Override46 public BeanDefinition parse(Element element, ParserContext parserContext) {47 if (isXmlSchemaRepository(element)) {48 registerXmlSchemaRepository(element, parserContext);49 } else if (isJsonSchemaRepository(element)) {50 registerJsonSchemaRepository(element, parserContext);51 }52 return null;53 }54 /**55 * Registers a JsonSchemaRepository definition in the parser context56 * @param element The element to be converted into a JsonSchemaRepository definition57 * @param parserContext The parser context to add the definitions to58 */59 private void registerJsonSchemaRepository(Element element, ParserContext parserContext) {60 BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(JsonSchemaRepository.class);61 addLocationsToBuilder(element, builder);62 parseSchemasElement(element, builder, parserContext);63 parserContext.getRegistry().registerBeanDefinition(element.getAttribute(ID), builder.getBeanDefinition());64 }65 /**66 * Registers a XsdSchemaRepository definition in the parser context67 * @param element The element to be converted into a XmlSchemaRepository definition68 * @param parserContext The parser context to add the definitions to69 */70 private void registerXmlSchemaRepository(Element element, ParserContext parserContext) {71 BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(XsdSchemaRepository.class);72 BeanDefinitionParserUtils.setPropertyReference(builder, element.getAttribute("schema-mapping-strategy"), "schemaMappingStrategy");73 addLocationsToBuilder(element, builder);74 parseSchemasElement(element, builder, parserContext);75 parserContext.getRegistry().registerBeanDefinition(element.getAttribute(ID), builder.getBeanDefinition());76 }77 /**78 * Decides whether the given element is a xml schema repository.79 *80 * Note:81 * If the "type" attribute has not been set, the repository is interpreted as a xml repository by definition.82 * This is important to guarantee downwards compatibility.83 * @param element The element to be checked84 * @return Whether the given element is a xml schema repository85 */86 private boolean isXmlSchemaRepository(Element element) {87 String schemaRepositoryType = element.getAttribute("type");88 return StringUtils.isEmpty(schemaRepositoryType) || "xml".equals(schemaRepositoryType);89 }90 /**91 * Decides whether the given element is a json schema repository92 * @param element The element to be checked93 * @return whether the given element is a json schema repository94 */95 private boolean isJsonSchemaRepository(Element element) {96 return Objects.equals(element.getAttribute("type"), "json");97 }98 /**99 * Adds the locations contained in the given locations element to the BeanDefinitionBuilder100 * @param element the element containing the locations to be added to the builder101 * @param builder the BeanDefinitionBuilder to add the locations to102 */103 private void addLocationsToBuilder(Element element, BeanDefinitionBuilder builder) {104 Element locationsElement = DomUtils.getChildElementByTagName(element, LOCATIONS);105 if (locationsElement != null) {106 List<Element> locationElements = DomUtils.getChildElementsByTagName(locationsElement, LOCATION);107 List<String> locations = locationElements.stream()108 .map(locationElement -> locationElement.getAttribute("path"))109 .collect(Collectors.toList());110 if (!locations.isEmpty()) {111 builder.addPropertyValue(LOCATIONS, locations);112 }113 }114 }115 /**116 * Parses the given schema element to RuntimeBeanReference in consideration of the given context117 * and adds them to the builder118 * @param element The element from where the schemas will be parsed119 * @param builder The builder to add the resulting RuntimeBeanReference to120 * @param parserContext The context to parse the schema elements in121 */122 private void parseSchemasElement(Element element,123 BeanDefinitionBuilder builder,124 ParserContext parserContext) {125 Element schemasElement = DomUtils.getChildElementByTagName(element, SCHEMAS);126 if (schemasElement != null) {127 List<Element> schemaElements = DomUtils.getChildElements(schemasElement);128 ManagedList<RuntimeBeanReference> beanReferences = constructRuntimeBeanReferences(parserContext, schemaElements);129 if (!beanReferences.isEmpty()) {130 builder.addPropertyValue(SCHEMAS, beanReferences);131 }132 }133 }134 /**135 * Construct a List of RuntimeBeanReferences from the given list of schema elements under136 * consideration of the given parser context137 * @param parserContext The context to parse the elements in138 * @param schemaElements The element to be parsed139 * @return A list of RuntimeBeanReferences that have been defined in the xml document140 */141 private ManagedList<RuntimeBeanReference> constructRuntimeBeanReferences(142 ParserContext parserContext,143 List<Element> schemaElements) {144 ManagedList<RuntimeBeanReference> runtimeBeanReferences = new ManagedList<>();145 for (Element schemaElement : schemaElements) {146 if (schemaElement.hasAttribute(SCHEMA)) {147 runtimeBeanReferences.add(148 new RuntimeBeanReference(schemaElement.getAttribute(SCHEMA)));149 } else {150 schemaParser.parse(schemaElement, parserContext);151 runtimeBeanReferences.add(152 new RuntimeBeanReference(schemaElement.getAttribute(ID)));153 }154 }155 return runtimeBeanReferences;156 }157}...

Full Screen

Full Screen

Source:SchemaParser.java Github

copy

Full Screen

...23import org.springframework.beans.factory.xml.ParserContext;24import org.springframework.xml.xsd.SimpleXsdSchema;25import org.w3c.dom.Element;26/**27 * Bean definition parser for schema configuration.28 *29 * @author Martin.Maher@consol.de30 * @since 1.3.131 */32public class SchemaParser implements BeanDefinitionParser {33 /**34 * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)35 */36 public BeanDefinition parse(Element element, ParserContext parserContext) {37 String location = element.getAttribute("location");38 BeanDefinitionBuilder builder = null;39 if (location.endsWith(".wsdl")) {40 builder = BeanDefinitionBuilder.genericBeanDefinition(WsdlXsdSchema.class);41 BeanDefinitionParserUtils.setPropertyValue(builder, location, "wsdl");42 } else if (location.endsWith(".xsd")) {43 builder = BeanDefinitionBuilder.genericBeanDefinition(SimpleXsdSchema.class);44 BeanDefinitionParserUtils.setPropertyValue(builder, location, "xsd");45 } else if (location.endsWith(".json")) {46 builder = BeanDefinitionBuilder.genericBeanDefinition(SimpleJsonSchema.class);47 BeanDefinitionParserUtils.setPropertyValue(builder, location, "json");48 }49 if (builder != null) {50 parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id"), builder.getBeanDefinition());51 }52 return null;53 }54}...

Full Screen

Full Screen

parse

Using AI Code Generation

copy

Full Screen

1import java.io.File;2import java.io.IOException;3import java.util.List;4import org.springframework.core.io.FileSystemResource;5import org.springframework.core.io.Resource;6import org.springframework.xml.xsd.SimpleXsdSchema;7import org.springframework.xml.xsd.XsdSchema;8import com.consol.citrus.config.xml.SchemaParser;9public class 4 {10 public static void main(String[] args) throws IOException {11 Resource resource = new FileSystemResource(new File("C:\\Users\\user\\Desktop\\test.xsd"));12 XsdSchema schema = new SimpleXsdSchema(resource);13 SchemaParser schemaParser = new SchemaParser(schema);14 List<String> list = schemaParser.parse();15 for (String string : list) {16 System.out.println(string);17 }18 }19}

Full Screen

Full Screen

parse

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.config.xml.SchemaParser;2import java.io.File;3import java.io.IOException;4import java.util.List;5import org.xml.sax.SAXException;6public class 4 {7public static void main(String[] args) throws IOException, SAXException {8SchemaParser parser = new SchemaParser();9List<SchemaParser.SchemaDefinition> schemas = parser.parse(new File("C:\\Users\\Sujit\\Desktop\\xsd\\schema.xsd"));10for (SchemaParser.SchemaDefinition schema : schemas) {11System.out.println("Schema namespace: " + schema.getNamespace());12System.out.println("Schema location: " + schema.getLocation());13System.out.println("Schema target namespace: " + schema.getTargetNamespace());14System.out.println("Schema elements: " + schema.getElements());15System.out.println("Schema types: " + schema.getTypes());16}17}18}

Full Screen

Full Screen

parse

Using AI Code Generation

copy

Full Screen

1import java.io.File;2import java.io.IOException;3import org.xml.sax.SAXException;4import com.consol.citrus.config.xml.SchemaParser;5public class 4 {6 public static void main(String[] args) throws IOException, SAXException {7 File xmlFile = new File("1.xml");8 File xsdFile = new File("1.xsd");9 SchemaParser parser = new SchemaParser();10 parser.parse(xmlFile, xsdFile);11 System.out.println("XML file parsed successfully");12 }13}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in SchemaParser

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful