How to use compileXsd method of com.consol.citrus.generate.javadsl.WsdlJavaTestGenerator class

Best Citrus code snippet using com.consol.citrus.generate.javadsl.WsdlJavaTestGenerator.compileXsd

Source:WsdlJavaTestGenerator.java Github

copy

Full Screen

...48 String wsdlNsDelaration = "declare namespace wsdl='http://schemas.xmlsoap.org/wsdl/' ";49 String soapNsDelaration = "declare namespace soap='http://schemas.xmlsoap.org/wsdl/soap/' ";50 // compile wsdl and xsds right now, otherwise later input is useless:51 XmlObject wsdlObject = compileWsdl(wsdl);52 SchemaTypeSystem schemaTypeSystem = compileXsd(wsdlObject);53 log.info("WSDL compilation successful");54 String serviceName = evaluateAsString(wsdlObject, wsdlNsDelaration + ".//wsdl:portType/@name");55 log.info("Found service: " + serviceName);56 if (!StringUtils.hasText(namePrefix)) {57 withNamePrefix(serviceName + "_");58 }59 log.info("Found service operations:");60 XmlObject[] messages = wsdlObject.selectPath(wsdlNsDelaration + ".//wsdl:message");61 XmlObject[] operations = wsdlObject.selectPath(wsdlNsDelaration + ".//wsdl:portType/wsdl:operation");62 for (XmlObject operation : operations) {63 log.info(evaluateAsString(operation, wsdlNsDelaration + "./@name"));64 }65 log.info("Generating test cases for service operations ...");66 for (XmlObject operation : operations) {67 SoapMessage request = new SoapMessage();68 SoapMessage response = new SoapMessage();69 String operationName = evaluateAsString(operation, wsdlNsDelaration + "./@name");70 if (StringUtils.hasText(this.operation) && !operationName.equals(this.operation)) {71 continue;72 }73 XmlObject[] bindingOperations = wsdlObject.selectPath(wsdlNsDelaration + ".//wsdl:binding/wsdl:operation");74 for (XmlObject bindingOperation : bindingOperations) {75 String bindingOperationName = evaluateAsString(bindingOperation, wsdlNsDelaration + "./@name");76 if (bindingOperationName.equals(operationName)) {77 String soapAction = removeNsPrefix(evaluateAsString(bindingOperation, soapNsDelaration + "./soap:operation/@soapAction"));78 request.soapAction(soapAction);79 break;80 }81 }82 String inputMessage = removeNsPrefix(evaluateAsString(operation, wsdlNsDelaration + "./wsdl:input/@message"));83 String outputMessage = removeNsPrefix(evaluateAsString(operation, wsdlNsDelaration + "./wsdl:output/@message"));84 String inputElement = null;85 String outputElement = null;86 for (XmlObject message : messages) {87 String messageName = evaluateAsString(message, wsdlNsDelaration + "./@name");88 if (messageName.equals(inputMessage)) {89 inputElement = removeNsPrefix(evaluateAsString(message, wsdlNsDelaration + "./wsdl:part/@element"));90 }91 if (messageName.equals(outputMessage)) {92 outputElement = removeNsPrefix(evaluateAsString(message, wsdlNsDelaration + "./wsdl:part/@element"));93 }94 }95 // Now generate it96 withName(namePrefix + operationName + nameSuffix);97 SchemaType requestElem = getSchemaType(schemaTypeSystem, operationName, inputElement);98 request.setPayload(SampleXmlUtil.createSampleForType(requestElem));99 withRequest(request);100 SchemaType responseElem = getSchemaType(schemaTypeSystem, operationName, outputElement);101 response.setPayload(SampleXmlUtil.createSampleForType(responseElem));102 withResponse(response);103 XmlConfigurer configurer = new XmlConfigurer();104 configurer.setSerializeSettings(Collections.singletonMap(XmlConfigurer.XML_DECLARATION, false));105 XMLUtils.initialize(configurer);106 super.create();107 log.info("Successfully created new test case " + getTargetPackage() + "." + getName());108 }109 }110 @Override111 protected Message generateInboundMessage(Message message) {112 return inboundDataDictionary.interceptMessageConstruction(message, MessageType.XML.name(), new TestContext());113 }114 @Override115 protected Message generateOutboundMessage(Message message) {116 return outboundDataDictionary.interceptMessageConstruction(message, MessageType.XML.name(), new TestContext());117 }118 /**119 * Finds nested XML schema definition and compiles it to a schema type system instance120 * @param wsdl121 * @return122 */123 private XmlObject compileWsdl(String wsdl) {124 File wsdlFile;125 try {126 wsdlFile = new PathMatchingResourcePatternResolver().getResource(wsdl).getFile();127 } catch (IOException e) {128 wsdlFile = new File(wsdl);129 }130 if (!wsdlFile.exists()) {131 throw new CitrusRuntimeException("Unable to read WSDL - does not exist in " + wsdlFile.getAbsolutePath());132 }133 if (!wsdlFile.canRead()) {134 throw new CitrusRuntimeException("Unable to read WSDL - could not open in read mode");135 }136 try {137 return XmlObject.Factory.parse(wsdlFile, (new XmlOptions()).setLoadLineNumbers().setLoadMessageDigest().setCompileDownloadUrls());138 } catch (XmlException e) {139 for (Object error : e.getErrors()) {140 log.error(((XmlError)error).getLine() + "" + error.toString());141 }142 throw new CitrusRuntimeException("WSDL could not be parsed", e);143 } catch (Exception e) {144 throw new CitrusRuntimeException("WSDL could not be parsed", e);145 }146 }147 /**148 * Finds nested XML schema definition and compiles it to a schema type system instance.149 * @param wsdl150 * @return151 */152 private SchemaTypeSystem compileXsd(XmlObject wsdl) {153 // extract namespaces defined on wsdl-level:154 String[] namespacesWsdl = extractNamespacesOnWsdlLevel(wsdl);155 // calc the namespace-prefix of the schema-tag, default ""156 String schemaNsPrefix = extractSchemaNamespacePrefix(wsdl);157 // extract each schema-element and add missing namespaces defined on wsdl-level158 String[] schemas = getNestedSchemas(wsdl, namespacesWsdl, schemaNsPrefix);159 XmlObject[] xsd = new XmlObject[schemas.length];160 try {161 for (int i=0; i < schemas.length; i++) {162 xsd[i] = XmlObject.Factory.parse(schemas[i], (new XmlOptions()).setLoadLineNumbers().setLoadMessageDigest().setCompileDownloadUrls());163 }164 } catch (Exception e) {165 throw new CitrusRuntimeException("Failed to parse XSD schema", e);166 }167 SchemaTypeSystem schemaTypeSystem = null;168 try {169 schemaTypeSystem = XmlBeans.compileXsd(xsd, XmlBeans.getContextTypeLoader(), new XmlOptions());170 } catch (XmlException e) {171 for (Object error : e.getErrors()) {172 log.error("Line " + ((XmlError)error).getLine() + ": " + error.toString());173 }174 throw new CitrusRuntimeException("Failed to compile XSD schema", e);175 } catch (Exception e) {176 throw new CitrusRuntimeException("Failed to compile XSD schema", e);177 }178 return schemaTypeSystem;179 }180 /**181 * @param schemaTypeSystem182 * @param operation183 * @param elementName...

Full Screen

Full Screen

compileXsd

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.endpoint.CitrusEndpoints;2import com.consol.citrus.dsl.runner.TestRunner;3import com.consol.citrus.ws.client.WebServiceClient;4import com.consol.citrus.ws.server.WebServiceServer;5import org.springframework.core.io.ClassPathResource;6import org.springframework.ws.soap.SoapVersion;7import static com.consol.citrus.actions.CreateVariablesAction.Builder.createVariable;8import static com.consol.citrus.ws.actions.SoapActionBuilder.soap;9public class TestWsdlJavaTestGenerator {10 public static void main(String[] args) {11 WsdlJavaTestGenerator generator = new WsdlJavaTestGenerator();12 generator.setWsdl("wsdl/HelloWorld.wsdl");13 generator.setPackageName("com.consol.citrus.samples");14 generator.setTestName("HelloWorldWsdl");15 generator.setTargetJavaDirectory("src/test/java");16 generator.setTargetXmlDirectory("src/test/resources");17 generator.setSoapVersion(SoapVersion.SOAP_11);18 generator.setEndpointConfigName("endpointConfig");19 generator.setEndpointConfigClass("com.consol.citrus.samples.SampleEndpointConfig");20 generator.setEndpointConfigResource(new ClassPathResource("endpoint-config.xml", TestWsdlJavaTestGenerator.class));21 generator.setEndpointAdapter("com.consol.citrus.samples.SampleEndpointAdapter");22 generator.setEndpointAdapterResource(new ClassPathResource("endpoint-adapter.xml", TestWsdlJavaTestGenerator.class));23 generator.setEndpointInterceptor("com.consol.citrus.samples.SampleEndpointInterceptor");24 generator.setEndpointInterceptorResource(new ClassPathResource("endpoint-interceptor.xml", TestWsdlJavaTestGenerator.class));25 generator.setEndpointMapping("com.consol.citrus.samples.SampleEndpointMapping");26 generator.setEndpointMappingResource(new ClassPathResource("endpoint-mapping.xml", TestWsdlJavaTestGenerator.class));27 generator.setEndpointResolver("com.consol.citrus.samples.SampleEndpointResolver");28 generator.setEndpointResolverResource(new ClassPathResource("endpoint-resolver.xml", TestWsdlJavaTestGenerator.class));29 generator.setEndpointTimeout(5000L);30 generator.setEndpointAutoStart(true);31 generator.setEndpointAutoCreateClient(true);32 generator.setEndpointAutoCreateServer(true);33 generator.setEndpointResource(new ClassPathResource("endpoint-config.xml", TestWsdlJava

Full Screen

Full Screen

compileXsd

Using AI Code Generation

copy

Full Screen

1WsdlJavaTestGenerator generator = new WsdlJavaTestGenerator();2generator.setCitrusVersion("2.7.2");3generator.setJavaPackage("com.consol.citrus");4generator.setTestName("SoapServiceTest");5generator.setTargetPath("src/test/java");6generator.compileXsd();7WsdlJavaTestGenerator generator = new WsdlJavaTestGenerator();8generator.setCitrusVersion("2.7.2");9generator.setJavaPackage("com.consol.citrus");10generator.setTestName("SoapServiceTest");11generator.setTargetPath("src/test/java");12generator.compileXsd();13WsdlJavaTestGenerator generator = new WsdlJavaTestGenerator();14generator.setCitrusVersion("2.7.2");15generator.setJavaPackage("com.consol.citrus");16generator.setTestName("SoapServiceTest");17generator.setTargetPath("src/test/java

Full Screen

Full Screen

compileXsd

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.generate.javadsl.WsdlJavaTestGenerator;2import com.consol.citrus.generate.javadsl.WsdlJavaTestGenerator.Builder;3import java.io.File;4import java.io.IOException;5public class WsdlJavaTestGeneratorTest {6 public static void main(String[] args) {7 Builder builder = new WsdlJavaTestGenerator.Builder();8 .packageName("com.consol.citrus.samples")9 .testName("GlobalWeather")10 .outputDirectory(new File("target/generated-test-sources"))11 .compileXsd(true);12 try {13 builder.build().generate();14 } catch (IOException e) {15 e.printStackTrace();16 }17 }18}19package com.consol.citrus.samples;20import com.consol.citrus.annotations.CitrusTest;21import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;22import com.consol.citrus.dsl.runner.TestRunner;23import com.consol.citrus.http.client.HttpClient;24import com.consol.citrus.testng.CitrusParameters;25import org.testng.annotations.Test;26import javax.xml.transform.Source;27import javax.xml.transform.stream.StreamSource;28import java.io.IOException;29import java.util.HashMap;30import java.util.Map;31public class GlobalWeather_IT extends JUnit4CitrusTestDesigner {32 private HttpClient globalWeatherClient = new HttpClient();33 @CitrusParameters({"operation"})34 @Test(dataProvider = "testParameters")35 public void globalWeather(String operation) throws IOException {36 globalWeatherClient.send().soap(action(operation));37 globalWeatherClient.receive().soap();38 }39 public void configure() {40 globalWeatherClient.endpointName("globalWeatherClient");41 globalWeatherClient.soap().version("1.1");42 globalWeatherClient.soap().encoding("UTF-8");43 }44 protected void applyBehavior(TestRunner runner) {45 runner.applyBehavior(global

Full Screen

Full Screen

compileXsd

Using AI Code Generation

copy

Full Screen

1WsdlJavaTestGenerator generator = new WsdlJavaTestGenerator();2generator.compileXsd("src/test/resources/soapui-project.xml", "src/test/resources/soapui-project.xsd");3WsdlJavaTestGenerator generator = new WsdlJavaTestGenerator();4generator.compileXsd("src/test/resources/soapui-project.xml", "src/test/resources/soapui-project.wsdl");5WsdlJavaTestGenerator generator = new WsdlJavaTestGenerator();6generator.generateTestCases("src/test/resources/soapui-project.xml", "src/test/resources/soapui-project.wsdl");7WsdlJavaTestGenerator generator = new WsdlJavaTestGenerator();8generator.generateTestCases("src/test/resources/soapui-project.xml", "src/test/resources/soapui-project.wsdl", "src/test/java");9WsdlJavaTestGenerator generator = new WsdlJavaTestGenerator();10generator.generateTestCases("src/test/resources/soapui-project.xml", "src/test/resources/soapui-project.wsdl", "src/test/java", "com.consol.citrus");11WsdlJavaTestGenerator generator = new WsdlJavaTestGenerator();12generator.generateTestCases("src/test/resources/soapui-project.xml", "src/test/resources/soapui-project.wsdl", "src/test/java", "com.consol.citrus", "com.consol.citrus");13WsdlJavaTestGenerator generator = new WsdlJavaTestGenerator();14generator.generateTestCases("src/test/resources/soapui-project.xml", "src/test/resources/soapui-project.wsdl", "src/test/java", "com.consol.citrus", "com.consol

Full Screen

Full Screen

compileXsd

Using AI Code Generation

copy

Full Screen

1WsdlJavaTestGenerator wsdlJavaTestGenerator = new WsdlJavaTestGenerator();2wsdlJavaTestGenerator.setTargetPackage("com.consol.citrus.samples");3wsdlJavaTestGenerator.setTargetPath("src/test/java");4wsdlJavaTestGenerator.setEndpointName("stockQuoteEndpoint");5wsdlJavaTestGenerator.setEndpointTimeout(5000L);6wsdlJavaTestGenerator.setEndpointPort("StockQuoteSoap");7wsdlJavaTestGenerator.setEndpointRequestPayloadRoot("GetQuote");8wsdlJavaTestGenerator.setEndpointResponsePayloadRoot("GetQuoteResponse");9wsdlJavaTestGenerator.setEndpointRequestPayloadValidation(true);10wsdlJavaTestGenerator.setEndpointResponsePayloadValidation(true);11wsdlJavaTestGenerator.setEndpointRequestHeaderValidation(true);12wsdlJavaTestGenerator.setEndpointResponseHeaderValidation(true);13wsdlJavaTestGenerator.setEndpointRequestHeaderSchema("classpath:com/consol/citrus/samples/stockquote/StockQuoteRequest.xsd");14wsdlJavaTestGenerator.setEndpointResponseHeaderSchema("classpath:com/consol/citrus/samples/stockquote/StockQuoteResponse.xsd");15wsdlJavaTestGenerator.setEndpointRequestPayloadSchema("classpath:com/consol/citrus/samples/stockquote/StockQuoteRequest.xsd");16wsdlJavaTestGenerator.setEndpointResponsePayloadSchema("classpath:com/consol/citrus/samples/stockquote/StockQuoteResponse.xsd");17wsdlJavaTestGenerator.setEndpointRequestPayloadData("classpath:com/consol/citrus/samples/stockquote/StockQuoteRequest.xml");18wsdlJavaTestGenerator.setEndpointResponsePayloadData("classpath:com/consol/citrus/samples/stockquote/StockQuoteResponse.xml");19wsdlJavaTestGenerator.setEndpointRequestHeaderData("classpath:com/consol/citrus/samples/stockquote/StockQuoteRequest

Full Screen

Full Screen

compileXsd

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.generate.javadsl.WsdlJavaTestGenerator;2public class WsdlTestGenerator {3 public static void main(String[] args) {4 "com.consol.citrus.generate");5 }6}7package com.consol.citrus.generate;8import com.consol.citrus.annotations.CitrusTest;9import com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner;10import com.consol.citrus.dsl.runner.TestRunner;11import com.consol.citrus.message.MessageType;12import com.consol.citrus.ws.actions.SoapActionBuilder;13import com.consol.citrus.ws.actions.WsActionBuilder;14import com.consol.citrus.ws.message.SoapMessage;15import org.testng.annotations.Test;16public class CalculatorIT extends JUnit4CitrusTestRunner {17 public void testAdd() {18 WsActionBuilder soapAction = soap();19 TestRunner builder = soapAction;20 description("Test add operation");21 variable("addRequest",

Full Screen

Full Screen

compileXsd

Using AI Code Generation

copy

Full Screen

1WsdlJavaTestGenerator generator = new WsdlJavaTestGenerator();2generator.setProjectPath("/Users/nitinaggarwal/Documents/Projects/Workspace/Java/citrus-samples");3generator.setPackageName("com.consol.citrus.samples");4generator.setWsdlUrl("file:/Users/nitinaggarwal/Documents/Projects/Workspace/Java/citrus-samples/src/test/resources/soap-wsdl-1.1.xsd");5generator.setSchemaUrl("file:/Users/nitinaggarwal/Documents/Projects/Workspace/Java/citrus-samples/src/test/resources/soap-wsdl-1.1.xsd");6generator.setTestName("SoapWsdl11IT");7generator.setTestTargetPort("Soap11Endpoint");8generator.setTestSoapVersion("SOAP11");9generator.setTestEndpointName("soap11Endpoint");

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful