Search in sources :

Example 1 with MarshallingRequest

use of org.kie.workbench.common.stunner.core.marshaller.MarshallingRequest 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

ByteArrayInputStream (java.io.ByteArrayInputStream)1 MarshallingRequest (org.kie.workbench.common.stunner.core.marshaller.MarshallingRequest)1 MarshallingResponse (org.kie.workbench.common.stunner.core.marshaller.MarshallingResponse)1 ProjectMetadata (org.kie.workbench.common.stunner.project.diagram.ProjectMetadata)1 ProjectMetadataImpl (org.kie.workbench.common.stunner.project.diagram.impl.ProjectMetadataImpl)1