Example #1
0
  /**
   * Finds a link to object if one exists.
   *
   * @param o Object that might have a page that can be linked.
   * @return Link to objects page or the toString() text if no link could not be created.
   */
  public static String getUrl(Object o) {
    if (o instanceof VerifierRule) {
      VerifierRule rule = (VerifierRule) o;
      return getRuleUrl(UrlFactory.RULE_FOLDER, rule.getId(), rule.getRuleName());
    }

    return o.toString();
  }
  public void testRulePossibilityRedundancy() throws Exception {
    StatelessSession session =
        getStatelessSession(this.getClass().getResourceAsStream("Possibilities.drl"));

    session.setAgendaFilter(new RuleNameMatchesAgendaFilter("Find rule possibility redundancy"));

    Collection<Object> data = new ArrayList<Object>();

    VerifierResult result = VerifierResultFactory.createVerifierResult();
    session.setGlobal("result", result);

    /*
     * First rules. These are redundant,
     */
    String ruleName1 = "Rule 1";
    String ruleName2 = "Rule 2";

    VerifierRule r1 = new VerifierRule();
    r1.setRuleName(ruleName1);
    VerifierRule r2 = new VerifierRule();
    r2.setRuleName(ruleName2);

    PatternPossibility pp1 = new PatternPossibility();
    pp1.setRuleName(ruleName1);
    PatternPossibility pp2 = new PatternPossibility();
    pp2.setRuleName(ruleName2);

    RulePossibility rp1 = new RulePossibility();
    rp1.setRuleId(r1.getId());
    rp1.setRuleName(ruleName1);
    rp1.add(pp1);

    RulePossibility rp2 = new RulePossibility();
    rp2.setRuleId(r2.getId());
    rp2.setRuleName(ruleName2);
    rp2.add(pp2);

    Redundancy possibilityredundancy = new Redundancy(RedundancyType.STRONG, pp1, pp2);
    Redundancy ruleRedundancy = new Redundancy(r1, r2);

    data.add(r1);
    data.add(r2);
    data.add(pp1);
    data.add(pp2);
    data.add(possibilityredundancy);
    data.add(ruleRedundancy);
    data.add(rp1);
    data.add(rp2);

    /*
     * These two rules are not redundant
     */
    String ruleName3 = "Rule 3";
    String ruleName4 = "Rule 4";

    VerifierRule r3 = new VerifierRule();
    r3.setRuleName(ruleName3);
    VerifierRule r4 = new VerifierRule();
    r4.setRuleName(ruleName4);

    PatternPossibility pp3 = new PatternPossibility();
    pp3.setRuleId(r3.getId());
    pp3.setRuleName(ruleName3);
    PatternPossibility pp4 = new PatternPossibility();
    pp4.setRuleId(r4.getId());
    pp4.setRuleName(ruleName4);
    // This possibility makes them different
    PatternPossibility pp5 = new PatternPossibility();
    pp5.setRuleId(r4.getId());
    pp5.setRuleName(ruleName4);

    RulePossibility rp3 = new RulePossibility();
    rp3.setRuleId(r3.getId());
    rp3.setRuleName(ruleName3);
    rp3.add(pp3);

    RulePossibility rp4 = new RulePossibility();
    rp4.setRuleId(r4.getId());
    rp4.setRuleName(ruleName4);
    rp4.add(pp4);
    rp4.add(pp5);

    Redundancy possibilityredundancy2 = new Redundancy(RedundancyType.STRONG, pp3, pp4);
    Redundancy ruleRedundancy2 = new Redundancy(r3, r4);

    data.add(r3);
    data.add(r4);
    data.add(pp3);
    data.add(pp4);
    data.add(pp5);
    data.add(possibilityredundancy2);
    data.add(ruleRedundancy2);
    data.add(rp3);
    data.add(rp4);

    StatelessSessionResult sessionResult = session.executeWithResults(data);

    Map<Cause, Set<Cause>> map =
        createRedundancyCauseMap(CauseType.RULE_POSSIBILITY, sessionResult.iterateObjects());

    assertTrue(TestBase.causeMapContains(map, rp1, rp2));
    assertFalse(TestBase.causeMapContains(map, rp3, rp4));

    if (!map.isEmpty()) {
      fail("More redundancies than was expected.");
    }
  }