Forum Discussion

Eckan's avatar
Eckan
New Contributor
11 years ago

Test data using insert into multiple tables

Hi all
I´m using SoapUI Pro and would like to create my own test data using SQL insert statements into multiple tables.
What would you recommend the best way to do this?
As far as I know you´re only allowed to enter 1 insert statement in a JDBC Request and then there will be a lot of JDBC Requests in the testcase?

Best Regards!
Eckan

4 Replies

  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    I am not a pro user but you can accomplish this rather simply with Groovy on the open source version.

    The following is my DBRead function that I commonly use. It's a java function so you will need to add the correct imports in the code. I will put the ones I think are related to this specific function. Also, I use Access DB so that would need to be corrected as well.


    import java.sql.*;


    public static void dbWrite(String Database, String query) throws SQLException, ClassNotFoundException {
    String currentDir = "/Dir/to/Database"
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + currentDir + Database;
    Connection conn = DriverManager.getConnection(database, "", "");
    Statement s = conn.createStatement();
    s.execute(query);
    conn.close();
    }
    }



    And an example of it in use:

      
    dbWrite("Resources.mdb", "UPDATE addresses SET Locals='" + locals + "' WHERE Zip like'" + zip[0] + "%';");



    Like this you can control your DB as you like with the information you want. This code is quite barbaric and I rarely use it since the majority of my calls are now done with a Java app I created that I can point at any API and have it send what data I want to at it quite easily. I was using this to verify things like addresses were valid in my system.
  • Eckan's avatar
    Eckan
    New Contributor
    Thanks PaulM

    I´m using the 'Setup Script' tab to insert the testdata into the database.

    Is there anyone out there using another technique or method please don´t be shy to share your ideas