Search in sources :

Example 66 with Command

use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.

the class NewFileUploaderTest method testCreateFailure.

@Test
public void testCreateFailure() {
    final ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
    uploader.create(pkg, "file", presenter);
    verify(moduleService, times(1)).resolveDefaultPath(pkg, "txt");
    verify(busyIndicatorView, times(1)).showBusyIndicator(any(String.class));
    verify(options, times(1)).upload(any(Command.class), commandArgumentCaptor.capture());
    // Emulate a successful upload
    final Command command = commandArgumentCaptor.getValue();
    assertNotNull(command);
    command.execute();
    verify(busyIndicatorView, times(1)).hideBusyIndicator();
    verify(presenter, never()).complete();
    verify(placeManager, never()).goTo(any(Path.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) Command(org.uberfire.mvp.Command) Test(org.junit.Test)

Example 67 with Command

use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.

the class NewFileUploaderTest method testCreateSuccess.

@Test
public void testCreateSuccess() {
    final ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
    final ArgumentCaptor<Path> pathArgumentCaptor = ArgumentCaptor.forClass(Path.class);
    final ArgumentCaptor<NewResourceSuccessEvent> newResourceSuccessEventArgumentCaptor = ArgumentCaptor.forClass(NewResourceSuccessEvent.class);
    uploader.create(pkg, "file", presenter);
    verify(moduleService, times(1)).resolveDefaultPath(pkg, "txt");
    verify(busyIndicatorView, times(1)).showBusyIndicator(any(String.class));
    verify(options, times(1)).upload(commandArgumentCaptor.capture(), any(Command.class));
    // Emulate a successful upload
    final Command command = commandArgumentCaptor.getValue();
    assertNotNull(command);
    command.execute();
    verify(busyIndicatorView, times(1)).hideBusyIndicator();
    verify(presenter, times(1)).complete();
    verify(newResourceSuccessEventMock, times(1)).fire(newResourceSuccessEventArgumentCaptor.capture());
    verify(placeManager, times(1)).goTo(pathArgumentCaptor.capture());
    // Check navigation
    final Path routedPath = pathArgumentCaptor.getValue();
    assertEquals("default://p0/src/main/resources/file.txt", routedPath.toURI());
    final NewResourceSuccessEvent newResourceSuccessEvent = newResourceSuccessEventArgumentCaptor.getValue();
    assertEquals("default://p0/src/main/resources/file.txt", newResourceSuccessEvent.getPath().toURI());
}
Also used : Path(org.uberfire.backend.vfs.Path) Command(org.uberfire.mvp.Command) NewResourceSuccessEvent(org.kie.workbench.common.widgets.client.handlers.NewResourceSuccessEvent) Test(org.junit.Test)

Example 68 with Command

use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.

the class ContainerCardPresenter method setup.

public void setup(final Container container) {
    final LinkTitlePresenter linkTitlePresenter = presenterProvider.select(LinkTitlePresenter.class).get();
    linkTitlePresenter.setup(container.getContainerName(), new Command() {

        @Override
        public void execute() {
            containerSpecSelectedEvent.fire(new ContainerSpecSelected(buildContainerSpecKey(container)));
        }
    });
    final InfoTitlePresenter infoTitlePresenter = presenterProvider.select(InfoTitlePresenter.class).get();
    infoTitlePresenter.setup(container.getResolvedReleasedId());
    final BodyPresenter bodyPresenter = presenterProvider.select(BodyPresenter.class).get();
    bodyPresenter.setup(container.getMessages());
    final FooterPresenter footerPresenter = presenterProvider.select(FooterPresenter.class).get();
    footerPresenter.setup(container.getUrl(), container.getResolvedReleasedId().getVersion());
    CardPresenter card = presenterProvider.select(CardPresenter.class).get();
    card.addTitle(linkTitlePresenter);
    card.addTitle(infoTitlePresenter);
    card.addBody(bodyPresenter);
    card.addFooter(footerPresenter);
    view.setCard(card.getView());
}
Also used : InfoTitlePresenter(org.kie.workbench.common.screens.server.management.client.widget.card.title.InfoTitlePresenter) Command(org.uberfire.mvp.Command) FooterPresenter(org.kie.workbench.common.screens.server.management.client.widget.card.footer.FooterPresenter) CardPresenter(org.kie.workbench.common.screens.server.management.client.widget.card.CardPresenter) ContainerSpecSelected(org.kie.workbench.common.screens.server.management.client.events.ContainerSpecSelected) LinkTitlePresenter(org.kie.workbench.common.screens.server.management.client.widget.card.title.LinkTitlePresenter) BodyPresenter(org.kie.workbench.common.screens.server.management.client.widget.card.body.BodyPresenter)

Example 69 with Command

use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.

the class ServerTemplatePresenterTest method testRemoveTemplate.

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

Example 70 with Command

use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.

the class DefaultWorkbenchFeaturesMenusHelperTest method logoutCommandRedirectIncludesLocaleTest.

@Test
@SuppressWarnings("unchecked")
public void logoutCommandRedirectIncludesLocaleTest() throws Throwable {
    final DefaultWorkbenchFeaturesMenusHelper.LogoutCommand logoutCommand = spy(menusHelper.new LogoutCommand() {

        @Override
        void doRedirect(final String url) {
        // Do nothing
        }

        @Override
        String getGWTModuleBaseURL() {
            return "/gwtModule/";
        }

        @Override
        String getGWTModuleName() {
            return "gwtModule";
        }

        @Override
        String getLocale() {
            return "en_GB";
        }
    });
    logoutCommand.execute();
    final ArgumentCaptor<Command> postSaveStateCommandCaptor = ArgumentCaptor.forClass(Command.class);
    final ArgumentCaptor<String> redirectURLCaptor = ArgumentCaptor.forClass(String.class);
    verify(perspectiveManager).savePerspectiveState(postSaveStateCommandCaptor.capture());
    final Command postSaveStateCommand = postSaveStateCommandCaptor.getValue();
    postSaveStateCommand.execute();
    verify(logoutCommand).getRedirectURL();
    verify(logoutCommand).doRedirect(redirectURLCaptor.capture());
    final String redirectURL = redirectURLCaptor.getValue();
    assertTrue(redirectURL.contains("/logout.jsp?locale=en_GB"));
}
Also used : AboutCommand(org.kie.workbench.common.widgets.client.menu.AboutCommand) Command(org.uberfire.mvp.Command) Test(org.junit.Test)

Aggregations

Command (org.uberfire.mvp.Command)117 Test (org.junit.Test)66 ParameterizedCommand (org.uberfire.mvp.ParameterizedCommand)15 ClientSessionCommand (org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand)11 Group (com.ait.lienzo.client.core.shape.Group)9 YesNoCancelPopup (org.uberfire.ext.widgets.common.client.common.popups.YesNoCancelPopup)9 Before (org.junit.Before)8 HasListSelectorControl (org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl)7 Path (org.uberfire.backend.vfs.Path)7 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)6 PlaceRequest (org.uberfire.mvp.PlaceRequest)5 MenuItem (org.uberfire.workbench.model.menu.MenuItem)5 IsWidget (com.google.gwt.user.client.ui.IsWidget)4 Inject (javax.inject.Inject)4 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)4 RemoteCallback (org.jboss.errai.common.client.api.RemoteCallback)4 DeleteHeaderValueCommand (org.kie.workbench.common.dmn.client.commands.general.DeleteHeaderValueCommand)4 SetCellValueCommand (org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand)4 SetHeaderValueCommand (org.kie.workbench.common.dmn.client.commands.general.SetHeaderValueCommand)4