Forum Discussion

Todor_Mollov's avatar
Todor_Mollov
Occasional Contributor
16 years ago

Automated start and stop

Hi,
We can use mockservicerunner.bat to start mock services. However I couldn't find any way how to stop automatically the started mock service.
Do you plan to create something like mockservicestopper.bat?
May be I can play somehow with the com.eviware.soapui.tools.SoapUIMockServiceRunner.class and initiate starting and stopping of the services myself, but before diving into the deep water I would ask if solution already exists.

Thanks,
Todor

7 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    actually, you are right, there is no way to stop the mock service "externally" ( the mockservicerunner waits for a key-press to terminate). How would you like to do this? What is your setup?

    regards!

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

    Thanks for the response.
    I will setup automated scripts that will execute each time a CVS code is changed. The SOAP ui xml files could aslo be modified, that's why the procedure should be able automatically to start and stop mock services.
    I have CruseControl that will trigger the build/JUnit and I have ant that will execute shell scripts or java applications.
    I have the idea that I will create a server application that will start/stop mock services. Something that takes as input the service name and start the service. Optional parameter will be a stop flag that will terminate the applciation and I hope stops the services.
    Thanks,
    Todor
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Todor,

    ok.. thanks for your input, I'll try to think of something. Initially maybe you could send an http-request to the mockservice which could terminate itself in the onrequest script?

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

    This is a good suggestion. I still have to investigate the scripting functionallity, but I guess this could be done.
    However the problem is if a web service is removed, I will not be able to detect this and will not stop the mock service.
    The best solution for me is to have a central server application that is feeded with project files, parses the files and starts each mock service found in the files. When an update is needed in the services, the application is restarted.
    I tried to play with the API and tried this code:
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.util.List;

    import com.eviware.soapui.impl.wsdl.WsdlProject;
    import com.eviware.soapui.model.mock.MockService;
    import com.eviware.soapui.model.project.ProjectFactory;
    import com.eviware.soapui.model.project.ProjectFactoryRegistry;


    public class TestServer {
    public static void main(String[] args){
    TestServer server = new TestServer();
    try {
    server.startServer();
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    System.exit(0);
    }

    }

    public void startServer() throws Exception{
    startEndListener();
    ProjectFactory projectFactory = ProjectFactoryRegistry.getProjectFactory("wsdl");
    WsdlProject project = (WsdlProject) projectFactory.createNew("file:/C:/wp/rsa/ServerSOAPUI/bin/projects/HelloWS-soapui-project.xml", "");
    List mockRunner =project.getMockServiceList();
    for(int i = 0 ; i < mockRunner.size() ; i ++){
    System.out.println(mockRunner.get(i));
    MockService service = mockRunner.get(i);
    service.start();
    }
    System.out.println("End of starting services.");
    }

    public void startEndListener() throws Exception{
    final ServerSocket serverSocket = new ServerSocket(0);
    System.out.println("==================Listening on port:"+serverSocket.getLocalPort());
    Thread thread = new Thread(){
    public void run(){

    try {
    Socket socket = serverSocket.accept();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    System.out.println("Exiting SOAP UI.");
    System.exit(0);
    }
    };
    thread.start();

    }
    }

    I'll elaborate on the application and will include it in the build.
  • Brandon_C's avatar
    Brandon_C
    Occasional Contributor
    Is there away to start the mock service via groovy scrip as one of the test steps? 

    I also need the ability to start the mock service automatically.
  • Hi,

    I am also looking for this kind of feature where the auto bild system build the OSB service, do start the SoapUI MockServer , run the soapUi tests against the mock server and then stop the mock server once the build cycle finished . ( i have enabled with Maven)

    At the moment, I am using " Deploy as WAR" and deploying all the soapui mock projects to a central tomcat server and then running my test againist its corresponding mock application.

    Please suggest any better of doing this.

    Thanks
    SOANNR