Search in sources :

Example 1 with ValidateSessionCommand

use of org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand in project kie-wb-common by kiegroup.

the class BPMNDiagramEditorTest method testMigrateWhenDirty.

@SuppressWarnings("unchecked")
@Test
public void testMigrateWhenDirty() {
    ObservablePath currentPath = mock(ObservablePath.class);
    when(versionRecordManager.getCurrentPath()).thenReturn(currentPath);
    doReturn(true).when(diagramEditor).isDirty(any(Integer.class));
    diagramEditor.onMigrate();
    verify(popupUtil, times(1)).showConfirmPopup(eq(MIGRATE_ACTION_TITLE), eq(MIGRATE_ACTION_WARNING), eq(InlineNotification.InlineNotificationType.WARNING), eq(MIGRATE_ACTION), eq(Button.ButtonStyleType.PRIMARY), eq(MIGRATE_CONFIRM_ACTION), commandCaptor.capture());
    commandCaptor.getValue().execute();
    ValidateSessionCommand validateSessionCommand = sessionCommandFactory.newValidateCommand();
    verify(validateSessionCommand, times(1)).execute(sessionCommandCallback.capture());
    sessionCommandCallback.getValue().onSuccess();
    verify(savePopUpPresenter, times(1)).show(eq(currentPath), parameterizedCommandCaptor.capture());
    parameterizedCommandCaptor.getValue().execute(COMMIT_MESSAGE);
    verify(clientProjectDiagramService, times(1)).saveOrUpdate(eq(currentPath), any(ProjectDiagram.class), any(Metadata.class), eq(COMMIT_MESSAGE), serviceCallbackCaptor.capture());
    serviceCallbackCaptor.getValue().onSuccess(diagram);
    verify(migrateDiagramEvent, times(1)).fire(migrateDiagramEventCaptor.capture());
    assertEquals(currentPath, migrateDiagramEventCaptor.getValue().getSourcePath());
    assertEquals(currentPlace, migrateDiagramEventCaptor.getValue().getSourcePlace());
}
Also used : ValidateSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) ObservablePath(org.uberfire.backend.vfs.ObservablePath) ProjectDiagram(org.kie.workbench.common.stunner.project.diagram.ProjectDiagram) AbstractProjectDiagramEditorTest(org.kie.workbench.common.stunner.project.client.editor.AbstractProjectDiagramEditorTest) Test(org.junit.Test)

Example 2 with ValidateSessionCommand

use of org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand in project kie-wb-common by kiegroup.

the class ValidationActionTest method loadingStarts.

@Test
public void loadingStarts() {
    final Command loadingStarts = mock(Command.class);
    new ValidationAction(editorSessionCommands, loadingStarts, () -> {
    /*  */
    }, s -> {
    /*  */
    }).validate();
    verify(loadingStarts).execute();
    verify(validateSessionCommand).execute(any());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) EditorSessionCommands(org.kie.workbench.common.stunner.client.widgets.editor.EditorSessionCommands) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Collection(java.util.Collection) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Captor(org.mockito.Captor) Mockito.verify(org.mockito.Mockito.verify) HashSet(java.util.HashSet) Consumer(java.util.function.Consumer) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) Mockito.never(org.mockito.Mockito.never) ArgumentCaptor(org.mockito.ArgumentCaptor) Command(com.google.gwt.user.client.Command) ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ValidateSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Command(com.google.gwt.user.client.Command) ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand) ValidateSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand) Test(org.junit.Test)

Example 3 with ValidateSessionCommand

use of org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand in project kie-wb-common by kiegroup.

the class ValidationActionTest method runAfterValidationActionsOnFailure.

@Test
public void runAfterValidationActionsOnFailure() {
    final ValidationAction validationAction = new ValidationAction(editorSessionCommands, () -> {
    /*  */
    }, () -> {
    /*  */
    }, s -> {
    /*  */
    });
    final Command onAfterValidation = mock(Command.class);
    validationAction.setAfterValidation(onAfterValidation);
    validationAction.validate();
    verify(validateSessionCommand).execute(violationsArgumentCapture.capture());
    violationsArgumentCapture.getValue().onError(new HashSet<>());
    verify(onAfterValidation).execute();
}
Also used : Command(com.google.gwt.user.client.Command) ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand) ValidateSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand) Test(org.junit.Test)

Example 4 with ValidateSessionCommand

use of org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand in project kie-wb-common by kiegroup.

the class ValidationActionTest method runAfterValidationActionsOnSuccess.

@Test
public void runAfterValidationActionsOnSuccess() {
    final ValidationAction validationAction = new ValidationAction(editorSessionCommands, () -> {
    /*  */
    }, () -> {
    /*  */
    }, s -> {
    /*  */
    });
    final Command onAfterValidation = mock(Command.class);
    validationAction.setAfterValidation(onAfterValidation);
    validationAction.validate();
    verify(validateSessionCommand).execute(violationsArgumentCapture.capture());
    violationsArgumentCapture.getValue().onSuccess();
    verify(onAfterValidation).execute();
}
Also used : Command(com.google.gwt.user.client.Command) ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand) ValidateSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand) Test(org.junit.Test)

Example 5 with ValidateSessionCommand

use of org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand in project kie-wb-common by kiegroup.

the class AbstractProjectDiagramEditorTest method assertBasicStunnerSaveOperation.

@SuppressWarnings("unchecked")
protected Overview assertBasicStunnerSaveOperation(final boolean validateSuccess) {
    tested.open(diagram);
    EditorSessionCommands editorSessionCommands = mock(EditorSessionCommands.class);
    when(menuSessionItems.getCommands()).thenReturn(editorSessionCommands);
    ValidateSessionCommand validateSessionCommand = mock(ValidateSessionCommand.class);
    when(editorSessionCommands.getValidateSessionCommand()).thenReturn(validateSessionCommand);
    doAnswer(invocation -> {
        ClientSessionCommand.Callback callback = (ClientSessionCommand.Callback) invocation.getArguments()[0];
        if (validateSuccess) {
            callback.onSuccess();
        } else {
            DiagramElementViolation<RuleViolation> violation = mock(DiagramElementViolation.class);
            when(violation.getViolationType()).thenReturn(Violation.Type.ERROR);
            callback.onError(Collections.singletonList(violation));
        }
        return null;
    }).when(validateSessionCommand).execute(Mockito.<ClientSessionCommand.Callback>any());
    tested.onSave();
    return overview;
}
Also used : ValidateSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) EditorSessionCommands(org.kie.workbench.common.stunner.client.widgets.editor.EditorSessionCommands) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand)

Aggregations

ValidateSessionCommand (org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand)7 Test (org.junit.Test)6 ClientSessionCommand (org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand)6 Command (com.google.gwt.user.client.Command)5 Consumer (java.util.function.Consumer)3 EditorSessionCommands (org.kie.workbench.common.stunner.client.widgets.editor.EditorSessionCommands)3 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Before (org.junit.Before)2 RunWith (org.junit.runner.RunWith)2 DiagramElementViolation (org.kie.workbench.common.stunner.core.validation.DiagramElementViolation)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)2 Captor (org.mockito.Captor)2 Mock (org.mockito.Mock)2 Mockito.doReturn (org.mockito.Mockito.doReturn)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.never (org.mockito.Mockito.never)2