Search in sources :

Example 1 with MarshallingResponse

use of org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse in project kie-wb-common by kiegroup.

the class DiagramMarshallerTest method unmarshallWithValidationError.

@Test
public void unmarshallWithValidationError() throws Exception {
    tested = spy(new DiagramMarshaller() {

        @Override
        public Graph unmarshall(Metadata metadata, InputStream input) {
            throw new RuntimeException(MESSAGE);
        }

        @Override
        public String marshall(Diagram diagram) {
            return null;
        }

        @Override
        public DiagramMetadataMarshaller getMetadataMarshaller() {
            return null;
        }
    });
    final MarshallingResponse response = tested.unmarshallWithValidation(request);
    verify(tested).unmarshall(metadata, input);
    assertNull(response.getResult());
    assertEquals(response.getState(), MarshallingResponse.State.ERROR);
    assertEquals(response.getMessages().size(), 1);
    final MarshallingMessage marshallingMessage = (MarshallingMessage) response.getMessages().stream().findFirst().get();
    assertEquals(marshallingMessage.getMessage(), MESSAGE);
}
Also used : MarshallingMessage(org.kie.workbench.common.stunner.core.marshaller.MarshallingMessage) InputStream(java.io.InputStream) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) MarshallingResponse(org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Example 2 with MarshallingResponse

use of org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse in project kie-wb-common by kiegroup.

the class IntegrationHandlerImpl method fromJBPMDesignerToStunner.

private void fromJBPMDesignerToStunner(Path path, PlaceRequest place) {
    final RemoteCallback<MarshallingResponse<ProjectDiagram>> successCallback = (result) -> onGetDiagramByPathSuccess(result, path, place);
    final ErrorCallback<Message> errorCallback = (message, throwable) -> onUnexpectedError(throwable);
    final Command okCommand = () -> integrationService.call(successCallback, errorCallback).getDiagramByPath(path, MarshallingRequest.Mode.AUTO);
    confirmAndMigrate(null, null, translationService.getValue(IntegrationClientConstants.MigrateToStunnerConfirmAction), okCommand);
}
Also used : MarshallingMessage(org.kie.workbench.common.stunner.core.marshaller.MarshallingMessage) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) ErrorCallback(org.jboss.errai.common.client.api.ErrorCallback) ErrorPopupPresenter(org.uberfire.client.workbench.widgets.common.ErrorPopupPresenter) InlineNotification(org.uberfire.client.views.pfly.widgets.InlineNotification) PlaceManager(org.uberfire.client.mvp.PlaceManager) PathPlaceRequest(org.uberfire.mvp.impl.PathPlaceRequest) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) Inject(javax.inject.Inject) ClientTranslationService(org.kie.workbench.common.stunner.core.client.i18n.ClientTranslationService) ProjectDiagram(org.kie.workbench.common.stunner.project.diagram.ProjectDiagram) MigrateResult(org.kie.workbench.common.stunner.bpmn.integration.service.MigrateResult) MigrateRequest(org.kie.workbench.common.stunner.bpmn.integration.service.MigrateRequest) Pair(org.uberfire.commons.data.Pair) MarshallingResponsePopup(org.kie.workbench.common.stunner.client.widgets.marshaller.MarshallingResponsePopup) Path(org.uberfire.backend.vfs.Path) Command(org.uberfire.mvp.Command) Event(javax.enterprise.event.Event) MarshallingRequest(org.kie.workbench.common.stunner.core.marshaller.MarshallingRequest) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback) MarshallingResponse(org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse) PlaceRequest(org.uberfire.mvp.PlaceRequest) Consumer(java.util.function.Consumer) List(java.util.List) Message(org.jboss.errai.bus.client.api.messaging.Message) Dependent(javax.enterprise.context.Dependent) Caller(org.jboss.errai.common.client.api.Caller) IntegrationClientConstants(org.kie.workbench.common.stunner.bpmn.integration.client.resources.IntegrationClientConstants) BPMNDefinitionSetResourceType(org.kie.workbench.common.stunner.bpmn.resource.BPMNDefinitionSetResourceType) PopupUtil(org.kie.workbench.common.stunner.client.widgets.popups.PopupUtil) IntegrationService(org.kie.workbench.common.stunner.bpmn.integration.service.IntegrationService) MarshallingMessage(org.kie.workbench.common.stunner.core.marshaller.MarshallingMessage) Message(org.jboss.errai.bus.client.api.messaging.Message) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Command(org.uberfire.mvp.Command) MarshallingResponse(org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse)

Example 3 with MarshallingResponse

use of org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse in project kie-wb-common by kiegroup.

the class IntegrationServiceImplTest method mockResponse.

private static MarshallingResponse mockResponse(MarshallingResponse.State state, List<MarshallingMessage> messages, Graph result) {
    MarshallingResponse response = mock(MarshallingResponse.class);
    when(response.getState()).thenReturn(state);
    when(response.getMessages()).thenReturn(messages);
    when(response.getResult()).thenReturn(result);
    return response;
}
Also used : MarshallingResponse(org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse)

Example 4 with MarshallingResponse

use of org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse in project kie-wb-common by kiegroup.

the class IntegrationServiceImplTest method testGetDiagramByPathSuccessful.

@Test
@SuppressWarnings("unchecked")
public void testGetDiagramByPathSuccessful() {
    Graph<DefinitionSet, ?> graph = mock(Graph.class);
    DefinitionSet definitionSet = mock(DefinitionSet.class);
    String definitionValue = "theDefinitionValue";
    when(graph.getContent()).thenReturn(definitionSet);
    when(definitionSet.getDefinition()).thenReturn(definitionValue);
    when(factoryRegistry.getDiagramFactory(definitionValue, ProjectMetadata.class)).thenReturn(diagramFactory);
    ProjectDiagram diagram = mock(ProjectDiagram.class);
    when(diagramFactory.build(eq(NAME), any(ProjectMetadata.class), eq(graph))).thenReturn(diagram);
    List<MarshallingMessage> messages = new ArrayList<>();
    MarshallingResponse response = mockResponse(MarshallingResponse.State.SUCCESS, messages, graph);
    MarshallingResponse result = prepareTestGetDiagramByPath(response, null);
    assertEquals(MarshallingResponse.State.SUCCESS, result.getState());
    assertEquals(messages, result.getMessages());
    assertNotNull(result.getResult());
    assertEquals(diagram, result.getResult());
}
Also used : MarshallingMessage(org.kie.workbench.common.stunner.core.marshaller.MarshallingMessage) ProjectMetadata(org.kie.workbench.common.stunner.project.diagram.ProjectMetadata) ArrayList(java.util.ArrayList) MarshallingResponse(org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProjectDiagram(org.kie.workbench.common.stunner.project.diagram.ProjectDiagram) Test(org.junit.Test)

Example 5 with MarshallingResponse

use of org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse in project kie-wb-common by kiegroup.

the class DiagramMarshallerTest method unmarshallWithValidation.

@Test
public void unmarshallWithValidation() throws Exception {
    tested = spy(new DiagramMarshaller() {

        @Override
        public Graph unmarshall(Metadata metadata, InputStream input) {
            return graph;
        }

        @Override
        public String marshall(Diagram diagram) {
            return null;
        }

        @Override
        public DiagramMetadataMarshaller getMetadataMarshaller() {
            return null;
        }
    });
    final MarshallingResponse response = tested.unmarshallWithValidation(request);
    verify(tested).unmarshall(metadata, input);
    assertEquals(response.getResult(), graph);
    assertEquals(response.getState(), MarshallingResponse.State.SUCCESS);
}
Also used : InputStream(java.io.InputStream) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) MarshallingResponse(org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Aggregations

MarshallingResponse (org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse)8 Test (org.junit.Test)5 MarshallingMessage (org.kie.workbench.common.stunner.core.marshaller.MarshallingMessage)5 ArrayList (java.util.ArrayList)3 InputStream (java.io.InputStream)2 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)2 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)2 MarshallingRequest (org.kie.workbench.common.stunner.core.marshaller.MarshallingRequest)2 ProjectDiagram (org.kie.workbench.common.stunner.project.diagram.ProjectDiagram)2 ProjectMetadata (org.kie.workbench.common.stunner.project.diagram.ProjectMetadata)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Dependent (javax.enterprise.context.Dependent)1 Event (javax.enterprise.event.Event)1 Inject (javax.inject.Inject)1 Message (org.jboss.errai.bus.client.api.messaging.Message)1 Caller (org.jboss.errai.common.client.api.Caller)1 ErrorCallback (org.jboss.errai.common.client.api.ErrorCallback)1 RemoteCallback (org.jboss.errai.common.client.api.RemoteCallback)1