@Test public void testCompareFile() throws Exception { String resources = getClass().getResource("/compare").toURI().getPath(); LOG.info("Resources folder: " + resources); // Text content and Binary both same String srcFile = resources + "/source.csv"; String refFile = resources + "/bin_same_ref.csv"; Assert.assertTrue(FileRuntimeHelper.compareInTextMode(srcFile, refFile, "UTF-8")); Assert.assertTrue(FileRuntimeHelper.compareInBinaryMode(srcFile, refFile)); // Text content are same and Binary is different srcFile = resources + "/prenoms_fr2.csv.short.dos"; refFile = resources + "/prenoms_fr2.csv.short.linux"; Assert.assertTrue(FileRuntimeHelper.compareInTextMode(srcFile, refFile, "UTF-8")); Assert.assertFalse(FileRuntimeHelper.compareInBinaryMode(srcFile, refFile)); // Text are different srcFile = resources + "/source.csv"; refFile = resources + "/text_diff_ref.csv"; Assert.assertFalse(FileRuntimeHelper.compareInTextMode(srcFile, refFile, "UTF-8")); Assert.assertFalse(FileRuntimeHelper.compareInBinaryMode(srcFile, refFile)); }
protected void basicOutputTest(TFileOutputDelimitedProperties properties, String refFilePath) throws Throwable { String fileName = properties.fileName.getStringValue(); if (properties.targetIsStream.getValue()) { properties.fileName.setValue(new FileOutputStream(new File(fileName))); } List<IndexedRecord> records = generateRecords(25); Result result = doWriteRows(properties, records); assertEquals(25, result.getTotalCount()); String outputFile = fileName; if (properties.compress.getValue()) { outputFile = outputFile.substring(0, outputFile.lastIndexOf(".")) + ".zip"; } assertTrue(FileRuntimeHelper.compareInTextMode(outputFile, refFilePath, getEncoding(properties.encoding))); // Need to close the stream firstly. then if (properties.targetIsStream.getValue()) { ((FileOutputStream) properties.fileName.getValue()).close(); } assertTrue(deleteFile(fileName)); }
@Test public void testWriteDecimal() throws Throwable { String resources = getResourceFolder(); String outputFile = resources + "/out/test_write_decimal.csv"; String refFilePath = resources + "/ref_test_write_decimal.csv"; LOGGER.debug("Test file path: " + outputFile); TFileOutputDelimitedProperties properties = createOutputProperties(outputFile, false); Schema outputSchema = SchemaBuilder.builder().record("Schema").fields().name("TestBigDecimal") .prop(SchemaConstants.TALEND_COLUMN_PRECISION, "10").prop(SchemaConstants.TALEND_COLUMN_PRECISION, "2") .type(AvroUtils._decimal()).noDefault().endRecord(); properties.main.schema.setValue(outputSchema); List<IndexedRecord> records = new ArrayList<>(); IndexedRecord r1 = new GenericData.Record(outputSchema); r1.put(0, "3.1415926"); IndexedRecord r2 = new GenericData.Record(outputSchema); r2.put(0, "9.1798"); records.add(r1); records.add(r2); // Delete generated empty file function not be checked doWriteRows(properties, records); assertTrue(FileRuntimeHelper.compareInTextMode(outputFile, refFilePath, getEncoding(properties.encoding))); assertTrue(deleteFile(outputFile)); }