/** Test method for {@link org.drools.reteoo.BetaNode#equals(java.lang.Object)}. */
  public void testEqualsObject() {
    final TupleSource ts = new MockTupleSource(1);
    final ObjectSource os = new MockObjectSource(2);

    ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
    BuildContext buildContext =
        new BuildContext(ruleBase, ruleBase.getReteooBuilder().getIdGenerator());

    final BetaNode j1 = new JoinNode(1, ts, os, EmptyBetaConstraints.getInstance(), buildContext);
    final BetaNode j2 = new JoinNode(2, ts, os, EmptyBetaConstraints.getInstance(), buildContext);
    final BetaNode n1 = new NotNode(3, ts, os, EmptyBetaConstraints.getInstance(), buildContext);
    final BetaNode n2 = new NotNode(4, ts, os, EmptyBetaConstraints.getInstance(), buildContext);

    assertEquals(j1, j1);
    assertEquals(j2, j2);
    assertEquals(j1, j2);
    assertEquals(n1, n1);
    assertEquals(n2, n2);
    assertEquals(n1, n2);

    assertFalse(j1.equals(n1));
    assertFalse(j1.equals(n2));
    assertFalse(n1.equals(j1));
    assertFalse(n1.equals(j2));
  }
Example #2
0
  @Test
  public void testEvalDetectionInBetaNode() {
    // Tests evals are generated and executed with Java dialect

    String drl = "";
    drl += "package org.test\n";
    drl += "import org.drools.Person\n";
    drl += "global java.util.List list\n";
    drl += "rule test1\n";
    drl += "when\n";
    drl += "   $s  : String()\n";
    drl += "   $p1 : Person( eval( name \n != $s ), name == ( new String($s+\"xxx\") ) )\n";
    drl += "then\n";
    drl += "end\n";

    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newReaderResource(new StringReader(drl)), ResourceType.DRL);
    KnowledgeBuilderErrors errors = kbuilder.getErrors();
    if (kbuilder.hasErrors()) {
      fail(kbuilder.getErrors().toString());
    }
    assertFalse(kbuilder.hasErrors());

    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

    List<ObjectTypeNode> nodes =
        ((InternalRuleBase) ((KnowledgeBaseImpl) kbase).ruleBase).getRete().getObjectTypeNodes();
    ObjectTypeNode node = null;
    for (ObjectTypeNode n : nodes) {
      if (((ClassObjectType) n.getObjectType()).getClassType() == Person.class) {
        node = n;
        break;
      }
    }

    BetaNode betaanode = (BetaNode) node.getSinkPropagator().getSinks()[0];
    BetaNodeFieldConstraint[] constraint = (BetaNodeFieldConstraint[]) betaanode.getConstraints();
    PredicateConstraint c = (PredicateConstraint) constraint[0];
    assertTrue(c.getPredicateExpression() instanceof PredicateExpression);
    assertTrue(c.getPredicateExpression() instanceof CompiledInvoker);
    assertTrue(!(c.getPredicateExpression() instanceof MVELPredicateExpression));

    ReturnValueRestriction r =
        (ReturnValueRestriction) ((VariableConstraint) constraint[1]).getRestriction();
    assertTrue(r.getExpression() instanceof ReturnValueExpression);
    assertTrue(r.getExpression() instanceof CompiledInvoker);
    assertTrue(!(r.getExpression() instanceof MVELReturnValueExpression));
  }
Example #3
0
 public void writeExternal(ObjectOutput out) throws IOException {
   super.writeExternal(out);
   out.writeBoolean(unwrapRightObject);
   out.writeObject(accumulate);
   out.writeObject(resultConstraints);
   out.writeObject(resultBinder);
 }
Example #4
0
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   super.readExternal(in);
   unwrapRightObject = in.readBoolean();
   accumulate = (Accumulate) in.readObject();
   resultConstraints = (AlphaNodeFieldConstraint[]) in.readObject();
   resultBinder = (BetaConstraints) in.readObject();
 }
Example #5
0
  /* (non-Javadoc)
   * @see java.lang.Object#equals(java.lang.Object)
   */
  public boolean equals(final Object object) {
    if (this == object) {
      return true;
    }

    if (object == null || !(object instanceof BetaNode)) {
      return false;
    }

    final BetaNode other = (BetaNode) object;

    return this.getClass() == other.getClass()
        && this.leftInput.equals(other.leftInput)
        && this.rightInput.equals(other.rightInput)
        && this.constraints.equals(other.constraints)
        && areNullSafeEquals(this.leftListenedProperties, other.leftListenedProperties)
        && areNullSafeEquals(this.rightListenedProperties, other.rightListenedProperties);
  }