Forum Discussion

Jahush's avatar
Jahush
Occasional Contributor
11 years ago

SoapUI API: Create DataSourceStep

Hello,
i am building an java application using the SoapUI Pro API. My application shall allow the user to create a full SoapUI project (testsuites, testcases, teststeps and so on).
But I am encountering a problem creating the datasource test step.

I tried a few things which did not work :

Test 1:

WsdlDataSourceTestStep testStep = (WsdlDataSourceTestStep) testCase.addTestStep(DataSourceStepFactory.DATASOURCE_TYPE,testStepName);
testStep.setDescription(ExcelDataSource.TYPE);
// This sends a NullPointerException due to testStep being null.


Test 2:

WsdlTestStep testStep = testCase.addTestStep(DataSourceStepFactory.DATASOURCE_TYPE, testStepName);
// Without parsing the object is not null, but what I need is a WsdlDataSourceTestStep and not a WsdlTestStep.

Test 3:

TestStepConfig testStepConfig = TestStepConfig.Factory.newInstance();
testStepConfig.setType(DataSourceStepFactory.DATASOURCE_TYPE);
testStepConfig.setName(testStepName);
testStepConfig.setDescription(description);

WsdlDataSourceTestStep testStep = new WsdlDataSourceTestStep(testCase,testStepConfig , true);

// The created testStep is of type com.eviware.soapui.impl.wsdl.teststeps.registry.ProPlaceholderStepFactory$WsdlProPlaceholderTestStep, so not really a WsdlDataSourceTestStep.

So here my question:

How do I create a datasource test step the right way?

Thanks in advance

7 Replies

  • Hi,

    DataSource testStep can be added only to SoapUI Pro and not for the open source SoapUI.

    // I added this code to setup script and it worked
    import com.eviware.soapui.impl.wsdl.teststeps.*;

    def registry = com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestStepRegistry.getInstance();

    def testStepconfig= registry.getFactory("datasource")

    def testCase = testRunner.testCase.testSuite.project.testSuites["TestSuite 2"].getTestCaseByName("TestCase 3")

    def config = testStepconfig.createNewTestStep(testCase,"DataSource");
    testCase.addTestStep( config );




    Thanks,
    Jeshtha
  • Jahush's avatar
    Jahush
    Occasional Contributor
    Thanks for the quick reply

    I think i should say a little bit more about the project, so that you know what i'd like to achieve:

    I'm working on a webservice which uses the SoapUI Pro 5.0.0 library.
    The webservice is written in java and one of it's features should be, that for an existing project a datasource step can be created.
    I know that the datasource steps are a pro-feature and only SoapUI Pro users can work with these steps.
    The users who will use the projects created by my webservice will be owners of pro licences.

    So i'd like to use the SoapUI library to create projects which are opened afterwards by SoapUI Pro users.

    I figured out by now, that the pro library contains a class called DataSourceStepFactory.
    Is this class the one used to create datasource step? And if it is, how do I use it?

    I've tried this:

    DataSourceStepFactory factory = new DataSourceStepFactory();

    TestStepConfig config = factory.createNewTestStep(testCase, "datasource");

    testCase.addTestStep(config);


    But i got a NullPointerException from the createNewTestStep-method:
    java.lang.NullPointerException
    at com.eviware.x.form.XFormFactory.createDialogBuilder(XFormFactory.java:19)
    at com.eviware.x.form.support.ADialogBuilder.buildDialog(ADialogBuilder.java:60)
    at com.eviware.soapui.SoapUIPro.b(SourceFile:440)
    at com.eviware.soapui.SoapUIPro.validateLicense(SourceFile:719)
    at com.eviware.soapui.SoapUIPro.validateLicense(SourceFile:697)
    at com.eviware.soapui.impl.wsdl.teststeps.registry.DataSourceStepFactory.createNewTestStep(SourceFile:36)
    at com.wl.soapui.UtilsSoapUI.createDataSourceTestStep(UtilsSoapUI.java:838)
    at com.wl.soapui.UtilsSoapUITest.testDataSourceTeststep(UtilsSoapUITest.java:48)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

    Could you please explain me what I did wrong?
    Is this factory the class I need and what parameters do I have to use?

    I'm really grateful for any kind of help Thanks in advance!
  • Jahush's avatar
    Jahush
    Occasional Contributor
    Hi,

    maybe I was not clear enough :

    I am using the java library from the Pro-version of SoapUI, not the light version.
    The class WsdlTestStepRegistry is part of the light version and can only get a ProPlaceholderStepFactory for the identifier key "datasource".
    I already looked into these factory-type and the only things I can get as a result from it are placeholders for datasource steps and no real datasource steps.

    As I suppose, this feature is used if light-version users want to create steps which are displayed in SoapUI afterwards, but can not be used, because of the missing pro-licence. Am I right?

    The users I'd like to support with my webservice are SoapUI Pro users. They can work with datasource steps.
    So what I need are the classes from the Pro-version library which can create real datasource-steps.
    I think this is the class: http://www.soapui.org/apidocs/pro/com/eviware/soapui/impl/wsdl/teststeps/WsdlDataSourceTestStep.html

    If possible, please give me a java code example, for this is the language I use for my webservice.

    Thanks in advance.
  • Hi,

    The java library from the Pro version should be able to access the WsdlTestStepRegistry as it can also access open source libraries.
    The code I provided will not work for open source SoapUI.
    For this question,
    As I suppose, this feature is used if light-version users want to create steps which are displayed in SoapUI afterwards, but can not be used, because of the missing pro-licence. Am I right?

    Nope this script will not create a dataSource testStep in opensource it will throw error. The WsdlTestStepRegistry is accessible for Pro, I would suggest you to try the code.

    Thanks,
    Jeshtha
  • Jahush's avatar
    Jahush
    Occasional Contributor
    Hi,

    I tried your code, but unfortunately it did not help. I'll explain what happened below:

    I create a factory like you explained and used the createNewTestStep-method with my testcase and "DataSource" as parameters.
    The result should have been a TestStepConfig which I used for the code "testCase.addTestStep(testStepConfig)".

    I tried this and got an error because the config was null. I debugged the code and I saw that the "object.getFactory("datasource")" would return a ProPlaceholderStepFactory, like I said before.
    I once saw a code from this class (I think it was from version 4.6.1) where this method was not implemented and would always return null. This would make sense somehow, because this class is from the opensource library.

    What kind of factory does your code return? Maybe I included the wrong libraries/ wrong versions for my project and therefore the WsdlTestStepRegistry does not support me with the correct factory.
    At the moment I tried to work with the soapui-pro-maven-plugin:

    <dependency>
    <groupId>com.smartbear.soapui</groupId>
    <artifactId>soapui-pro-maven-plugin</artifactId>
    <version>5.1.1</version>
    </dependency>

    from your repository:

    <repositories>
    <repository>
    <id>SmartBearRepository</id>
    <url>http://www.soapui.org/repository/maven2/</url>
    </repository>
    </repositories>

    The libraries I received from that are the soapui-5.1.1.jar, the soapui-pro-5.1.1.jar as well as their dependencies.
    Do I use the correct sources or is there another way to get the libaries I need? For as far as I understood, I need both libraries. The pro and the opensource one, right?

    ----------------------------------------------------------------------------------------
    This is a different approach I have used to solve the problem:
    I use the following Maven configuration:

                    
    <dependency>
    <groupId>com.github.redfish4ktc.soapui</groupId>
    <artifactId>maven-soapui-extension-plugin</artifactId>
    <version>4.6.4.1</version>
    </dependency>
    <dependency>
    <groupId>com.fifesoft</groupId>
    <artifactId>rsyntaxtextarea</artifactId>
    <version>1.4.1</version>
    </dependency>
    <dependency>
    <groupId>com.jgoodies</groupId>
    <artifactId>looks</artifactId>
    <version>2.2.2</version>
    </dependency>


    This configuration allows me to create and manage soapui projects and save them as xml file via JAVA.
    The following test steps I can already create:

    -Delay
    -Groovy
    -JDBCStep
    -Manual
    -Properties
    -PropertyTransfer
    -RunTestCase
    -SoapRequest

    But I do not get how to create a DataSource test step correctly.
    Currently it works with the following code to generate the DataSource Steps,
    but i dont get it, how I can add optional parameters.
    Or, how do I set the datasource to: JDBC, Excel or File?

    First I have created a project (projectA.xml) via JAVA.
    Then I have a created a testsuite (testsuiteA) and a testcase (testcaseA) via JAVA.
    Now I want to create in the "testcaseA" a new DataSourceStep via JAVA!
    This is my java method which can create DataSourceTestStep with a few paramaters but not with all:

    String projectName = "projectA";
    String testSuiteName = "testsuiteA";
    String testCaseName ="testcaseA";
    String testStepName ="stepA";
    String description = "something here";

    try {
    projectName = utils.getProjectDirectory(projectName);
    File projectFile = new File(projectName);
    WsdlProjectPro project = new WsdlProjectPro(projectName);
    WsdlTestSuitePro testSuite = (WsdlTestSuitePro) project.getTestSuiteByName(testSuiteName);
    WsdlTestCasePro testCase = (WsdlTestCasePro) testSuite.getTestCaseByName(testCaseName);

    // WsdlTestStep testStep = testCase.addTestStep(DataSourceStepFactory.DATASOURCE_TYPE, testStepName);
    // WsdlDataSourceTestStep testStep =
    (WsdlDataSourceTestStep) testCase.addTestStep(DataSourceStepFactory.DATASOURCE_TYPE,testStepName);

    // testStep.setDataSource(ExcelDataSource.TYPE);
    // testStep.setDescription(description);

    TestStepConfig testStepConfig = TestStepConfig.Factory.newInstance();
    testStepConfig.setType(DataSourceStepFactory.DATASOURCE_TYPE);
    testStepConfig.setName(testStepName);
    testStepConfig.setDescription(description);

    WsdlProPlaceholderTestStep myTestStep = (WsdlProPlaceholderTestStep) testCase.addTestStep(testStepConfig);
    //ExcelDataSource excelDS = new ExcelDataSource();
    // WsdlDataSourceTestStep testStep = new WsdlDataSourceTestStep( testCase,testStepConfig , true);
    // testStep.setDescription(description);// testStep.setDataSource(ExcelDataSource.TYPE);
    // WsdlTestStep myTestStep = testCase.addTestStep(testStepConfig);
    project.saveIn(projectFile);
    } catch (Exception ex) {ex.printStackTrace();}


    How can I set all the other parameters with values​​?
    For instance something like that:
            
    WsdlDataSourceTestStep configs = new WsdlDataSourceTestStep();
    configs.setDisabled(true);
    configs.setFailOnEmpty(false);
    configs.setExpandProperties(true);
    ...


    Many thanks in advance