Skip to content

Commit

Permalink
wrangler e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
priyabhatnagar25 authored and AnkitCLI committed Dec 30, 2023
1 parent 5790e4b commit e4fad20
Show file tree
Hide file tree
Showing 19 changed files with 986 additions and 28 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<groupId>io.cdap.wrangler</groupId>
<artifactId>wrangler</artifactId>
<version>4.11.0-SNAPSHOT</version>
<version>4.10.0-SNAPSHOT</version>
<name>Wrangler</name>
<packaging>pom</packaging>
<description>An interactive tool for data cleansing and transformation.</description>
Expand Down Expand Up @@ -492,7 +492,7 @@
<execution>
<goals>
<goal>integration-test</goal>
<!-- <goal>verify</goal>-->
<goal>verify</goal>
</goals>
</execution>
</executions>
Expand Down Expand Up @@ -547,7 +547,7 @@
<dependency>
<groupId>io.cdap.tests.e2e</groupId>
<artifactId>cdap-e2e-framework</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>0.4.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion wrangler-transform/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>wrangler</artifactId>
<groupId>io.cdap.wrangler</groupId>
<version>4.11.0-SNAPSHOT</version>
<version>4.10.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# the License.

@Wrangler
Feature: Wrangler - Run time scenarios
Feature: Wrangler - Run time scenarios for parse csv

@BQ_SOURCE_CSV_TEST @BQ_SINK_TEST
Scenario: To verify User is able to run a pipeline using parse csv directive
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright © 2023 Cask Data, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

@Wrangler_Required
Feature: Parse as Excel

@GCS_SOURCE_TEST @BQ_SINK_TEST
Scenario: To verify User is able to run a pipeline using parse Excel directive
Given Open Datafusion Project to configure pipeline
Then Click on the Plus Green Button to import the pipelines
Then Select the file for importing the pipeline for the plugin "Directive_parse_excel"
Then Navigate to the properties page of plugin: "GCSFile"
Then Replace input plugin property: "project" with value: "projectId"
Then Replace input plugin property: "path" with value: "gcsSourceBucket"
Then Click on the Get Schema button
Then Click on the Validate button
Then Close the Plugin Properties page
Then Navigate to the properties page of plugin: "BigQuery"
Then Replace input plugin property: "project" with value: "projectId"
Then Replace input plugin property: "table" with value: "bqTargetTable"
Then Replace input plugin property: "dataset" with value: "dataset"
Then Click on the Validate button
Then Close the Plugin Properties page
Then Rename the pipeline
Then Deploy the pipeline
Then Run the Pipeline in Runtime
Then Wait till pipeline is in running state
Then Open and capture logs
Then Verify the pipeline status is "Succeeded"
Then Close the pipeline logs
Then Validate The Data From BQ To BQ With Actual And Expected File for: "ExpectedDirective_parse_excel"
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright © 2023 Cask Data, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

@Wrangler
Feature: parse as Json

@BQ_SOURCE_JSON_TEST @BQ_SINK_TEST
Scenario: To verify User is able to run a pipeline using parse Json directive
Given Open Datafusion Project to configure pipeline
Then Click on the Plus Green Button to import the pipelines
Then Select the file for importing the pipeline for the plugin "Directive_parse_json"
Then Navigate to the properties page of plugin: "BigQueryTable"
Then Replace input plugin property: "project" with value: "projectId"
Then Replace input plugin property: "dataset" with value: "dataset"
Then Replace input plugin property: "table" with value: "bqSourceTable"
Then Click on the Get Schema button
Then Click on the Validate button
Then Close the Plugin Properties page
Then Navigate to the properties page of plugin: "BigQuery2"
Then Replace input plugin property: "project" with value: "projectId"
Then Replace input plugin property: "table" with value: "bqTargetTable"
Then Replace input plugin property: "dataset" with value: "dataset"
Then Click on the Validate button
Then Close the Plugin Properties page
Then Rename the pipeline
Then Deploy the pipeline
Then Run the Pipeline in Runtime
Then Wait till pipeline is in running state
Then Open and capture logs
Then Verify the pipeline status is "Succeeded"
Then Close the pipeline logs
Then Validate The Data From BQ To BQ With Actual And Expected File for: "ExpectedDirective_parse_json"
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright © 2023 Cask Data, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

@Wrangler
Feature: parse as XmlToJson

@BQ_SOURCE_XML_TEST @BQ_SINK_TEST
Scenario: To verify User is able to run a pipeline using parse XmlToJson directive
Given Open Datafusion Project to configure pipeline
Then Click on the Plus Green Button to import the pipelines
Then Select the file for importing the pipeline for the plugin "Directive_parse_xml"
Then Navigate to the properties page of plugin: "BigQueryTable"
Then Replace input plugin property: "project" with value: "projectId"
Then Replace input plugin property: "dataset" with value: "dataset"
Then Replace input plugin property: "table" with value: "bqSourceTable"
Then Click on the Get Schema button
Then Click on the Validate button
Then Close the Plugin Properties page
Then Navigate to the properties page of plugin: "BigQuery2"
Then Replace input plugin property: "project" with value: "projectId"
Then Replace input plugin property: "table" with value: "bqTargetTable"
Then Replace input plugin property: "dataset" with value: "dataset"
Then Click on the Validate button
Then Close the Plugin Properties page
Then Rename the pipeline
Then Deploy the pipeline
Then Run the Pipeline in Runtime
Then Wait till pipeline is in running state
Then Open and capture logs
Then Verify the pipeline status is "Succeeded"
Then Close the pipeline logs
Then Validate The Data From BQ To BQ With Actual And Expected File for: "ExpectedDirective_parse_xml"
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
package io.cdap.plugin.common.stepsdesign;

import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.StorageException;
import io.cdap.e2e.utils.BigQueryClient;
import io.cdap.e2e.utils.PluginPropertyUtils;
import io.cdap.e2e.utils.StorageClient;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
import stepsdesign.BeforeActions;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand All @@ -37,11 +41,14 @@
*/
public class TestSetupHooks {

public static String gcsSourceBucketName = StringUtils.EMPTY;

@Before(order = 1, value = "@BQ_SOURCE_CSV_TEST")
public static void createTempSourceBQTable() throws IOException, InterruptedException {
createSourceBQTableWithQueries(PluginPropertyUtils.pluginProp("CreateBQTableQueryFileCsv"),
PluginPropertyUtils.pluginProp("InsertBQDataQueryFileCsv"));
PluginPropertyUtils.pluginProp("InsertBQDataQueryFileCsv"));
}

@Before(order = 1, value = "@BQ_SINK_TEST")
public static void setTempTargetBQTableName() {
String bqTargetTableName = "E2E_TARGET_" + UUID.randomUUID().toString().replaceAll("-", "_");
Expand All @@ -54,7 +61,8 @@ public static void deleteTempTargetBQTable() throws IOException, InterruptedExce
String bqTargetTableName = PluginPropertyUtils.pluginProp("bqTargetTable");
try {
BigQueryClient.dropBqQuery(bqTargetTableName);
BeforeActions.scenario.write("BQ Target table - " + bqTargetTableName + " deleted successfully");
BeforeActions.scenario.write(
"BQ Target table - " + bqTargetTableName + " deleted successfully");
PluginPropertyUtils.removePluginProp("bqTargetTable");
} catch (BigQueryException e) {
if (e.getMessage().contains("Not found: Table")) {
Expand All @@ -66,27 +74,30 @@ public static void deleteTempTargetBQTable() throws IOException, InterruptedExce
}

/**
* Create BigQuery table.
* Create BigQuery table test.
*/
@Before(order = 1, value = "@BQ_SOURCE_FXDLEN_TEST")
public static void createTempSourceBQTableFxdLen() throws IOException, InterruptedException {
createSourceBQTableWithQueries(PluginPropertyUtils.pluginProp("CreateBQDataQueryFileFxdLen"),
PluginPropertyUtils.pluginProp("InsertBQDataQueryFileFxdLen"));
PluginPropertyUtils.pluginProp("InsertBQDataQueryFileFxdLen"));
}

@Before(order = 1, value = "@BQ_SOURCE_HL7_TEST")
public static void createTempSourceBQTableHl7() throws IOException, InterruptedException {
createSourceBQTableWithQueries(PluginPropertyUtils.pluginProp("CreateBQDataQueryFileHl7"),
PluginPropertyUtils.pluginProp("InsertBQDataQueryFileHl7"));
PluginPropertyUtils.pluginProp("InsertBQDataQueryFileHl7"));
}

@Before(order = 1, value = "@BQ_SOURCE_TS_TEST")
public static void createTempSourceBQTableTimestamp() throws IOException, InterruptedException {
createSourceBQTableWithQueries(PluginPropertyUtils.pluginProp("CreateBQDataQueryFileTimestamp"),
PluginPropertyUtils.pluginProp("InsertBQDataQueryFileTimestamp"));
PluginPropertyUtils.pluginProp("InsertBQDataQueryFileTimestamp"));
}

@Before(order = 1, value = "@BQ_SOURCE_DATETIME_TEST")
public static void createTempSourceBQTableDateTime() throws IOException, InterruptedException {
createSourceBQTableWithQueries(PluginPropertyUtils.pluginProp("CreateBQDataQueryFileDatetime"),
PluginPropertyUtils.pluginProp("InsertBQDataQueryFileDatetime"));
PluginPropertyUtils.pluginProp("InsertBQDataQueryFileDatetime"));
}

@After(order = 1, value = "@BQ_SOURCE_TEST")
Expand All @@ -97,35 +108,91 @@ public static void deleteTempSourceBQTable() throws IOException, InterruptedExce
PluginPropertyUtils.removePluginProp("bqSourceTable");
}

private static void createSourceBQTableWithQueries(String bqCreateTableQueryFile, String bqInsertDataQueryFile)
throws IOException, InterruptedException {
String bqSourceTable = "E2E_SOURCE_" + UUID.randomUUID().toString().substring(0, 5).replaceAll("-",
"_");
@Before(order = 1, value = "@BQ_SOURCE_JSON_TEST")
public static void createTempSourceBQTableJson() throws IOException, InterruptedException {
createSourceBQTableWithQueries(PluginPropertyUtils.pluginProp("CreateBQTableQueryFileJson"),
PluginPropertyUtils.pluginProp("InsertBQDataQueryFileJson"));
}

@Before(order = 1, value = "@BQ_SOURCE_XML_TEST")
public static void createTempSourceBQTableXml() throws IOException, InterruptedException {
createSourceBQTableWithQueries(PluginPropertyUtils.pluginProp("CreateBQDataQueryFileXml"),
PluginPropertyUtils.pluginProp("InsertBQDataQueryFileXml"));
}

@Before(order = 1, value = "@GCS_SOURCE_TEST")
public static void createBucketWithEXCELFile() throws IOException, URISyntaxException {
gcsSourceBucketName = createGCSBucketWithFile(PluginPropertyUtils.pluginProp("testFile"));
PluginPropertyUtils.addPluginProp("gcsSourceBucket", "gs://" + gcsSourceBucketName + "/" +
PluginPropertyUtils.pluginProp("testFile"));
BeforeActions.scenario.write("GCS source bucket1 name - " + gcsSourceBucketName);
}

private static String createGCSBucketWithFile(String filePath)
throws IOException, URISyntaxException {
String bucketName = StorageClient.createBucket("e2e-test-" + UUID.randomUUID()).getName();
StorageClient.uploadObject(bucketName, filePath, filePath);
return bucketName;
}

@After(order = 1, value = "@GCS_SOURCE_TEST")
public static void deleteSourceBucketWithFile() {
deleteGCSBucket(gcsSourceBucketName);
gcsSourceBucketName = StringUtils.EMPTY;
}

private static void deleteGCSBucket(String bucketName) {
try {
for (Blob blob : StorageClient.listObjects(bucketName).iterateAll()) {
StorageClient.deleteObject(bucketName, blob.getName());
}
StorageClient.deleteBucket(bucketName);
BeforeActions.scenario.write("Deleted GCS Bucket " + bucketName);
} catch (StorageException | IOException e) {
if (e.getMessage().contains("The specified bucket does not exist")) {
BeforeActions.scenario.write("GCS Bucket " + bucketName + " does not exist.");
} else {
Assert.fail(e.getMessage());
}
}
}


private static void createSourceBQTableWithQueries(String bqCreateTableQueryFile,
String bqInsertDataQueryFile)
throws IOException, InterruptedException {
String bqSourceTable =
"E2E_SOURCE_" + UUID.randomUUID().toString().substring(0, 5).replaceAll("-",
"_");

String createTableQuery = StringUtils.EMPTY;
try {
createTableQuery = new String(Files.readAllBytes(Paths.get(TestSetupHooks.class.getResource
("/" + bqCreateTableQueryFile).toURI()))
, StandardCharsets.UTF_8);
createTableQuery = createTableQuery.replace("DATASET", PluginPropertyUtils.pluginProp("dataset"))
.replace("TABLE_NAME", bqSourceTable);
("/" + bqCreateTableQueryFile).toURI()))
, StandardCharsets.UTF_8);
createTableQuery = createTableQuery.replace("DATASET",
PluginPropertyUtils.pluginProp("dataset"))
.replace("TABLE_NAME", bqSourceTable);
} catch (Exception e) {
BeforeActions.scenario.write("Exception in reading " + bqCreateTableQueryFile + " - " + e.getMessage());
BeforeActions.scenario.write(
"Exception in reading " + bqCreateTableQueryFile + " - " + e.getMessage());
Assert.fail("Exception in BigQuery testdata prerequisite setup " +
"- error in reading create table query file " + e.getMessage());
"- error in reading create table query file " + e.getMessage());
}

String insertDataQuery = StringUtils.EMPTY;
try {
insertDataQuery = new String(Files.readAllBytes(Paths.get(TestSetupHooks.class.getResource
("/" + bqInsertDataQueryFile).toURI()))
, StandardCharsets.UTF_8);
insertDataQuery = insertDataQuery.replace("DATASET", PluginPropertyUtils.pluginProp("dataset"))
.replace("TABLE_NAME", bqSourceTable);
("/" + bqInsertDataQueryFile).toURI()))
, StandardCharsets.UTF_8);
insertDataQuery = insertDataQuery.replace("DATASET",
PluginPropertyUtils.pluginProp("dataset"))
.replace("TABLE_NAME", bqSourceTable);
} catch (Exception e) {
BeforeActions.scenario.write("Exception in reading " + bqInsertDataQueryFile + " - " + e.getMessage());
BeforeActions.scenario.write(
"Exception in reading " + bqInsertDataQueryFile + " - " + e.getMessage());
Assert.fail("Exception in BigQuery testdata prerequisite setup " +
"- error in reading insert data query file " + e.getMessage());
"- error in reading insert data query file " + e.getMessage());
}
BigQueryClient.getSoleQueryResult(createTableQuery);
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"copiedname":"very","id":0,"name":"very","phone":"8838.0","rollno":"3.0","uniquenum":"very,0"}
{"copiedname":"hello","id":2,"name":"hell","phone":"12345.0","rollno":"1.0","uniquenum":"hello,2"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"Body":"hello abc","copied":{"first":"Root","last":"joy"},"desc":"nick, hello abc","id":22,"json_age":"{\"json_id\":22,\"copied\":{\"first\":\"Root\",\"last\":\"joy\"},\"json_age\":1,\"json_name\":{\"first\":\"Root\",\"last\":\"joy\"},\"json_pet\":\"testing\",\"json_id_json_name\":\"22,{\\\"first\\\":\\\"Root\\\",\\\"last\\\":\\\"joy\\\"}\",\"body\":\"hello abc\",\"desc\":\"nick, hello abc\"}","json_id_json_name":"22,{\"first\":\"Root\",\"last\":\"joy\"}","json_name":{"first":"Root","last":"joy"},"json_pet":"testing"}
{"Body":"hello def","copied":{"first":"dded","last":"share"},"desc":"hello, hello def","id":23,"json_age":"{\"json_id\":23,\"copied\":{\"first\":\"dded\",\"last\":\"share\"},\"json_age\":2,\"json_name\":{\"first\":\"dded\",\"last\":\"share\"},\"json_pet\":\"testing\",\"json_id_json_name\":\"23,{\\\"first\\\":\\\"dded\\\",\\\"last\\\":\\\"share\\\"}\",\"body\":\"hello def\",\"desc\":\"hello, hello def\"}","json_id_json_name":"23,{\"first\":\"dded\",\"last\":\"share\"}","json_name":{"first":"dded","last":"share"},"json_pet":"testing"}
{"Body":"hello ghi","copied":{"first":"Root","last":"Joltie"},"desc":"doms, hello ghi","id":24,"json_age":"{\"json_id\":24,\"copied\":{\"first\":\"Root\",\"last\":\"Joltie\"},\"json_age\":3,\"json_name\":{\"first\":\"Root\",\"last\":\"Joltie\"},\"json_pet\":\"testing\",\"json_id_json_name\":\"24,{\\\"first\\\":\\\"Root\\\",\\\"last\\\":\\\"Joltie\\\"}\",\"body\":\"hello ghi\",\"desc\":\"doms, hello ghi\"}","json_id_json_name":"24,{\"first\":\"Root\",\"last\":\"Joltie\"}","json_name":{"first":"Root","last":"Joltie"},"json_pet":"testing"}
Loading

0 comments on commit e4fad20

Please sign in to comment.