Neo4JDbFeatureExecutor extends AbstractDbFeatureExecutor<Graph<Node, Edge>, Connection> { @Override protected DbFeature<Connection> createApplyCustomScriptFeature(final List<String> scriptPaths) { return (final Connection connection) -> { try { for (final String scriptPath : scriptPaths) { executeScript(loadScript(scriptPath), connection); } connection.commit(); } catch (IOException | URISyntaxException | SQLException e) { throw new DbFeatureException("Could not apply custom scripts feature", e); } }; } protected  Neo4JDbFeatureExecutor(final FeatureResolver featureResolver, final List<Class<?>> entityClasses);   }
@Test public void testApplyCustomScriptFeatureExecutionUsingAvailableFilePaths() throws DbFeatureException, SQLException { final DbFeature<Connection> feature = featureExecutor.createApplyCustomScriptFeature(Arrays.asList("test.script", "test.script")); assertThat(feature, notNullValue()); feature.execute(connection); verify(connection, times(2)).prepareStatement(any(String.class)); verify(ps, times(2)).execute(); verify(ps, times(2)).close(); }
@Test public void testApplyCustomScriptFeatureExecutionHandlesSQLExceptionsProperly() throws DbFeatureException, SQLException { when(ps.execute()).thenThrow(new SQLException("error")); final DbFeature<Connection> feature = featureExecutor.createApplyCustomScriptFeature(Arrays.asList("test.script")); assertThat(feature, notNullValue()); try { feature.execute(connection); fail("exception expected"); } catch (final DbFeatureException e) { } verify(connection).prepareStatement(any(String.class)); verify(ps).execute(); verify(ps).close(); }
@Test public void testApplyCustomScriptFeatureExecutionUsingEmpyFile() throws DbFeatureException, IOException, SQLException { final File tmpFile = tmpFolder.newFile(); final DbFeature<Connection> feature = featureExecutor.createApplyCustomScriptFeature(Arrays.asList(tmpFile.getPath())); assertThat(feature, notNullValue()); feature.execute(connection); verify(connection, never()).prepareStatement(anyString()); }
@Test(expected = DbFeatureException.class) public void testApplyCustomScriptFeatureExecutionUsingNotAvailableFilePaths() throws DbFeatureException { final DbFeature<Connection> feature = featureExecutor.createApplyCustomScriptFeature(Arrays.asList("test-data1.xml")); assertThat(feature, notNullValue()); feature.execute(connection); }