@Test public void testIndexDrlLHSTypeExpressionField2() throws IOException, InterruptedException { // Add test files final Path path1 = basePath.resolve("drl4.drl"); final String drl1 = loadText("drl4.drl"); ioService().write(path1, drl1); Thread.sleep( 5000); // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) // -> lucene index final Index index = getConfig() .getIndexManager() .get(org.uberfire.ext.metadata.io.KObjectUtil.toKCluster(basePath.getFileSystem())); { final Query query = new SingleTermQueryBuilder( new ValueReferenceIndexTerm( "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", ResourceType.JAVA)) .build(); searchFor(index, query, 1, path1); } { final Query query = new SingleTermQueryBuilder( new ValueReferenceIndexTerm( "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Mortgage", ResourceType.JAVA)) .build(); searchFor(index, query, 1, path1); } { final Query query = new SingleTermQueryBuilder( new ValuePartReferenceIndexTerm( "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Mortgage", "applicant", PartType.FIELD)) .build(); searchFor(index, query, 1, path1); } { final Query query = new SingleTermQueryBuilder( new ValuePartReferenceIndexTerm( "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", "age", PartType.FIELD)) .build(); searchFor(index, query, 1, path1); } }
@Test public void testIndexDrlRuleAttributeNameAndValueComposition() throws IOException, InterruptedException { // Add test files final Path path = basePath.resolve("drl5.drl"); final String drl = loadText("drl5.drl"); ioService().write(path, drl); Thread.sleep( 5000); // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) // -> lucene index final Index index = getConfig() .getIndexManager() .get(org.uberfire.ext.metadata.io.KObjectUtil.toKCluster(basePath.getFileSystem())); // DRL defining a RuleFlow-Group named myRuleFlowGroup. This should match drl5.drl // This checks whether there is a Rule Attribute "ruleflow-group" and its Value is // "myRuleflowGroup" { final Query query = new SingleTermQueryBuilder( new ValueSharedPartIndexTerm("myRuleFlowGroup", PartType.RULEFLOW_GROUP)) .build(); searchFor(index, query, 1, path); } // DRL defining a RuleFlow-Group named myAgendaGroup. This should *NOT* match drl5.drl { final Query query = new SingleTermQueryBuilder( new ValueSharedPartIndexTerm("myAgendaGroup", PartType.RULEFLOW_GROUP)) .build(); searchFor(index, query, 0); } }
@Test public void testIndexDrlLHSTypeExpressionField4() throws IOException, InterruptedException { // Add test files final Path path1 = basePath.resolve("drl6.drl"); final String drl1 = loadText("drl6.drl"); ioService().write(path1, drl1); Thread.sleep( 5000); // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) // -> lucene index final Index index = getConfig() .getIndexManager() .get(org.uberfire.ext.metadata.io.KObjectUtil.toKCluster(basePath.getFileSystem())); { final IndexSearcher searcher = ((LuceneIndex) index).nrtSearcher(); final TopScoreDocCollector collector = TopScoreDocCollector.create(10, true); final Query query = new QueryBuilder() .addTerm( new ValueTypeIndexTerm( "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Bank")) .build(); searcher.search(query, collector); final ScoreDoc[] hits = collector.topDocs().scoreDocs; assertEquals(1, hits.length); final List<KObject> results = new ArrayList<KObject>(); for (int i = 0; i < hits.length; i++) { results.add(KObjectUtil.toKObject(searcher.doc(hits[i].doc))); } assertContains(results, path1); ((LuceneIndex) index).nrtRelease(searcher); } { final IndexSearcher searcher = ((LuceneIndex) index).nrtSearcher(); final TopScoreDocCollector collector = TopScoreDocCollector.create(10, true); final Query query = new QueryBuilder() .addTerm( new ValueTypeIndexTerm( "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Mortgage")) .build(); searcher.search(query, collector); final ScoreDoc[] hits = collector.topDocs().scoreDocs; assertEquals(1, hits.length); final List<KObject> results = new ArrayList<KObject>(); for (int i = 0; i < hits.length; i++) { results.add(KObjectUtil.toKObject(searcher.doc(hits[i].doc))); } assertContains(results, path1); ((LuceneIndex) index).nrtRelease(searcher); } { final IndexSearcher searcher = ((LuceneIndex) index).nrtSearcher(); final TopScoreDocCollector collector = TopScoreDocCollector.create(10, true); final Query query = new QueryBuilder() .addTerm( new ValueTypeIndexTerm( "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant")) .build(); searcher.search(query, collector); final ScoreDoc[] hits = collector.topDocs().scoreDocs; assertEquals(1, hits.length); final List<KObject> results = new ArrayList<KObject>(); for (int i = 0; i < hits.length; i++) { results.add(KObjectUtil.toKObject(searcher.doc(hits[i].doc))); } assertContains(results, path1); ((LuceneIndex) index).nrtRelease(searcher); } { final IndexSearcher searcher = ((LuceneIndex) index).nrtSearcher(); final TopScoreDocCollector collector = TopScoreDocCollector.create(10, true); final Query query = new QueryBuilder() .addTerm( new ValueTypeIndexTerm( "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Bank")) .addTerm(new ValueFieldIndexTerm("mortgage")) .build(); searcher.search(query, collector); final ScoreDoc[] hits = collector.topDocs().scoreDocs; assertEquals(1, hits.length); final List<KObject> results = new ArrayList<KObject>(); for (int i = 0; i < hits.length; i++) { results.add(KObjectUtil.toKObject(searcher.doc(hits[i].doc))); } assertContains(results, path1); ((LuceneIndex) index).nrtRelease(searcher); } { final IndexSearcher searcher = ((LuceneIndex) index).nrtSearcher(); final TopScoreDocCollector collector = TopScoreDocCollector.create(10, true); final Query query = new QueryBuilder() .addTerm( new ValueTypeIndexTerm( "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Mortgage")) .addTerm(new ValueFieldIndexTerm("applicant")) .build(); searcher.search(query, collector); final ScoreDoc[] hits = collector.topDocs().scoreDocs; assertEquals(1, hits.length); final List<KObject> results = new ArrayList<KObject>(); for (int i = 0; i < hits.length; i++) { results.add(KObjectUtil.toKObject(searcher.doc(hits[i].doc))); } assertContains(results, path1); ((LuceneIndex) index).nrtRelease(searcher); } { final IndexSearcher searcher = ((LuceneIndex) index).nrtSearcher(); final TopScoreDocCollector collector = TopScoreDocCollector.create(10, true); final Query query = new QueryBuilder() .addTerm( new ValueTypeIndexTerm( "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant")) .addTerm(new ValueFieldIndexTerm("age")) .build(); searcher.search(query, collector); final ScoreDoc[] hits = collector.topDocs().scoreDocs; assertEquals(1, hits.length); final List<KObject> results = new ArrayList<KObject>(); for (int i = 0; i < hits.length; i++) { results.add(KObjectUtil.toKObject(searcher.doc(hits[i].doc))); } assertContains(results, path1); ((LuceneIndex) index).nrtRelease(searcher); } }
@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); Thread.sleep( 5000); // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) // -> lucene index final Index index = getConfig() .getIndexManager() .get(org.uberfire.ext.metadata.io.KObjectUtil.toKCluster(basePath.getFileSystem())); // Score Cards using // org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Applicant { final IndexSearcher searcher = ((LuceneIndex) index).nrtSearcher(); final TopScoreDocCollector collector = TopScoreDocCollector.create(10, true); final Query query = new BasicQueryBuilder() .addTerm( new ValueTypeIndexTerm( "org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Applicant")) .build(); searcher.search(query, collector); final ScoreDoc[] hits = collector.topDocs().scoreDocs; assertEquals(2, hits.length); final List<KObject> results = new ArrayList<KObject>(); for (int i = 0; i < hits.length; i++) { results.add(KObjectUtil.toKObject(searcher.doc(hits[i].doc))); } assertContains(results, path1); assertContains(results, path2); ((LuceneIndex) index).nrtRelease(searcher); } // Score Cards using // org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage { final IndexSearcher searcher = ((LuceneIndex) index).nrtSearcher(); final TopScoreDocCollector collector = TopScoreDocCollector.create(10, true); final Query query = new BasicQueryBuilder() .addTerm( new ValueTypeIndexTerm( "org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage")) .build(); searcher.search(query, collector); final ScoreDoc[] hits = collector.topDocs().scoreDocs; assertEquals(1, hits.length); final List<KObject> results = new ArrayList<KObject>(); for (int i = 0; i < hits.length; i++) { results.add(KObjectUtil.toKObject(searcher.doc(hits[i].doc))); } assertContains(results, path1); ((LuceneIndex) index).nrtRelease(searcher); } // Score Cards using // org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage#amount { final IndexSearcher searcher = ((LuceneIndex) index).nrtSearcher(); final TopScoreDocCollector collector = TopScoreDocCollector.create(10, true); final Query query = new BasicQueryBuilder() .addTerm( new ValueTypeIndexTerm( "org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage")) .addTerm(new ValueFieldIndexTerm("amount")) .build(); searcher.search(query, collector); final ScoreDoc[] hits = collector.topDocs().scoreDocs; assertEquals(1, hits.length); final List<KObject> results = new ArrayList<KObject>(); for (int i = 0; i < hits.length; i++) { results.add(KObjectUtil.toKObject(searcher.doc(hits[i].doc))); } assertContains(results, path1); ((LuceneIndex) index).nrtRelease(searcher); } // Score Cards using java.lang.Integer { final IndexSearcher searcher = ((LuceneIndex) index).nrtSearcher(); final TopScoreDocCollector collector = TopScoreDocCollector.create(10, true); final Query query = new BasicQueryBuilder().addTerm(new ValueTypeIndexTerm("java.lang.Integer")).build(); searcher.search(query, collector); final ScoreDoc[] hits = collector.topDocs().scoreDocs; assertEquals(2, hits.length); final List<KObject> results = new ArrayList<KObject>(); for (int i = 0; i < hits.length; i++) { results.add(KObjectUtil.toKObject(searcher.doc(hits[i].doc))); } assertContains(results, path1); assertContains(results, path2); ((LuceneIndex) index).nrtRelease(searcher); } }