public org.pentaho.di.engine.model.Hop createHop( Operation from, Operation to, String type ) { Preconditions.checkArgument( operations.contains( from ), "!operations.contains(from)" ); Preconditions.checkArgument( operations.contains( to ), "!operations.contains(to)" ); Preconditions.checkArgument( from != to, "from == to" ); org.pentaho.di.engine.model.Hop hop = new org.pentaho.di.engine.model.Hop( from, to, type ); Preconditions.checkState( hops.stream().noneMatch( it -> it.getFrom() == from && it.getTo() == to ), "Hop from %s to %s already exists", from, to ); hops.add( hop ); return hop; }
@Test public void errorHops() throws Exception { TransMeta meta = new TransMeta(); meta.setFilename( "fileName" ); StepMeta from = new StepMeta( "step1", stepMetaInterface ); meta.addStep( from ); StepMeta to = new StepMeta( "step2", stepMetaInterface ); meta.addStep( to ); meta.addTransHop( new TransHopMeta( from, to ) ); StepMeta error = new StepMeta( "errorHandler", stepMetaInterface ); meta.addStep( error ); TransHopMeta errorHop = new TransHopMeta( from, error ); errorHop.setErrorHop( true ); meta.addTransHop( errorHop ); Transformation trans = TransMetaConverter.convert( meta ); Map<String, List<Hop>> hops = trans.getHops().stream().collect( Collectors.groupingBy( Hop::getType ) ); List<Hop> normalHops = hops.get( Hop.TYPE_NORMAL ); assertThat( normalHops.size(), is( 1 ) ); assertThat( normalHops.get( 0 ).getTo().getId(), is( "step2" ) ); List<Hop> errorHops = hops.get( Hop.TYPE_ERROR ); assertThat( errorHops.size(), is( 1 ) ); assertThat( errorHops.get( 0 ).getTo().getId(), is( "errorHandler" ) ); assertThat( hops.values().stream() .flatMap( List::stream ) .map( Hop::getFrom ).map( Operation::getId ) .collect( Collectors.toList() ), everyItem( equalTo( "step1" ) ) ); }
@Test public void testRemovingDisabledInputSteps() { TransMeta trans = new TransMeta(); StepMeta inputToBeRemoved = new StepMeta( "InputToBeRemoved", stepMetaInterface ); trans.addStep( inputToBeRemoved ); StepMeta inputToStay = new StepMeta( "InputToStay", stepMetaInterface ); trans.addStep( inputToStay ); StepMeta inputReceiver1 = new StepMeta( "InputReceiver1", stepMetaInterface ); trans.addStep( inputReceiver1 ); StepMeta inputReceiver2 = new StepMeta( "InputReceiver2", stepMetaInterface ); trans.addStep( inputReceiver2 ); TransHopMeta hop1 = new TransHopMeta( inputToBeRemoved, inputReceiver1, false ); TransHopMeta hop2 = new TransHopMeta( inputToStay, inputReceiver1 ); TransHopMeta hop3 = new TransHopMeta( inputToBeRemoved, inputReceiver2, false ); trans.addTransHop( hop1 ); trans.addTransHop( hop2 ); trans.addTransHop( hop3 ); Transformation transformation = TransMetaConverter.convert( trans ); List<String> steps = transformation.getOperations().stream().map( op -> op.getId() ).collect( Collectors.toList() ); assertThat( "Only 2 ops should exist", steps.size(), is( 2 ) ); assertThat( steps, hasItems( "InputToStay", "InputReceiver1" ) ); List<String> hops = transformation.getHops().stream().map( hop -> hop.getId() ).collect( Collectors.toList() ); assertThat( "Only 1 hop should exist", hops.size(), is( 1 ) ); assertThat( hops, hasItems( "InputToStay -> InputReceiver1" ) ); }
"AfterEnabledDisabled" ) ); List<String> hops = transformation.getHops().stream().map( hop -> hop.getId() ).collect( Collectors.toList() ); assertThat( "Only 4 hops should exist", hops.size(), is( 4 ) ); assertThat( hops, hasItems( "Start -> WithEnabledHop", "WithEnabledHop -> ShouldStay",
@Test public void transWithHops() { TransMeta meta = new TransMeta(); meta.setFilename( "fileName" ); StepMeta from = new StepMeta( "step1", stepMetaInterface ); meta.addStep( from ); StepMeta to = new StepMeta( "step2", stepMetaInterface ); meta.addStep( to ); meta.addTransHop( new TransHopMeta( from, to ) ); Transformation trans = TransMetaConverter.convert( meta ); assertThat( trans.getId(), is( meta.getFilename() ) ); assertThat( trans.getOperations().size(), is( 2 ) ); assertThat( trans.getHops().size(), is( 1 ) ); assertThat( trans.getHops().get( 0 ).getFrom().getId(), is( from.getName() ) ); assertThat( trans.getHops().get( 0 ).getTo().getId(), is( to.getName() ) ); assertThat( trans.getHops().stream().map( Hop::getType ).collect( Collectors.toList() ), everyItem( is( Hop.TYPE_NORMAL ) ) ); }