Java Code Examples for org.apache.flink.util.FileUtils#readFile()

The following examples show how to use org.apache.flink.util.FileUtils#readFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestAPIDocGeneratorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public 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.")));
}
 
Example 2
Source File: ConfigOptionsDocGeneratorTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testCommonOptions() throws IOException, ClassNotFoundException {
	final String projectRootDir = System.getProperty("rootDir");
	final String outputDirectory = TMP.newFolder().getAbsolutePath();

	final OptionsClassLocation[] locations = new OptionsClassLocation[] {
		new OptionsClassLocation("flink-docs", TestCommonOptions.class.getPackage().getName())
	};

	ConfigOptionsDocGenerator.generateCommonSection(projectRootDir, outputDirectory, locations, "src/test/java");
	Formatter formatter = new HtmlFormatter();

	String expected =
		"<table class=\"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: 65%\">Description</th>\n" +
		"        </tr>\n" +
		"    </thead>\n" +
		"    <tbody>\n" +
		"        <tr>\n" +
		"            <td><h5>" + TestCommonOptions.COMMON_POSITIONED_OPTION.key() + "</h5></td>\n" +
		"            <td style=\"word-wrap: break-word;\">" + TestCommonOptions.COMMON_POSITIONED_OPTION.defaultValue() + "</td>\n" +
		"            <td>" + formatter.format(TestCommonOptions.COMMON_POSITIONED_OPTION.description()) + "</td>\n" +
		"        </tr>\n" +
		"        <tr>\n" +
		"            <td><h5>" + TestCommonOptions.COMMON_OPTION.key() + "</h5></td>\n" +
		"            <td style=\"word-wrap: break-word;\">" + TestCommonOptions.COMMON_OPTION.defaultValue() + "</td>\n" +
		"            <td>" + formatter.format(TestCommonOptions.COMMON_OPTION.description()) + "</td>\n" +
		"        </tr>\n" +
		"    </tbody>\n" +
		"</table>\n";

	String output = FileUtils.readFile(Paths.get(outputDirectory, ConfigOptionsDocGenerator.COMMON_SECTION_FILE_NAME).toFile(), StandardCharsets.UTF_8.name());

	assertEquals(expected, output);
}
 
Example 3
Source File: ConfigOptionsDocGeneratorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCommonOptions() throws IOException, ClassNotFoundException {
	final String projectRootDir = System.getProperty("rootDir");
	final String outputDirectory = TMP.newFolder().getAbsolutePath();

	final OptionsClassLocation[] locations = new OptionsClassLocation[] {
		new OptionsClassLocation("flink-docs", TestCommonOptions.class.getPackage().getName())
	};

	ConfigOptionsDocGenerator.generateCommonSection(projectRootDir, outputDirectory, locations, "src/test/java");
	Formatter formatter = new HtmlFormatter();

	String expected =
		"<table class=\"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: 65%\">Description</th>\n" +
		"        </tr>\n" +
		"    </thead>\n" +
		"    <tbody>\n" +
		"        <tr>\n" +
		"            <td><h5>" + TestCommonOptions.COMMON_POSITIONED_OPTION.key() + "</h5></td>\n" +
		"            <td style=\"word-wrap: break-word;\">" + TestCommonOptions.COMMON_POSITIONED_OPTION.defaultValue() + "</td>\n" +
		"            <td>" + formatter.format(TestCommonOptions.COMMON_POSITIONED_OPTION.description()) + "</td>\n" +
		"        </tr>\n" +
		"        <tr>\n" +
		"            <td><h5>" + TestCommonOptions.COMMON_OPTION.key() + "</h5></td>\n" +
		"            <td style=\"word-wrap: break-word;\">" + TestCommonOptions.COMMON_OPTION.defaultValue() + "</td>\n" +
		"            <td>" + formatter.format(TestCommonOptions.COMMON_OPTION.description()) + "</td>\n" +
		"        </tr>\n" +
		"    </tbody>\n" +
		"</table>\n";

	String output = FileUtils.readFile(Paths.get(outputDirectory, ConfigOptionsDocGenerator.COMMON_SECTION_FILE_NAME).toFile(), StandardCharsets.UTF_8.name());

	assertEquals(expected, output);
}
 
Example 4
Source File: ConfigOptionsDocGeneratorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testSections() throws IOException, ClassNotFoundException {
	final String projectRootDir = getProjectRootDir();
	final String outputDirectory = TMP.newFolder().getAbsolutePath();

	final OptionsClassLocation[] locations = new OptionsClassLocation[] {
		new OptionsClassLocation("flink-docs", TestCommonOptions.class.getPackage().getName())
	};

	ConfigOptionsDocGenerator.generateCommonSection(projectRootDir, outputDirectory, locations, "src/test/java");
	Formatter formatter = new HtmlFormatter();

	String expected1 =
		"<table class=\"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>" + TestCommonOptions.COMMON_POSITIONED_OPTION.key() + "</h5></td>\n" +
		"            <td style=\"word-wrap: break-word;\">" + TestCommonOptions.COMMON_POSITIONED_OPTION.defaultValue() + "</td>\n" +
		"            <td>Integer</td>\n" +
		"            <td>" + formatter.format(TestCommonOptions.COMMON_POSITIONED_OPTION.description()) + "</td>\n" +
		"        </tr>\n" +
		"        <tr>\n" +
		"            <td><h5>" + TestCommonOptions.COMMON_OPTION.key() + "</h5></td>\n" +
		"            <td style=\"word-wrap: break-word;\">" + TestCommonOptions.COMMON_OPTION.defaultValue() + "</td>\n" +
		"            <td>Integer</td>\n" +
		"            <td>" + formatter.format(TestCommonOptions.COMMON_OPTION.description()) + "</td>\n" +
		"        </tr>\n" +
		"    </tbody>\n" +
		"</table>\n";

	String expected2 =
		"<table class=\"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>" + TestCommonOptions.COMMON_OPTION.key() + "</h5></td>\n" +
			"            <td style=\"word-wrap: break-word;\">" + TestCommonOptions.COMMON_OPTION.defaultValue() + "</td>\n" +
			"            <td>Integer</td>\n" +
			"            <td>" + formatter.format(TestCommonOptions.COMMON_OPTION.description()) + "</td>\n" +
			"        </tr>\n" +
			"    </tbody>\n" +
			"</table>\n";

	final String fileName1 = ConfigOptionsDocGenerator.getSectionFileName(TestCommonOptions.SECTION_1);
	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);
}