TestStep is listed under WsdlTestCase on debug, however cannot be saved to project file at .saveIn()
Hi all, I've recently saved a wsdl project without any hassle, and now would like to do the similar with REST endpoints.
I've come up with a piece of code that can actually working up to a point; where it seems RestTestRequestStep is hold inside the RestRequest. (observed on debug.)
wsdlTestCase.insertTestStep(testStepConfigx, -1); // it does put the test step under the test case in debug.
wsdlTestCase.getTestStepList().get(0) on debug returns a RestTestRequestStep with below config.
it has such config:
<xml-fragment service="http://jsonplaceholder.typicode.com" resourcePath="/posts" methodName="Posts 1" xsi:type="con:RestRequestStep" xmlns:con="http://eviware.com/soapui/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <con:restRequest name="Step" id="a66d91c1-0189-4a08-a9bb-b1c25d22c559" mediaType="application/json"> <con:settings/> <con:endpoint>http://jsonplaceholder.typicode.com</con:endpoint> <con:parameters/> </con:restRequest> </xml-fragment>
My question is how do I persist this request step as well, into the project xml file? Currently saved file does not contain this part and once imported to SOAPUI, I cannot see any test steps or requests, below test case of the corresponding test suite.
In general, we supply WsdlTestCase a TestStepConfig, and this config supposed to be in some specific form to be persisted in a file? I haven't done such thing for wsdl projects.
My code is as follows:
//ApplicationRunner.java
public class ApplicationRunner {
public static void main(String[] args) throws XmlException, IOException, SoapUIException, RestRequestStepFactory.ItemDeletedException {
String url = "http://jsonplaceholder.typicode.com/posts";
String fileName = "project.xml";
File projectFile = new File("fileDir/" + fileName);
RestConfiguration restConfiguration = new RestConfiguration(RestRequestConfig.Factory.newInstance(),
RestResourceConfig.Factory.newInstance(),
RestServiceConfig.Factory.newInstance(),
TestStepConfig.Factory.newInstance(),
TestCaseConfig.Factory.newInstance(),
RestMethodConfig.Factory.newInstance());
TestCaseConfig testCaseConfig = restConfiguration.getTestCaseConfig();
WsdlProject wsdlProject = new WsdlProject();
wsdlProject.setName("restProject");
WsdlTestSuite wsdlTestSuite = wsdlProject.addNewTestSuite("Suite");
wsdlTestSuite.addNewTestCase("Case");
WsdlTestCase wsdlTestCase = new WsdlTestCase(wsdlTestSuite, testCaseConfig, false);
RestServiceBuilder serviceBuilder = new RestServiceBuilder();
serviceBuilder.createRestService(wsdlProject, url);
RestService restService = (RestService) wsdlProject.getInterfaceList().get(0);
RestResource restResource = restService.getOperationAt(0);
RestRequest requestx = restResource.getRequestAt( 0 );
TestStepConfig testStepConfigx = RestRequestStepFactory.createConfig(requestx, "Step");
wsdlTestCase.insertTestStep(testStepConfigx, -1);
/* I can even set requestContent at runtime.
TestStep testStep = wsdlTestCase.insertTestStep(testStepConfigx, -1); // insertTestStep can be seen as of typ RestTestRequestStep inside wsdlTestCase.getTestStepList()
RestTestRequestStep restTestRequestStep = (RestTestRequestStep) testStep;
restTestRequestStep.getTestRequest().setRequestContent("requestContentHere")
*/
// attached the outputted xml project file.
wsdlProject.saveIn(projectFile);
}
}
//RestConfiguration.java
public class RestConfiguration {
RestRequestConfig restRequestConfig;
RestResourceConfig restResourceConfig;
RestServiceConfig restServiceConfig;
TestStepConfig testStepConfig;
TestCaseConfig testCaseConfig;
RestMethodConfig restMethodConfig;
public RestConfiguration(RestRequestConfig restRequestConfig, RestResourceConfig restResourceConfig, RestServiceConfig restServiceConfig, TestStepConfig testStepConfig, TestCaseConfig testCaseConfig, RestMethodConfig restMethodConfig){
this.restRequestConfig = restRequestConfig;
this.restResourceConfig = restResourceConfig;
this.restServiceConfig = restServiceConfig;
this.testStepConfig = testStepConfig;
this.testCaseConfig = testCaseConfig;
this.restMethodConfig = restMethodConfig;
}
public RestRequestConfig getRestRequestConfig() {
return restRequestConfig;
}
public RestResourceConfig getRestResourceConfig() {
return restResourceConfig;
}
public RestServiceConfig getRestServiceConfig() {
return restServiceConfig;
}
public TestStepConfig getTestStepConfig() {
return testStepConfig;
}
public TestCaseConfig getTestCaseConfig() {
return testCaseConfig;
}
public RestMethodConfig getRestMethodConfig() {
return restMethodConfig;
}
}
Hi there,
There's a problem here:
WsdlTestSuite wsdlTestSuite = wsdlProject.addNewTestSuite("Suite"); wsdlTestSuite.addNewTestCase("Case"); WsdlTestCase wsdlTestCase = new WsdlTestCase(wsdlTestSuite, testCaseConfig, false);
Looks like the test case assigned to wsdlTestCase is not the same one that is added to the Test Suite.
Instead, try this:
WsdlTestSuite wsdlTestSuite = wsdlProject.addNewTestSuite("Suite");
WsdlTestCase wsdlTestCase = new WsdlTestCase(wsdlTestSuite, testCaseConfig, false);
wsdlTestCase = wsdlTestSuite.importTestCase(wsdlTestCase, "Case", -1, false, false, false);It works in the UI and I can see it in the project.xml too.