cancel
Showing results for 
Search instead for 
Did you mean: 

TestStep is listed under WsdlTestCase on debug, however cannot be saved to project file at .saveIn()

SOLVED
Highlighted
Occasional Contributor

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;
}
}

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: TestStep is listed under WsdlTestCase on debug, however cannot be saved to project file at .save

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.

View solution in original post

3 REPLIES 3
Highlighted
Occasional Contributor

Re: TestStep is listed under WsdlTestCase on debug, however cannot be saved to project file at .save

So, apart from the question, haven't seen such implementation in Java, in elsewhere for the REST services.

 

If there is really no-one tried this or just no one have the idea, I'd replicate this to stackoverflow. I've added further configuration and enriched the RestMethodConfig auth, originalUrl etc.

 

If anyone have saved a REST project.xml before, let me know please.

 

 

Highlighted
Community Hero

Re: TestStep is listed under WsdlTestCase on debug, however cannot be saved to project file at .save

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.

View solution in original post

Highlighted
Occasional Contributor

Re: TestStep is listed under WsdlTestCase on debug, however cannot be saved to project file at .save

Hi,

 

It works, really appreciated.

 

Thank you very much, JHunt! 

New Here?
Join us and watch the welcome video:
Top Kudoed Authors