DataServiceTreeDelegateExtension implements ExtensionPointInterface { @Override public void callExtensionPoint( LogChannelInterface log, Object extension ) throws KettleException { SpoonTreeDelegateExtension treeDelExt = (SpoonTreeDelegateExtension) extension; int caseNumber = treeDelExt.getCaseNumber(); if ( !( treeDelExt.getTransMeta() instanceof TransMeta ) ) { return; } TransMeta transMeta = (TransMeta) treeDelExt.getTransMeta(); String[] path = treeDelExt.getPath(); List<TreeSelection> objects = treeDelExt.getObjects(); TreeSelection object = null; if ( path[2].equals( STRING_DATA_SERVICES ) ) { switch ( caseNumber ) { case 3: object = new TreeSelection( path[2], DataServiceMeta.class, transMeta ); break; case 4: try { DataServiceMeta dataService = metaStoreUtil.getDataService( path[3], transMeta ); object = new TreeSelection( path[ 3 ], dataService, transMeta ); } catch ( Exception e ) { } break; } } if ( object != null ) { objects.add( object ); } } DataServiceTreeDelegateExtension( DataServiceContext context ); @Override void callExtensionPoint( LogChannelInterface log, Object extension ); static final String STRING_DATA_SERVICES; }
@Test public void testCallExtensionPoint() throws Exception { List<TreeSelection> objects = new ArrayList<>(); String[] path = new String[] { "/", "/", DataServiceTreeDelegateExtension.STRING_DATA_SERVICES, "" }; when( spoonTreeDelegateExtension.getCaseNumber() ).thenReturn( CASE_NUMBER_THREE ); when( spoonTreeDelegateExtension.getTransMeta() ).thenReturn( transMeta ); when( spoonTreeDelegateExtension.getPath() ).thenReturn( path ); when( spoonTreeDelegateExtension.getObjects() ).thenReturn( objects ); dataServiceTreeDelegateExtension.callExtensionPoint( log, spoonTreeDelegateExtension ); when( spoonTreeDelegateExtension.getCaseNumber() ).thenReturn( CASE_NUMBER_FOUR ); when( metaStoreUtil.getDataService( "", transMeta ) ).thenReturn( dataServiceMeta ); dataServiceTreeDelegateExtension.callExtensionPoint( log, spoonTreeDelegateExtension ); verify( spoonTreeDelegateExtension, times( 2 ) ).getCaseNumber(); verify( spoonTreeDelegateExtension, times( 2 ) ).getPath(); assertThat( objects.isEmpty(), is( false ) ); }