コード例 #1
0
  @Test
  public void testIndexDrlRuleMultipleTypes() throws IOException, InterruptedException {
    // Add test files
    final Path path1 = basePath.resolve("drl3.rdrl");
    final String drl1 = loadText("drl3.rdrl");
    ioService().write(path1, drl1);
    final Path path2 = basePath.resolve("drl4.rdrl");
    final String drl2 = loadText("drl4.rdrl");
    ioService().write(path2, drl2);

    Thread.sleep(
        5000); // wait for events to be consumed from jgit -> (notify changes -> watcher -> index)
    // -> lucene index

    final Index index =
        getConfig()
            .getIndexManager()
            .get(org.kie.uberfire.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.drools.workbench.screens.guided.rule.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);
    }

    {
      final IndexSearcher searcher = ((LuceneIndex) index).nrtSearcher();
      final TopScoreDocCollector collector = TopScoreDocCollector.create(10, true);
      final Query query =
          new QueryBuilder()
              .addTerm(
                  new ValueTypeIndexTerm(
                      "org.drools.workbench.screens.guided.rule.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, path2);

      ((LuceneIndex) index).nrtRelease(searcher);
    }
  }
  @Test
  public void testIndexGuidedDecisionTableBRLFragmentActions()
      throws IOException, InterruptedException {
    // Add test files
    final Path path = basePath.resolve("dtable1.gdst");
    final GuidedDecisionTable52 model =
        GuidedDecisionTableFactory.makeTableWithBRLFragmentActionCol(
            "org.drools.workbench.screens.guided.dtable.backend.server.indexing",
            new ArrayList<Import>() {
              {
                add(
                    new Import(
                        "org.drools.workbench.screens.guided.dtable.backend.server.indexing.classes.Applicant"));
                add(
                    new Import(
                        "org.drools.workbench.screens.guided.dtable.backend.server.indexing.classes.Mortgage"));
              }
            },
            "dtable1");
    final String xml = GuidedDTXMLPersistence.getInstance().marshal(model);
    ioService().write(path, xml);

    Thread.sleep(
        5000); // wait for events to be consumed from jgit -> (notify changes -> watcher -> index)
               // -> lucene index

    final Index index =
        getConfig()
            .getIndexManager()
            .get(org.kie.uberfire.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.drools.workbench.screens.guided.dtable.backend.server.indexing.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, path);

      ((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.drools.workbench.screens.guided.dtable.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, path);

      ((LuceneIndex) index).nrtRelease(searcher);
    }
  }