Search in sources :

Example 96 with Import

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

the class IndexGuidedScoreCardTest method testIndexGuidedScoreCard.

@Test
public void testIndexGuidedScoreCard() throws IOException, InterruptedException {
    // Add test files
    final Path path1 = basePath.resolve("scorecard1.scgd");
    final ScoreCardModel model1 = GuidedScoreCardFactory.makeScoreCardWithCharacteristics("org.drools.workbench.screens.guided.scorecard.backend.server.indexing", new ArrayList<Import>() {

        {
            add(new Import("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Applicant"));
            add(new Import("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage"));
        }
    }, "scorecard1");
    final String xml1 = GuidedScoreCardXMLPersistence.getInstance().marshal(model1);
    ioService().write(path1, xml1);
    final Path path2 = basePath.resolve("scorecard2.scgd");
    final ScoreCardModel model2 = GuidedScoreCardFactory.makeScoreCardWithoutCharacteristics("org.drools.workbench.screens.guided.scorecard.backend.server.indexing", new ArrayList<Import>() {

        {
            add(new Import("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Applicant"));
            add(new Import("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage"));
        }
    }, "scorecard2");
    final String xml2 = GuidedScoreCardXMLPersistence.getInstance().marshal(model2);
    ioService().write(path2, xml2);
    final Path path3 = basePath.resolve("scorecard3.scgd");
    final ScoreCardModel model3 = GuidedScoreCardFactory.makeEmptyScoreCard("org.drools.workbench.screens.guided.scorecard.backend.server.indexing", "scorecard3");
    final String xml3 = GuidedScoreCardXMLPersistence.getInstance().marshal(model3);
    ioService().write(path3, xml3);
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId());
    // Score Cards using org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Applicant
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Applicant", ResourceType.JAVA)).build();
        searchFor(index, query, 2, path1, path2);
    }
    // Score Cards referring to org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage", ResourceType.JAVA)).build();
        searchFor(index, query, 2, path1);
    }
    // Score Cards using org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage#amount
    {
        final Query query = new SingleTermQueryBuilder(new ValuePartReferenceIndexTerm("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage", "amount", PartType.FIELD)).build();
        searchFor(index, query, 1, path1);
    }
    // Score Cards using java.lang.Integer
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("java.lang.Integer", ResourceType.JAVA)).build();
        searchFor(index, query, 2, path1, path2);
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValuePartReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartReferenceIndexTerm) Import(org.kie.soup.project.datamodel.imports.Import) Query(org.apache.lucene.search.Query) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) ValueReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm) ScoreCardModel(org.drools.workbench.models.guided.scorecard.shared.ScoreCardModel) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 97 with Import

use of org.kie.soup.project.datamodel.imports.Import 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 98 with Import

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

the class DecisionTableAnalyzerConflictResolverLimitedDTableTest method testConflict.

@Test
public void testConflict() throws Exception {
    table52 = new LimitedGuidedDecisionTableBuilder("org.test", new ArrayList<Import>(), "mytable").withIntegerColumn("a", "Person", "age", "==", 0).withAction("a", "approved", DataType.TYPE_BOOLEAN, new DTCellValue52() {

        {
            setBooleanValue(true);
        }
    }).withAction("a", "approved", DataType.TYPE_BOOLEAN, new DTCellValue52() {

        {
            setBooleanValue(false);
        }
    }).withData(new Object[][] { { 1, "", "description", true, true, false }, { 2, "", "description", true, false, true } }).buildTable();
    fireUpAnalyzer();
    assertContains(analyzerProvider.getAnalysisReport(), CheckType.CONFLICTING_ROWS, Severity.WARNING, 2);
    assertContains(analyzerProvider.getAnalysisReport(), CheckType.CONFLICTING_ROWS, Severity.WARNING, 1);
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) LimitedGuidedDecisionTableBuilder(org.drools.workbench.services.verifier.plugin.client.testutil.LimitedGuidedDecisionTableBuilder) Test(org.junit.Test)

Example 99 with Import

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

the class DecisionTableAnalyzerSubsumptionResolverTest method testNoIssues2.

@Test
public void testNoIssues2() throws Exception {
    GuidedDecisionTable52 table52 = new ExtendedGuidedDecisionTableBuilder("org.test", new ArrayList<Import>(), "mytable").withConditionIntegerColumn("application", "LoanApplication", "amount", ">").withConditionIntegerColumn("application", "LoanApplication", "amount", "<=").withConditionIntegerColumn("application", "LoanApplication", "lengthYears", "==").withConditionIntegerColumn("application", "LoanApplication", "deposit", "<").withStringColumn("income", "IncomeSource", "type", "==").withActionSetField("application", "approved", DataType.TYPE_BOOLEAN).withActionSetField("application", "insuranceCost", DataType.TYPE_NUMERIC_INTEGER).withActionSetField("application", "approvedRate", DataType.TYPE_NUMERIC_INTEGER).withData(new Object[][] { { 1, "", "description", 131000, 200000, 30, 20000, "Asset", true, 0, 2 }, { 2, "", "description", 1000, 200000, 30, 20000, "Asset", true, 0, 2 }, { 3, "", "description", 100001, 130000, 20, 3000, "Job", true, 10, 6 } }).buildTable();
    Analyzer analyzer = analyzerProvider.makeAnalyser(table52);
    analyzer.resetChecks();
    analyzer.analyze();
    assertDoesNotContain(CheckType.REDUNDANT_ROWS, analyzerProvider.getAnalysisReport());
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Import(org.kie.soup.project.datamodel.imports.Import) ExtendedGuidedDecisionTableBuilder(org.drools.workbench.services.verifier.plugin.client.testutil.ExtendedGuidedDecisionTableBuilder) Analyzer(org.drools.verifier.core.main.Analyzer) Test(org.junit.Test)

Example 100 with Import

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

the class DecisionTableAnalyzerSubsumptionResolverTest method testRedundantRows001.

@Test
@Ignore("This randomly does not pick up the issue. Better that way, I'm hoping future changes will find the cause. Every other test works 100%")
public void testRedundantRows001() throws Exception {
    GuidedDecisionTable52 table52 = new ExtendedGuidedDecisionTableBuilder("org.test", new ArrayList<Import>(), "mytable").withNumericColumn("application", "LoanApplication", "amount", ">").withNumericColumn("application", "LoanApplication", "amount", "<=").withNumericColumn("application", "LoanApplication", "lengthYears", "==").withNumericColumn("application", "LoanApplication", "deposit", "<").withStringColumn("income", "IncomeSource", "type", "==").withActionSetField("application", "approved", DataType.TYPE_BOOLEAN).withActionSetField("application", "insuranceCost", DataType.TYPE_NUMERIC).withActionSetField("application", "approvedRate", DataType.TYPE_NUMERIC).withData(new Object[][] { { 1, "", "description", 131000, 200000, 30, 20000, "Asset", true, 0, 2 }, { 2, "", "description", 131000, 200000, 30, 20000, "Asset", true, 0, 2 }, { 3, "", "description", 100001, 130000, 20, 3000, "Job", true, 10, 6 } }).buildTable();
    Analyzer analyzer = analyzerProvider.makeAnalyser(table52);
    analyzer.resetChecks();
    analyzer.analyze();
    assertContains(analyzerProvider.getAnalysisReport(), CheckType.REDUNDANT_ROWS, Severity.WARNING, 1, 2);
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Import(org.kie.soup.project.datamodel.imports.Import) ExtendedGuidedDecisionTableBuilder(org.drools.workbench.services.verifier.plugin.client.testutil.ExtendedGuidedDecisionTableBuilder) Analyzer(org.drools.verifier.core.main.Analyzer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Import (org.kie.soup.project.datamodel.imports.Import)103 Test (org.junit.Test)79 Imports (org.kie.soup.project.datamodel.imports.Imports)26 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)25 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)14 ArrayList (java.util.ArrayList)12 Path (org.uberfire.java.nio.file.Path)12 Query (org.apache.lucene.search.Query)11 FactData (org.drools.workbench.models.testscenarios.shared.FactData)11 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)11 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)11 SingleTermQueryBuilder (org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder)11 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)10 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)9 KieSession (org.kie.api.runtime.KieSession)9 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)9 ValueReferenceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm)9 Path (org.uberfire.backend.vfs.Path)9 ProjectImports (org.guvnor.common.services.project.model.ProjectImports)8 Analyzer (org.drools.verifier.core.main.Analyzer)7