You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ch...@apache.org on 2022/04/08 16:31:11 UTC
[flink] branch master updated: [FLINK-27143][docs][tests] Migrate flink-docs to JUnit 5
This is an automated email from the ASF dual-hosted git repository.
chesnay pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/master by this push:
new 11829438516 [FLINK-27143][docs][tests] Migrate flink-docs to JUnit 5
11829438516 is described below
commit 118294385161c9b76511ab6bf1ee999fb843cb77
Author: Roc Marshal <fl...@126.com>
AuthorDate: Sat Apr 9 00:31:01 2022 +0800
[FLINK-27143][docs][tests] Migrate flink-docs to JUnit 5
---
.../ConfigOptionsDocGeneratorTest.java | 225 ++++++++++-----------
.../ConfigOptionsDocsCompletenessITCase.java | 10 +-
.../flink/docs/rest/OpenApiSpecGeneratorTest.java | 4 +-
.../flink/docs/rest/RestAPIDocGeneratorTest.java | 38 ++--
.../org.junit.jupiter.api.extension.Extension | 16 ++
5 files changed, 147 insertions(+), 146 deletions(-)
diff --git a/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocGeneratorTest.java b/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocGeneratorTest.java
index d369b47295e..e621921043e 100644
--- a/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocGeneratorTest.java
+++ b/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocGeneratorTest.java
@@ -30,11 +30,9 @@ import org.apache.flink.configuration.description.Formatter;
import org.apache.flink.configuration.description.HtmlFormatter;
import org.apache.flink.configuration.description.InlineElement;
import org.apache.flink.docs.configuration.data.TestCommonOptions;
-import org.apache.flink.util.FileUtils;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import java.io.File;
import java.io.IOException;
@@ -46,17 +44,11 @@ import java.util.List;
import java.util.Map;
import static org.apache.flink.configuration.description.TextElement.text;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.empty;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for the {@link ConfigOptionsDocGenerator}. */
@SuppressWarnings("unused")
-public class ConfigOptionsDocGeneratorTest {
-
- @ClassRule public static final TemporaryFolder TMP = new TemporaryFolder();
+class ConfigOptionsDocGeneratorTest {
static class TestConfigGroup {
public static ConfigOption<Integer> firstOption =
@@ -143,7 +135,7 @@ public class ConfigOptionsDocGeneratorTest {
}
@Test
- public void testCreatingTypes() {
+ void testCreatingTypes() {
final String expectedTable =
"<table class=\"configuration table table-bordered\">\n"
+ " <thead>\n"
@@ -204,11 +196,11 @@ public class ConfigOptionsDocGeneratorTest {
.get(0)
.f1;
- assertEquals(expectedTable, htmlTable);
+ assertThat(htmlTable).isEqualTo(expectedTable);
}
@Test
- public void testCreatingDescription() {
+ void testCreatingDescription() {
final String expectedTable =
"<table class=\"configuration table table-bordered\">\n"
+ " <thead>\n"
@@ -237,7 +229,7 @@ public class ConfigOptionsDocGeneratorTest {
final String htmlTable =
ConfigOptionsDocGenerator.generateTablesForClass(TestConfigGroup.class).get(0).f1;
- assertEquals(expectedTable, htmlTable);
+ assertThat(htmlTable).isEqualTo(expectedTable);
}
@ConfigGroups(
@@ -276,23 +268,21 @@ public class ConfigOptionsDocGeneratorTest {
}
@Test
- public void testLongestPrefixMatching() {
+ void testLongestPrefixMatching() {
final List<Tuple2<ConfigGroup, String>> tables =
ConfigOptionsDocGenerator.generateTablesForClass(TestConfigPrefix.class);
- assertEquals(3, tables.size());
+ assertThat(tables).hasSize(3);
final Map<String, String> tablesConverted = new HashMap<>(tables.size());
for (final Tuple2<ConfigGroup, String> table : tables) {
tablesConverted.put(table.f0 != null ? table.f0.name() : "default", table.f1);
}
- assertThat(tablesConverted.get("group1"), containsString("a.b.option"));
- assertThat(tablesConverted.get("group1"), containsString("a.b.c.option"));
- assertThat(tablesConverted.get("group1"), containsString("a.b.c.e.option"));
- assertThat(tablesConverted.get("group2"), containsString("a.b.c.d.option"));
- assertThat(tablesConverted.get("group1"), not(containsString("a.b.c.d.option")));
- assertThat(tablesConverted.get("default"), containsString("a.option"));
- assertThat(tablesConverted.get("default"), containsString("a.c.b.option"));
+ assertThat(tablesConverted.get("group1"))
+ .contains("a.b.option", "a.b.c.option", "a.b.c.e.option")
+ .doesNotContain("a.b.c.d.option");
+ assertThat(tablesConverted.get("group2")).contains("a.b.c.d.option");
+ assertThat(tablesConverted.get("default")).contains("a.option", "a.c.b.option");
}
@ConfigGroups(
@@ -327,82 +317,87 @@ public class ConfigOptionsDocGeneratorTest {
}
@Test
- public void testCreatingMultipleGroups() {
+ void testCreatingMultipleGroups() {
final List<Tuple2<ConfigGroup, String>> tables =
ConfigOptionsDocGenerator.generateTablesForClass(TestConfigMultipleSubGroup.class);
- assertEquals(tables.size(), 3);
+ assertThat(tables).hasSize(3);
final HashMap<String, String> tablesConverted = new HashMap<>();
for (Tuple2<ConfigGroup, String> table : tables) {
tablesConverted.put(table.f0 != null ? table.f0.name() : "default", table.f1);
}
- assertEquals(
- "<table class=\"configuration table table-bordered\">\n"
- + " <thead>\n"
- + " <tr>\n"
- + " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n"
- + " <th class=\"text-left\" style=\"width: 15%\">Default</th>\n"
- + " <th class=\"text-left\" style=\"width: 10%\">Type</th>\n"
- + " <th class=\"text-left\" style=\"width: 55%\">Description</th>\n"
- + " </tr>\n"
- + " </thead>\n"
- + " <tbody>\n"
- + " <tr>\n"
- + " <td><h5>first.option.a</h5></td>\n"
- + " <td style=\"word-wrap: break-word;\">2</td>\n"
- + " <td>Integer</td>\n"
- + " <td>This is example description for the first option.</td>\n"
- + " </tr>\n"
- + " </tbody>\n"
- + "</table>\n",
- tablesConverted.get("firstGroup"));
- assertEquals(
- "<table class=\"configuration table table-bordered\">\n"
- + " <thead>\n"
- + " <tr>\n"
- + " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n"
- + " <th class=\"text-left\" style=\"width: 15%\">Default</th>\n"
- + " <th class=\"text-left\" style=\"width: 10%\">Type</th>\n"
- + " <th class=\"text-left\" style=\"width: 55%\">Description</th>\n"
- + " </tr>\n"
- + " </thead>\n"
- + " <tbody>\n"
- + " <tr>\n"
- + " <td><h5>second.option.a</h5></td>\n"
- + " <td style=\"word-wrap: break-word;\">(none)</td>\n"
- + " <td>String</td>\n"
- + " <td>This is long example description for the second option.</td>\n"
- + " </tr>\n"
- + " </tbody>\n"
- + "</table>\n",
- tablesConverted.get("secondGroup"));
- assertEquals(
- "<table class=\"configuration table table-bordered\">\n"
- + " <thead>\n"
- + " <tr>\n"
- + " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n"
- + " <th class=\"text-left\" style=\"width: 15%\">Default</th>\n"
- + " <th class=\"text-left\" style=\"width: 10%\">Type</th>\n"
- + " <th class=\"text-left\" style=\"width: 55%\">Description</th>\n"
- + " </tr>\n"
- + " </thead>\n"
- + " <tbody>\n"
- + " <tr>\n"
- + " <td><h5>fourth.option.a</h5></td>\n"
- + " <td style=\"word-wrap: break-word;\">(none)</td>\n"
- + " <td>String</td>\n"
- + " <td>This is long example description for the fourth option.</td>\n"
- + " </tr>\n"
- + " <tr>\n"
- + " <td><h5>third.option.a</h5></td>\n"
- + " <td style=\"word-wrap: break-word;\">2</td>\n"
- + " <td>Integer</td>\n"
- + " <td>This is example description for the third option.</td>\n"
- + " </tr>\n"
- + " </tbody>\n"
- + "</table>\n",
- tablesConverted.get("default"));
+ assertThat(tablesConverted)
+ .containsEntry(
+ "firstGroup",
+ "<table class=\"configuration table table-bordered\">\n"
+ + " <thead>\n"
+ + " <tr>\n"
+ + " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n"
+ + " <th class=\"text-left\" style=\"width: 15%\">Default</th>\n"
+ + " <th class=\"text-left\" style=\"width: 10%\">Type</th>\n"
+ + " <th class=\"text-left\" style=\"width: 55%\">Description</th>\n"
+ + " </tr>\n"
+ + " </thead>\n"
+ + " <tbody>\n"
+ + " <tr>\n"
+ + " <td><h5>first.option.a</h5></td>\n"
+ + " <td style=\"word-wrap: break-word;\">2</td>\n"
+ + " <td>Integer</td>\n"
+ + " <td>This is example description for the first option.</td>\n"
+ + " </tr>\n"
+ + " </tbody>\n"
+ + "</table>\n");
+
+ assertThat(tablesConverted)
+ .containsEntry(
+ "secondGroup",
+ "<table class=\"configuration table table-bordered\">\n"
+ + " <thead>\n"
+ + " <tr>\n"
+ + " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n"
+ + " <th class=\"text-left\" style=\"width: 15%\">Default</th>\n"
+ + " <th class=\"text-left\" style=\"width: 10%\">Type</th>\n"
+ + " <th class=\"text-left\" style=\"width: 55%\">Description</th>\n"
+ + " </tr>\n"
+ + " </thead>\n"
+ + " <tbody>\n"
+ + " <tr>\n"
+ + " <td><h5>second.option.a</h5></td>\n"
+ + " <td style=\"word-wrap: break-word;\">(none)</td>\n"
+ + " <td>String</td>\n"
+ + " <td>This is long example description for the second option.</td>\n"
+ + " </tr>\n"
+ + " </tbody>\n"
+ + "</table>\n");
+
+ assertThat(tablesConverted)
+ .containsEntry(
+ "default",
+ "<table class=\"configuration table table-bordered\">\n"
+ + " <thead>\n"
+ + " <tr>\n"
+ + " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n"
+ + " <th class=\"text-left\" style=\"width: 15%\">Default</th>\n"
+ + " <th class=\"text-left\" style=\"width: 10%\">Type</th>\n"
+ + " <th class=\"text-left\" style=\"width: 55%\">Description</th>\n"
+ + " </tr>\n"
+ + " </thead>\n"
+ + " <tbody>\n"
+ + " <tr>\n"
+ + " <td><h5>fourth.option.a</h5></td>\n"
+ + " <td style=\"word-wrap: break-word;\">(none)</td>\n"
+ + " <td>String</td>\n"
+ + " <td>This is long example description for the fourth option.</td>\n"
+ + " </tr>\n"
+ + " <tr>\n"
+ + " <td><h5>third.option.a</h5></td>\n"
+ + " <td style=\"word-wrap: break-word;\">2</td>\n"
+ + " <td>Integer</td>\n"
+ + " <td>This is example description for the third option.</td>\n"
+ + " </tr>\n"
+ + " </tbody>\n"
+ + "</table>\n");
}
static class TestConfigGroupWithOverriddenDefault {
@@ -422,7 +417,7 @@ public class ConfigOptionsDocGeneratorTest {
}
@Test
- public void testOverrideDefault() {
+ void testOverrideDefault() {
final String expectedTable =
"<table class=\"configuration table table-bordered\">\n"
+ " <thead>\n"
@@ -454,13 +449,13 @@ public class ConfigOptionsDocGeneratorTest {
.get(0)
.f1;
- assertEquals(expectedTable, htmlTable);
+ assertThat(htmlTable).isEqualTo(expectedTable);
}
@Test
- public void testSections() throws IOException, ClassNotFoundException {
+ void testSections(@TempDir File tmpDir) throws IOException, ClassNotFoundException {
final String projectRootDir = getProjectRootDir();
- final String outputDirectory = TMP.newFolder().getAbsolutePath();
+ final String outputDirectory = tmpDir.getAbsolutePath();
final OptionsClassLocation[] locations =
new OptionsClassLocation[] {
@@ -541,15 +536,12 @@ public class ConfigOptionsDocGeneratorTest {
final String fileName2 =
ConfigOptionsDocGenerator.getSectionFileName(TestCommonOptions.SECTION_2);
- final String output1 =
- FileUtils.readFile(
- new File(outputDirectory, fileName1), StandardCharsets.UTF_8.name());
- final String output2 =
- FileUtils.readFile(
- new File(outputDirectory, fileName2), StandardCharsets.UTF_8.name());
-
- assertEquals(expected1, output1);
- assertEquals(expected2, output2);
+ assertThat(new File(outputDirectory, fileName1))
+ .content(StandardCharsets.UTF_8)
+ .isEqualTo(expected1);
+ assertThat(new File(outputDirectory, fileName2))
+ .content(StandardCharsets.UTF_8)
+ .isEqualTo(expected2);
}
static class TestConfigGroupWithExclusion {
@@ -572,7 +564,7 @@ public class ConfigOptionsDocGeneratorTest {
* are not documented.
*/
@Test
- public void testConfigOptionExclusion() {
+ void testConfigOptionExclusion() {
final String expectedTable =
"<table class=\"configuration table table-bordered\">\n"
+ " <thead>\n"
@@ -597,24 +589,25 @@ public class ConfigOptionsDocGeneratorTest {
.get(0)
.f1;
- assertEquals(expectedTable, htmlTable);
+ assertThat(htmlTable).isEqualTo(expectedTable);
}
@ConfigGroups(groups = {@ConfigGroup(name = "firstGroup", keyPrefix = "first")})
static class EmptyConfigOptions {}
@Test
- public void testClassWithoutOptionsIsIgnored() {
- assertThat(
- ConfigOptionsDocGenerator.generateTablesForClass(EmptyConfigOptions.class),
- empty());
+ void testClassWithoutOptionsIsIgnored() {
+ assertThat(ConfigOptionsDocGenerator.generateTablesForClass(EmptyConfigOptions.class))
+ .isEmpty();
}
@Test
- public void testSnakeCaseConversion() {
- assertEquals("rocks_options", ConfigOptionsDocGenerator.toSnakeCase("RocksOptions"));
- assertEquals("rocksdb_options", ConfigOptionsDocGenerator.toSnakeCase("RocksDBOptions"));
- assertEquals("db_options", ConfigOptionsDocGenerator.toSnakeCase("DBOptions"));
+ void testSnakeCaseConversion() {
+ assertThat(ConfigOptionsDocGenerator.toSnakeCase("RocksOptions"))
+ .isEqualTo("rocks_options");
+ assertThat(ConfigOptionsDocGenerator.toSnakeCase("RocksDBOptions"))
+ .isEqualTo("rocksdb_options");
+ assertThat(ConfigOptionsDocGenerator.toSnakeCase("DBOptions")).isEqualTo("db_options");
}
static String getProjectRootDir() {
diff --git a/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocsCompletenessITCase.java b/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocsCompletenessITCase.java
index 41ae4d35a21..c282ae26ec7 100644
--- a/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocsCompletenessITCase.java
+++ b/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocsCompletenessITCase.java
@@ -23,8 +23,7 @@ import org.apache.flink.configuration.ConfigOption;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -51,6 +50,7 @@ import static org.apache.flink.docs.configuration.ConfigOptionsDocGenerator.getD
import static org.apache.flink.docs.configuration.ConfigOptionsDocGenerator.processConfigOptions;
import static org.apache.flink.docs.configuration.ConfigOptionsDocGenerator.stringifyDefault;
import static org.apache.flink.docs.configuration.ConfigOptionsDocGenerator.typeToHtml;
+import static org.assertj.core.api.Fail.fail;
/**
* This test verifies that all {@link ConfigOption ConfigOptions} in the configured {@link
@@ -58,10 +58,10 @@ import static org.apache.flink.docs.configuration.ConfigOptionsDocGenerator.type
* exist for the same key with different descriptions/default values), and that the documentation
* does not refer to non-existent options.
*/
-public class ConfigOptionsDocsCompletenessITCase {
+class ConfigOptionsDocsCompletenessITCase {
@Test
- public void testCompleteness() throws IOException, ClassNotFoundException {
+ void testCompleteness() throws IOException, ClassNotFoundException {
final Map<String, List<DocumentedOption>> documentedOptions = parseDocumentedOptions();
final Map<String, List<ExistingOption>> existingOptions =
findExistingOptions(ignored -> true);
@@ -208,7 +208,7 @@ public class ConfigOptionsDocsCompletenessITCase {
sb.append("\t\t");
sb.append(problem);
}
- Assert.fail(sb.toString());
+ fail(sb.toString());
}
}
diff --git a/flink-docs/src/test/java/org/apache/flink/docs/rest/OpenApiSpecGeneratorTest.java b/flink-docs/src/test/java/org/apache/flink/docs/rest/OpenApiSpecGeneratorTest.java
index b012976292c..f3d3555b94d 100644
--- a/flink-docs/src/test/java/org/apache/flink/docs/rest/OpenApiSpecGeneratorTest.java
+++ b/flink-docs/src/test/java/org/apache/flink/docs/rest/OpenApiSpecGeneratorTest.java
@@ -25,7 +25,6 @@ import org.apache.flink.runtime.rest.handler.RestHandlerSpecification;
import org.apache.flink.runtime.rest.util.DocumentingRestEndpoint;
import org.apache.flink.runtime.rest.versioning.RestAPIVersion;
import org.apache.flink.util.FileUtils;
-import org.apache.flink.util.TestLogger;
import org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler;
@@ -38,7 +37,8 @@ import java.util.concurrent.CompletableFuture;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
-class OpenApiSpecGeneratorTest extends TestLogger {
+/** Test class for {@link OpenApiSpecGenerator}. */
+class OpenApiSpecGeneratorTest {
@Test
void testExcludeFromDocumentation() throws Exception {
diff --git a/flink-docs/src/test/java/org/apache/flink/docs/rest/RestAPIDocGeneratorTest.java b/flink-docs/src/test/java/org/apache/flink/docs/rest/RestAPIDocGeneratorTest.java
index 9057966dc03..6b6e4b5db62 100644
--- a/flink-docs/src/test/java/org/apache/flink/docs/rest/RestAPIDocGeneratorTest.java
+++ b/flink-docs/src/test/java/org/apache/flink/docs/rest/RestAPIDocGeneratorTest.java
@@ -25,47 +25,39 @@ import org.apache.flink.runtime.rest.handler.RestHandlerSpecification;
import org.apache.flink.runtime.rest.util.DocumentingRestEndpoint;
import org.apache.flink.runtime.rest.versioning.RestAPIVersion;
import org.apache.flink.util.FileUtils;
-import org.apache.flink.util.TestLogger;
import org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.not;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for the {@link RestAPIDocGenerator}. */
-public class RestAPIDocGeneratorTest extends TestLogger {
+class RestAPIDocGeneratorTest {
@Test
- public void testExcludeFromDocumentation() throws Exception {
+ void testExcludeFromDocumentation() throws Exception {
File file = File.createTempFile("rest_v0_", ".html");
RestAPIDocGenerator.createHtmlFile(
new TestExcludeDocumentingRestEndpoint(), RestAPIVersion.V0, file.toPath());
String actual = FileUtils.readFile(file, "UTF-8");
- assertThat(actual, containsString("/test/empty1"));
- assertThat(actual, containsString("This is a testing REST API."));
- assertThat(actual, containsString("/test/empty2"));
- assertThat(actual, containsString("This is another testing REST API."));
- assertThat(actual, not(containsString("/test/exclude1")));
- assertThat(
- actual,
- not(
- containsString(
- "This REST API should not appear in the generated documentation.")));
- assertThat(actual, not(containsString("/test/exclude2")));
- assertThat(
- actual,
- not(
- containsString(
- "This REST API should also not appear in the generated documentation.")));
+ assertThat(actual).containsSequence("/test/empty1");
+ assertThat(actual).containsSequence("This is a testing REST API.");
+ assertThat(actual).containsSequence("/test/empty2");
+ assertThat(actual).containsSequence("This is another testing REST API.");
+ assertThat(actual).doesNotContain("/test/exclude1");
+ assertThat(actual)
+ .doesNotContain("This REST API should not appear in the generated documentation.");
+ assertThat(actual).doesNotContain("/test/exclude2");
+ assertThat(actual)
+ .doesNotContain(
+ "This REST API should also not appear in the generated documentation.");
}
private static class TestExcludeDocumentingRestEndpoint implements DocumentingRestEndpoint {
diff --git a/flink-docs/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension b/flink-docs/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
new file mode 100644
index 00000000000..0b74fd4603c
--- /dev/null
+++ b/flink-docs/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+
+org.apache.flink.util.TestLoggerExtension