Forum Discussion

apoorva's avatar
apoorva
Occasional Contributor
16 years ago

Create MockService through java program rather than using SoapUI GUI

Hi,

I want to create MockResponse for a particular interface through java program.. I downloaded source code of soapui and successfully build it using maven 1.0.2... Now I am trying to write java program which will create mockservice and save in porject.xml file so later on I can also open in SoapUI as well...

I will appreciate if any inpute will available..

Thanks,
Jim

5 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Jim,

    do the following from your Java code:

    1) create a new WsdlProject
    2) add your WSDL to the project with the WsdlImporter class
    3) add a new WsdlMockService to your project with project.addNewMockService
    4) add the desired mockOperation/mockResponses
    5) save the project with project.save(..)

    ok?

    regards!

    /Ole
    eviware.com
  • apoorva's avatar
    apoorva
    Occasional Contributor
    Hi Ole,

    Thanks for your reply. The steps you mentioned helped me a lot. I have one more concern. I am able to generate MockResponse now. But I want to generate the MockResponse content from the schema..

    I guess
    WsdlMockResponse mockresp =mockope.addNewMockResponse(mockresponseConfig);
    will do something but not aware how to set mockresponseConfig...

    Can you please throw some light on this please and provide a couple of line of code which will generate mockresponse from schema..

    Thank you for precious time.

    Regards,
    Jim
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Jim,

    have you resolved this issue?

    regards,

    /Ole
    eviware.com
  • apoorva's avatar
    apoorva
    Occasional Contributor
    Hi Ole,

    I am able to generate MockResponse from schema now.. Just need to set one property WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS to true

    SoapUI.getSettings().setBoolean(WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS ,true);

    But I have another concern,

    When I am trying to save project.xml file using Save() method it gives me null pointer excption

    The problem is
    public boolean save() {

    // this give me error because i m not saving project using soapui GUI
    file = UISupport.getFileDialogs().saveAs(this, "Save project " + getName(), ".xml", "XML Files (*.xml)", new File( path ));
    ........

    //and i cant even call saveIn to bypass save() because saveIn is private method
    return saveIn(projectFile);

    }

    right now i just change the source code and make saveIn to public .. Is there any alternative way to save project?

    Looking forward to here from you.

    Thanks,
    Jim
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    no, we'll make saveIn public in the next release.. thanks for pointing this out.

    regards,

    /Ole
    eviware.com