Forum Discussion

soapuiuser2013's avatar
soapuiuser2013
New Contributor
12 years ago

How to Set Endpoint in Java TestCase

Hi

I am trying to create my own Java app that runs my SOAPUI test cases.

I have code that looks like this:

List<TestSuite> testSuites = project.getTestSuiteList();
for( TestSuite suite : testSuites ) {

List<TestCase> testCases = suite.getTestCaseList();
for( TestCase testCase : testCases ) {
System.out.println("Running SoapUI test [" + testCase.getName() + "]");
TestCaseRunner runner = testCase.run(new PropertiesMap(), false);
}
}


Does anyone know how I can set the endpoint, I have searched the API high and low but cant find anything.

I guess I need to set it on the testCase , perhaps as a property but I have no idea what I would call that property or how to add it..

Thanks

2 Replies

  • If anyone is interested, I found a way to change the endpoint. The code is pretty nasty and only works with one interface defined, but I couldn't find anything in the API and it can easily be adapted to work with multiple interfaces.


    String projectFile = String.format("src/main/resources/%s-soapui-project.xml", projectName);
    project = (WsdlProject)ProjectFactoryRegistry.getProjectFactory("wsdl").createNew(projectFile);

    Interface i = project.getInterfaceAt(0);
    for(String existingEndpoint : i.getEndpoints()) {
    i.changeEndpoint(existingEndpoint, endpoint);
    }
  • Here is an example how you can change de endpoint of each testStep.
    note: this is test code


    @Test
    public void fullControl() throws Exception {
    WsdlProject project = new WsdlProject("my-soapui-project.xml");

    List<TestSuite> testSuites = project.getTestSuiteList();
    for( TestSuite suite : testSuites ) {
    System.out.println("Running SoapUI TestSuite [" + suite.getName() + "]");
    List<TestCase> testCases = suite.getTestCaseList();
    for( TestCase testCase : testCases ) {

    System.out.println("TestStep count [" + testCase.getTestStepCount() + "]");

    for (TestStep testStep : testCase.getTestStepList()) {
    System.out.println("TestSteps [" + testStep.getName() + "]");

    //get the current endpoint of this testStep
    System.out.println("endpoint:" + testStep.getPropertyValue("Endpoint"));
    //Change the endpoint property of this testStep
    testStep.setPropertyValue("EndPoint", "http://www.java.com");
    //Check if the endpoint property is changed
    System.out.println("endpoint:" + testStep.getPropertyValue("Endpoint"));

    //Save the project
    //project.save();

    TestSuite testSuite = project.getTestSuiteByName(suite.getName());
    TestCase testCase1 = testSuite.getTestCaseByName(testCase.getName());
    TestStep testStep1 = testCase.getTestStepByName(testStep.getName());
    TestCaseRunner testCaseRunner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner((WsdlTestCase)testCase1, null);
    TestCaseRunContext testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep1);


    //testStep.run(testCaseRunner, testStepContext);
    }
    }
    }
    }