DataServiceStepDeleteExtensionPointPlugin implements ExtensionPointInterface { @Override public void callExtensionPoint( LogChannelInterface log, Object object ) throws KettleException { if ( object != null && object instanceof StepMeta[] ) { StepMeta[] stepsToBeRemoved = (StepMeta[]) object; TransMeta trans = stepsToBeRemoved[0].getParentTransMeta(); List<String> stepsToBeRemovedNames = new ArrayList<>( stepsToBeRemoved.length ); for ( StepMeta step : stepsToBeRemoved ) { stepsToBeRemovedNames.add( step.getName() ); } List<String> transSteps = Arrays.asList( trans.getStepNames() ); List<String> remainingStepNames = ListUtils.subtract( transSteps, stepsToBeRemovedNames ); for ( StepMeta stepToBeRemoved : stepsToBeRemoved ) { DataServiceMeta dataService = dataServiceDelegate .getDataServiceByStepName( stepToBeRemoved.getParentTransMeta(), stepToBeRemoved.getName() ); if ( dataService != null ) { List<String> dataServiceSteps = new ArrayList<>(); for ( DataServiceMeta ds : dataServiceDelegate.getDataServices( stepToBeRemoved.getParentTransMeta() ) ) { dataServiceSteps.add( ds.getStepname() ); } switch ( dataServiceDelegate.showRemapConfirmationDialog( dataService, ListUtils.subtract( remainingStepNames, dataServiceSteps ) ) ) { case CANCEL: throw new KettleException( "Steps deletion cancelled by user" ); case REMAP: if ( dataServiceDelegate .showRemapStepChooserDialog( dataService, ListUtils.subtract( remainingStepNames, dataServiceSteps ), trans ) == DataServiceRemapStepChooserDialog.Action.CANCEL ) { throw new KettleException( "Steps deletion cancelled by user" ); } break; case DELETE: context.removeServiceTransExecutor( dataService.getName() ); context.getDataServiceDelegate().removeDataService( dataService ); break; } } } } } DataServiceStepDeleteExtensionPointPlugin( DataServiceContext context ); @Override void callExtensionPoint( LogChannelInterface log, Object object );  }
@Test public void testCallExtensionPoint() throws Exception { DataServiceContext context = mock( DataServiceContext.class ); TransMeta trans = mock( TransMeta.class ); DataServiceDelegate delegate = mock( DataServiceDelegate.class ); when( context.getDataServiceDelegate() ).thenReturn( delegate ); when( delegate.showRemapConfirmationDialog( any( DataServiceMeta.class ), anyList() ) ).thenReturn( DataServiceRemapConfirmationDialog.Action.CANCEL, DataServiceRemapConfirmationDialog.Action.REMAP, DataServiceRemapConfirmationDialog.Action.DELETE ); when( delegate.showRemapStepChooserDialog( any( DataServiceMeta.class ), anyList(), any( TransMeta.class ) ) ) .thenReturn( DataServiceRemapStepChooserDialog.Action.CANCEL ); StepMeta step1 = mock( StepMeta.class ); when( step1.getParentTransMeta() ).thenReturn( trans ); when( step1.getName() ).thenReturn( "Step1" ); when( trans.getStepNames() ).thenReturn( new String[] { "Step1" } ); DataServiceMeta dataService = mock( DataServiceMeta.class ); when( dataService.getStepname() ).thenReturn( "Step1" ); when( delegate.getDataServices( trans ) ).thenReturn( Arrays.asList( dataService ) ); when( delegate.getDataServiceByStepName( trans, "Step1" ) ).thenReturn( dataService ); StepMeta[] steps = new StepMeta[] { step1 }; DataServiceStepDeleteExtensionPointPlugin plugin = new DataServiceStepDeleteExtensionPointPlugin( context ); try { plugin.callExtensionPoint( null, steps ); } catch ( KettleException ke ) { } verify( delegate, times( 0 ) ) .showRemapStepChooserDialog( any( DataServiceMeta.class ), anyList(), any( TransMeta.class ) ); try { plugin.callExtensionPoint( null, steps ); } catch ( KettleException ke ) { } verify( delegate, times( 1 ) ) .showRemapStepChooserDialog( any( DataServiceMeta.class ), anyList(), any( TransMeta.class ) ); plugin.callExtensionPoint( null, steps ); verify( delegate, times( 1 ) ).removeDataService( dataService ); verify( context, times( 1 ) ).removeServiceTransExecutor( dataService.getName() ); }