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