List of usage examples for org.apache.commons.io FileUtils readFileToString
public static String readFileToString(File file) throws IOException
From source file:com.meltmedia.cadmium.copyright.service.CopyrightResourceHandlerTest.java
@Test public void handleFile() throws Exception { File preUpdate = new File("target/test-classes/pre-update.html"); File postUpdate = new File("target/test-classes/post-update.html"); CopyrightResourceHandler handler = new CopyrightResourceHandler(); handler.year = 2013;//w ww.j av a 2 s . c o m long preUpdateSize = preUpdate.length(); handler.handleFile(preUpdate); assertTrue("File size didn't change.", preUpdateSize != preUpdate.length()); String postUpdateFile = FileUtils.readFileToString(postUpdate); assertEquals("File didn't update as suspected.", FileUtils.readFileToString(preUpdate), postUpdateFile); }
From source file:de.uzk.hki.da.convert.RdfToJsonLdConverterTests.java
/** * Test./*from ww w .j a va 2 s. c o m*/ * @throws Exception */ @Test public void test() throws Exception { File edmFile = new File(BASE_DIR + "/edm.rdf"); String edm = FileUtils.readFileToString(edmFile); RdfToJsonLdConverter converter = new RdfToJsonLdConverter("conf/frame.jsonld"); Map<String, Object> json = converter.convert(edm); assertNotNull(json); System.out.println(JSONUtils.toPrettyString(json)); System.out.println(json.get("@graph").getClass()); }
From source file:io.github.microcks.util.openapi.OpenAPISchemaValidatorTest.java
@Test public void testValidateJsonSuccess() { boolean valid = false; String schemaText = null;//from w w w . ja v a2s . co m String jsonText = "{\"name\": \"307\", \"model\": \"Peugeot 307\", \"year\": 2003}"; try { // Load schema from file. schemaText = FileUtils.readFileToString( new File("target/test-classes/io/github/microcks/util/openapi/car-schema.json")); // Validate Json according schema. valid = OpenAPISchemaValidator.isJsonValid(schemaText, jsonText); } catch (Exception e) { fail("Exception should not be thrown"); } // Assert Json object is valid. assertTrue(valid); }
From source file:io.github.sn0cr.rapidRunner.testRunner.TestCase.java
/** * @throws IOException// w ww . j a v a 2 s . co m * */ public TestCase(String name, Pair<Path, Path> testCasePair, String[] arguments, Path workingDirectory) throws IOException { this.testCasePair = testCasePair; this.input = FileUtils.readFileToString(testCasePair.getA().toFile()); this.expectedOutput = FileUtils.readFileToString(testCasePair.getB().toFile()); this.arguments = arguments; this.name = name; this.workingDirectory = workingDirectory; }
From source file:File.TXT.ReadFile.java
public ArrayList read_all_files(String path) { FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".txt"); }/*from w w w.jav a 2 s. com*/ }; ArrayList hasil = new ArrayList(); File folder = new File(path); File[] listOfFiles = folder.listFiles(filter); for (int i = 0; i < listOfFiles.length; i++) { File file = listOfFiles[i]; try { if (file.canRead()) { String content = FileUtils.readFileToString(file); hasil.add(content); } else { hasil.add("kosong"); } } catch (IOException ex) { Logger.getLogger(ReadFile.class.getName()).log(Level.SEVERE, null, ex); } } return hasil; }
From source file:fr.paris.lutece.plugins.updater.util.sql.SqlUtils.java
/** * Executes a SQL script file/*from ww w . j a v a 2s . co m*/ * @param strFilename The filename * @param plugin The plugin * @throws IOException If an IO exception occurs * @throws SQLException If an SQL exception occurs */ public static void executeSqlFileScript(String strFilename, Plugin plugin) throws IOException, SQLException { try { File file = new File(strFilename); String strScript = FileUtils.readFileToString(file); executeSqlScript(strScript, plugin); } catch (IOException ex) { AppLogService.error("updater - execute SQL script error : " + ex.getMessage(), ex); throw ex; } }
From source file:com.alibaba.druid.sql.oracle.demo.OracleResourceTest.java
public void test_0() throws Exception { File file = new File("/Users/wenshao/Downloads/eoa_tmp_sqltext_1.csv"); String sql = FileUtils.readFileToString(file); OracleStatementParser parser = new OracleStatementParser(sql); List<SQLStatement> statementList = parser.parseStatementList(); // Assert.assertEquals(1, statementList.size()); System.out.println(sql);/*from www . j a v a 2 s .c om*/ print(statementList); OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor(); for (int i = 0, size = statementList.size(); i < size; ++i) { SQLStatement statement = statementList.get(i); statement.accept(visitor); } System.out.println("Tables : " + visitor.getTables()); System.out.println("fields : " + visitor.getColumns()); System.out.println(); System.out.println(); }
From source file:com.seleniumtests.it.core.TestRetry.java
@Test(groups = { "it" }) public void testRetryOnException() throws Exception { executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClass" }, ParallelMode.METHODS, new String[] { "testAndSubActions", "testInError", "testWithException" }); String mainReportContent = FileUtils.readFileToString(new File( new File(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory()).getAbsolutePath() + File.separator + "SeleniumTestReport.html")); mainReportContent = mainReportContent.replace("\n", "").replace("\r", ""); Assert.assertTrue(//from w w w. j av a2 s. c o m mainReportContent.matches(".*<a href\\='testInError/TestReport\\.html'.*?>testInError</a>.*")); Assert.assertTrue(mainReportContent .matches(".*<a href\\='testWithException/TestReport\\.html'.*?>testWithException</a>.*")); // check failed test is not retried (AssertionError) based on log. No more direct way found String detailedReportContent2 = FileUtils .readFileToString(Paths.get(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory(), "testInError", "TestReport.html").toFile()); detailedReportContent2 = detailedReportContent2.replace("\n", "").replace("\r", "").replaceAll(">\\s+<", "><"); Assert.assertTrue(detailedReportContent2.contains("Failed in 1 times")); Assert.assertFalse(detailedReportContent2 .contains("[RETRYING] class com.seleniumtests.it.stubclasses.StubTestClass.testInError")); // check test with exception is retried based on log. No more direct way found String detailedReportContent3 = FileUtils .readFileToString(Paths.get(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory(), "testWithException", "TestReport.html").toFile()); detailedReportContent3 = detailedReportContent3.replace("\n", "").replace("\r", "").replaceAll(">\\s+<", "><"); Assert.assertTrue(detailedReportContent3.contains("Failed in 3 times")); Assert.assertTrue(detailedReportContent3 .contains("[RETRYING] class com.seleniumtests.it.stubclasses.StubTestClass.testWithException")); // check that in case of retry, steps are not logged twice Assert.assertTrue(detailedReportContent3.contains("step 1")); Assert.assertTrue(detailedReportContent3.contains("<li>played 3 times")); // only the last step is retained Assert.assertFalse(detailedReportContent3.contains("<li>played 2 times")); // only the last step is retained Assert.assertEquals(StringUtils.countOccurrencesOf(detailedReportContent3, "step 1"), 1); }
From source file:hudson.plugins.mstest.MSTestPublisherJenkinsRuleTest.java
@Test public void testResolveEnvironmentVariables() throws InterruptedException, IOException, Exception { EnvironmentVariablesNodeProperty prop = new EnvironmentVariablesNodeProperty(); EnvVars envVars = prop.getEnvVars(); envVars.put("TRX", "build.trx"); j.jenkins.getGlobalNodeProperties().add(prop); FreeStyleProject project = j.createFreeStyleProject(); project.getPublishersList().add(new MSTestPublisher("$TRX")); FreeStyleBuild build = project.scheduleBuild2(0).get(); if (build != null) { String s = FileUtils.readFileToString(build.getLogFile()); assertFalse(s.contains("Processing tests results in file(s) $TRX")); assertTrue(s.contains("build.trx")); }//from ww w .j a v a2 s.c o m }
From source file:de.tudarmstadt.ukp.dkpro.examples.tokenizedwriter.TokenizedWriterPipelineTest.java
@Test public void testMain() throws IOException, UIMAException { File expectedOutput = new File("src/test/resources/tokenized.txt"); TokenizedWriterPipeline.TARGET_FILE.delete(); TokenizedWriterPipeline.main(new String[] {}); assertTrue("Output file not generated.", TokenizedWriterPipeline.TARGET_FILE.exists()); assertEquals("Output file content does not match.", FileUtils.readFileToString(expectedOutput), FileUtils.readFileToString(TokenizedWriterPipeline.TARGET_FILE)); }