@Test public void testRemoveContainer() { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { final Command command = (Command) invocation.getArguments()[0]; if (command != null) { command.execute(); } return null; } }).when(view).confirmRemove(any(Command.class)); final String successMessage = "SUCCESS"; when(view.getRemoveContainerSuccessMessage()).thenReturn(successMessage); presenter.loadContainers(containerSpecData); presenter.removeContainer(); verify(specManagementService).deleteContainerSpec(serverTemplateKey.getId(), containerSpec.getId()); final ArgumentCaptor<NotificationEvent> notificationCaptor = ArgumentCaptor.forClass(NotificationEvent.class); verify(notification).fire(notificationCaptor.capture()); final NotificationEvent event = notificationCaptor.getValue(); assertEquals(NotificationEvent.NotificationType.SUCCESS, event.getType()); assertEquals(successMessage, event.getNotification()); final ArgumentCaptor<ServerTemplateSelected> serverTemplateSelectedCaptor = ArgumentCaptor.forClass(ServerTemplateSelected.class); verify(serverTemplateSelectedEvent).fire(serverTemplateSelectedCaptor.capture()); assertEquals(serverTemplateKey.getId(), serverTemplateSelectedCaptor.getValue().getServerTemplateKey().getId()); final String errorMessage = "ERROR"; when(view.getRemoveContainerErrorMessage()).thenReturn(errorMessage); doThrow(new RuntimeException()).when(specManagementService).deleteContainerSpec(serverTemplateKey.getId(), containerSpec.getId()); presenter.removeContainer(); verify(notification).fire(new NotificationEvent(errorMessage, NotificationEvent.NotificationType.ERROR)); verify(serverTemplateSelectedEvent, times(2)).fire(new ServerTemplateSelected(containerSpec.getServerTemplateKey())); }
public void removeContainer() { view.confirmRemove(new Command() { @Override public void execute() { specManagementService.call(new RemoteCallback<Void>() { @Override public void callback(final Void response) { notification.fire(new NotificationEvent(view.getRemoveContainerSuccessMessage(), NotificationEvent.NotificationType.SUCCESS)); serverTemplateSelectedEvent.fire(new ServerTemplateSelected(containerSpec.getServerTemplateKey())); } }, new ErrorCallback<Object>() { @Override public boolean error(final Object o, final Throwable throwable) { notification.fire(new NotificationEvent(view.getRemoveContainerErrorMessage(), NotificationEvent.NotificationType.ERROR)); serverTemplateSelectedEvent.fire(new ServerTemplateSelected(containerSpec.getServerTemplateKey())); return false; } }).deleteContainerSpec(containerSpec.getServerTemplateKey().getId(), containerSpec.getId()); } }); }
ContainerPresenter { public void removeContainer() { view.confirmRemove(new Command() { @Override public void execute() { specManagementService.call(new RemoteCallback<Void>() { @Override public void callback(final Void response) { notification.fire(new NotificationEvent(view.getRemoveContainerSuccessMessage(), NotificationEvent.NotificationType.SUCCESS)); serverTemplateSelectedEvent.fire(new ServerTemplateSelected(containerSpec.getServerTemplateKey())); } }, new ErrorCallback<Object>() { @Override public boolean error(final Object o, final Throwable throwable) { notification.fire(new NotificationEvent(view.getRemoveContainerErrorMessage(), NotificationEvent.NotificationType.ERROR)); serverTemplateSelectedEvent.fire(new ServerTemplateSelected(containerSpec.getServerTemplateKey())); return false; } }).deleteContainerSpec(containerSpec.getServerTemplateKey().getId(), containerSpec.getId()); } }); } }
ContainerPresenter { public void removeContainer() { view.confirmRemove(new Command() { @Override public void execute() { specManagementService.call(new RemoteCallback<Void>() { @Override public void callback(final Void response) { notification.fire(new NotificationEvent(view.getRemoveContainerSuccessMessage(), NotificationEvent.NotificationType.SUCCESS)); serverTemplateSelectedEvent.fire(new ServerTemplateSelected(containerSpec.getServerTemplateKey())); } }, new ErrorCallback<Object>() { @Override public boolean error(final Object o, final Throwable throwable) { notification.fire(new NotificationEvent(view.getRemoveContainerErrorMessage(), NotificationEvent.NotificationType.ERROR)); serverTemplateSelectedEvent.fire(new ServerTemplateSelected(containerSpec.getServerTemplateKey())); return false; } }).deleteContainerSpec(containerSpec.getServerTemplateKey().getId(), containerSpec.getId()); } }); } @Inject  ContainerPresenter(final Logger logger,
                              final View view,
                              final ContainerRemoteStatusPresenter containerRemoteStatusPresenter,
                              final ContainerStatusEmptyPresenter containerStatusEmptyPresenter,
                              final ContainerProcessConfigPresenter containerProcessConfigPresenter,
                              final ContainerRulesConfigPresenter containerRulesConfigPresenter,
                              final Caller<RuntimeManagementService> runtimeManagementService,
                              final Caller<SpecManagementService> specManagementService,
                              final Event<ServerTemplateSelected> serverTemplateSelectedEvent,
                              final Event<NotificationEvent> notification); }
ContainerPresenter { public void removeContainer() { view.confirmRemove(new Command() { @Override public void execute() { specManagementService.call(new RemoteCallback<Void>() { @Override public void callback(final Void response) { notification.fire(new NotificationEvent(view.getRemoveContainerSuccessMessage(), NotificationEvent.NotificationType.SUCCESS)); serverTemplateSelectedEvent.fire(new ServerTemplateSelected(containerSpec.getServerTemplateKey())); } }, new ErrorCallback<Object>() { @Override public boolean error(final Object o, final Throwable throwable) { notification.fire(new NotificationEvent(view.getRemoveContainerErrorMessage(), NotificationEvent.NotificationType.ERROR)); serverTemplateSelectedEvent.fire(new ServerTemplateSelected(containerSpec.getServerTemplateKey())); return false; } }).deleteContainerSpec(containerSpec.getServerTemplateKey().getId(), containerSpec.getId()); } }); } @Inject  ContainerPresenter(final Logger logger,
                              final View view,
                              final ContainerRemoteStatusPresenter containerRemoteStatusPresenter,
                              final ContainerStatusEmptyPresenter containerStatusEmptyPresenter,
                              final ContainerProcessConfigPresenter containerProcessConfigPresenter,
                              final ContainerRulesConfigPresenter containerRulesConfigPresenter,
                              final Caller<RuntimeManagementService> runtimeManagementService,
                              final Caller<SpecManagementService> specManagementService,
                              final Event<ServerTemplateSelected> serverTemplateSelectedEvent,
                              final Event<NotificationEvent> notification); @PostConstruct void init(); View getView(); void onRefresh(@Observes final RefreshRemoteServers refresh); void load(@Observes final ContainerSpecSelected containerSpecSelected); void onInstanceUpdated(@Observes ServerInstanceUpdated instanceUpdated); void loadContainers(@Observes final ContainerSpecData content); void refreshOnContainerUpdateEvent(@Observes final ContainerUpdateEvent updateEvent); void refresh(); void load(final ContainerSpecKey containerSpecKey); void removeContainer(); void stopContainer(); void startContainer(); void toggleActivationContainer(); }
ContainerPresenter { public void removeContainer() { view.confirmRemove(new Command() { @Override public void execute() { specManagementService.call(new RemoteCallback<Void>() { @Override public void callback(final Void response) { notification.fire(new NotificationEvent(view.getRemoveContainerSuccessMessage(), NotificationEvent.NotificationType.SUCCESS)); serverTemplateSelectedEvent.fire(new ServerTemplateSelected(containerSpec.getServerTemplateKey())); } }, new ErrorCallback<Object>() { @Override public boolean error(final Object o, final Throwable throwable) { notification.fire(new NotificationEvent(view.getRemoveContainerErrorMessage(), NotificationEvent.NotificationType.ERROR)); serverTemplateSelectedEvent.fire(new ServerTemplateSelected(containerSpec.getServerTemplateKey())); return false; } }).deleteContainerSpec(containerSpec.getServerTemplateKey().getId(), containerSpec.getId()); } }); } @Inject  ContainerPresenter(final Logger logger,
                              final View view,
                              final ContainerRemoteStatusPresenter containerRemoteStatusPresenter,
                              final ContainerStatusEmptyPresenter containerStatusEmptyPresenter,
                              final ContainerProcessConfigPresenter containerProcessConfigPresenter,
                              final ContainerRulesConfigPresenter containerRulesConfigPresenter,
                              final Caller<RuntimeManagementService> runtimeManagementService,
                              final Caller<SpecManagementService> specManagementService,
                              final Event<ServerTemplateSelected> serverTemplateSelectedEvent,
                              final Event<NotificationEvent> notification); @PostConstruct void init(); View getView(); void onRefresh(@Observes final RefreshRemoteServers refresh); void load(@Observes final ContainerSpecSelected containerSpecSelected); void onInstanceUpdated(@Observes ServerInstanceUpdated instanceUpdated); void loadContainers(@Observes final ContainerSpecData content); void refreshOnContainerUpdateEvent(@Observes final ContainerUpdateEvent updateEvent); void refresh(); void load(final ContainerSpecKey containerSpecKey); void removeContainer(); void stopContainer(); void startContainer(); void toggleActivationContainer();  }