Build REST project in JAVA with TestSuite and TestCase - Link resource and test step
Hi,
I'm trying to build in JAVA a SoapUI Rest project with a resource definition, a testsuite-testcase with a teststep (rest request to the resource).
I've tried it in many ways, but my problem is I cannot link the resource definition with the test step. After build XML file I try to import the generated project in SoapUI tool, and I always have a popup window "Missing REST Resource for TestRequest"; it's asking to link the teststep rest request to a definition in project (there is only one).
My code:
WsdlProject project = new WsdlProject(); project.setName("AutoGenerado Rest"); RestServiceBuilder serviceBuilder = new RestServiceBuilder(); String myEndpoint = "http://blablabla"; serviceBuilder.createRestService(project, myEndpoint); RestService service = (RestService) project.getInterfaceAt(0); RestResource resource = (RestResource) service.getOperationAt(0); resource.setName("resourceName"); resource.setConfig(RestResourceConfig.Factory.newInstance()); RestMethod restMethod = resource.getRestMethodAt(0); RestRequest request = restMethod.getRequestAt(0); request.setRequestHeaders(getHeaders()); WsdlTestSuite ts = project.addNewTestSuite("TestSuite"); WsdlTestCase tc = ts.addNewTestCase("TestCase 1"); TestStepConfig tsc = RestRequestStepFactory.createConfig((RestRequest) service.getOperationList().get(0).getRequestAt(0), resource.getName()); tc.addTestStep(tsc).setName("REST request");
Is there any way to build the TestCase item and avoid SoapUI asking me to link the resource and the test step when I'm importing the project?
Regards,
Hi all,
After a while going crazy, I've found where was the fail ... I need to set the path for the RestResource object; the code is as follows:
WsdlProject project = new WsdlProject(); project.setName("AutoGenerado Rest"); RestServiceBuilder serviceBuilder = new RestServiceBuilder(); String myEndpoint = "http://blablabla/bla123"; serviceBuilder.createRestService(project, myEndpoint); RestService service = (RestService) project.getInterfaceAt(0); RestResource resource = (RestResource) service.getOperationAt(0); resource.setName("resourceName"); resource.setConfig(RestResourceConfig.Factory.newInstance()); resource.setPath("/bla123"); RestMethod restMethod = resource.getRestMethodAt(0); RestRequest request = restMethod.getRequestAt(0); request.setRequestHeaders(getHeaders()); WsdlTestSuite ts = project.addNewTestSuite("TestSuite"); WsdlTestCase tc = ts.addNewTestCase("TestCase 1"); TestStepConfig tsc = RestRequestStepFactory.createConfig((RestRequest) service.getOperationList().get(0).getRequestAt(0), resource.getName()); tc.addTestStep(tsc).setName("REST request");
Thanks all readers to try help me :)