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;
}
Aggregations