@Test public void testOnServerInstanceUpdatedWithoutCurrentServer() { final ServerTemplate serverTemplate = new ServerTemplate( "ServerTemplateId", "ServerTemplateName" ); final ServerInstance serverInstance = new ServerInstance( serverTemplate.getId(), "serverName", "serverInstanceId", "url", "1.0", Collections.<Message>emptyList(), Collections.<Container>emptyList() ); presenter.onServerInstanceUpdated( new ServerInstanceUpdated( serverInstance ) ); verify(view, never()).addServerInstance( anyString(), anyString(), anyString(), any(Command.class)); }
public void setup( final ServerTemplate serverTemplate, final ContainerSpec firstContainerSpec ) { view.clear(); this.serverTemplate = serverTemplate; view.setTemplate( serverTemplate.getId(), serverTemplate.getName() ); view.setProcessCapability( serverTemplate.getCapabilities().contains( Capability.PROCESS.toString() ) ); view.setRulesCapability( serverTemplate.getCapabilities().contains( Capability.RULE.toString() ) ); view.setPlanningCapability( serverTemplate.getCapabilities().contains( Capability.PLANNING.toString() ) ); if ( firstContainerSpec != null ) { addContainer( firstContainerSpec ); for ( final ContainerSpec containerSpec : serverTemplate.getContainersSpec() ) { if ( !containerSpec.getId().equals( firstContainerSpec.getId() ) ) { addContainer( containerSpec ); } } containerSpecSelectedEvent.fire( new ContainerSpecSelected( firstContainerSpec ) ); } for ( final ServerInstanceKey serverInstanceKey : serverTemplate.getServerInstanceKeys() ) { addServerInstance( serverInstanceKey ); } }
@Test public void testRemoveTemplate() { when( view.getRemoveTemplateErrorMessage() ).thenReturn( "ERROR" ); doAnswer( new Answer<Void>() { @Override public Void answer( final InvocationOnMock invocation ) throws Throwable { Command command = (Command) invocation.getArguments()[ 0 ]; if ( command != null ) { command.execute(); } return null; } } ).when( view ).confirmRemove( any( Command.class ) ); final ServerTemplate serverTemplate = new ServerTemplate( "ServerTemplateKeyId", "ServerTemplateKeyName" ); presenter.setup( serverTemplate, null ); presenter.removeTemplate(); verify( specManagementService ).deleteServerTemplate( serverTemplate.getId() ); verify( serverTemplateListRefreshEvent ).fire( any( ServerTemplateListRefresh.class ) ); doThrow( new RuntimeException() ).when( specManagementService ).deleteServerTemplate( serverTemplate.getId() ); presenter.removeTemplate(); verify( specManagementService, times( 2 ) ).deleteServerTemplate( serverTemplate.getId() ); verify( serverTemplateListRefreshEvent, times( 2 ) ).fire( any( ServerTemplateListRefresh.class ) ); verify( notification ).fire( new NotificationEvent( "ERROR", NotificationEvent.NotificationType.ERROR ) ); }
assertEquals( serverTemplate, presenter.getCurrentServerTemplate() ); verify( view ).clear(); verify( view ).setTemplate( serverTemplate.getId(), serverTemplate.getName() ); verify( view ).setProcessCapability( false ); verify( view ).setRulesCapability( false ); verify( view ).setPlanningCapability( false ); verify( view ).addContainer( eq( containerSpec.getServerTemplateKey().getId() ), eq( containerSpec.getId() ), any( Command.class ) ); verify( view ).addContainer( eq( containerSpec1.getServerTemplateKey().getId() ), eq( containerSpec1.getId() ), assertEquals( containerSpec, selectedCaptor.getValue().getContainerSpecKey() ); verify( view ).addServerInstance( eq( serverInstanceKey.getServerTemplateId() ), eq( serverInstanceKey.getServerInstanceId() ),
@Test public void testOnServerInstanceUpdated() { final ServerTemplate serverTemplate = new ServerTemplate( "ServerTemplateId", "ServerTemplateName" ); presenter.setup( serverTemplate, null ); assertEquals( serverTemplate, presenter.getCurrentServerTemplate() ); final ServerInstance serverInstance = new ServerInstance( serverTemplate.getId(), "serverName", "serverInstanceId", "url", "1.0", Collections.<Message>emptyList(), Collections.<Container>emptyList() ); presenter.onServerInstanceUpdated( new ServerInstanceUpdated( serverInstance ) ); presenter.onServerInstanceUpdated( new ServerInstanceUpdated( serverInstance ) ); verify( view ).addServerInstance( eq( serverInstance.getServerTemplateId() ), eq( serverInstance.getServerInstanceId() ), eq( serverInstance.getServerName() ), any( Command.class ) ); presenter.onServerInstanceDeleted( new ServerInstanceDeleted( serverInstance.getServerInstanceId() ) ); presenter.onServerInstanceUpdated( new ServerInstanceUpdated( serverInstance ) ); verify( view, times( 2 ) ).addServerInstance( eq( serverInstance.getServerTemplateId() ), eq( serverInstance.getServerInstanceId() ), eq( serverInstance.getServerName() ), any( Command.class ) ); }
public void removeTemplate() { view.confirmRemove( new Command() { @Override public void execute() { specManagementService.call( new RemoteCallback<Void>() { @Override public void callback( final Void aVoid ) { serverTemplateListRefreshEvent.fire( new ServerTemplateListRefresh() ); } }, new ErrorCallback<Object>() { @Override public boolean error( final Object o, final Throwable throwable ) { notification.fire( new NotificationEvent( view.getRemoveTemplateErrorMessage(), NotificationEvent.NotificationType.ERROR ) ); serverTemplateListRefreshEvent.fire( new ServerTemplateListRefresh() ); return false; } } ).deleteServerTemplate( serverTemplate.getId() ); } } ); }
@PostConstruct public void init() { view.init( this ); }
@Test public void testOnServerInstanceSelect() { final ServerInstanceKey serverInstanceKey = new ServerInstanceKey( "serverInstanceKeyId", "serverName", "serverInstanceId", "url" ); presenter.onServerInstanceSelect( new ServerInstanceSelected( serverInstanceKey ) ); verify( view ).selectServerInstance( serverInstanceKey.getServerTemplateId(), serverInstanceKey.getServerInstanceId() ); }
@Test public void testSetupCapabilities() { final ServerTemplate serverTemplate = new ServerTemplate( "ServerTemplateKeyId", "ServerTemplateKeyName" ); serverTemplate.getCapabilities().add( Capability.PROCESS.toString() ); serverTemplate.getCapabilities().add( Capability.PLANNING.toString() ); serverTemplate.getCapabilities().add( Capability.RULE.toString() ); presenter.setup( serverTemplate, null ); assertEquals( serverTemplate, presenter.getCurrentServerTemplate() ); verify( view ).clear(); verify( view ).setTemplate( serverTemplate.getId(), serverTemplate.getName() ); verify( view ).setProcessCapability( true ); verify( view ).setRulesCapability( true ); verify( view ).setPlanningCapability( true ); }
public void onServerInstanceSelect( @Observes final ServerInstanceSelected serverInstanceSelected ) { if ( serverInstanceSelected != null && serverInstanceSelected.getServerInstanceKey() != null && serverInstanceSelected.getServerInstanceKey().getServerTemplateId() != null && serverInstanceSelected.getServerInstanceKey().getServerInstanceId() != null ) { view.selectServerInstance( serverInstanceSelected.getServerInstanceKey().getServerTemplateId(), serverInstanceSelected.getServerInstanceKey().getServerInstanceId() ); } else { logger.warn( "Illegal event argument." ); } }
@Test public void testInit() { presenter.init(); verify( view ).init( presenter ); assertEquals( view, presenter.getView() ); }
private void addContainer( final ContainerSpec containerSpec ) { view.addContainer( containerSpec.getServerTemplateKey().getId(), containerSpec.getId(), containerSpec.getContainerName(), new Command() { @Override public void execute() { containerSpecSelectedEvent.fire( new ContainerSpecSelected( containerSpec ) ); } } ); }
public void onContainerSelect( @Observes final ContainerSpecSelected containerSpecSelected ) { if ( containerSpecSelected != null && containerSpecSelected.getContainerSpecKey() != null && containerSpecSelected.getContainerSpecKey().getServerTemplateKey() != null && containerSpecSelected.getContainerSpecKey().getServerTemplateKey().getId() != null && containerSpecSelected.getContainerSpecKey().getId() != null ) { view.selectContainer( containerSpecSelected.getContainerSpecKey().getServerTemplateKey().getId(), containerSpecSelected.getContainerSpecKey().getId() ); } else { logger.warn( "Illegal event argument." ); } }
@Test public void testOnContainerSelect() { final ServerTemplateKey serverTemplateKey = new ServerTemplateKey( "ServerTemplateKeyId", "ServerTemplateKeyName" ); final ContainerSpecKey containerSpecKey = new ContainerSpecKey( "containerId", "containerName", serverTemplateKey ); presenter.onContainerSelect( new ContainerSpecSelected( containerSpecKey ) ); verify( view ).selectContainer( serverTemplateKey.getId(), containerSpecKey.getId() ); }
private void addServerInstance( final ServerInstanceKey serverInstanceKey ) { serverInstances.add( serverInstanceKey.getServerInstanceId() ); view.addServerInstance( serverInstanceKey.getServerTemplateId(), serverInstanceKey.getServerInstanceId(), serverInstanceKey.getServerName(), new Command() { @Override public void execute() { serverInstanceSelectedEvent.fire( new ServerInstanceSelected( serverInstanceKey ) ); } } ); }