HadoopClusterDelegateImpl extends SpoonDelegate { public String newNamedCluster( VariableSpace variableSpace, IMetaStore metaStore, Shell shell ) { if ( metaStore == null ) { metaStore = spoon.getMetaStore(); } NamedCluster nc = namedClusterService.getClusterTemplate(); NamedClusterDialogImpl namedClusterDialogImpl = commonDialogFactory .createNamedClusterDialog( shell, namedClusterService, runtimeTestActionService, runtimeTester, nc ); namedClusterDialogImpl.setNewClusterCheck( true ); String result = namedClusterDialogImpl.open(); if ( result != null ) { if ( variableSpace != null ) { nc.shareVariablesWith( (VariableSpace) variableSpace ); } else { nc.initializeVariablesFrom( null ); } try { saveNamedCluster( metaStore, nc ); addConfigProperties( nc ); } catch ( Exception e ) { commonDialogFactory.createErrorDialog( spoon.getShell(), BaseMessages.getString( PKG, SPOON_DIALOG_ERROR_SAVING_NAMED_CLUSTER_TITLE ), BaseMessages.getString( PKG, SPOON_DIALOG_ERROR_SAVING_NAMED_CLUSTER_MESSAGE, nc.getName() ), e ); spoon.refreshTree(); return nc.getName(); } spoon.refreshTree( STRING_NAMED_CLUSTERS ); return nc.getName(); } return null; } HadoopClusterDelegateImpl( Spoon spoon, NamedClusterService namedClusterService,
                                    RuntimeTestActionService runtimeTestActionService, RuntimeTester runtimeTester );  HadoopClusterDelegateImpl( Spoon spoon, NamedClusterService namedClusterService,
                                    RuntimeTestActionService runtimeTestActionService, RuntimeTester runtimeTester,
                                    CommonDialogFactory commonDialogFactory ); void dupeNamedCluster( IMetaStore metaStore, NamedCluster nc, Shell shell ); void delNamedCluster( IMetaStore metaStore, NamedCluster namedCluster ); String editNamedCluster( IMetaStore metaStore, NamedCluster namedCluster, Shell shell ); String newNamedCluster( VariableSpace variableSpace, IMetaStore metaStore, Shell shell ); static final String SPOON_DIALOG_ERROR_DELETING_NAMED_CLUSTER_TITLE; static final String SPOON_DIALOG_ERROR_DELETING_NAMED_CLUSTER_MESSAGE; static final String SPOON_VARIOUS_DUPE_NAME; static final String SPOON_DIALOG_ERROR_SAVING_NAMED_CLUSTER_TITLE; static final String SPOON_DIALOG_ERROR_SAVING_NAMED_CLUSTER_MESSAGE; static Class<?> PKG; static final String STRING_NAMED_CLUSTERS; static final String SPOON_DIALOG_ERROR_ADDING_NEW_CONFIGURATION_FOR_CLUSTER_TITLE; static final String SPOON_DIALOG_ERROR_ADDING_NEW_CONFIGURATION_FOR_CLUSTER_MESSAGE; static final String SPOON_DIALOG_ERROR_RENAMING_PREVIOUS_CLUSTER_CONFIG_TITLE; static final String SPOON_DIALOG_ERROR_RENAMING_PREVIOUS_CLUSTER_CONFIG_MESSAGE; }
@Test public void testNewNamedClusterNullMetastore() throws MetaStoreException { DelegatingMetaStore spoonMetastore = mock( DelegatingMetaStore.class ); when( spoon.getMetaStore() ).thenReturn( spoonMetastore ); when( namedClusterService.getClusterTemplate() ).thenReturn( namedCluster ); NamedClusterDialogImpl namedClusterDialog = mock( NamedClusterDialogImpl.class ); when( commonDialogFactory .createNamedClusterDialog( shell, namedClusterService, runtimeTestActionService, runtimeTester, namedCluster ) ).thenReturn( namedClusterDialog ); when( namedClusterDialog.open() ).thenReturn( namedClusterName ); assertEquals( namedClusterName, hadoopClusterDelegate.newNamedCluster( variables, null, shell ) ); verify( namedClusterDialog ).setNewClusterCheck( true ); verify( namedCluster ).shareVariablesWith( variables ); verify( namedClusterService ).create( namedCluster, spoonMetastore ); verify( spoon ).refreshTree( HadoopClusterDelegateImpl.STRING_NAMED_CLUSTERS ); }
@Test public void testNewNamedClusterNullVariables() throws MetaStoreException { when( namedClusterService.getClusterTemplate() ).thenReturn( namedCluster ); NamedClusterDialogImpl namedClusterDialog = mock( NamedClusterDialogImpl.class ); when( commonDialogFactory .createNamedClusterDialog( shell, namedClusterService, runtimeTestActionService, runtimeTester, namedCluster ) ).thenReturn( namedClusterDialog ); when( namedClusterDialog.open() ).thenReturn( namedClusterName ); assertEquals( namedClusterName, hadoopClusterDelegate.newNamedCluster( null, metaStore, shell ) ); verify( namedClusterDialog ).setNewClusterCheck( true ); verify( namedCluster ).initializeVariablesFrom( null ); verify( namedClusterService ).create( namedCluster, metaStore ); verify( spoon ).refreshTree( HadoopClusterDelegateImpl.STRING_NAMED_CLUSTERS ); }
@Test public void testNewNamedClusterNullResult() throws MetaStoreException { when( namedClusterService.getClusterTemplate() ).thenReturn( namedCluster ); NamedClusterDialogImpl namedClusterDialog = mock( NamedClusterDialogImpl.class ); when( commonDialogFactory .createNamedClusterDialog( shell, namedClusterService, runtimeTestActionService, runtimeTester, namedCluster ) ).thenReturn( namedClusterDialog ); when( namedClusterDialog.open() ).thenReturn( null ); assertNull( hadoopClusterDelegate.newNamedCluster( null, metaStore, shell ) ); verify( namedClusterDialog ).setNewClusterCheck( true ); verify( namedClusterService, times( 0 ) ).create( any( NamedCluster.class ), any( IMetaStore.class ) ); verify( spoon, times( 0 ) ).refreshTree( HadoopClusterDelegateImpl.STRING_NAMED_CLUSTERS ); }
@Test public void testNewNamedClusterErrorSaving() throws MetaStoreException { when( namedClusterService.getClusterTemplate() ).thenReturn( namedCluster ); NamedClusterDialogImpl namedClusterDialog = mock( NamedClusterDialogImpl.class ); when( commonDialogFactory .createNamedClusterDialog( shell, namedClusterService, runtimeTestActionService, runtimeTester, namedCluster ) ).thenReturn( namedClusterDialog ); when( namedClusterDialog.open() ).thenReturn( namedClusterName ); MetaStoreException metaStoreException = new MetaStoreException(); doThrow( metaStoreException ).when( namedClusterService ).create( namedCluster, metaStore ); hadoopClusterDelegate.newNamedCluster( variables, metaStore, shell ); verify( commonDialogFactory ).createErrorDialog( shell, BaseMessages.getString( PKG, SPOON_DIALOG_ERROR_SAVING_NAMED_CLUSTER_TITLE ), BaseMessages.getString( PKG, SPOON_DIALOG_ERROR_SAVING_NAMED_CLUSTER_MESSAGE, namedCluster.getName() ), metaStoreException ); }