Forum Discussion

Michael_Foley's avatar
Michael_Foley
New Contributor
17 years ago

starting the MockServiceRunner programmatically

Anybody know how to start the mock service runner programmatically?  Ideally, I'd like to do something like this within the setUp() method of my JUnit test:

Object obj = new com.eviware.soapui.SoapUIProMockServiceRunner()

or

use ProcessBuilder approach to start the mock service ...but not having any luck with that approach.

Any ideas?

Mike
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Mike,

    you're on the right track; create the runner object, set required properties (projectFile, etc) and then call run()..

    Hope this helps,

    /Ole
    eviware.com
  • Working on this approach now.....which seems to almost work.  I am just starting a new thread, and then calling main() on the SoapUIProMockServiceRunner class:

      SoapUIProMockServiceRunner.main(new String[]{"c:\\my-soapui-project.xml"});

    Help me out, what are the args that main() takes?  I see that one is my project file.  Anything else?

    Thanks,

    Mike
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    these are the same arguments as on the commandline as described at http://www.soapui.org/userguide/command ... unner.html, so for example specify

    SoapUIProMockServiceRunner.main(new String[]{"-mMockService", "c:\\my-soapui-project.xml"});

    to run the MockService "MockService" in the specified file..

    regards,

    /Ole
    eviware.com
  • I'm trying to do this programmatically and this is as far as I've gotten:


    SoapUIMockServiceRunner runner = new SoapUIProMockServiceRunner();

    runner.setMockService(mock);
    runner.setProjectFile(project);
    runner.setBlock(false);
    runner.setSaveAfterRun(false);
    runner.setEnableUI(false);

    System.setProperty("soapui.properties", soapui
    + "\\bin\\soapui.properties");
    System.setProperty("groovy.source.encoding", "UTF-8");
    System.setProperty("soapui.home", soapui + "\\bin\\");
    System.setProperty("soapui.ext.libraries", soapui + "\\bin\\ext");
    System.setProperty("soapui.ext.listeners", soapui + "\\bin\\listeners");
    System.setProperty("soapui.ext.actions", soapui + "\\bin\\actions");

    runner.run();


    where soapui contains the installation directory. This should mimic what mockservicerunner.bat does, but the output is (when running is code as an Ant task):


    [mockservice] soapUI Pro 3.6 MockService Runner
    [mockservice] 10:30:08,882 INFO [SoapUI] Failed to add jar to org.apache.tools.ant.AntClassLoader, trying parent
    [mockservice] 10:30:08,883 INFO [SoapUI] Added [file:/C:/Program%20Files/eviware/soapUI-Pro-3.6/bin/ext/gs4adapter-client.jar] to classpath
    [mockservice] 10:30:08,884 INFO [SoapUI] Failed to add jar to org.apache.tools.ant.AntClassLoader, trying parent
    [mockservice] 10:30:08,884 INFO [SoapUI] Added [file:/C:/Program%20Files/eviware/soapUI-Pro-3.6/bin/ext/httprpc-clientlib.jar] to classpath
    [mockservice] 10:30:08,884 INFO [SoapUI] Failed to add jar to org.apache.tools.ant.AntClassLoader, trying parent
    [mockservice] 10:30:08,884 INFO [SoapUI] Added [file:/C:/Program%20Files/eviware/soapUI-Pro-3.6/bin/ext/integrationapi.jar] to classpath
    [mockservice] 10:30:08,885 INFO [SoapUI] Failed to add jar to org.apache.tools.ant.AntClassLoader, trying parent
    [mockservice] 10:30:08,885 INFO [SoapUI] Added [file:/C:/Program%20Files/eviware/soapUI-Pro-3.6/bin/ext/ojdbc6.jar] to classpath
    [mockservice] 10:30:09,199 INFO [DefaultSoapUICore] initialized soapui-settings from [C:\Users\olsjon\soapui-settings.xml]
    [mockservice] 10:30:10,179 INFO [SoapUIProGroovyScriptEngineFactory] Setting Script Library to [C:\Program Files\eviware\soapui-pro-3.6\bin\scripts]
    [mockservice] 10:30:10,189 INFO [DefaultSoapUICore] Adding listeners from [C:\Program Files\eviware\soapUI-Pro-3.6\bin\listeners\demo-listeners.xml]
    [mockservice] 10:30:10,893 INFO [WsdlProject] Loaded project from [file:C:/Subversion/GMS/Sportingbet_EBO_Adapter/trunk/soapUI/SPBSimulator.xml]
    [mockservice] java.lang.ClassCastException: com.eviware.soapui.config.impl.InterfaceConfigImpl cannot be cast to com.eviware.soapui.config.WsdlInterfaceConfig
    [mockservice] at com.eviware.soapui.impl.WsdlInterfaceFactory.build(WsdlInterfaceFactory.java:41)
    [mockservice] at com.eviware.soapui.impl.WsdlInterfaceFactory.build(WsdlInterfaceFactory.java:34)
    [mockservice] at com.eviware.soapui.impl.wsdl.InterfaceFactoryRegistry.build(InterfaceFactoryRegistry.java:49)
    [mockservice] at com.eviware.soapui.impl.wsdl.WsdlProjectPro.loadProject(SourceFile:190)
    [mockservice] at com.eviware.soapui.impl.wsdl.WsdlProject.<init>(WsdlProject.java:209)
    [mockservice] at com.eviware.soapui.impl.wsdl.WsdlProjectPro.<init>(SourceFile:132)
    [mockservice] at com.eviware.soapui.impl.wsdl.WsdlProjectProFactory.createNew(SourceFile:32)
    [mockservice] at com.eviware.soapui.impl.wsdl.WsdlProjectProFactory.createNew(SourceFile:16)
    [mockservice] at com.eviware.soapui.tools.SoapUIMockServiceRunner.runRunner(SoapUIMockServiceRunner.java:102)
    [mockservice] at com.eviware.soapui.tools.AbstractSoapUIRunner.run(AbstractSoapUIRunner.java:138)
    [mockservice] at com.bossmedia.tools.ant.mockservice.Task.startMockService(Task.java:106)
    [mockservice] at com.bossmedia.tools.ant.mockservice.Task.execute(Task.java:69)
    [mockservice] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    [mockservice] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [mockservice] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [mockservice] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [mockservice] at java.lang.reflect.Method.invoke(Method.java:597)
    [mockservice] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [mockservice] at org.apache.tools.ant.Task.perform(Task.java:348)
    [mockservice] at org.apache.tools.ant.taskdefs.Parallel$TaskRunnable.run(Parallel.java:428)
    [mockservice] at java.lang.Thread.run(Thread.java:619)
    [mockservice] 10:30:10,949 ERROR [SoapUI] An error occured [Failed to load project from file [file:C:/Subversion/GMS/Sportingbet_EBO_Adapter/trunk/soapUI/SPBSimulator.xml]], see error log for details
    [mockservice] com.eviware.soapui.support.SoapUIException: Failed to load project from file [file:C:/Subversion/GMS/Sportingbet_EBO_Adapter/trunk/soapUI/SPBSimulator.xml]
    [mockservice] at com.eviware.soapui.impl.wsdl.WsdlProjectPro.loadProject(SourceFile:272)
    [mockservice] at com.eviware.soapui.impl.wsdl.WsdlProject.<init>(WsdlProject.java:209)
    [mockservice] at com.eviware.soapui.impl.wsdl.WsdlProjectPro.<init>(SourceFile:132)
    [mockservice] at com.eviware.soapui.impl.wsdl.WsdlProjectProFactory.createNew(SourceFile:32)
    [mockservice] at com.eviware.soapui.impl.wsdl.WsdlProjectProFactory.createNew(SourceFile:16)
    [mockservice] at com.eviware.soapui.tools.SoapUIMockServiceRunner.runRunner(SoapUIMockServiceRunner.java:102)
    [mockservice] at com.eviware.soapui.tools.AbstractSoapUIRunner.run(AbstractSoapUIRunner.java:138)
    [mockservice] at com.bossmedia.tools.ant.mockservice.Task.startMockService(Task.java:106)
    [mockservice] at com.bossmedia.tools.ant.mockservice.Task.execute(Task.java:69)
    [mockservice] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    [mockservice] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [mockservice] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [mockservice] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [mockservice] at java.lang.reflect.Method.invoke(Method.java:597)
    [mockservice] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [mockservice] at org.apache.tools.ant.Task.perform(Task.java:348)
    [mockservice] at org.apache.tools.ant.taskdefs.Parallel$TaskRunnable.run(Parallel.java:428)
    [mockservice] at java.lang.Thread.run(Thread.java:619)
    [mockservice] Caused by: java.lang.ClassCastException: com.eviware.soapui.config.impl.InterfaceConfigImpl cannot be cast to com.eviware.soapui.config.WsdlInterfaceConfig
    [mockservice] at com.eviware.soapui.impl.WsdlInterfaceFactory.build(WsdlInterfaceFactory.java:41)
    [mockservice] at com.eviware.soapui.impl.WsdlInterfaceFactory.build(WsdlInterfaceFactory.java:34)
    [mockservice] at com.eviware.soapui.impl.wsdl.InterfaceFactoryRegistry.build(InterfaceFactoryRegistry.java:49)
    [mockservice] at com.eviware.soapui.impl.wsdl.WsdlProjectPro.loadProject(SourceFile:190)
    [mockservice] ... 17 more
    [mockservice] java.lang.ClassCastException: com.eviware.soapui.config.impl.EndpointStrategyConfigImpl cannot be cast to com.eviware.soapui.config.DefaultEndpointStrategyConfig
    [mockservice] at com.eviware.soapui.impl.wsdl.endpoint.DefaultEndpointStrategy.initConfig(DefaultEndpointStrategy.java:95)
    [mockservice] at com.eviware.soapui.impl.wsdl.endpoint.DefaultEndpointStrategy.init(DefaultEndpointStrategy.java:68)
    [mockservice] at com.eviware.soapui.impl.wsdl.WsdlProject.<init>(WsdlProject.java:265)
    [mockservice] at com.eviware.soapui.impl.wsdl.WsdlProjectPro.<init>(SourceFile:132)
    [mockservice] at com.eviware.soapui.impl.wsdl.WsdlProjectProFactory.createNew(SourceFile:32)
    [mockservice] at com.eviware.soapui.impl.wsdl.WsdlProjectProFactory.createNew(SourceFile:16)
    [mockservice] at com.eviware.soapui.tools.SoapUIMockServiceRunner.runRunner(SoapUIMockServiceRunner.java:102)
    [mockservice] at com.eviware.soapui.tools.AbstractSoapUIRunner.run(AbstractSoapUIRunner.java:138)
    [mockservice] at com.bossmedia.tools.ant.mockservice.Task.startMockService(Task.java:106)
    [mockservice] at com.bossmedia.tools.ant.mockservice.Task.execute(Task.java:69)
    [mockservice] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    [mockservice] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [mockservice] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [mockservice] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [mockservice] at java.lang.reflect.Method.invoke(Method.java:597)
    [mockservice] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [mockservice] at org.apache.tools.ant.Task.perform(Task.java:348)
    [mockservice] at org.apache.tools.ant.taskdefs.Parallel$TaskRunnable.run(Parallel.java:428)
    [mockservice] at java.lang.Thread.run(Thread.java:619)


    The simulator works perfectly with mockservicerunner.bat and the SoapUI graphical client.