protected Properties readConfiguration(Path configFilePath) throws IOException { File configFile = Testing.Files.createTestingFile(configFilePath); Properties props = new Properties(); try (InputStream ostream = new FileInputStream(configFile)) { props.load(ostream); } return props; }
protected void writeConfigurationFile(Path configFilePath, Properties props) throws IOException { File configFile = Testing.Files.createTestingFile(configFilePath); try (OutputStream ostream = new FileOutputStream(configFile)) { props.store(ostream, "MockConnector configuration"); } }
/** * Create a randomly-named file within the test data directory. * * @return the reference to the existing readable and writable file */ public static File createTestingFile() { return createTestingFile(UUID.randomUUID().toString()); }
/** * Read the contents of the supplied {@link InputStream}, replace all variables found in the content, and write the * result to a temporary file. * * @param stream the input stream containing zero or more {@link Strings#replaceVariables(String, java.util.function.Function) * variable expressions} * @param variables the variables * @return the temporary file that exists in the data directory * @throws IOException if there is a problem reading the input stream or writing to the temporary file */ protected static File replaceVariables(InputStream stream, AvailableVariables variables) throws IOException { File tmpFile = Testing.Files.createTestingFile(); try (OutputStream ostream = new FileOutputStream(tmpFile)) { IoUtil.readLines(stream, (line) -> { String newLine = Strings.replaceVariables(line, variables::variableForName); try { ostream.write(newLine.getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { throw new RuntimeException("Error writing to file '" + tmpFile + "'", e); } }, StandardCharsets.UTF_8); } return tmpFile; } }
protected Properties readConfiguration(Path configFilePath) throws IOException { File configFile = Testing.Files.createTestingFile(configFilePath); Properties props = new Properties(); try (InputStream ostream = new FileInputStream(configFile)) { props.load(ostream); } return props; }
@Before public void beforeEach() throws Exception { nextConsumedLineNumber = 1; linesAdded = 0; Testing.Files.delete(TEST_FILE_PATH); inputFile = Testing.Files.createTestingFile(TEST_FILE_PATH); // Basic connector configuration; the remaining engine configuration props are set in base class in startup connectorConfig = Configuration.create() .with(FileStreamSourceConnector.FILE_CONFIG, TEST_FILE_PATH) .with(FileStreamSourceConnector.TOPIC_CONFIG, "topicX") .build(); }
protected void writeConfigurationFile(Path configFilePath, Properties props) throws IOException { File configFile = Testing.Files.createTestingFile(configFilePath); try (OutputStream ostream = new FileOutputStream(configFile)) { props.store(ostream, "MockConnector configuration"); } }
/** * Read the contents of the supplied {@link InputStream}, replace all variables found in the content, and write the * result to a temporary file. * * @param stream the input stream containing zero or more {@link Strings#replaceVariables(String, java.util.function.Function) * variable expressions} * @param variables the variables * @return the temporary file that exists in the data directory * @throws IOException if there is a problem reading the input stream or writing to the temporary file */ protected static File replaceVariables(InputStream stream, AvailableVariables variables) throws IOException { File tmpFile = Testing.Files.createTestingFile(); try (OutputStream ostream = new FileOutputStream(tmpFile)) { IoUtil.readLines(stream, (line) -> { String newLine = Strings.replaceVariables(line, variables::variableForName); try { ostream.write(newLine.getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { throw new RuntimeException("Error writing to file '" + tmpFile + "'", e); } }, StandardCharsets.UTF_8); } return tmpFile; } }
@Before public void beforeEach() throws Exception { nextConsumedLineNumber = 1; linesAdded = 0; Testing.Files.delete(TEST_FILE_PATH); inputFile = Testing.Files.createTestingFile(TEST_FILE_PATH); // Basic connector configuration; the remaining engine configuration props are set in base class in startup connectorConfig = Configuration.create() .with(FileStreamSourceConnector.FILE_CONFIG, TEST_FILE_PATH) .with(FileStreamSourceConnector.TOPIC_CONFIG, "topicX") .build(); }