Search in sources :

Example 1 with ServerTemplateListRefresh

use of org.kie.workbench.common.screens.server.management.client.events.ServerTemplateListRefresh in project kie-wb-common by kiegroup.

the class ServerTemplatePresenterTest method testCopyTemplate.

@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());
}
Also used : ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ServerTemplateListRefresh(org.kie.workbench.common.screens.server.management.client.events.ServerTemplateListRefresh) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Test(org.junit.Test)

Example 2 with ServerTemplateListRefresh

use of org.kie.workbench.common.screens.server.management.client.events.ServerTemplateListRefresh in project kie-wb-common by kiegroup.

the class NewServerTemplateWizard method complete.

@Override
public void complete() {
    final ServerTemplate newServerTemplate = buildServerTemplate();
    specManagementService.call(new RemoteCallback<Void>() {

        @Override
        public void callback(final Void o) {
            notification.fire(new NotificationEvent(newTemplatePresenter.getView().getNewServerTemplateWizardSaveSuccess(), NotificationEvent.NotificationType.SUCCESS));
            clear();
            NewServerTemplateWizard.super.complete();
            serverTemplateListRefreshEvent.fire(new ServerTemplateListRefresh(newServerTemplate.getId()));
        }
    }, new ErrorCallback<Object>() {

        @Override
        public boolean error(final Object o, final Throwable throwable) {
            notification.fire(new NotificationEvent(newTemplatePresenter.getView().getNewServerTemplateWizardSaveError(), NotificationEvent.NotificationType.ERROR));
            NewServerTemplateWizard.this.pageSelected(0);
            NewServerTemplateWizard.this.start();
            return false;
        }
    }).saveServerTemplate(newServerTemplate);
}
Also used : ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) ErrorCallback(org.jboss.errai.common.client.api.ErrorCallback) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) ServerTemplateListRefresh(org.kie.workbench.common.screens.server.management.client.events.ServerTemplateListRefresh) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback)

Example 3 with ServerTemplateListRefresh

use of org.kie.workbench.common.screens.server.management.client.events.ServerTemplateListRefresh in project kie-wb-common by kiegroup.

the class NewServerTemplateWizardTest method testComplete.

@Test
public void testComplete() {
    when(newTemplatePresenter.isProcessCapabilityChecked()).thenReturn(true);
    when(newContainerFormPresenter.isEmpty()).thenReturn(true);
    when(newContainerFormPresenter.isEmpty()).thenReturn(true);
    when(newTemplatePresenter.getTemplateName()).thenReturn("template-name");
    final String successMessage = "SUCCESS";
    when(newTemplatePresenterView.getNewServerTemplateWizardSaveSuccess()).thenReturn(successMessage);
    newServerTemplateWizard.complete();
    verify(notification).fire(new NotificationEvent(successMessage, NotificationEvent.NotificationType.SUCCESS));
    verifyClear();
    verify(serverTemplateListRefreshEvent).fire(new ServerTemplateListRefresh("template-name"));
    doThrow(new RuntimeException()).when(specManagementService).saveServerTemplate(any(ServerTemplate.class));
    final String errorMessage = "ERROR";
    when(newTemplatePresenterView.getNewServerTemplateWizardSaveError()).thenReturn(errorMessage);
    newServerTemplateWizard.complete();
    verify(notification).fire(new NotificationEvent(errorMessage, NotificationEvent.NotificationType.ERROR));
    verify(newServerTemplateWizard).pageSelected(0);
    verify(newServerTemplateWizard).start();
    verify(newContainerFormPresenter).initialise();
}
Also used : ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) ServerTemplateListRefresh(org.kie.workbench.common.screens.server.management.client.events.ServerTemplateListRefresh) Test(org.junit.Test)

Aggregations

ServerTemplate (org.kie.server.controller.api.model.spec.ServerTemplate)3 ServerTemplateListRefresh (org.kie.workbench.common.screens.server.management.client.events.ServerTemplateListRefresh)3 Test (org.junit.Test)2 NotificationEvent (org.uberfire.workbench.events.NotificationEvent)2 ErrorCallback (org.jboss.errai.common.client.api.ErrorCallback)1 RemoteCallback (org.jboss.errai.common.client.api.RemoteCallback)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 ParameterizedCommand (org.uberfire.mvp.ParameterizedCommand)1