Search in sources :

Example 11 with Imports

use of org.kie.soup.project.datamodel.imports.Imports in project drools-wb by kiegroup.

the class GuidedDecisionTableGraphEditorPresenterTest method checkInitialiseKieEditorTabs.

@Test
public void checkInitialiseKieEditorTabs() {
    final ObservablePath dtGraphPath = mock(ObservablePath.class);
    final PlaceRequest dtGraphPlaceRequest = mock(PlaceRequest.class);
    final GuidedDecisionTableEditorGraphContent dtGraphContent = makeDecisionTableGraphContent(0);
    when(dtGraphPath.toURI()).thenReturn("dtGraphPath");
    when(dtGraphPath.getFileName()).thenReturn("filename");
    when(dtGraphService.loadContent(eq(dtGraphPath))).thenReturn(dtGraphContent);
    when(versionRecordManager.getCurrentPath()).thenReturn(dtGraphPath);
    when(versionRecordManager.getVersion()).thenReturn("version");
    presenter.onStartup(dtGraphPath, dtGraphPlaceRequest);
    verify(kieEditorWrapperView, times(1)).clear();
    final GuidedDecisionTableView.Presenter document = mock(GuidedDecisionTableView.Presenter.class);
    final AsyncPackageDataModelOracle dmo = mock(AsyncPackageDataModelOracle.class);
    final Imports imports = mock(Imports.class);
    final boolean isReadOnly = true;
    final ArgumentCaptor<com.google.gwt.user.client.Command> onFocusCommandCaptor = ArgumentCaptor.forClass(com.google.gwt.user.client.Command.class);
    presenter.initialiseKieEditorTabs(document, dtGraphContent.getOverview(), dmo, imports, isReadOnly);
    verify(kieEditorWrapperView, times(2)).clear();
    verify(kieEditorWrapperView, times(2)).addMainEditorPage(view);
    verify(kieEditorWrapperView, times(2)).addOverviewPage(eq(overviewWidget), onFocusCommandCaptor.capture());
    verify(overviewWidget, times(2)).setContent(eq(dtGraphContent.getOverview()), any(ObservablePath.class));
    verify(kieEditorWrapperView, times(1)).addSourcePage(any(ViewDRLSourceWidget.class));
    verify(kieEditorWrapperView, times(1)).addImportsTab(eq(importsWidget));
    verify(importsWidget, times(1)).setContent(eq(dmo), eq(imports), eq(isReadOnly));
    final com.google.gwt.user.client.Command onFocusCommand = onFocusCommandCaptor.getValue();
    assertNotNull(onFocusCommand);
    onFocusCommand.execute();
    verify(overviewWidget, times(1)).refresh(eq("version"));
}
Also used : PathPlaceRequest(org.uberfire.mvp.impl.PathPlaceRequest) PlaceRequest(org.uberfire.mvp.PlaceRequest) AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) Imports(org.kie.soup.project.datamodel.imports.Imports) GuidedDecisionTableView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView) GuidedDecisionTableEditorGraphContent(org.drools.workbench.screens.guided.dtable.model.GuidedDecisionTableEditorGraphContent) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Command(org.uberfire.mvp.Command) ViewDRLSourceWidget(org.kie.workbench.common.widgets.client.source.ViewDRLSourceWidget) ObservablePath(org.uberfire.backend.vfs.ObservablePath) Test(org.junit.Test)

Example 12 with Imports

use of org.kie.soup.project.datamodel.imports.Imports in project drools-wb by kiegroup.

the class GuidedScoreCardIndexVisitor method visit.

public void visit() {
    // Add type
    final String typeName = model.getFactName();
    if (typeName == null || typeName.isEmpty()) {
        return;
    }
    final String fullyQualifiedClassName = getFullyQualifiedClassName(typeName);
    ResourceReference resRef = addResourceReference(fullyQualifiedClassName, ResourceType.JAVA);
    // Add field
    final String fieldName = model.getFieldName();
    if (fieldName == null || fieldName.isEmpty()) {
        return;
    }
    resRef.addPartReference(fieldName, PartType.FIELD);
    final String fieldFullyQualifiedClassName = getFieldFullyQualifiedClassName(fullyQualifiedClassName, fieldName);
    addResourceReference(fieldFullyQualifiedClassName, ResourceType.JAVA);
    // Add Characteristics
    for (Characteristic c : model.getCharacteristics()) {
        visit(c);
    }
    // agenda-group, ruleflow-group
    String agendaGroup = model.getAgendaGroup();
    if (agendaGroup != null && !agendaGroup.isEmpty()) {
        addSharedReference(agendaGroup, PartType.AGENDA_GROUP);
    }
    String ruleFlowGroup = model.getRuleFlowGroup();
    if (ruleFlowGroup != null && !ruleFlowGroup.isEmpty()) {
        addSharedReference(ruleFlowGroup, PartType.RULEFLOW_GROUP);
    }
    Imports imports = model.getImports();
    if (imports != null) {
        visit(imports);
    }
}
Also used : Characteristic(org.drools.workbench.models.guided.scorecard.shared.Characteristic) ResourceReference(org.kie.workbench.common.services.refactoring.ResourceReference) Imports(org.kie.soup.project.datamodel.imports.Imports)

Example 13 with Imports

use of org.kie.soup.project.datamodel.imports.Imports in project drools-wb by kiegroup.

the class FromAccumulateCompositeFactPatternWidgetTest method setUp.

@Before
public void setUp() throws Exception {
    // listBox is used for verification fo added available fact types into UI
    GwtMockito.useProviderForType(ListBox.class, aClass -> listBox);
    // Mock partially the AsyncPackageDataModelOracle
    validatorInstance = new MockInstanceImpl<>();
    oracle = spy(new AsyncPackageDataModelOracleImpl(new CallerMock<>(incrementalDataModelService), validatorInstance));
    // Mock partially the AsyncPackageDataModelOracleFactory and ensure oracle will contain data form payload below
    doReturn(syncBeanDef).when(syncBeanManager).lookupBean(AsyncPackageDataModelOracle.class);
    doReturn(oracle).when(syncBeanDef).getInstance();
    doReturn(oracle).when(ruleModeller).getDataModelOracle();
    // Prepare base payload that simulates two Facts in the package, Person and Car
    dataModelPayload = new PackageDataModelOracleBaselinePayload();
    dataModelPayload.setModelFields(new HashMap<String, ModelField[]>() {

        {
            final String fqnPerson = REDHAT_PACKAGE + "." + FACT_TYPE_PERSON;
            final String fqnCar = REDHAT_PACKAGE + "." + FACT_TYPE_CAR;
            final String fqnNumber = Number.class.getName();
            put(fqnPerson, new ModelField[] { modelField(DataType.TYPE_THIS, fqnPerson) });
            put(fqnCar, new ModelField[] { modelField(DataType.TYPE_THIS, fqnCar) });
            put(fqnNumber, new ModelField[] { modelField(DataType.TYPE_THIS, fqnNumber) });
        }
    });
    // Prevent NPE in FromAccumulateCompositeFactPatternWidget constructor
    when(pattern.useFunctionOrCode()).thenReturn(FromAccumulateCompositeFactPattern.USE_FUNCTION);
    fromAccumulateWidget = new FromAccumulateCompositeFactPatternWidget(ruleModeller, eventBus, pattern);
    ruleModelWithImportedNumber = new RuleModel() {

        {
            setImports(new Imports() {

                {
                    addImport(new Import(Number.class));
                }
            });
        }
    };
}
Also used : AsyncPackageDataModelOracleImpl(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracleImpl) Import(org.kie.soup.project.datamodel.imports.Import) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) Matchers.anyString(org.mockito.Matchers.anyString) Imports(org.kie.soup.project.datamodel.imports.Imports) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Before(org.junit.Before)

Example 14 with Imports

use of org.kie.soup.project.datamodel.imports.Imports in project drools-wb by kiegroup.

the class ScenarioTestEditorServiceImpl method load.

@Override
public Scenario load(final Path path) {
    try {
        final String content = ioService.readAllString(Paths.convert(path));
        final Scenario scenario = ScenarioXMLPersistence.getInstance().unmarshal(content);
        scenario.setName(path.getFileName());
        return scenario;
    } catch (final Exception e) {
        logger.error("Unable to unmarshal content. Returning an empty Test Scenario.", e);
        final Package resolvedPackage = moduleService.resolvePackage(path);
        final Scenario scenario = new Scenario();
        if (resolvedPackage != null) {
            scenario.setPackageName(resolvedPackage.getPackageName());
        }
        scenario.setImports(new Imports());
        return scenario;
    }
}
Also used : Package(org.guvnor.common.services.project.model.Package) Imports(org.kie.soup.project.datamodel.imports.Imports) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario)

Example 15 with Imports

use of org.kie.soup.project.datamodel.imports.Imports in project drools-wb by kiegroup.

the class ScenarioTestEditorServiceImplTest method runScenarioWithDependentImportsAndWithoutFactData.

@Test
public void runScenarioWithDependentImportsAndWithoutFactData() throws Exception {
    final ArrayList<Fixture> fixtures = new ArrayList<Fixture>();
    final Imports imports = new Imports() {

        {
            addImport(new Import("java.sql.ClientInfoStatus"));
        }
    };
    final Map<String, ModelField[]> modelFields = new HashMap<String, ModelField[]>() {

        {
            put("java.sql.ClientInfoStatus", new ModelField[] { modelField("java.sql.JDBCType") });
        }
    };
    when(scenario.getFixtures()).thenReturn(fixtures);
    when(dataModelService.getDataModel(path)).thenReturn(modelOracle);
    when(modelOracle.getModuleModelFields()).thenReturn(modelFields);
    when(scenario.getImports()).thenReturn(imports);
    testEditorService.addDependentImportsToScenario(scenario, path);
    assertEquals(2, scenario.getImports().getImports().size());
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) Imports(org.kie.soup.project.datamodel.imports.Imports) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Aggregations

Imports (org.kie.soup.project.datamodel.imports.Imports)17 Test (org.junit.Test)8 Import (org.kie.soup.project.datamodel.imports.Import)8 ArrayList (java.util.ArrayList)5 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)5 HashMap (java.util.HashMap)4 Fixture (org.drools.workbench.models.testscenarios.shared.Fixture)4 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)3 Mockito.anyString (org.mockito.Mockito.anyString)3 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)2 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)2 GuidedDecisionTableView (org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView)2 Before (org.junit.Before)2 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)2 URI (java.net.URI)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 DroolsParserException (org.drools.compiler.compiler.DroolsParserException)1 AnnotationDescr (org.drools.compiler.lang.descr.AnnotationDescr)1 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)1