SqlDbFeatureExecutor extends AbstractDbFeatureExecutor<IDataSet, IDatabaseConnection> { @Override protected DbFeature<IDatabaseConnection> createApplyCustomScriptFeature(final List<String> scriptPaths) { return (final IDatabaseConnection connection) -> { try { for (final String scriptPath : scriptPaths) { executeScript(loadScript(scriptPath), connection.getConnection()); } } catch (final SQLException | IOException | URISyntaxException e) { throw new DbFeatureException("Could not apply custom scripts feature", e); } }; } SqlDbFeatureExecutor(final FeatureResolver featureResolver);   }
@Test public void testApplyCustomScriptFeatureExecutionUsingAvailableFilePaths() throws DbFeatureException, SQLException { final DbFeature<IDatabaseConnection> feature = featureExecutor .createApplyCustomScriptFeature(Arrays.asList("test-data.json", "test-data.json")); assertThat(feature, notNullValue()); feature.execute(connection); verify(statement, times(2)).execute(anyString()); }
@Test public void testApplyCustomScriptFeatureExecutionUsingEmpyFile() throws DbFeatureException, IOException, SQLException { final File tmpFile = tmpFolder.newFile(); final DbFeature<IDatabaseConnection> feature = featureExecutor.createApplyCustomScriptFeature(Arrays.asList(tmpFile.getPath())); assertThat(feature, notNullValue()); feature.execute(connection); verify(statement, never()).execute(anyString()); }
@Test(expected = DbFeatureException.class) public void testApplyCustomScriptFeatureExecutionUsingNotAvailableFilePaths() throws DbFeatureException { final DbFeature<IDatabaseConnection> feature = featureExecutor.createApplyCustomScriptFeature(Arrays.asList("test-data1.json")); assertThat(feature, notNullValue()); feature.execute(connection); }