8

I want to create a Java class that will do the following
1. load/create a SOAPUI project using a wsdl.
2. run requests to the operations in that wsdl.

This is my SoapJavaTest.java file(though this is not complete, it is just registering a project in SOAP UI and printing the operations contained in it)

public class SoapJavaTest{
    public static void main(String args[]) throws Exception{
        String projectFile ="SoapUIJavaTest\\SoapUIProjects\\soapui-project1.xml";
        WsdlProject project = new WsdlProject (projectFile);
        //WsdlProject project = new WsdlProject();
        WsdlInterface[] wsdls = WsdlImporter.importWsdl(project, "http://metalmaker.net/metalmaker.asmx?WSDL");
        WsdlInterface wsdl = wsdls[0];
        for (Operation operation : wsdl.getOperationList()){
            WsdlOperation op = (WsdlOperation) operation;
            System.out.println("OP:"+op.getName());System.out.println(op.createRequest(true));
            System.out.println("Response:");System.out.println(op.createResponse(true));
            }
        }

    }

I am getting the following error - 'NoSuchMethodError: org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(Ljava/lang/ClassLoader;Ljava/lang/String;)Lorg/apache/xmlbeans/SchemaTypeSystem;'.

I have included the following jar files 1. commons-cli-1.2
2. commons-httpclient-3.1
3. log4j
4. soapui-3.6-beta2
5. soapui-xmlbeans-2.0.2
6. wsdl-xmlbeans-1.1
7. xbean-1.0.3
8. xmlbeans-xmlpublic-2.2.0
9. XmlSchema-1.0.3

What jar file am I missing or is it the wrong classes that I am using? Any help would be appreciated.

tgkprog
  • 4,493
  • 4
  • 41
  • 70
priti
  • 639
  • 3
  • 8
  • 25
  • did this work for you finally? maven as suggested might get the correct dependancies – tgkprog May 30 '13 at 09:21
  • 1
    I didnt try Maven. I integrated SoapUI and Junit by following [this link](http://www.soapui.org/Test-Automation/integrating-with-junit.html). However in that we are setting an already saved Soap UI project in the Junit test. I wanted to do something like creating and then saving the SOAPUI project at some desired location provided that I only have to use service wsdl. Any idea how to implement that through code. – priti May 30 '13 at 10:30
  • The problem was with the jar files included in the project classpath.We need to include all the jar files available in the soapUI-4.5.1\lib folder in our project classpath.However,I am getting another problem.I have tried the following code `String projectFile ="SOAPUITests/SoapUIProjects/soapui-project1.xml"; SoapUI.setSoapUICore(new StandaloneSoapUICore(true)); WsdlProject project = new WsdlProject (projectFile);` but I am getting `java.net.MalformedURLException: no protocol: SOAPUITests/SoapUIProjects/soapui-project1.xml` error in `WsdlProject project = new WsdlProject (projectFile)` line. – priti May 31 '13 at 12:54
  • attempting to reproduce in 2017 using maven. Smartbear now owns soapui so all of the classes and package names are difference and your sample code no longer works. Any pointers? – spy Nov 05 '17 at 13:00

2 Answers2

7

Finally I am able to solve this. I am creating a SoapUI project, saving it and sending requests all via code. Please refer to link here for complete details. Thanks.

priti
  • 639
  • 3
  • 8
  • 25
6

Rather than programmatically calling SoapUI to run your tests, have you considered using the maven-soapui-pro-plugin ?

Here's an introduction to Apache Maven, if you need to read about it :)

Now, given you have a maven project, edit your pom.xml and add a profile similar to the one below. Then you can run maven with -Dsoapuitests, and your SoapUI test suite(s) will run.

    <profile>
        <id>soapuitests</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>eviware</groupId>
                    <artifactId>maven-soapui-pro-plugin</artifactId>
                    <version>4.5.1</version>
                    <executions>
                        <execution>
                            <id>soapuitests</id>
                            <phase>test</phase>
                            <goals>
                                <goal>test</goal>
                            </goals>
                            <configuration>
                                <endpoint>http://myserver/myendpoint</endpoint>
                                <projectFile>
                                    ${project.basedir}/src/test/resources/my-soapui-project.xml
                                </projectFile>
                                <projectProperties>
                                </projectProperties>
                                <outputFolder>${project.build.directory}\soapui-logs</outputFolder>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

I hope this is of help to you, good luck.

vikingsteve
  • 38,481
  • 23
  • 112
  • 156