Search in sources :

Example 1 with GlobalsModel

use of org.drools.workbench.screens.globals.model.GlobalsModel in project drools-wb by kiegroup.

the class GlobalsEditorPresenterTest method loadContent.

@Test
public void loadContent() {
    presenter.loadContent();
    verify(view, times(1)).showLoading();
    verify(globalsEditorService, times(1)).loadContent(any(Path.class));
    when(versionRecordManager.getCurrentPath()).thenReturn(mock(ObservablePath.class));
    // Emulate the globals being successfully loaded
    GlobalsEditorContent globalsEditorContent = mock(GlobalsEditorContent.class);
    Overview overview = mock(Overview.class);
    when(overview.getMetadata()).thenReturn(mock(Metadata.class));
    when(globalsEditorContent.getOverview()).thenReturn(overview);
    GlobalsModel globalsModel = mock(GlobalsModel.class);
    when(globalsEditorContent.getModel()).thenReturn(globalsModel);
    presenter.getModelSuccessCallback().callback(globalsEditorContent);
    verify(view, times(1)).setContent(anyListOf(Global.class), anyListOf(String.class), anyBoolean(), anyBoolean());
    verify(view, times(1)).hideBusyIndicator();
}
Also used : Path(org.uberfire.backend.vfs.Path) ObservablePath(org.uberfire.backend.vfs.ObservablePath) GlobalsEditorContent(org.drools.workbench.screens.globals.model.GlobalsEditorContent) GlobalsModel(org.drools.workbench.screens.globals.model.GlobalsModel) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) Overview(org.guvnor.common.services.shared.metadata.model.Overview) ObservablePath(org.uberfire.backend.vfs.ObservablePath) Global(org.drools.workbench.screens.globals.model.Global) Test(org.junit.Test)

Example 2 with GlobalsModel

use of org.drools.workbench.screens.globals.model.GlobalsModel in project drools-wb by kiegroup.

the class GlobalsEditorServiceImpl method constructContent.

@Override
protected GlobalsEditorContent constructContent(Path path, Overview overview) {
    // De-serialize model
    final GlobalsModel model = load(path);
    final ModuleDataModelOracle oracle = dataModelService.getModuleDataModel(path);
    final String[] fullyQualifiedClassNames = new String[oracle.getModuleModelFields().size()];
    oracle.getModuleModelFields().keySet().toArray(fullyQualifiedClassNames);
    // Signal opening to interested parties
    resourceOpenedEvent.fire(new ResourceOpenedEvent(path, safeSessionInfo));
    return new GlobalsEditorContent(model, overview, Arrays.asList(fullyQualifiedClassNames));
}
Also used : GlobalsEditorContent(org.drools.workbench.screens.globals.model.GlobalsEditorContent) GlobalsModel(org.drools.workbench.screens.globals.model.GlobalsModel) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ResourceOpenedEvent(org.uberfire.workbench.events.ResourceOpenedEvent)

Example 3 with GlobalsModel

use of org.drools.workbench.screens.globals.model.GlobalsModel in project drools-wb by kiegroup.

the class GlobalsEditorServiceTest method testSaveAndRename.

@Test
public void testSaveAndRename() throws Exception {
    final GlobalsEditorServiceImpl service = (GlobalsEditorServiceImpl) globalsEditorService;
    final Path path = mock(Path.class);
    final String newFileName = "newFileName";
    final Metadata metadata = mock(Metadata.class);
    final GlobalsModel content = mock(GlobalsModel.class);
    final String comment = "comment";
    service.saveAndRename(path, newFileName, metadata, content, comment);
    verify(saveAndRenameService).saveAndRename(path, newFileName, metadata, content, comment);
}
Also used : Path(org.uberfire.backend.vfs.Path) GlobalsModel(org.drools.workbench.screens.globals.model.GlobalsModel) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 4 with GlobalsModel

use of org.drools.workbench.screens.globals.model.GlobalsModel in project drools-wb by kiegroup.

the class GlobalsPersistenceTest method testMarshalling.

@Test
public void testMarshalling() {
    final GlobalsModel model = new GlobalsModel();
    final String expected = "global java.lang.String myString;\n";
    model.getGlobals().add(new Global("myString", "java.lang.String"));
    final String actual = GlobalsPersistence.getInstance().marshal(model);
    assertNotNull(actual);
    assertEquals(expected, actual);
}
Also used : GlobalsModel(org.drools.workbench.screens.globals.model.GlobalsModel) Global(org.drools.workbench.screens.globals.model.Global) Test(org.junit.Test)

Example 5 with GlobalsModel

use of org.drools.workbench.screens.globals.model.GlobalsModel in project drools-wb by kiegroup.

the class DecisionTableXLSToDecisionTableGuidedConverter method makeGlobalsModel.

private GlobalsModel makeGlobalsModel(final List<Import> imports, final List<Global> globals, final ConversionResult result) {
    final GlobalsModel model = new GlobalsModel();
    for (Global global : globals) {
        if (global.getClassName().contains(".")) {
            model.getGlobals().add(new org.drools.workbench.screens.globals.model.Global(global.getIdentifier(), global.getClassName()));
        } else {
            boolean mapped = false;
            for (Import imp : imports) {
                if (imp.getClassName().contains(".")) {
                    final String fullyQualifiedClassName = imp.getClassName();
                    final String leafClassName = fullyQualifiedClassName.substring(fullyQualifiedClassName.lastIndexOf(".") + 1);
                    if (global.getClassName().equals(leafClassName)) {
                        model.getGlobals().add(new org.drools.workbench.screens.globals.model.Global(global.getIdentifier(), fullyQualifiedClassName));
                        mapped = true;
                        break;
                    }
                }
            }
            if (!mapped) {
                result.addMessage("Unable to determine Fully Qualified Class Name for Global '" + global.getIdentifier() + "'. Skipping.", ConversionMessageType.ERROR);
            }
        }
    }
    return model;
}
Also used : Import(org.drools.template.model.Import) GlobalsModel(org.drools.workbench.screens.globals.model.GlobalsModel) Global(org.drools.template.model.Global)

Aggregations

GlobalsModel (org.drools.workbench.screens.globals.model.GlobalsModel)12 Test (org.junit.Test)7 Path (org.uberfire.backend.vfs.Path)5 Global (org.drools.workbench.screens.globals.model.Global)3 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)3 GlobalsEditorContent (org.drools.workbench.screens.globals.model.GlobalsEditorContent)2 Matchers.anyString (org.mockito.Matchers.anyString)2 CommentedOption (org.uberfire.java.nio.base.options.CommentedOption)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Global (org.drools.template.model.Global)1 Import (org.drools.template.model.Import)1 ConversionResult (org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult)1 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)1 Overview (org.guvnor.common.services.shared.metadata.model.Overview)1 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)1 ObservablePath (org.uberfire.backend.vfs.ObservablePath)1 Pair (org.uberfire.commons.data.Pair)1 HasBusyIndicatorDefaultErrorCallback (org.uberfire.ext.widgets.common.client.callbacks.HasBusyIndicatorDefaultErrorCallback)1