Search in sources :

Example 6 with MarshallingResponse

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

the class IntegrationServiceImplTest method testGetDiagramByPathWithError.

@Test
@SuppressWarnings("unchecked")
public void testGetDiagramByPathWithError() {
    List<MarshallingMessage> messages = new ArrayList<>();
    MarshallingResponse response = mockResponse(MarshallingResponse.State.ERROR, messages, null);
    MarshallingResponse result = prepareTestGetDiagramByPath(response, null);
    assertEquals(MarshallingResponse.State.ERROR, result.getState());
    assertEquals(messages, result.getMessages());
    assertNull(result.getResult());
}
Also used : MarshallingMessage(org.kie.workbench.common.stunner.core.marshaller.MarshallingMessage) ArrayList(java.util.ArrayList) MarshallingResponse(org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse) Test(org.junit.Test)

Example 7 with MarshallingResponse

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

the class IntegrationServiceImplTest method testGetDiagramByPathWithUnexpectedError.

@Test
public void testGetDiagramByPathWithUnexpectedError() {
    List<MarshallingMessage> messages = new ArrayList<>();
    MarshallingResponse response = mockResponse(MarshallingResponse.State.ERROR, messages, null);
    RuntimeException unexpectedError = new RuntimeException("Unexpected error");
    expectedException.expectMessage("An error was produced while diagram loading from file " + PATH_URI);
    prepareTestGetDiagramByPath(response, unexpectedError);
}
Also used : MarshallingMessage(org.kie.workbench.common.stunner.core.marshaller.MarshallingMessage) ArrayList(java.util.ArrayList) MarshallingResponse(org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse) Test(org.junit.Test)

Example 8 with MarshallingResponse

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

the class IntegrationServiceImplTest method prepareTestGetDiagramByPath.

@SuppressWarnings("unchecked")
private MarshallingResponse prepareTestGetDiagramByPath(MarshallingResponse response, RuntimeException unexpectedError) {
    MarshallingRequest.Mode mode = MarshallingRequest.Mode.AUTO;
    when(moduleService.resolvePackage(path)).thenReturn(modulePackage);
    when(moduleService.resolveModule(path)).thenReturn(kieModule);
    when(overviewLoader.loadOverview(path)).thenReturn(overview);
    when(ioService.readAllBytes(Paths.convert(path))).thenReturn(bytes);
    ProjectMetadata metadata = new ProjectMetadataImpl.ProjectMetadataBuilder().forDefinitionSetId(defSetId).forModuleName(kieModule.getModuleName()).forProjectPackage(modulePackage).forOverview(overviewLoader.loadOverview(path)).forTitle(NAME).forPath(path).build();
    MarshallingRequest expectedRequest = MarshallingRequest.builder().metadata(metadata).input(new ByteArrayInputStream(bytes)).mode(mode).build();
    if (unexpectedError == null) {
        when(diagramMarshaller.unmarshallWithValidation(any(MarshallingRequest.class))).thenReturn(response);
    } else {
        when(diagramMarshaller.unmarshallWithValidation(any(MarshallingRequest.class))).thenThrow(unexpectedError);
    }
    MarshallingResponse result = service.getDiagramByPath(path, MarshallingRequest.Mode.AUTO);
    verify(diagramMarshaller).unmarshallWithValidation(marshallingRequestCaptor.capture());
    assertEquals(expectedRequest.getMetadata(), metadata);
    assertEquals(expectedRequest.getMode(), mode);
    return result;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ProjectMetadata(org.kie.workbench.common.stunner.project.diagram.ProjectMetadata) MarshallingResponse(org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse) ProjectMetadataImpl(org.kie.workbench.common.stunner.project.diagram.impl.ProjectMetadataImpl) MarshallingRequest(org.kie.workbench.common.stunner.core.marshaller.MarshallingRequest)

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