TransMutators { public static void disableAllUnrelatedHops( final String stepName, final TransMeta serviceTrans, final boolean includeTargetedSteps ) { StepMeta step = serviceTrans.findStep( stepName ); List<TransHopMeta> allHops = IntStream.range( 0, serviceTrans.nrTransHops() ) .mapToObj( serviceTrans::getTransHop ).collect( toList() ); HashSet<TransHopMeta> upstreamHops = new HashSet<>(); findUpstreamHops( upstreamHops, allHops, step, includeTargetedSteps ); if ( upstreamHops.isEmpty() ) { serviceTrans.getSteps().clear(); serviceTrans.addStep( step ); IntStream.generate( () -> 0 ).limit( serviceTrans.nrTransHops() ).forEach( serviceTrans::removeTransHop ); } else { allHops.stream().filter( thm -> !upstreamHops.contains( thm ) ).forEach( thm -> thm.setEnabled( false ) ); } }  static void disableAllUnrelatedHops(
    final String stepName, final TransMeta serviceTrans, final boolean includeTargetedSteps );  }
@Test public void testDisableAllButFirst() throws Exception { TransMeta transMeta = prepareTrans( "Tasty Dishes", ( stepName, serviceTrans ) -> TransMutators.disableAllUnrelatedHops( stepName, serviceTrans, true ) ); assertEquals( 1, transMeta.nrSteps() ); assertEquals( 0, transMeta.nrTransHops() ); }
@Test public void testDisablesAllTheWayDownStream() throws Exception { TransMeta transMeta = prepareTrans( "Write Unfiltered", ( stepName, serviceTrans ) -> TransMutators.disableAllUnrelatedHops( stepName, serviceTrans, true ) ); assertHopsEnabled( transMeta, false, false, false, false, false, false ); }
@Test public void testDisableKeepsRequiredDownstreamSteps() throws Exception { TransMeta transMeta = prepareTrans( "Filter Rows", ( stepName, serviceTrans ) -> TransMutators.disableAllUnrelatedHops( stepName, serviceTrans, true ) ); assertHopsEnabled( transMeta, true, true, true, false, true, true ); }
@Test public void testDisableKeepsIndirectRequiredDownstreamSteps() throws Exception { TransMeta transMeta = prepareTrans( "Write Success", ( stepName, serviceTrans ) -> TransMutators.disableAllUnrelatedHops( stepName, serviceTrans, true ) ); assertHopsEnabled( transMeta, true, true, true, false, true, true ); }
@Test public void testDisableKeepsCycledStep() throws Exception { TransMeta transMeta = prepareTrans( "Map Failures", ( stepName, serviceTrans ) -> TransMutators.disableAllUnrelatedHops( stepName, serviceTrans, true ) ); assertHopsEnabled( transMeta, true, true, true, false, true, true ); }
@Test public void testDisableFromFinalStep() throws Exception { TransMeta transMeta = prepareTrans( "Write Again", ( stepName, serviceTrans ) -> TransMutators.disableAllUnrelatedHops( stepName, serviceTrans, true ) ); assertHopsEnabled( transMeta, true, true, true, true, true, true ); }
@Test public void testDisableWithoutIncludingTargets() throws Exception { TransMeta transMeta = prepareTrans( "Filter Rows", ( stepName, serviceTrans ) -> TransMutators.disableAllUnrelatedHops( stepName, serviceTrans, false ) ); assertHopsEnabled( transMeta, true, false, false, false, true, false ); }