@SuppressWarnings("unchecked") protected Overview openInvalidBPMNFile(final String xml) { final ClientRuntimeError clientRuntimeError = mock(ClientRuntimeError.class); final DiagramParsingException dpe = mock(DiagramParsingException.class); final ProjectMetadata metadata = mock(ProjectMetadata.class); final Overview overview = mock(Overview.class); when(metadata.getTitle()).thenReturn(TITLE); when(metadata.getOverview()).thenReturn(overview); when(clientRuntimeError.getThrowable()).thenReturn(dpe); when(dpe.getMetadata()).thenReturn(metadata); when(dpe.getXml()).thenReturn(xml); when(diagram.getMetadata()).thenReturn(metadata); doAnswer(i -> { final ServiceCallback serviceCallback = (ServiceCallback) i.getArguments()[1]; serviceCallback.onError(clientRuntimeError); return null; }).when(clientProjectDiagramService).getByPath(any(Path.class), any(ServiceCallback.class)); presenter.loadContent(); verify(presenter).destroySession(); return overview; }
LOG.error("Cannot unmarshall diagram for diagram's path [" + file + "]", e); final String xml = getIoService().readAllString(Paths.convert(file)); throw new DiagramParsingException(metadata, xml);
protected void onLoadError(final ClientRuntimeError error) { final Throwable e = error.getThrowable(); if (e instanceof DiagramParsingException) { final DiagramParsingException dpe = (DiagramParsingException) e; final Metadata metadata = dpe.getMetadata(); final String xml = dpe.getXml(); setOriginalHash(xml.hashCode()); updateTitle(metadata.getTitle()); resetEditorPages(((ProjectMetadata) metadata).getOverview()); menuSessionItems.setEnabled(false); xmlEditorView.setReadOnly(isReadOnly); xmlEditorView.setContent(xml, AceEditorMode.XML); getView().setWidget(xmlEditorView.asWidget()); editorProxy = makeXmlEditorProxy(); hideLoadingViews(); notification.fire(new NotificationEvent(translationService.getValue(DIAGRAM_PARSING_ERROR, Objects.toString(e.getMessage(), "")), NotificationEvent.NotificationType.ERROR)); Scheduler.get().scheduleDeferred(xmlEditorView::onResize); } else { editorProxy = ProjectDiagramEditorProxy.NULL_EDITOR; showError(error); //close editor in case of error when opening the editor placeManager.forceClosePlace(new PathPlaceRequest(versionRecordManager.getCurrentPath(), getEditorIdentifier())); } }
@Test @SuppressWarnings("unchecked") public void testGetDiagramByPathParseException() throws IOException { final String processDefinition = "broken DEFINITION"; final Path path = mockGetDiagramByPathObjects(); when(ioService.readAllString(Paths.convert(path))).thenReturn(processDefinition); //Mock failure to unmarshall XML to Graph try { Mockito.when(diagramMarshaller.unmarshall(anyObject(), anyObject())).thenThrow(IOException.class); diagramService.getDiagramByPath(path); } catch (DiagramParsingException dpe) { assertEquals(processDefinition, dpe.getXml()); assertNotNull(dpe.getMetadata()); } catch (Exception e) { fail("Exception should have been caught and wrapped as DiagramParsingException"); } }