Search in sources :

Example 1 with EditorSessionCommands

use of org.kie.workbench.common.stunner.client.widgets.editor.EditorSessionCommands 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 2 with EditorSessionCommands

use of org.kie.workbench.common.stunner.client.widgets.editor.EditorSessionCommands 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)

Example 3 with EditorSessionCommands

use of org.kie.workbench.common.stunner.client.widgets.editor.EditorSessionCommands in project kie-wb-common by kiegroup.

the class ValidationActionTest method loadingCompletedOnSuccess.

@Test
public void loadingCompletedOnSuccess() {
    final Command loadingCompleted = mock(Command.class);
    new ValidationAction(editorSessionCommands, () -> {
    /*  */
    }, loadingCompleted, s -> {
    /*  */
    }).validate();
    verify(validateSessionCommand).execute(violationsArgumentCapture.capture());
    violationsArgumentCapture.getValue().onSuccess();
    verify(loadingCompleted).execute();
}
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)

Aggregations

EditorSessionCommands (org.kie.workbench.common.stunner.client.widgets.editor.EditorSessionCommands)3 ClientSessionCommand (org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand)3 ValidateSessionCommand (org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand)3 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)3 Command (com.google.gwt.user.client.Command)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Consumer (java.util.function.Consumer)2 Before (org.junit.Before)2 Test (org.junit.Test)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