HadoopClusterDelegateImpl extends SpoonDelegate { public String editNamedCluster( IMetaStore metaStore, NamedCluster namedCluster, Shell shell ) { if ( metaStore == null ) { metaStore = spoon.getMetaStore(); } NamedClusterDialogImpl namedClusterDialogImpl = commonDialogFactory.createNamedClusterDialog( shell, namedClusterService, runtimeTestActionService, runtimeTester, namedCluster.clone() ); namedClusterDialogImpl.setNewClusterCheck( false ); String result = namedClusterDialogImpl.open(); if ( result == null ) { return null; } NamedCluster selectedNamedCluster = namedClusterDialogImpl.getNamedCluster(); saveNamedCluster( metaStore, selectedNamedCluster ); String previousNamedClusterName = namedCluster.getName(); String selectedNamedClusterName = selectedNamedCluster.getName(); String previousShimIdentifier = namedCluster.getShimIdentifier(); String selectedShimIdentifier = selectedNamedCluster.getShimIdentifier(); if ( !previousShimIdentifier.equals( selectedShimIdentifier ) ) { backupAndAddShimConfiguration( metaStore, namedCluster, selectedNamedCluster ); } if ( previousNamedClusterName != null && previousNamedClusterName.equals( selectedNamedClusterName ) ) { return selectedNamedClusterName; } XmlMetaStore xmlMetaStore; try { xmlMetaStore = getXmlMetastore( metaStore ); } catch ( MetaStoreException ex ) { xmlMetaStore = null; } File source = new File( getNamedClusterConfigsRootDir( xmlMetaStore ) + File.separator + previousNamedClusterName ); File destination = new File( getNamedClusterConfigsRootDir( xmlMetaStore ) + File.separator + selectedNamedClusterName ); try { FileUtils.copyDirectory( source, destination ); } catch ( IOException ex ) { } deleteNamedCluster( metaStore, namedCluster ); String shimIdentifier = namedClusterDialogImpl.getNamedCluster().getShimIdentifier(); if ( !namedCluster.getShimIdentifier().equals( shimIdentifier ) ) { try { addConfigProperties( namedClusterDialogImpl.getNamedCluster() ); } catch ( Exception e ) { } } spoon.refreshTree( STRING_NAMED_CLUSTERS ); if ( namedClusterDialogImpl.getNamedCluster() != null ) { return namedClusterDialogImpl.getNamedCluster().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 testEditNamedClusterNullMetastore() throws MetaStoreException { DelegatingMetaStore spoonMetastore = mock( DelegatingMetaStore.class ); when( spoon.getMetaStore() ).thenReturn( spoonMetastore ); NamedClusterDialogImpl namedClusterDialog = mock( NamedClusterDialogImpl.class ); NamedCluster clonedNamedCluster = mock( NamedCluster.class ); when( namedClusterService.read( namedClusterName, spoonMetastore ) ).thenReturn( namedCluster ); when( namedCluster.clone() ).thenReturn( clonedNamedCluster ); String shimId = "shimId"; when( namedCluster.getShimIdentifier() ).thenReturn( shimId ); when( commonDialogFactory .createNamedClusterDialog( shell, namedClusterService, runtimeTestActionService, runtimeTester, clonedNamedCluster ) ).thenReturn( namedClusterDialog ); String clonedName = "clonedName"; when( clonedNamedCluster.getName() ).thenReturn( clonedName ); when( clonedNamedCluster.getShimIdentifier() ).thenReturn( shimId ); when( namedClusterDialog.open() ).thenReturn( clonedName ); when( namedClusterDialog.getNamedCluster() ).thenReturn( clonedNamedCluster ); assertEquals( clonedName, hadoopClusterDelegate.editNamedCluster( null, namedCluster, shell ) ); verify( namedClusterDialog ).setNewClusterCheck( false ); verify( spoon ).refreshTree( HadoopClusterDelegateImpl.STRING_NAMED_CLUSTERS ); verify( namedClusterService ).create( clonedNamedCluster, spoonMetastore ); }
@Test public void testEditNamedClusterNull() throws MetaStoreException { NamedClusterDialogImpl namedClusterDialog = mock( NamedClusterDialogImpl.class ); NamedCluster clonedNamedCluster = mock( NamedCluster.class ); when( namedClusterService.read( namedClusterName, metaStore ) ).thenReturn( namedCluster ); when( namedCluster.clone() ).thenReturn( clonedNamedCluster ); when( commonDialogFactory .createNamedClusterDialog( shell, namedClusterService, runtimeTestActionService, runtimeTester, clonedNamedCluster ) ).thenReturn( namedClusterDialog ); when( namedClusterDialog.open() ).thenReturn( null ); hadoopClusterDelegate.editNamedCluster( metaStore, namedCluster, shell ); verify( namedClusterDialog ).setNewClusterCheck( false ); verifyNoMoreInteractions( namedClusterService ); }