io.cucumber.datatable.DataTable Java Examples

The following examples show how to use io.cucumber.datatable.DataTable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatabaseSpec.java    From bdt with Apache License 2.0 6 votes vote down vote up
/**
 * Execute a query on (mongo) database
 *
 * @param query         path to query
 * @param type          type of data in query (string or json)
 * @param collection    collection in database
 * @param modifications modifications to perform in query
 */
@When("^I execute a query '(.+?)' of type '(json|string)' in mongo '(.+?)' database using collection '(.+?)' with:$")
public void sendQueryOfType(String query, String type, String database, String collection, DataTable modifications) throws Exception {
    try {
        commonspec.setResultsType("mongo");
        String retrievedData = commonspec.retrieveData(query, type);
        String modifiedData = commonspec.modifyData(retrievedData, type, modifications);
        commonspec.getMongoDBClient().connectToMongoDBDataBase(database);
        DBCollection dbCollection = commonspec.getMongoDBClient().getMongoDBCollection(collection);
        DBObject dbObject = (DBObject) JSON.parse(modifiedData);
        DBCursor cursor = dbCollection.find(dbObject);
        commonspec.setMongoResults(cursor);
    } catch (Exception e) {
        commonspec.getExceptions().add(e);
    }
}
 
Example #2
Source File: CommonGTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void modifyDataAddToJsonNumberTest_3() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("key1", new JSONArray(Arrays.asList("value1")));
    String data = jsonObject.toString();
    String expectedData = "{\"key1\":[\"value1\",0]}";
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key1", "ADDTO", "0", "number"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example #3
Source File: RestTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void testsendRequestDataTableTimeout() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();
    commong.setRestHost("jenkins.int.stratio.com");
    commong.setRestPort(":80");
    String endPoint = "endpoint";
    String expectedMsg = "regex:tag";
    String requestType = "POST";
    String baseData = "retrieveDataStringTest.conf";
    String type = "string";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key1", "DELETE", "N/A"));
    DataTable modifications = DataTable.create(rawData);

    RestSpec rest = new RestSpec(commong);

    try {
        rest.sendRequestDataTableTimeout(10, 1, requestType, endPoint, null, expectedMsg, baseData, type, modifications);
        fail("Expected Exception");
    } catch (NullPointerException e) {
        assertThat(e.getClass().toString()).as("Unexpected exception").isEqualTo(NullPointerException.class.toString());
        assertThat(e.getMessage()).as("Unexpected exception message").isEqualTo(null);
    }

}
 
Example #4
Source File: CommonGTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void csvTest() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();

    List<Map<String, String>> csvResults = new ArrayList<Map<String, String>>();
    Map<String, String> row = new HashMap<String, String>();
    row.put("id", "1");
    row.put("name", "aaa");
    row.put("value", "test");
    csvResults.add(row);

    List<List<String>> rawData = Arrays.asList(Arrays.asList("id", "name", "value"), Arrays.asList("1", "aaa", "test"));
    DataTable csvList = DataTable.create(rawData);

    commong.setCSVResults(csvResults);
    commong.resultsMustBeCSV(csvList);
}
 
Example #5
Source File: MongoDBUtils.java    From bdt with Apache License 2.0 6 votes vote down vote up
/**
 * Create a MongoDB collection.
 *
 * @param colectionName
 * @param options
 */
public void createMongoDBCollection(String colectionName, DataTable options) {
    BasicDBObject aux = new BasicDBObject();
    // Recorremos las options para castearlas y aƱadirlas a la collection
    List<List<String>> rowsOp = options.cells();
    for (int i = 0; i < rowsOp.size(); i++) {
        List<String> rowOp = rowsOp.get(i);
        if (rowOp.get(0).equals("size") || rowOp.get(0).equals("max")) {
            int intproperty = Integer.parseInt(rowOp.get(1));
            aux.append(rowOp.get(0), intproperty);
        } else {
            Boolean boolProperty = Boolean.parseBoolean(rowOp.get(1));
            aux.append(rowOp.get(0), boolProperty);
        }
    }
    dataBase.createCollection(colectionName, aux);
}
 
Example #6
Source File: CommonGTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void modifyDataAddToJsonNullTest_2() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("key1", new JSONArray(Arrays.asList("value1")));
    String data = jsonObject.toString();
    String expectedData = "{\"key1\":[\"value1\",null]}";
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key1", "ADDTO", "", "null"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example #7
Source File: CommonGTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void modifyDataAddToJsonObjectTest_1() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("key1", new JSONArray(Arrays.asList("value1")));
    String data = jsonObject.toString();
    String expectedData = "{\"key1\":[\"value1\",{\"key2\": \"value2\"}]}";
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key1", "ADDTO", "{\"key2\": \"value2\"}", "object"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example #8
Source File: CommonGTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void modifyDataAddToJsonStringTest_1() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("key1", new JSONArray(Arrays.asList("value1")));
    String data = jsonObject.toString();
    String expectedData = "{\"key1\":[\"value1\",\"value2\"]}";
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key1", "ADDTO", "value2", "string"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example #9
Source File: CommonGTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void modifyDataAddToJsonBooleanTest_3() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("key1", new JSONArray(Arrays.asList("value1")));
    String data = jsonObject.toString();
    String expectedData = "{\"key1\":[\"value1\",false]}";
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key1", "ADDTO", "", "boolean"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example #10
Source File: CommonGTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void modifyDataAddToJsonBooleanTest_2() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("key1", new JSONArray(Arrays.asList("value1")));
    String data = jsonObject.toString();
    String expectedData = "{\"key1\":[\"value1\",false]}";
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key1", "ADDTO", "false", "boolean"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example #11
Source File: DatabaseSpec.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Then("^I check that result is:$")
public void comparetable(DataTable dataTable) throws Exception {

    //from Cucumber Datatable, the pattern to verify
    List<String> tablePattern = new ArrayList<String>();
    tablePattern = dataTable.asList(String.class);

    //the result from select
    List<String> sqlTable = new ArrayList<String>();

    //the result is taken from previous step
    for (int i = 0; ThreadProperty.get("queryresponse" + i) != null; i++) {
        String ip_value = ThreadProperty.get("queryresponse" + i);
        sqlTable.add(i, ip_value);
    }

    for (int i = 0; ThreadProperty.get("queryresponse" + i) != null; i++) {
        ThreadProperty.remove("queryresponse" + i);
    }

    assertThat(tablePattern).as("response is not equal to the expected").isEqualTo(sqlTable);
}
 
Example #12
Source File: CommonGTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void modifyDataAddToJsonBooleanTest_1() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("key1", new JSONArray(Arrays.asList("value1")));
    String data = jsonObject.toString();
    String expectedData = "{\"key1\":[\"value1\",true]}";
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key1", "ADDTO", "true", "boolean"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example #13
Source File: CommonGTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void modifyDataAddToJsonArrayTest_1() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("key1", new JSONArray(Arrays.asList("value1")));
    String data = jsonObject.toString();
    String expectedData = "{\"key1\":[\"value1\",[\"value2\"]]}";
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key1", "ADDTO", "[\"value2\"]", "array"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example #14
Source File: FileTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadFileToVariableJSON() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());

    String baseData = "schemas/testCreateFile.json";
    String type = "json";
    String envVar = "myjson";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key1", "UPDATE", "new_value", "n/a"), Arrays.asList("key2", "ADDTO", "[\"new_value\"]", "array"));
    DataTable modifications = DataTable.create(rawData);

    CommonG commong = new CommonG();
    FileSpec file = new FileSpec(commong);

    file.readFileToVariable(baseData, type, envVar, modifications);

    String envVarResult = ThreadProperty.get(envVar);
    String expectedResult = "{\"key1\":\"new_value\",\"key2\":[[\"new_value\"]],\"key3\":{\"key3_2\":\"value3_2\",\"key3_1\":\"value3_1\"}}";

    assertThat(envVarResult).as("Not as expected").isEqualTo(expectedResult);
}
 
Example #15
Source File: CommonG.java    From bdt with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the different results of a previous query to Elasticsearch database
 *
 * @param expectedResults A DataTable Object with all data needed for check the results. The DataTable must contains at least 2 columns:
 *                        a) A field column from the result
 *                        b) Occurrences column (Integer type)
 *                        <p>
 *                        Example:
 *                        |latitude| longitude|place     |occurrences|
 *                        |12.5    |12.7      |Valencia  |1           |
 *                        |2.5     | 2.6      |Stratio   |0           |
 *                        |12.5    |13.7      |Sevilla   |1           |
 *                        IMPORTANT: All columns must exist
 * @throws Exception exception
 */
public void resultsMustBeElasticsearch(DataTable expectedResults) throws Exception {
    if (getElasticsearchResults() != null) {
        List<List<String>> expectedResultList = expectedResults.cells();
        //Check size
        assertThat(expectedResultList.size() - 1).overridingErrorMessage(
                "Expected number of columns to be" + (expectedResultList.size() - 1)
                        + "but was " + previousElasticsearchResults.size())
                .isEqualTo(previousElasticsearchResults.size());
        List<String> columnNames = expectedResultList.get(0);
        for (int i = 0; i < previousElasticsearchResults.size(); i++) {
            for (int j = 0; j < columnNames.size(); j++) {
                assertThat(expectedResultList.get(i + 1).get(j)).overridingErrorMessage("In row " + i + "and "
                        + "column " + j
                        + "have "
                        + "been "
                        + "found "
                        + expectedResultList.get(i + 1).get(j) + " results and " + previousElasticsearchResults.get(i).get(columnNames.get(j)).toString() + " were "
                        + "expected").isEqualTo(previousElasticsearchResults.get(i).get(columnNames.get(j)).toString());
            }
        }
    } else {
        throw new Exception("You must execute a query before trying to get results");
    }
}
 
Example #16
Source File: MiscTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void testSizeInJSON() throws Exception {
    String baseData = "consulMesosJSON.conf";
    String envVar = "exampleEnvVar";
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();
    MiscSpec misc = new MiscSpec(commong);

    String result = new String(Files.readAllBytes(
            Paths.get(getClass().getClassLoader().getResource(baseData).getFile())));

    ThreadProperty.set(envVar, result);

    List<String> row1 = Arrays.asList("$", "size", "4");
    List<String> row2 = Arrays.asList("$.[0].ServiceTags", "size", "2");

    List<List<String>> rawData = Arrays.asList(row1, row2);

    DataTable table = DataTable.create(rawData);

    misc.matchWithExpresion(envVar, table);

}
 
Example #17
Source File: MiscTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = AssertionError.class)
public void testWrongOperatorInJSON() throws Exception {
    String baseData = "consulMesosJSON.conf";
    String envVar = "consulMesos";
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();
    MiscSpec misc = new MiscSpec(commong);

    String result = new String(Files.readAllBytes(
            Paths.get(getClass().getClassLoader().getResource(baseData).getFile())));

    ThreadProperty.set(envVar, result);

    List<String> row1 = Arrays.asList("$.[0].ServiceTags", "&&", "leader");
    List<String> row2 = Arrays.asList("[1].Node", "||", "paaslab32.stratio.com");

    List<List<String>> rawData = Arrays.asList(row1, row2);

    DataTable table = DataTable.create(rawData);

    misc.matchWithExpresion(envVar, table);

}
 
Example #18
Source File: FileTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadFileToVariableString() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());

    String baseData = "schemas/krb5.conf";
    String type = "string";
    String envVar = "mystring";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("foo", "REPLACE", "bar", "n/a"));
    DataTable modifications = DataTable.create(rawData);

    CommonG commong = new CommonG();
    FileSpec file = new FileSpec(commong);

    file.readFileToVariable(baseData, type, envVar, modifications);

    String envVarResult = ThreadProperty.get(envVar);
    String expectedResult = "bar = bar";

    assertThat(envVarResult).as("Not as expected").isEqualTo(expectedResult);
}
 
Example #19
Source File: MiscTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void testValueEqualInJSON() throws Exception {
    String baseData = "consulMesosJSON.conf";
    String envVar = "consulMesos";
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();
    MiscSpec misc = new MiscSpec(commong);

    String result = new String(Files.readAllBytes(
            Paths.get(getClass().getClassLoader().getResource(baseData).getFile())));

    ThreadProperty.set(envVar, result);

    List<String> row1 = Arrays.asList("$.[0].Node", "equal", "paaslab31.stratio.com");
    List<String> row2 = Arrays.asList("[0].Node", "equal", "paaslab31.stratio.com");

    List<List<String>> rawData = Arrays.asList(row1, row2);

    DataTable table = DataTable.create(rawData);

    misc.matchWithExpresion(envVar, table);

}
 
Example #20
Source File: MiscTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = AssertionError.class, expectedExceptionsMessageRegExp = ".*?Expected array for size operation.*?")
public void testNotArraySizeInJSON() throws Exception {
    String baseData = "consulMesosJSON.conf";
    String envVar = "exampleEnvVar";
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();
    MiscSpec misc = new MiscSpec(commong);

    String result = new String(Files.readAllBytes(
            Paths.get(getClass().getClassLoader().getResource(baseData).getFile())));

    ThreadProperty.set(envVar, result);

    List<String> row1 = Arrays.asList("$.[0].Node", "size", "4");
    List<List<String>> rawData = Arrays.asList(row1);

    DataTable table = DataTable.create(rawData);

    misc.matchWithExpresion(envVar, table);
}
 
Example #21
Source File: CommonGTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void modifyDataAddToJsonArrayTest_3() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("key1", new JSONArray(Arrays.asList("value1")));
    String data = jsonObject.toString();
    String expectedData = "{\"key1\":[\"value1\",[[]]]}";
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key1", "ADDTO", "[[]]", "array"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example #22
Source File: DatabaseSpec.java    From bdt with Apache License 2.0 6 votes vote down vote up
/**
 * Create table
 *
 * @param table     Cassandra table
 * @param datatable datatable used for parsing elements
 * @param keyspace  Cassandra keyspace
 */
@Given("^I create a Cassandra table named '(.+?)' using keyspace '(.+?)' with:$")
public void createTableWithData(String table, String keyspace, DataTable datatable) {
    try {
        commonspec.getCassandraClient().useKeyspace(keyspace);
        int attrLength = datatable.cells().get(0).size();
        Map<String, String> columns = new HashMap<String, String>();
        ArrayList<String> pk = new ArrayList<String>();

        for (int i = 0; i < attrLength; i++) {
            columns.put(datatable.cells().get(0).get(i),
                    datatable.cells().get(1).get(i));
            if ((datatable.cells().size() == 3) && datatable.cells().get(2).get(i).equalsIgnoreCase("PK")) {
                pk.add(datatable.cells().get(0).get(i));
            }
        }
        if (pk.isEmpty()) {
            throw new Exception("A PK is needed");
        }
        commonspec.getCassandraClient().createTableWithData(table, columns, pk);
    } catch (Exception e) {
        commonspec.getLogger().debug("Exception captured");
        commonspec.getLogger().debug(e.toString());
        commonspec.getExceptions().add(e);
    }
}
 
Example #23
Source File: DatabaseSpec.java    From bdt with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if a cassandra table contains the values of a DataTable.
 *
 * @param keyspace
 * @param tableName
 * @param data
 * @throws InterruptedException
 */
@Then("^a Cassandra keyspace '(.+?)' contains a table '(.+?)' with values:$")
public void assertValuesOfTable(String keyspace, String tableName, DataTable data) throws InterruptedException {
    //  USE of Keyspace
    commonspec.getCassandraClient().useKeyspace(keyspace);
    // Obtain the types and column names of the datatable
    // to return in a hashmap,
    Map<String, String> dataTableColumns = extractColumnNamesAndTypes(data.cells().get(0));
    // check if the table has columns
    String query = "SELECT * FROM " + tableName + " LIMIT 1;";
    com.datastax.driver.core.ResultSet res = commonspec.getCassandraClient().executeQuery(query);
    equalsColumns(res.getColumnDefinitions(), dataTableColumns);
    //receiving the string from the select with the columns
    // that belong to the dataTable
    List<String> selectQueries = giveQueriesList(data, tableName, columnNames(data.cells().get(0)));
    //Check the data  of cassandra with different queries
    int index = 1;
    for (String execQuery : selectQueries) {
        res = commonspec.getCassandraClient().executeQuery(execQuery);
        List<Row> resAsList = res.all();
        assertThat(resAsList.size()).as("The query " + execQuery + " not return any result on Cassandra").isGreaterThan(0);
        assertThat(resAsList.get(0).toString()
                .substring(VALUE_SUBSTRING)).as("The resultSet is not as expected").isEqualTo(data.cells().get(index).toString().replace("'", ""));
        index++;
    }
}
 
Example #24
Source File: JdbcSteps.java    From yaks with Apache License 2.0 6 votes vote down vote up
@Then("^verify columns$")
public void verifyResultSet(DataTable expectedResults) {
    ExecuteSQLQueryAction.Builder action = query(dataSource)
                                                .statements(sqlQueryStatements);

    List<List<String>> rows = expectedResults.asLists(String.class);
    rows.forEach(row -> {
        if (!row.isEmpty()) {
            String columnName = row.remove(0);
            action.validate(columnName, row.toArray(new String[]{}));
        }
    });

    runner.run(action);
    sqlQueryStatements.clear();
}
 
Example #25
Source File: CommonGTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void modifyDataInvalidModificationTypeStringTest() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();
    String data = "username=username&password=password";
    String type = "string";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("username=username", "REMOVE", "N/A"));
    DataTable modifications = DataTable.create(rawData);

    try {
        commong.modifyData(data, type, modifications);
        fail("Expected Exception");
    } catch (Exception e) {
        assertThat(e.getClass().toString()).as("Unexpected exception").isEqualTo(Exception.class.toString());
        assertThat(e.getMessage()).as("Unexpected exception message").isEqualTo("Modification type does not exist: REMOVE");
    }
}
 
Example #26
Source File: CommonGTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void modifyDataInvalidModificationTypeJsonTest() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();
    String data = jsonObject1.toString();
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("username=username", "REMOVE", "N/A"));
    DataTable modifications = DataTable.create(rawData);

    try {
        commong.modifyData(data, type, modifications);
        fail("Expected Exception");
    } catch (Exception e) {
        assertThat(e.getClass().toString()).as("Unexpected exception").isEqualTo(Exception.class.toString());
        assertThat(e.getMessage()).as("Unexpected exception message").isEqualTo("Modification type does not exist: REMOVE");
    }
}
 
Example #27
Source File: CommonGTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void modifyDataAddToJsonStringTest_2() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("key1", new JSONArray(Arrays.asList("value1")));
    String data = jsonObject.toString();
    String expectedData = "{\"key1\":[\"value1\",\"\"]}";
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key1", "ADDTO", "", "string"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example #28
Source File: DatabaseSpec.java    From bdt with Apache License 2.0 5 votes vote down vote up
private List<String> giveQueriesList(DataTable data, String tableName, String colNames) {
    List<String> queryList = new ArrayList<String>();
    for (int i = 1; i < data.cells().size(); i++) {
        String query = "SELECT " + colNames + " FROM " + tableName;
        List<String> row = data.cells().get(i);
        query += conditionWhere(row, colNames.split(",")) + ";";
        queryList.add(query);
    }
    return queryList;
}
 
Example #29
Source File: CommonGTest.java    From bdt with Apache License 2.0 5 votes vote down vote up
@Test
public void modifyDataArrayAddToStringTest() throws Exception{
    String data = "[{\"businessAssets\":{\"id\":1},\"metadataPath\":\"\",\"description\":\"\",\"id\":-1,\"name\":\"\"}]";
    String expectedData = "[{\"businessAssets\":{\"id\":1},\"metadataPath\":\"\",\"description\":\"\",\"id\":-1,\"name\":\"\"},\"value\"]";
    CommonG commong = new CommonG();

    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("$", "ADDTO", "value", "string"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example #30
Source File: GosecSpec.java    From bdt with Apache License 2.0 5 votes vote down vote up
/**
 * Convert DataTable to modifiable list
 *
 * @param dataTable : DataTable data
 * @return
 */
private List<List<String>> convertDataTableToModifiableList(DataTable dataTable) {
    List<List<String>> lists = dataTable.asLists(String.class);
    List<List<String>> updateableLists = new ArrayList<>();
    for (int i = 0; i < lists.size(); i++) {
        List<String> list = lists.get(i);
        List<String> updateableList = new ArrayList<>();
        for (int j = 0; j < list.size(); j++) {
            updateableList.add(j, list.get(j));
        }
        updateableLists.add(i, updateableList);
    }
    return updateableLists;
}