Skip to content

Commit

Permalink
Migrate deprecated QueryAssert.assertThat method calls
Browse files Browse the repository at this point in the history
The method `io.trino.tempto.assertions.QueryAssert.assertThat(io.trino.tempto.query.QueryResult)`
has been marked as deprecated.
The usages of this method in the code base were replaced with
calls to `io.trino.tempto.assertions.QueryAssert.assertQueryFailure(io.trino.tempto.assertions.QueryAssert.QueryCallback)`
  • Loading branch information
findinpath authored and losipiuk committed Dec 3, 2021
1 parent 31ccf0d commit 73ba897
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.trino.tempto.fulfillment.table.hive.tpch.ImmutableTpchTablesRequirements.ImmutableNationTable;
import org.testng.annotations.Test;

import static io.trino.tempto.assertions.QueryAssert.assertQueryFailure;
import static io.trino.tempto.assertions.QueryAssert.assertThat;
import static io.trino.tempto.context.ContextDsl.executeWith;
import static io.trino.tempto.query.QueryExecutor.query;
Expand Down Expand Up @@ -72,8 +73,8 @@ public void createOrReplaceSimpleView()
public void createSimpleViewTwiceShouldFail()
{
executeWith(createViewAs("SELECT * FROM nation"), view -> {
assertThat(() -> query(format("CREATE VIEW %s AS SELECT * FROM nation", view.getName())))
.failsWithMessage("View already exists");
assertQueryFailure(() -> query(format("CREATE VIEW %s AS SELECT * FROM nation", view.getName())))
.hasMessageContaining("View already exists");
assertThat(query(format("SELECT * FROM %s", view.getName())))
.hasRowsCount(25);
});
Expand All @@ -87,8 +88,8 @@ public void dropViewTest()
.hasRowsCount(25);
assertThat(query(format("DROP VIEW %s", view.getName())))
.hasRowsCount(1);
assertThat(() -> query(format("SELECT * FROM %s", view.getName())))
.failsWithMessage("does not exist");
assertQueryFailure(() -> query(format("SELECT * FROM %s", view.getName())))
.hasMessageContaining("does not exist");
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static io.airlift.http.client.HttpUriBuilder.uriBuilderFrom;
import static io.airlift.http.client.Request.Builder.prepareDelete;
import static io.airlift.http.client.ResponseHandlerUtils.propagate;
import static io.trino.tempto.assertions.QueryAssert.assertQueryFailure;
import static io.trino.tempto.assertions.QueryAssert.assertThat;
import static io.trino.tempto.query.QueryExecutor.query;
import static io.trino.tests.product.TestGroups.CANCEL_QUERY;
Expand Down Expand Up @@ -89,8 +90,8 @@ public void cancelCreateTable()
String sql = format("CREATE TABLE %s AS SELECT * FROM tpch.sf1.lineitem", tableName);

runAndCancelQuery(sql);
assertThat(() -> query("SELECT * from " + tableName))
.failsWithMessage(format("Table 'hive.default.%s' does not exist", tableName));
assertQueryFailure(() -> query("SELECT * from " + tableName))
.hasMessageContaining("Table 'hive.default.%s' does not exist", tableName);
}

@Test(groups = CANCEL_QUERY, timeOut = 60_000L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ public void testInsertIntoTupleType()
onCasssandra(format("CREATE TABLE %s.%s (key int, value frozen<tuple<int, text, float>>, PRIMARY KEY (key))",
KEY_SPACE, tableName));

assertThat(() -> query(format("INSERT INTO %s.%s.%s (key, value) VALUES (1, ROW(1, 'text-1', 1.11))", CONNECTOR_NAME, KEY_SPACE, tableName)))
.failsWithMessage("Unsupported column type: row(integer, varchar, real)");
assertQueryFailure(() -> query(format("INSERT INTO %s.%s.%s (key, value) VALUES (1, ROW(1, 'text-1', 1.11))", CONNECTOR_NAME, KEY_SPACE, tableName)))
.hasMessageContaining("Unsupported column type: row(integer, varchar, real)");

onCasssandra(format("DROP TABLE IF EXISTS %s.%s", KEY_SPACE, tableName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import io.trino.tempto.configuration.Configuration;
import org.testng.annotations.Test;

import static io.trino.tempto.assertions.QueryAssert.assertThat;
import static io.trino.tempto.assertions.QueryAssert.assertQueryFailure;
import static io.trino.tempto.fulfillment.table.TableRequirements.immutableTable;
import static io.trino.tempto.query.QueryExecutor.query;
import static io.trino.tests.product.TestGroups.CASSANDRA;
Expand All @@ -43,23 +43,23 @@ public Requirement getRequirements(Configuration configuration)
public void testInvalidTable()
{
String tableName = format("%s.%s.%s", CONNECTOR_NAME, KEY_SPACE, "bogus");
assertThat(() -> query(format("SELECT * FROM %s", tableName)))
.failsWithMessage(format("Table '%s' does not exist", tableName));
assertQueryFailure(() -> query(format("SELECT * FROM %s", tableName)))
.hasMessageContaining(format("Table '%s' does not exist", tableName));
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
public void testInvalidSchema()
{
String tableName = format("%s.%s.%s", CONNECTOR_NAME, "does_not_exist", "bogus");
assertThat(() -> query(format("SELECT * FROM %s", tableName)))
.failsWithMessage("Schema 'does_not_exist' does not exist");
assertQueryFailure(() -> query(format("SELECT * FROM %s", tableName)))
.hasMessageContaining("Schema 'does_not_exist' does not exist");
}

@Test(groups = {CASSANDRA, PROFILE_SPECIFIC_TESTS})
public void testInvalidColumn()
{
String tableName = format("%s.%s.%s", CONNECTOR_NAME, KEY_SPACE, CASSANDRA_NATION.getName());
assertThat(() -> query(format("SELECT bogus FROM %s", tableName)))
.failsWithMessage("Column 'bogus' cannot be resolved");
assertQueryFailure(() -> query(format("SELECT bogus FROM %s", tableName)))
.hasMessageContaining("Column 'bogus' cannot be resolved");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import org.testng.annotations.Test;

import static io.trino.tempto.assertions.QueryAssert.assertThat;
import static io.trino.tempto.assertions.QueryAssert.assertQueryFailure;
import static io.trino.tests.product.utils.QueryExecutors.onHive;
import static io.trino.tests.product.utils.QueryExecutors.onTrino;

Expand All @@ -31,7 +31,7 @@ public void testReadDeltaLakeTable()
"CREATE TABLE test_delta_lake_table (ignored int) " +
"TBLPROPERTIES ('spark.sql.sources.provider'='DELTA')");

assertThat(() -> onTrino().executeQuery("SELECT * FROM test_delta_lake_table")).failsWithMessage("Cannot query Delta Lake table");
assertQueryFailure(() -> onTrino().executeQuery("SELECT * FROM test_delta_lake_table")).hasMessageContaining("Cannot query Delta Lake table");

onHive().executeQuery("DROP TABLE test_delta_lake_table");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.function.Consumer;

import static io.trino.tempto.assertions.QueryAssert.Row.row;
import static io.trino.tempto.assertions.QueryAssert.assertQueryFailure;
import static io.trino.tempto.assertions.QueryAssert.assertThat;
import static io.trino.tempto.query.QueryExecutor.query;
import static io.trino.tests.product.TestGroups.HIVE_VIEW_COMPATIBILITY;
Expand Down Expand Up @@ -69,8 +70,8 @@ public void testExistingView()
onCompatibilityTestServer().executeQuery("DROP VIEW IF EXISTS hive_duplicate_view");
onCompatibilityTestServer().executeQuery("CREATE VIEW hive_duplicate_view AS SELECT * FROM nation");

assertThat(() -> query("CREATE VIEW hive_duplicate_view AS SELECT * FROM nation"))
.failsWithMessage("View already exists");
assertQueryFailure(() -> query("CREATE VIEW hive_duplicate_view AS SELECT * FROM nation"))
.hasMessageContaining("View already exists");
}

protected static void assertViewQuery(QueryExecutor queryExecutor, String query, Consumer<QueryAssert> assertion)
Expand Down
Loading

0 comments on commit 73ba897

Please sign in to comment.