Forum Discussion

jme's avatar
jme
New Contributor
6 years ago

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 probl...
  • jme's avatar
    6 years ago

    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  :)