@Test
public void testCopyTemplate() {
final String newTemplateName = "NewTemplateName";
doAnswer( new Answer<Void>() {
@Override
public Void answer( final InvocationOnMock invocation ) throws Throwable {
final ParameterizedCommand command = (ParameterizedCommand) invocation.getArguments()[ 0 ];
if ( command != null ) {
command.execute( newTemplateName );
}
return null;
}
} ).when( copyPresenter ).copy( any( ParameterizedCommand.class ) );
final ServerTemplate serverTemplate = new ServerTemplate( "ServerTemplateKeyId", "ServerTemplateKeyName" );
presenter.setup( serverTemplate, null );
assertEquals( serverTemplate, presenter.getCurrentServerTemplate() );
presenter.copyTemplate();
verify( specManagementService ).copyServerTemplate( serverTemplate.getId(), newTemplateName, newTemplateName );
verify( copyPresenter ).hide();
final ArgumentCaptor<ServerTemplateListRefresh> serverTemplateCaptor = ArgumentCaptor.forClass( ServerTemplateListRefresh.class );
verify( serverTemplateListRefreshEvent ).fire( serverTemplateCaptor.capture() );
assertEquals( newTemplateName, serverTemplateCaptor.getValue().getSelectServerTemplateId() );
doThrow( new RuntimeException() ).when( specManagementService ).copyServerTemplate( serverTemplate.getId(), newTemplateName, newTemplateName );
presenter.copyTemplate();
verify( specManagementService, times( 2 ) ).copyServerTemplate( serverTemplate.getId(), newTemplateName, newTemplateName );
verify( copyPresenter ).errorDuringProcessing( anyString() );
}