Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce cukes-db module to simplify data preparation/verification in RDBMS #110

Open
sergeytrasko opened this issue Nov 23, 2017 · 1 comment

Comments

@sergeytrasko
Copy link
Member

Sometimes for test execution it is necessary to prepare some data inside RDBMS.
One option would be to expose a test specific RESTful API that will create initial data. Another option is to provide direct DB access (for sure it should be used with care).

Structure and API should be more-less the same as for LDAP:

  • basic CRUD for entity (table)
  • data querying (SELECT by condition)
@DmitryPrigodich
Copy link

DmitryPrigodich commented Dec 6, 2017

I suggest following step definitions:

    //CREATE
    @And("^DB table \"([^\"]+)\" record with ([^\"]+) is \"([^\"]+)\" is created$")
    public void createRecordInDB(String tableName, String key, String keyValue) {
    }

    @And("^DB table \"([^\"]+)\" record with ([^\"]+) is \"([^\"]+)\" is created:$")
    public void createRecordWithAttributesInDB(String tableName, String key, String keyValue, List<Map<String, String>> attributeList) {
    }


    //READ
    @And("^DB table \"([^\"]+)\" records with ([^\"]+) is \"([^\"]+)\" are retrieved$")
    public void getRecordsFromDB(String tableName, String key, String keyValue) {
    }

    @And("^DB table \"([^\"]+)\" records with ([^\"]+) is \"([^\"]+)\" and following attributes are retrieved$")
    public void getRecordsWithCertainAttributesFromDB(String tableName, String key, String keyValue, List<Map<String,String>> attributeList) {
    }


    //UPDATE
    @And("^DB table \"([^\"]+)\" record with ([^\"]+) is \"([^\"]+)\" attribute \"([^\"]+)\" value is updated to \"([^\"]+)\"")
    public void updateRecordInDB(String tableName, String key, String keyValue, String attribute, String updatedValue) {
    }

    @And("^DB table \"([^\"]+)\" record with ([^\"]+) is \"([^\"]+)\" attributes are updated:")
    public void updateRecordInDB(String tableName, String key, String keyValue, List<Map<String, String>> attributeList) {
    }

    //DELETE
    @And("^DB table \"([^\"]+)\" record with ([^\"]+) is \"([^\"]+)\" is deleted")
    public void deleteRecordInDB(String tableName, String key, String keyValue) {
    }

    //ASSERT
    @Then("^DB table \"([^\"]+)\" record with ([^\"]+) is \"([^\"]+)\" should( not|) exist$")
    public void checkRecordExistsInDB(String tableName, String key, String keyValue, String condition) {
        boolean shouldExist = condition.isEmpty();
    }

    @Then("^DB table record should( not|) exist$")
    public void checkRecordExistsInDB(String condition) {
        //Goes only with getRecordsFromDB() step
        boolean shouldExist = condition.isEmpty();
    }

    @Then("^DB table \"([^\"]+)\" records with ([^\"]+) is \"([^\"]+)\" count should be (=|!=|<|<=|=>|>) (\\d+)$")
    public void checkRecordCountInDB(String tableName, String key, String keyValue, String operation) {
    }

    @Then("^DB table records count should be (=|!=|<|<=|=>|>) (\\d+)$")
    public void checkRecordCountInDB(String operation) {
        //Goes only with getRecordsFromDB() step
    }

    @Then("^DB table \"([^\"]+)\" record with ([^\"]+) is \"([^\"]+)\" attribute \"([^\"]+)\" should( not|) be equal to \"([^\"]*)\"$")
    public void checkRecordAttributeEqualsInDB(String tableName, String key, String keyValue, String attribute, String condition, String expectedValue) {
        boolean shouldBeEqual = condition.isEmpty();
    }

    @Then("^DB table record attribute \"([^\"]+)\" should( not|) be equal to \"([^\"]*)\"$")
    public void checkRecordAttributeEqualsInDB(String attribute, String condition, String expectedValue) {
        //Goes only with getRecordsFromDB() step
        boolean shouldBeEqual = condition.isEmpty();
    }

    @Then("^DB table \"([^\"]+)\" record with ([^\"]+) is \"([^\"]+)\" attribute \"([^\"]+)\" should( not|) contain \"([^\"]+)\"$")
    public void checkRecordAttributeContainsInDB(String tableName, String key, String keyValue, String attribute, String condition, String expectedValue) {
        boolean shouldContain = condition.isEmpty();
    }

    @Then("^DB table record attribute \"([^\"]+)\" should( not|) contain \"([^\"]+)\"$")
    public void checkRecordAttributeContainsInDB(String attribute, String condition, String expectedValue) {
        //Goes only with getRecordsFromDB() step
        boolean shouldContain = condition.isEmpty();
    }

    @Then("^DB table \"([^\"]+)\" record with ([^\"]+) is \"([^\"]+)\" attribute \"([^\"]+)\" should( not|) be empty$")
    public void checkRecordAttributeEmptyInDB(String tableName, String key, String keyValue, String attribute, String condition) {
        boolean shouldBeEmpty = condition.isEmpty();
    }

    @Then("^DB table record attribute \"([^\"]+)\" should( not|) be empty$")
    public void checkRecordAttributeEmptyInDB(String attribute, String condition) {
        //Goes only with getRecordsFromDB() step
        boolean shouldBeEmpty = condition.isEmpty();
    }

    @Then("^DB table \"([^\"]+)\" record with ([^\"]+) is \"([^\"]+)\" attributes should match:$")
    public void checkRecordAttributeEmptyInDB(String tableName, String key, String keyValue, List<Map<String,String>> attributeList) {
    }

    @Then("^DB table record attributes should match:$")
    public void checkRecordAttributeEmptyInDB(List<Map<String,String>> attributeList) {
        //Goes only with getRecordsFromDB() step
    }

So that final look would be:

    #CREATE
    And DB table "USERS" record with ID is "001" is created
    And DB table "USERS" record with ID is "002" is created:
        | attribute | value |
        | NAME      | Maria |
    #UPDATE
    And DB table "USERS" record with ID is "002" attribute "SURNAME" value is updated to "S0NNS8"
    And DB table "USERS" record with ID is "002" attributes are updated:
        | attribute | value    |
        | SURNAME   | Zaytseva |
    #DELETE
    And DB table "USERS" record with ID is "002" is deleted
    #READ
    Then DB table "USERS" record with ID is "001" should exist
    Then DB table "USERS" record with ID is "002" should not exist
    Then DB table "USERS" record with ID is "001" attribute "NAME" should not be equal to "Maria"
    Then DB table "USERS" records with ID is "002" count should be > 1
    Then DB table "USERS" record with ID is "001" attributes should match:
        | attribute | value    | operation    |
        | NAME      | Mark     | not equals   |
        | NAME      | Maria    | equals       |
        | SURNAME   | Zaytseva | contains     |
        | SURNAME   | sko      | not contains |
        | ATTR1     |          | empty        |
        | ATTR2     |          | not empty    |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants