@Test
 public void testKeepReference() throws Exception {
   /* Make sure the RuleBase is referencing all 4 Working Memories */
   assertLength(4, this.ruleBase.getStatefulSessions());
   assertContains(this.wm1, this.ruleBase.getStatefulSessions());
   assertContains(this.wm2, this.ruleBase.getStatefulSessions());
   assertContains(this.wm3, this.ruleBase.getStatefulSessions());
   assertContains(this.wm4, this.ruleBase.getStatefulSessions());
 }
  @Test
  public void testProjectDMOAnnotationAttributes2() throws Exception {
    final ProjectDataModelOracleBuilder builder =
        ProjectDataModelOracleBuilder.newProjectOracleBuilder();
    final ProjectDataModelOracleImpl oracle = new ProjectDataModelOracleImpl();

    final ClassFactBuilder cb =
        new ClassFactBuilder(builder, RoleSmurf.class, false, TypeSource.JAVA_PROJECT);
    cb.build(oracle);

    assertEquals(1, oracle.getProjectModelFields().size());
    assertContains(
        "org.kie.workbench.common.services.datamodel.backend.server.testclasses.annotations.RoleSmurf",
        oracle.getProjectModelFields().keySet());

    final Set<Annotation> annotations =
        oracle
            .getProjectTypeAnnotations()
            .get(
                "org.kie.workbench.common.services.datamodel.backend.server.testclasses.annotations.RoleSmurf");
    assertNotNull(annotations);
    assertEquals(1, annotations.size());

    final Annotation annotation = annotations.iterator().next();
    assertEquals("org.kie.api.definition.type.Role", annotation.getQualifiedTypeName());
    assertEquals(Role.Type.EVENT.name(), annotation.getAttributes().get("value"));
  }
示例#3
0
  /**
   * POST Test: specify an option.
   *
   * @throws IOException I/O exception
   */
  @Test
  public void postOption() throws IOException {
    assertEquals(
        "2",
        post(
            "",
            "<query xmlns=\""
                + URI
                + "\">"
                + "<text>2, delete node &lt;a/&gt;</text>"
                + "<option name='"
                + MainOptions.MIXUPDATES.name()
                + "' value='true'/></query>",
            APP_XML));

    try {
      post(
          "",
          "<query xmlns=\""
              + URI
              + "\">"
              + "<text>1, delete node &lt;a/&gt;</text>"
              + "<option name='"
              + MainOptions.MIXUPDATES.name()
              + "' value='false'/></query>",
          APP_XML);
      fail("Error expected.");
    } catch (final IOException ex) {
      assertContains(ex.getMessage(), "[XUST0001]");
    }
  }
示例#4
0
 /** POST Test: execute buggy query. */
 @Test
 public void postErr() {
   try {
     assertEquals("", post("", "<query xmlns=\"" + URI + "\"><text>(</text></query>", APP_XML));
   } catch (final IOException ex) {
     assertContains(ex.getMessage(), "[XPST0003]");
   }
 }
示例#5
0
  @Test
  public void canGetMultiplePathsInASmallRoadNetwork() throws Exception {
    Node nodeA = graph.makeNode("A");
    Node nodeB = graph.makeNode("B");
    Node nodeC = graph.makeNode("C");
    Node nodeD = graph.makeNode("D");
    Node nodeE = graph.makeNode("E");
    Node nodeF = graph.makeNode("F");
    graph.makeEdge("A", "B", "length", 2d);
    graph.makeEdge("A", "C", "length", 2.5d);
    graph.makeEdge("C", "D", "length", 7.3d);
    graph.makeEdge("B", "D", "length", 2.5d);
    graph.makeEdge("D", "E", "length", 3d);
    graph.makeEdge("C", "E", "length", 5d);
    graph.makeEdge("E", "F", "length", 5d);
    graph.makeEdge("C", "F", "length", 12d);
    graph.makeEdge("A", "F", "length", 25d);

    Dijkstra algo =
        new Dijkstra(
            PathExpanders.allTypesAndDirections(), CommonEvaluators.doubleCostEvaluator("length"));

    // Try the search in both directions.
    for (Node[] nodes : new Node[][] {{nodeA, nodeF}, {nodeF, nodeA}}) {
      int found = 0;
      Iterator<WeightedPath> paths = algo.findAllPaths(nodes[0], nodes[1]).iterator();
      for (int i = 0; i < 2; i++) {
        assertTrue("expected more paths", paths.hasNext());
        Path path = paths.next();
        if (path.length() != found && path.length() == 3) {
          assertContains(path.nodes(), nodeA, nodeC, nodeE, nodeF);
        } else if (path.length() != found && path.length() == 4) {
          assertContains(path.nodes(), nodeA, nodeB, nodeD, nodeE, nodeF);
        } else {
          fail("unexpected path length: " + path.length());
        }
        found = path.length();
      }
      assertFalse("expected at most two paths", paths.hasNext());
    }
  }
  @Test
  public void testImpossibleMatch001() throws Exception {
    analyzer =
        analyzerProvider
            .makeAnalyser()
            .withPersonAgeColumn(">")
            .withPersonAgeColumn("<")
            .withData(DataBuilderProvider.row(100, 0).end())
            .buildAnalyzer();

    fireUpAnalyzer();

    assertContains("ImpossibleMatch", analyzerProvider.getAnalysisReport());
  }
  @Test
  public void testConflictWithASubsumingRow() throws Exception {
    analyzer =
        analyzerProvider
            .makeAnalyser()
            .withPersonAgeColumn("==")
            .withPersonNameColumn("==")
            .withPersonLastNameColumn("==")
            .withPersonSalarySetFieldAction()
            .withPersonDescriptionSetActionField()
            .withData(
                DataBuilderProvider.row(null, null, null, 100, "ok")
                    .row(null, "Toni", null, 200, "ok")
                    .row(12, "Toni", "Rikkola", 300, "ok")
                    .row(null, null, null, null, null)
                    .end())
            .buildAnalyzer();

    fireUpAnalyzer();

    assertContains("ConflictingRows", analyzerProvider.getAnalysisReport(), 2);
    assertContains("ConflictingRows", analyzerProvider.getAnalysisReport(), 3);
  }
  @Test
  public void testNoIssueWithNulls() throws Exception {
    table52 =
        analyzerProvider
            .makeAnalyser()
            .withPersonAgeColumn(">")
            .withPersonAgeColumn("<")
            .withData(DataBuilderProvider.row(null, null).end())
            .buildTable();

    // After a save has been done, the server side sometimes sets the String field value to "" for
    // numbers, even when the data type is a number
    table52.getData().get(0).get(2).setStringValue("");
    table52.getData().get(0).get(3).setStringValue("");

    fireUpAnalyzer();

    assertContains("EmptyRule", analyzerProvider.getAnalysisReport(), 1);
  }
  @Test
  public void testProjectDMOZeroAnnotationAttributes() throws Exception {
    final ProjectDataModelOracleBuilder builder =
        ProjectDataModelOracleBuilder.newProjectOracleBuilder();
    final ProjectDataModelOracleImpl oracle = new ProjectDataModelOracleImpl();

    final ClassFactBuilder cb =
        new ClassFactBuilder(builder, Product.class, false, TypeSource.JAVA_PROJECT);
    cb.build(oracle);

    assertEquals(1, oracle.getProjectModelFields().size());
    assertContains(
        "org.kie.workbench.common.services.datamodel.backend.server.testclasses.Product",
        oracle.getProjectModelFields().keySet());

    final Set<Annotation> annotations =
        oracle
            .getProjectTypeAnnotations()
            .get("org.kie.workbench.common.services.datamodel.backend.server.testclasses.Product");
    assertNotNull(annotations);
    assertEquals(0, annotations.size());
  }
  @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 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);
    }
  }
  @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);
    }
  }