Search in sources :

Example 6 with AsyncPackageDataModelOracleImpl

use of org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracleImpl in project drools-wb by kiegroup.

the class ConstraintValueEditorHelperTest method testEvents_BoundTypeIsEvent.

@Test
public void testEvents_BoundTypeIsEvent() throws Exception {
    AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(serviceCaller, validatorInstance);
    oracle.setPackageName("org.test");
    oracle.addModelFields(new HashMap<String, ModelField[]>() {

        {
            put("org.test.Event1", new ModelField[] { modelField("this", "org.test.Event1") });
            put("org.test.Event2", new ModelField[] { modelField("this", "org.test.Event2") });
        }
    });
    oracle.addEventTypes(new HashMap<String, Boolean>() {

        {
            put("org.test.Event1", true);
            put("org.test.Event2", false);
        }
    });
    oracle.addSuperTypes(new HashMap<String, List<String>>() {

        {
            put("org.test.Event1", Collections.EMPTY_LIST);
            put("org.test.Event2", Collections.EMPTY_LIST);
        }
    });
    oracle.filter();
    FactPattern pattern1 = new FactPattern();
    pattern1.setFactType("Event1");
    pattern1.setBoundName("$e");
    SingleFieldConstraint constraint = new SingleFieldConstraint();
    constraint.setFactType("Event1");
    constraint.setFieldName("this");
    constraint.setFieldType("Event1");
    constraint.setOperator(OperatorsOracle.SIMPLE_CEP_OPERATORS[0]);
    pattern1.addConstraint(constraint);
    model.addLhsItem(pattern1);
    ConstraintValueEditorHelper helper = new ConstraintValueEditorHelper(model, oracle, "Event2", "this", constraint, "Event2", new DropDownData());
    helper.isApplicableBindingsInScope("$e", new Callback<Boolean>() {

        @Override
        public void callback(Boolean result) {
            assertFalse(result);
        }
    });
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ConstraintValueEditorHelper(org.drools.workbench.screens.guided.rule.client.editor.util.ConstraintValueEditorHelper) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) AsyncPackageDataModelOracleImpl(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracleImpl) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) List(java.util.List) Test(org.junit.Test)

Example 7 with AsyncPackageDataModelOracleImpl

use of org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracleImpl 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)

Aggregations

AsyncPackageDataModelOracleImpl (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracleImpl)7 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)6 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)3 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)3 ConstraintValueEditorHelper (org.drools.workbench.screens.guided.rule.client.editor.util.ConstraintValueEditorHelper)3 Before (org.junit.Before)3 Test (org.junit.Test)3 DropDownData (org.kie.soup.project.datamodel.oracle.DropDownData)3 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)3 HashMap (java.util.HashMap)2 List (java.util.List)2 HashSet (java.util.HashSet)1 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)1 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)1 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)1 Connectives (org.drools.workbench.screens.guided.rule.client.editor.factPattern.Connectives)1 FactTypes (org.drools.workbench.services.verifier.plugin.client.api.FactTypes)1 Import (org.kie.soup.project.datamodel.imports.Import)1 Imports (org.kie.soup.project.datamodel.imports.Imports)1 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)1