private void setModel(EditorModelContent model) { view.setContext(context); setSource(model.getSource()); if (model.getDataObject() != null) { context.setParseStatus(DataModelerContext.ParseStatus.PARSED); } else { context.setParseStatus(DataModelerContext.ParseStatus.PARSE_ERRORS); } }
/** * Tests that a java file without parse errors was successfully loaded. * * @param loadTypesInfo indicates if the types and annotations definitions loading should be * simulated. */ private void loadFileSuccessfulTest(boolean loadTypesInfo) { EditorModelContent content = createContent(loadTypesInfo, false); when(versionRecordManager.getCurrentPath()).thenReturn(path); when(modelerService.loadContent(path, loadTypesInfo)).thenReturn(content); when(javaSourceEditor.getContent()).thenReturn(content.getSource()); if (loadTypesInfo) { // types info is not loaded into the DataModelerWBContext. when(dataModelerWBContext.isTypesInfoLoaded()).thenReturn(false); } else { // types info is already into the DataModelerWBContext. when(dataModelerWBContext.isTypesInfoLoaded()).thenReturn(true); } // just for convenience, since the DataModelerContext is initialized by taking this definitions // from the DMWC. when(dataModelerWBContext.getAnnotationDefinitions()).thenReturn(testAnnotationDefs); when(dataModelerWBContext.getPropertyTypes()).thenReturn(testTypeDefs); presenter.onStartup(path, placeRequest); // Verifications during and after model loading. verify(view, times(1)).showLoading(); verify(view, times(1)).hideBusyIndicator(); // presenter should ask the DataModelerWBContext if the types info is already loaded. verify(dataModelerWBContext, times(1)).isTypesInfoLoaded(); if (loadTypesInfo) { // the types info should have been set into the DataModelerWBContext as part of the presenter // loading. verify(dataModelerWBContext, times(1)).setPropertyTypes(testTypeDefs); verify(dataModelerWBContext, times(1)).setAnnotationDefinitions(testAnnotationDefs); } else { // the types info shouldn't have been set into the DataModelerWBContext as part of the // presenter loading. verify(dataModelerWBContext, times(0)).setPropertyTypes(testTypeDefs); verify(dataModelerWBContext, times(0)).setAnnotationDefinitions(testAnnotationDefs); } // presenter should clear the system messages related to this editor. verify(unpublishMessagesEvent, times(1)).fire(any(UnpublishMessagesEvent.class)); // presenter should read the expected path. verify(modelerService, times(1)).loadContent(path, loadTypesInfo); // verify that the context created by the presenter was properly initialized. DataModelerContext context = presenter.context; assertEquals(testModel, context.getDataModel()); assertEquals(testObject1, context.getDataObject()); assertEquals(kieProject, context.getCurrentProject()); assertEquals(testPackages, context.getCurrentProjectPackages()); assertEquals(testAnnotationDefs, context.getAnnotationDefinitions()); assertEquals(content, context.getEditorModelContent()); // the file was read successfully, so the status should be PARSED assertEquals(DataModelerContext.ParseStatus.PARSED, context.getParseStatus()); // the file was read and parsed successfully, so the editor should be now in the editor tab. assertEquals(DataModelerContext.EditionMode.GRAPHICAL_MODE, context.getEditionMode()); // file was just read, so the status should be NO_CHANGES. assertEquals(DataModelerContext.EditionStatus.NO_CHANGES, context.getEditionStatus()); // the view should have been initialized with the context. verify(view, times(1)).setContext(context); // the source editor should have been initialized with the source returned form server. verify(javaSourceEditor, times(1)).setContent(testSource); // current context should have been activated verify(dataModelerWBContext, times(1)).setActiveContext(context); // and notifications should have been sent. verify(dataModelerFocusEvent, times(1)).fire(any(DataModelerWorkbenchFocusEvent.class)); }
/** * Tests that a java file with parse errors was successfully loaded. * * @param loadTypesInfo indicates if the types and annotations definitions loading should be * simulated. */ private void loadFileUnSuccessfulTest(boolean loadTypesInfo) { EditorModelContent content = createContent(loadTypesInfo, true); // when there are parse errors the returned data object is null. content.setDataObject(null); when(versionRecordManager.getCurrentPath()).thenReturn(path); when(modelerService.loadContent(path, loadTypesInfo)).thenReturn(content); when(javaSourceEditor.getContent()).thenReturn(content.getSource()); if (loadTypesInfo) { // types info is not loaded into the DataModelerWBContext. when(dataModelerWBContext.isTypesInfoLoaded()).thenReturn(false); } else { // types info is already into the DataModelerWBContext. when(dataModelerWBContext.isTypesInfoLoaded()).thenReturn(true); } // just for convenience, since the DataModelerContext is initialized by taking this definitions // from the DMWC. when(dataModelerWBContext.getAnnotationDefinitions()).thenReturn(testAnnotationDefs); when(dataModelerWBContext.getPropertyTypes()).thenReturn(testTypeDefs); presenter.onStartup(path, placeRequest); // Verifications during and after model loading. verify(view, times(1)).showLoading(); verify(view, times(1)).hideBusyIndicator(); // presenter should ask the DataModelerWBContext if the types info is already loaded. verify(dataModelerWBContext, times(1)).isTypesInfoLoaded(); if (loadTypesInfo) { // the types info should have been set into the DataModelerWBContext as part of the presenter // loading. verify(dataModelerWBContext, times(1)).setPropertyTypes(testTypeDefs); verify(dataModelerWBContext, times(1)).setAnnotationDefinitions(testAnnotationDefs); } else { // the types info shouldn't have been set into the DataModelerWBContext as part of the // presenter loading. verify(dataModelerWBContext, times(0)).setPropertyTypes(testTypeDefs); verify(dataModelerWBContext, times(0)).setAnnotationDefinitions(testAnnotationDefs); } // presenter should clear the system messages related to this editor. verify(unpublishMessagesEvent, times(1)).fire(any(UnpublishMessagesEvent.class)); // presenter should read the expected path. verify(modelerService, times(1)).loadContent(path, loadTypesInfo); // parse errors should have been published. verify(publishBatchMessagesEvent, times(1)).fire(any(PublishBatchMessagesEvent.class)); // parse errors dialog should have been raised. verify(view, times(1)).showParseErrorsDialog(anyString(), anyString(), any(Command.class)); // at this point the parse errors popup is raised and waiting for the user to press the ok // button. // emulate the user click on the button. presenter.getOnLoadParseErrorCommand().execute(); // verify that the context created by the presenter was properly initialized. DataModelerContext context = presenter.context; assertEquals(testModel, context.getDataModel()); assertEquals(null, context.getDataObject()); assertEquals(kieProject, context.getCurrentProject()); assertEquals(testPackages, context.getCurrentProjectPackages()); assertEquals(testAnnotationDefs, context.getAnnotationDefinitions()); assertEquals(content, context.getEditorModelContent()); // parse errors wherer produced on server so the status should be PARSE_ERRORS assertEquals(DataModelerContext.ParseStatus.PARSE_ERRORS, context.getParseStatus()); // the file wasn't parsed the editor should go to the source tab. assertEquals(DataModelerContext.EditionMode.SOURCE_MODE, context.getEditionMode()); // file was just read, so the status should be NO_CHANGES. assertEquals(DataModelerContext.EditionStatus.NO_CHANGES, context.getEditionStatus()); // context wasn't set on the view since there aren't a data object to show. verify(view, times(0)).setContext(context); // the source editor should have been initialized with the source returned form server. verify(javaSourceEditor, times(2)).setContent(testSource); // current context should have been activated verify(dataModelerWBContext, times(1)).setActiveContext(context); // and notifications should have been sent. verify(dataModelerFocusEvent, times(1)).fire(any(DataModelerWorkbenchFocusEvent.class)); }