Java Code Examples for io.cucumber.datatable.DataTable#create()

The following examples show how to use io.cucumber.datatable.DataTable#create() . 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: 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 2
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 3
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 4
Source File: MiscTest.java    From bdt with Apache License 2.0 6 votes vote down vote up
@Test
public void testKeysContainsInJSON() throws Exception {
    String baseData = "exampleJSON.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("$.glossary.~[0]", "contains", "title");
    List<String> row2 = Arrays.asList("$.glossary.GlossDiv.~", "contains", "GlossList");

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

    DataTable table = DataTable.create(rawData);

    misc.matchWithExpresion(envVar, table);

}
 
Example 5
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 6
Source File: CommonGTest.java    From bdt with Apache License 2.0 5 votes vote down vote up
@Test
public void modifyDataReplaceJsonNumberTest_3() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();
    String data = jsonObject1.toString();
    String expectedData = jsonObject16.toString();
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key2.key3", "REPLACE", "0", "number"));
    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 5 votes vote down vote up
@Test
public void modifyDataReplaceJsonObjectTest_1() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();
    String data = jsonObject1.toString();
    String expectedData = jsonObject19.toString();
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key2.key3", "REPLACE", "{\"a\":\"1\", \"b\":\"1\", \"c\":\"1\"}", "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 5 votes vote down vote up
@Test
public void modifyDataArrayReplaceBooleanTest() throws Exception{
    String data = "[{\"businessAssets\":{\"id\":1},\"metadataPath\":\"\",\"description\":\"\",\"id\":-1,\"name\":\"\"}]";
    String expectedData = "[{\"businessAssets\":{\"id\":1},\"metadataPath\":\"\",\"description\":\"\",\"id\":-1,\"name\":true}]";
    CommonG commong = new CommonG();

    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("$.[0].name", "REPLACE", "true", "boolean"));
    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 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 10
Source File: CommonGTest.java    From bdt with Apache License 2.0 5 votes vote down vote up
@Test
public void modifyDataReplaceJsonArrayTest_2() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();
    String data = jsonObject2.toString();
    String expectedData = jsonObject3.toString();
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("type", "REPLACE", "[\"a\", \"b\", \"c\"]", "array"));
    DataTable modifications = DataTable.create(rawData);
    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example 11
Source File: CommonGTest.java    From bdt with Apache License 2.0 5 votes vote down vote up
@Test
public void modifyDataReplaceJsonArrayTest_1() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();
    String data = jsonObject2.toString();
    String expectedData = "{\"type\":[]}";
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("type", "REPLACE", "[]", "array"));
    DataTable modifications = DataTable.create(rawData);
    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example 12
Source File: CommonGTest.java    From bdt with Apache License 2.0 5 votes vote down vote up
@Test
public void modifyDataReplaceJsonBooleanTest_1() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();
    String data = jsonObject1.toString();
    String expectedData = jsonObject11.toString();
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key2.key3", "REPLACE", "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 5 votes vote down vote up
@Test
public void modifyDataAppendJsonTest() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();
    String data = jsonObject1.toString();
    String expectedData = jsonObject8.toString();
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key2.key3", "APPEND", "Append"));
    DataTable modifications = DataTable.create(rawData);

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

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

    try {
        commong.resultsMustBeCSV(csvList);
        org.testng.Assert.fail("Expected Exception");
    } catch (Exception e) {
        assertThat(e.getMessage()).as("CSV Results not setted").isEqualTo("You must execute a query before trying to get results");
    }
}
 
Example 15
Source File: CommonGTest.java    From bdt with Apache License 2.0 5 votes vote down vote up
@Test
public void modifyDataArrayDeleteTest() throws Exception{
    String data = "[{\"businessAssets\":{\"id\":1},\"metadataPath\":\"\",\"description\":\"\",\"id\":-1,\"name\":\"\"},{\"businessAssets\":{\"id\":1},\"metadataPath\":\"\",\"description\":\"\",\"id\":-1,\"name\":\"\"}]";
    String expectedData = "[{\"businessAssets\":{\"id\":1},\"metadataPath\":\"\",\"description\":\"\",\"id\":-1,\"name\":\"\"}]";
    CommonG commong = new CommonG();

    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("$.[1]", "DELETE", "N/A", "N/A"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example 16
Source File: CommonGTest.java    From bdt with Apache License 2.0 5 votes vote down vote up
@Test
public void modifyDataArrayAddNumberTest() throws Exception{
    String data = "[{\"businessAssets\":{\"id\":1},\"metadataPath\":\"\",\"description\":\"\",\"id\":-1,\"name\":\"\"}]";
    String expectedData = "[{\"businessAssets\":{\"id\":1},\"metadataPath\":\"\",\"description\":\"\",\"id\":-1,\"name\":\"\",\"key\":1}]";
    CommonG commong = new CommonG();

    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("$.[0].key", "ADD", "1", "number"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example 17
Source File: CommonGTest.java    From bdt with Apache License 2.0 5 votes vote down vote up
@Test
public void modifyDataArrayAppendTest() throws Exception{
    String data = "[{\"businessAssets\":{\"id\":1},\"metadataPath\":\"\",\"description\":\"description\",\"id\":-1,\"name\":\"name\"}]";
    String expectedData = "[{\"businessAssets\":{\"id\":1},\"metadataPath\":\"\",\"description\":\"description\",\"id\":-1,\"name\":\"nameappended\"}]";
    CommonG commong = new CommonG();

    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("$.[0].name", "APPEND", "appended"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example 18
Source File: CommonGTest.java    From bdt with Apache License 2.0 5 votes vote down vote up
@Test
public void modifyDataDeleteStringTest() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();
    String data = "username=username&password=password";
    String expectedData = "password=password";
    String type = "string";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("username=username&", "DELETE", "N/A"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    assertThat(modifiedData).as("Unexpected modified data").isEqualTo(expectedData);
}
 
Example 19
Source File: CommonGTest.java    From bdt with Apache License 2.0 5 votes vote down vote up
@Test
public void modifyDataArrayAddStringTest() throws Exception{
    String data = "[{\"businessAssets\":{\"id\":1},\"metadataPath\":\"\",\"description\":\"\",\"id\":-1,\"name\":\"\"}]";
    String expectedData = "[{\"businessAssets\":{\"id\":1},\"metadataPath\":\"\",\"description\":\"\",\"id\":-1,\"name\":\"\",\"key\":\"value\"}]";
    CommonG commong = new CommonG();

    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("$.[0].key", "ADD", "value", "string"));
    DataTable modifications = DataTable.create(rawData);

    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}
 
Example 20
Source File: CommonGTest.java    From bdt with Apache License 2.0 5 votes vote down vote up
@Test
public void modifyDataReplaceJsonNumberTest_2() throws Exception {
    ThreadProperty.set("class", this.getClass().getCanonicalName());
    CommonG commong = new CommonG();
    String data = jsonObject1.toString();
    String expectedData = jsonObject15.toString();
    String type = "json";
    List<List<String>> rawData = Arrays.asList(Arrays.asList("key2.key3", "REPLACE", "5.0", "number"));
    DataTable modifications = DataTable.create(rawData);
    String modifiedData = commong.modifyData(data, type, modifications);
    JSONAssert.assertEquals(expectedData, modifiedData, false);
}