Skip to content

Commit e50f533

Browse files
XuQianJin-Starsvlsi
authored andcommitted
[CALCITE-3625] Update mongo tests upgrade from junit4 to junit5 (Qianjin Xu)
closes apache#1685
1 parent 5f10de3 commit e50f533

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

mongodb/gradle.properties

-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,3 @@
1616
#
1717
description=MongoDB adapter for Calcite
1818
artifact.name=Calcite MongoDB
19-
# JUnit4 use is allowed until the rest of the tests are migrated to JUnit5
20-
junit4=true

mongodb/src/test/java/org/apache/calcite/adapter/mongodb/MongoAdapterTest.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
import org.bson.BsonString;
3939
import org.bson.Document;
4040
import org.bson.json.JsonWriterSettings;
41-
import org.junit.BeforeClass;
42-
import org.junit.ClassRule;
43-
import org.junit.Ignore;
44-
import org.junit.Test;
41+
import org.junit.jupiter.api.BeforeAll;
42+
import org.junit.jupiter.api.Disabled;
43+
import org.junit.jupiter.api.Test;
44+
import org.junit.jupiter.api.extension.RegisterExtension;
4545

4646
import java.io.IOException;
4747
import java.io.UncheckedIOException;
@@ -81,12 +81,12 @@ public class MongoAdapterTest implements SchemaFactory {
8181
/** Number of records in local file */
8282
protected static final int ZIPS_SIZE = 149;
8383

84-
@ClassRule
84+
@RegisterExtension
8585
public static final MongoDatabasePolicy POLICY = MongoDatabasePolicy.create();
8686

8787
private static MongoSchema schema;
8888

89-
@BeforeClass
89+
@BeforeAll
9090
public static void setUp() throws Exception {
9191
MongoDatabase database = POLICY.database();
9292

@@ -207,7 +207,7 @@ private CalciteAssert.AssertThat assertModel(URL url) {
207207
"{$project: {STATE: '$state', ID: '$_id'}}"));
208208
}
209209

210-
@Ignore
210+
@Disabled
211211
@Test public void testFilterSort() {
212212
// LONGITUDE and LATITUDE are null because of CALCITE-194.
213213
Util.discard(Bug.CALCITE_194_FIXED);
@@ -253,7 +253,7 @@ private CalciteAssert.AssertThat assertModel(URL url) {
253253
"CITY=LAWTON; LONGITUDE=null; LATITUDE=null; POP=45542; STATE=OK; ID=73505");
254254
}
255255

256-
@Ignore("broken; [CALCITE-2115] is logged to fix it")
256+
@Disabled("broken; [CALCITE-2115] is logged to fix it")
257257
@Test public void testUnionPlan() {
258258
assertModel(MODEL)
259259
.query("select * from \"sales_fact_1997\"\n"
@@ -272,7 +272,7 @@ private CalciteAssert.AssertThat assertModel(URL url) {
272272
"product_id=337", "product_id=1512"));
273273
}
274274

275-
@Ignore(
275+
@Disabled(
276276
"java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double")
277277
@Test public void testFilterUnionPlan() {
278278
assertModel(MODEL)
@@ -494,7 +494,7 @@ private CalciteAssert.AssertThat assertModel(URL url) {
494494
"{$sort: {STATE: 1}}"));
495495
}
496496

497-
@Ignore("https://issues.apache.org/jira/browse/CALCITE-270")
497+
@Disabled("https://issues.apache.org/jira/browse/CALCITE-270")
498498
@Test public void testGroupByHaving2() {
499499
assertModel(MODEL)
500500
.query("select state, count(*) as c from zips\n"
@@ -553,7 +553,7 @@ private CalciteAssert.AssertThat assertModel(URL url) {
553553
"{$project: {C: 1, STATE: 1, CITY: 1}}"));
554554
}
555555

556-
@Ignore("broken; [CALCITE-2115] is logged to fix it")
556+
@Disabled("broken; [CALCITE-2115] is logged to fix it")
557557
@Test public void testDistinctCount() {
558558
assertModel(MODEL)
559559
.query("select state, count(distinct city) as cdc from zips\n"
@@ -605,7 +605,7 @@ private CalciteAssert.AssertThat assertModel(URL url) {
605605
"{$limit: 5}"));
606606
}
607607

608-
@Ignore("broken; [CALCITE-2115] is logged to fix it")
608+
@Disabled("broken; [CALCITE-2115] is logged to fix it")
609609
@Test public void testProject() {
610610
assertModel(MODEL)
611611
.query("select state, city, 0 as zero from zips order by state, city")

mongodb/src/test/java/org/apache/calcite/adapter/mongodb/MongoDatabasePolicy.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import com.mongodb.MongoClient;
2323
import com.mongodb.client.MongoDatabase;
2424

25-
import org.junit.rules.ExternalResource;
25+
import org.junit.jupiter.api.extension.AfterAllCallback;
26+
import org.junit.jupiter.api.extension.ExtensionContext;
2627

2728
import java.io.Closeable;
2829
import java.net.InetSocketAddress;
@@ -42,7 +43,7 @@
4243
* {@code $ mvn -Pit install}) this rule will connect to an existing (external)
4344
* Mongo instance ({@code localhost}).
4445
*/
45-
class MongoDatabasePolicy extends ExternalResource {
46+
class MongoDatabasePolicy implements AfterAllCallback {
4647

4748
private static final String DB_NAME = "test";
4849

@@ -57,6 +58,10 @@ private MongoDatabasePolicy(MongoClient client, Closer closer) {
5758
closer.add(client::close);
5859
}
5960

61+
@Override public void afterAll(ExtensionContext context) {
62+
closer.close();
63+
}
64+
6065
/**
6166
* Creates an instance based on current maven profile (as defined by {@code -Pit}).
6267
*
@@ -81,13 +86,7 @@ static MongoDatabasePolicy create() {
8186
return new MongoDatabasePolicy(client, closer);
8287
}
8388

84-
8589
MongoDatabase database() {
8690
return database;
8791
}
88-
89-
@Override protected void after() {
90-
closer.close();
91-
}
92-
9392
}

mongodb/src/test/java/org/apache/calcite/test/MongoAssertions.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131

3232
import static org.hamcrest.CoreMatchers.equalTo;
3333
import static org.hamcrest.MatcherAssert.assertThat;
34-
import static org.junit.Assume.assumeTrue;
34+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
35+
3536

3637
/**
3738
* Util class which needs to be in the same package as {@link CalciteAssert}
@@ -102,6 +103,6 @@ public static boolean useFake() {
102103
* @see <a href="https://github.com/fakemongo/fongo/issues/152">Aggregation with $cond (172)</a>
103104
*/
104105
public static void assumeRealMongoInstance() {
105-
assumeTrue("Expect mongo instance", useMongo());
106+
assumeTrue(useMongo(), "Expect mongo instance");
106107
}
107108
}

0 commit comments

Comments
 (0)