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

Migrate tests to JUnit #19766

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions plugin/trino-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -237,33 +237,5 @@
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
<!-- allow both JUnit and TestNG -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit-platform</artifactId>
<version>${dep.plugin.surefire.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>${dep.plugin.surefire.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assumptions.abort;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;

@TestInstance(PER_CLASS)
public class TestMongoConnectorTest
Expand Down Expand Up @@ -213,20 +210,30 @@ public void createTableWithEveryType()
assertUpdate(query, 1);

MaterializedResult results = getQueryRunner().execute(getSession(), "SELECT * FROM " + tableName).toTestTypes();
assertEquals(results.getRowCount(), 1);
assertThat(results.getRowCount())
.isEqualTo(1);
MaterializedRow row = results.getMaterializedRows().get(0);
assertEquals(row.getField(0), "foo");
assertEquals(row.getField(1), "bar".getBytes(UTF_8));
assertEquals(row.getField(2), 1L);
assertEquals(row.getField(3), 3.14);
assertEquals(row.getField(4), true);
assertEquals(row.getField(5), LocalDate.of(1980, 5, 7));
assertEquals(row.getField(6), LocalDateTime.of(1980, 5, 7, 11, 22, 33, 456_000_000));
assertEquals(row.getField(8), "{\"name\":\"alice\"}");
assertEquals(row.getField(9), new BigDecimal("12.30000"));
assertThat(row.getField(0))
.isEqualTo("foo");
assertThat(row.getField(1))
.isEqualTo("bar".getBytes(UTF_8));
assertThat(row.getField(2))
.isEqualTo(1L);
assertThat(row.getField(3))
.isEqualTo(3.14);
assertThat(row.getField(4))
.isEqualTo(true);
assertThat(row.getField(5))
.isEqualTo(LocalDate.of(1980, 5, 7));
assertThat(row.getField(6))
.isEqualTo(LocalDateTime.of(1980, 5, 7, 11, 22, 33, 456_000_000));
assertThat(row.getField(8))
.isEqualTo("{\"name\":\"alice\"}");
assertThat(row.getField(9))
.isEqualTo(new BigDecimal("12.30000"));
assertUpdate("DROP TABLE " + tableName);

assertFalse(getQueryRunner().tableExists(getSession(), tableName));
assertThat(getQueryRunner().tableExists(getSession(), tableName)).isFalse();
}

@Test
Expand Down Expand Up @@ -263,18 +270,27 @@ public void testInsertWithEveryType()
getQueryRunner().execute(getSession(), insertSql);

MaterializedResult results = getQueryRunner().execute(getSession(), "SELECT * FROM " + tableName).toTestTypes();
assertEquals(results.getRowCount(), 1);
assertThat(results.getRowCount())
.isEqualTo(1);
MaterializedRow row = results.getMaterializedRows().get(0);
assertEquals(row.getField(0), "foo");
assertEquals(row.getField(1), "bar".getBytes(UTF_8));
assertEquals(row.getField(2), 1L);
assertEquals(row.getField(3), 3.14);
assertEquals(row.getField(4), true);
assertEquals(row.getField(5), LocalDate.of(1980, 5, 7));
assertEquals(row.getField(6), LocalDateTime.of(1980, 5, 7, 11, 22, 33, 456_000_000));
assertEquals(row.getField(8), "{\"name\":\"alice\"}");
assertThat(row.getField(0))
.isEqualTo("foo");
assertThat(row.getField(1))
.isEqualTo("bar".getBytes(UTF_8));
assertThat(row.getField(2))
.isEqualTo(1L);
assertThat(row.getField(3))
.isEqualTo(3.14);
assertThat(row.getField(4))
.isEqualTo(true);
assertThat(row.getField(5))
.isEqualTo(LocalDate.of(1980, 5, 7));
assertThat(row.getField(6))
.isEqualTo(LocalDateTime.of(1980, 5, 7, 11, 22, 33, 456_000_000));
assertThat(row.getField(8))
.isEqualTo("{\"name\":\"alice\"}");
assertUpdate("DROP TABLE " + tableName);
assertFalse(getQueryRunner().tableExists(getSession(), tableName));
assertThat(getQueryRunner().tableExists(getSession(), tableName)).isFalse();
}

@Test
Expand Down Expand Up @@ -1356,13 +1372,17 @@ private void testFiltersOnDereferenceColumnReadsLessData(String expectedValue, S
sessionWithoutPushdown,
format("SELECT 1 FROM %s WHERE col_0.col_1 = %s", table.getName(), expectedValue),
statsWithoutPushdown -> {
assertEquals(statsWithoutPushdown.getProcessedInputPositions(), 3);
assertEquals(processedInputPositionWithPushdown, 2);
assertThat(statsWithoutPushdown.getProcessedInputPositions())
.isEqualTo(3);
assertThat(processedInputPositionWithPushdown)
.isEqualTo(2);
assertThat(statsWithoutPushdown.getProcessedInputPositions()).isGreaterThan(processedInputPositionWithPushdown);
},
results -> assertEquals(results.getOnlyColumnAsSet(), expected));
results -> assertThat(results.getOnlyColumnAsSet())
.isEqualTo(expected));
},
results -> assertEquals(results.getOnlyColumnAsSet(), expected));
results -> assertThat(results.getOnlyColumnAsSet())
.isEqualTo(expected));

assertQueryStats(
getSession(),
Expand All @@ -1373,13 +1393,17 @@ private void testFiltersOnDereferenceColumnReadsLessData(String expectedValue, S
sessionWithoutPushdown,
format("SELECT 1 FROM %s WHERE col_0.col_2.col_3 = %s", table.getName(), expectedValue),
statsWithoutPushdown -> {
assertEquals(statsWithoutPushdown.getProcessedInputPositions(), 3);
assertEquals(processedInputPositionWithPushdown, 1);
assertThat(statsWithoutPushdown.getProcessedInputPositions())
.isEqualTo(3);
assertThat(processedInputPositionWithPushdown)
.isEqualTo(1);
assertThat(statsWithoutPushdown.getProcessedInputPositions()).isGreaterThan(processedInputPositionWithPushdown);
},
results -> assertEquals(results.getOnlyColumnAsSet(), expected));
results -> assertThat(results.getOnlyColumnAsSet())
.isEqualTo(expected));
},
results -> assertEquals(results.getOnlyColumnAsSet(), expected));
results -> assertThat(results.getOnlyColumnAsSet())
.isEqualTo(expected));

assertQueryStats(
getSession(),
Expand All @@ -1390,13 +1414,17 @@ private void testFiltersOnDereferenceColumnReadsLessData(String expectedValue, S
sessionWithoutPushdown,
format("SELECT 1 FROM %s WHERE col_0.col_2.col_4.col_5 = %s", table.getName(), expectedValue),
statsWithoutPushdown -> {
assertEquals(statsWithoutPushdown.getProcessedInputPositions(), 3);
assertEquals(processedInputPositionWithPushdown, 2);
assertThat(statsWithoutPushdown.getProcessedInputPositions())
.isEqualTo(3);
assertThat(processedInputPositionWithPushdown)
.isEqualTo(2);
assertThat(statsWithoutPushdown.getProcessedInputPositions()).isGreaterThan(processedInputPositionWithPushdown);
},
results -> assertEquals(results.getOnlyColumnAsSet(), expected));
results -> assertThat(results.getOnlyColumnAsSet())
.isEqualTo(expected));
},
results -> assertEquals(results.getOnlyColumnAsSet(), expected));
results -> assertThat(results.getOnlyColumnAsSet())
.isEqualTo(expected));
}
}

Expand All @@ -1413,8 +1441,10 @@ public void testFiltersOnDereferenceColumnReadsLessDataNativeQuery()
assertQueryStats(
getSession(),
"SELECT row_field.first.second FROM TABLE(mongodb.system.query(database => 'test', collection => '" + tableName + "', filter => '{ \"row_field.first.second\": 1 }'))",
stats -> assertEquals(stats.getProcessedInputPositions(), 1L),
results -> assertEquals(results.getOnlyColumnAsSet(), ImmutableSet.of(1L)));
stats -> assertThat(stats.getProcessedInputPositions())
.isEqualTo(1L),
results -> assertThat(results.getOnlyColumnAsSet())
.isEqualTo(ImmutableSet.of(1L)));

assertUpdate("DROP TABLE test." + tableName);
}
Expand Down Expand Up @@ -1847,8 +1877,10 @@ protected Optional<SetColumnTypeSetup> filterSetColumnTypesDataProvider(SetColum
private void assertOneNotNullResult(String query)
{
MaterializedResult results = getQueryRunner().execute(getSession(), query).toTestTypes();
assertEquals(results.getRowCount(), 1);
assertEquals(results.getMaterializedRows().get(0).getFieldCount(), 1);
assertNotNull(results.getMaterializedRows().get(0).getField(0));
assertThat(results.getRowCount())
.isEqualTo(1);
assertThat(results.getMaterializedRows().get(0).getFieldCount())
.isEqualTo(1);
assertThat(results.getMaterializedRows().get(0).getField(0)).isNotNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import static com.google.common.collect.Iterables.getOnlyElement;
import static io.trino.plugin.mongodb.ObjectIdType.OBJECT_ID;
import static org.testng.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

public class TestMongoPlugin
{
Expand All @@ -40,7 +40,7 @@ public void testCreateConnector()
new TestingConnectorContext());

Type type = getOnlyElement(plugin.getTypes());
assertEquals(type, OBJECT_ID);
assertThat(type).isEqualTo(OBJECT_ID);

connector.shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import io.trino.testing.DistributedQueryRunner;
import io.trino.testing.QueryRunner;
import org.bson.Document;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Optional;
Expand All @@ -34,7 +33,6 @@
import static io.trino.plugin.mongodb.AuthenticatedMongoServer.privilege;
import static io.trino.plugin.mongodb.AuthenticatedMongoServer.resource;
import static io.trino.plugin.mongodb.AuthenticatedMongoServer.role;
import static io.trino.testing.DataProviders.toDataProvider;
import static io.trino.testing.TestingSession.testSessionBuilder;
import static java.util.Locale.ENGLISH;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -71,22 +69,28 @@ protected QueryRunner createQueryRunner()
}
}

@Test(dataProvider = "databases")
public void testSchemasVisibility(String database)
@Test
public void testSchemasVisibility()
{
assertQuery("SHOW SCHEMAS FROM " + getCatalogName(database), "VALUES 'information_schema','%s'".formatted(database.toLowerCase(ENGLISH)));
for (String database : DATABASES) {
assertQuery("SHOW SCHEMAS FROM " + getCatalogName(database), "VALUES 'information_schema','%s'".formatted(database.toLowerCase(ENGLISH)));
}
}

@Test(dataProvider = "databases")
public void testTablesVisibility(String database)
@Test
public void testTablesVisibility()
{
assertQuery("SHOW TABLES FROM %s.%s".formatted(getCatalogName(database), database), "VALUES '%s'".formatted(TEST_COLLECTION.toLowerCase(ENGLISH)));
for (String database : DATABASES) {
assertQuery("SHOW TABLES FROM %s.%s".formatted(getCatalogName(database), database), "VALUES '%s'".formatted(TEST_COLLECTION.toLowerCase(ENGLISH)));
}
}

@Test(dataProvider = "databases")
public void testSelectFromTable(String database)
@Test
public void testSelectFromTable()
{
assertQuery("SELECT * from %s.%s.%s".formatted(getCatalogName(database), database, TEST_COLLECTION), "VALUES ('abc', 1)");
for (String database : DATABASES) {
assertQuery("SELECT * from %s.%s.%s".formatted(getCatalogName(database), database, TEST_COLLECTION), "VALUES ('abc', 1)");
}
}

private static AuthenticatedMongoServer setupMongoServer()
Expand Down Expand Up @@ -157,10 +161,4 @@ private static String getPassword(String database)
{
return database + "pass";
}

@DataProvider
public static Object[][] databases()
{
return DATABASES.stream().collect(toDataProvider());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import static io.trino.spi.type.VarcharType.createUnboundedVarcharType;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.assertEquals;

public class TestMongoSession
{
Expand All @@ -61,7 +60,8 @@ public void testBuildProjectionWithoutId()
.append(COL1.getBaseName(), 1)
.append(COL2.getBaseName(), 1)
.append(ID_COL.getBaseName(), 0);
assertEquals(output, expected);
assertThat(output)
.isEqualTo(expected);
}

@Test
Expand All @@ -74,7 +74,8 @@ public void testBuildProjectionWithId()
.append(COL1.getBaseName(), 1)
.append(COL2.getBaseName(), 1)
.append(ID_COL.getBaseName(), 1);
assertEquals(output, expected);
assertThat(output)
.isEqualTo(expected);
}

@Test
Expand All @@ -89,7 +90,8 @@ public void testBuildQuery()
.append("$and", ImmutableList.of(
new Document(COL1.getBaseName(), new Document().append("$gt", 100L).append("$lte", 200L)),
new Document(COL2.getBaseName(), new Document("$eq", "a value"))));
assertEquals(query, expected);
assertThat(query)
.isEqualTo(expected);
}

@Test
Expand All @@ -104,7 +106,8 @@ public void testBuildQueryStringType()
.append("$and", ImmutableList.of(
new Document(COL3.getBaseName(), new Document().append("$gt", "hello").append("$lte", "world")),
new Document(COL2.getBaseName(), new Document("$gte", "a value"))));
assertEquals(query, expected);
assertThat(query)
.isEqualTo(expected);
}

@Test
Expand All @@ -115,7 +118,8 @@ public void testBuildQueryIn()

Document query = MongoSession.buildQuery(tupleDomain);
Document expected = new Document(COL2.getBaseName(), new Document("$in", ImmutableList.of("hello", "world")));
assertEquals(query, expected);
assertThat(query)
.isEqualTo(expected);
}

@Test
Expand All @@ -128,7 +132,8 @@ public void testBuildQueryOr()
Document expected = new Document("$or", asList(
new Document(COL1.getBaseName(), new Document("$lt", 100L)),
new Document(COL1.getBaseName(), new Document("$gt", 200L))));
assertEquals(query, expected);
assertThat(query)
.isEqualTo(expected);
}

@Test
Expand All @@ -141,7 +146,8 @@ public void testBuildQueryNull()
Document expected = new Document("$or", asList(
new Document(COL1.getBaseName(), new Document("$gt", 200L)),
new Document(COL1.getBaseName(), new Document("$eq", null))));
assertEquals(query, expected);
assertThat(query)
.isEqualTo(expected);
}

@Test
Expand All @@ -151,7 +157,8 @@ public void testBooleanPredicatePushdown()

Document query = MongoSession.buildQuery(tupleDomain);
Document expected = new Document().append(COL4.getBaseName(), new Document("$eq", true));
assertEquals(query, expected);
assertThat(query)
.isEqualTo(expected);
}

@Test
Expand All @@ -168,7 +175,8 @@ public void testBuildQueryNestedField()
new Document(COL5.getQualifiedName(), new Document("$gt", 200L)),
new Document(COL5.getQualifiedName(), new Document("$eq", null)))),
new Document(COL6.getQualifiedName(), new Document("$eq", "a value"))));
assertEquals(query, expected);
assertThat(query)
.isEqualTo(expected);
}

@Test
Expand Down
Loading
Loading