Forum Discussion

klabbe_f's avatar
klabbe_f
New Contributor
16 years ago

Start mock services when loading project

I've got quite a few projects in my workspace placed on a build server running mock services. Cruise Control is using those for unit tests when building.

Sometimes we're changing workspace or need to restart the soapUI instance. When starting the workspace, it is quite tedious to open each project, clicking each mock service to start it.

I heard from some of the Eviware staff on the EuroSTAR conference last week that it is possible to create a short script that is automatically starts the mock services when loading a project.

It could also be nice to be able to shut down the instance on the build server without being asked if save project or not.
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    This might work:

    import com.eviware.soapui.model.mock.MockService;
    import com.eviware.soapui.model.mock.MockRunner;

    log.info("Attempting to start service")

    MockService mockService = project.getMockServiceByName( "My Mock Service" );
    MockRunner runner
    try {
    runner = mockService.start()
    } catch (Exception e) {
    runner.cancel( "Could not start service" )
    }

    // add to service reference to context for later access from other scripts
    context.put("runner", runner)

    log.info("Service started")
  • klabbe_f's avatar
    klabbe_f
    New Contributor
    Thanks!

    That one worked fine.

    The only problem is "My Mock Service" which forces me to explicitly/hard code each Mock Service instead of dynamically start all MS for a project (we're having up to 5 Mock Services per project and about 20 projects). I'm trying to loop through all Mock Services within a project but still haven't made it.
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    project.getMockServiceList() will list all the services. Then you could create a MockRunner list and loop through the services to start them.

    See http://www.soapui.org/apidocs/com/eviware/soapui/model/project/Project.html for all the Project methods.

    This might work (not tested!)

    import com.eviware.soapui.model.mock.MockService;
    import com.eviware.soapui.model.mock.MockRunner;

    log.info("Attempting to start services")

    def mockServiceList = project.getMockServices()
    def mockRunnerList = []

    try {
        for (ms in mockServiceList) {
            MockRunner mr = ms.start()
            mockRunnerList.add(mr)
        }
        // add to mockRunnerList to context for later access in tear down
        context.put("runnerList", mockRunnerList)
        log.info("Services started")

    } catch (Exception e) {
        for (mr in mockRunnerList) {
            // cancel all started services
            mr.cancel("Startup of some services failed.")
        }
    }
  • Hi,

    this way to start a couple of mockservices makes our test with soapui a little bit easier. The started mockservices sends the responses with the expected and configured content.
    Sometimes it is necessary to check the response. But the mockservices are started without a window and the response message can't be checked from the UI.
    It is possible to open the mockservice editor (with groovy script) after automated service startup? The mockservice editor displays the message log which shows the time and dureation of processing the response.

    Best Regards