Package org.drools.guvnor.client.modeldriven.brl

Examples of org.drools.guvnor.client.modeldriven.brl.RuleModel


    System.out.println(brl);
  }

  public void testGetVariableNameForRHS() {
    RuleModel m = new RuleModel();
    m.name = "blah";

    FactPattern pat = new FactPattern();
    pat.boundName = "pat";
    pat.factType = "Person";

    m.addLhsItem(pat);

    List l = m.getAllVariables();
    assertEquals(1, l.size());
    assertEquals("pat", l.get(0));

  }
View Full Code Here


    assertEquals("pat", l.get(0));

  }

  public void testIsDSLEnhanced() throws Exception {
    RuleModel m = new RuleModel();

    assertFalse(m.hasDSLSentences());

    m.addLhsItem(new FactPattern());
    assertFalse(m.hasDSLSentences());

    m.addRhsItem(new ActionSetField("q"));

    assertFalse(m.hasDSLSentences());

    m.addLhsItem(new DSLSentence());
    assertTrue(m.hasDSLSentences());

    m.addRhsItem(new DSLSentence());
    assertTrue(m.hasDSLSentences());

    m = new RuleModel();

    m.addLhsItem(new DSLSentence());
    assertTrue(m.hasDSLSentences());

    m = new RuleModel();
    m.addRhsItem(new DSLSentence());
    assertTrue(m.hasDSLSentences());

  }
View Full Code Here

    assertTrue(m.hasDSLSentences());

  }

  public void testMetaData() {
    final RuleModel m = new RuleModel();

    final RuleMetadata rm = new RuleMetadata("foo", "bar");

    // test add
    m.addMetadata(rm);
    assertEquals(1, m.metadataList.length);
    assertEquals(rm, m.metadataList[0]);

    // should be able to find it
    RuleMetadata gm = m.getMetaData("foo");
    assertNotNull(gm);

    // test add and remove
    final RuleMetadata rm2 = new RuleMetadata("foo2", "bar2");
    m.addMetadata(rm2);
    assertEquals(2, m.metadataList.length);
    assertEquals(rm2, m.metadataList[1]);
    assertEquals("@foo(bar)", rm.toString());

    m.removeMetadata(0);
    assertEquals(1, m.metadataList.length);
    assertEquals(rm2, m.metadataList[0]);
    assertEquals("@foo2(bar2)", (m.metadataList[0]).toString());

    // should be able to find it now that it was removed
    gm = m.getMetaData("foo");
    assertNull(gm);

    // test add via update method
    m.updateMetadata(rm);
    gm = m.getMetaData("foo");
    assertNotNull(gm);

    // test update of existing element
    rm.value = "bar2";
    m.updateMetadata(rm);
    gm = m.getMetaData("foo");
    assertNotNull(gm);
    assertEquals("bar2", gm.value);

  }
View Full Code Here

    assertEquals("bar2", gm.value);

  }

  public void testRemoveItemLhs() {
    final RuleModel model = new RuleModel();

    model.lhs = new IPattern[3];
    final FactPattern x = new FactPattern("Car");
    model.lhs[0] = x;
    x.boundName = "x";

    final FactPattern y = new FactPattern("Car");
    model.lhs[1] = y;
    y.boundName = "y";

    final FactPattern other = new FactPattern("House");
    model.lhs[2] = other;

    assertEquals(3, model.lhs.length);
    assertEquals(x, model.lhs[0]);

    model.removeLhsItem(0);

    assertEquals(2, model.lhs.length);
    assertEquals(y, model.lhs[0]);
  }
View Full Code Here

    assertEquals(2, model.lhs.length);
    assertEquals(y, model.lhs[0]);
  }

  public void testRemoveItemRhs() {
    final RuleModel model = new RuleModel();

    model.rhs = new IAction[3];
    final ActionRetractFact r0 = new ActionRetractFact("x");
    final ActionRetractFact r1 = new ActionRetractFact("y");
    final ActionRetractFact r2 = new ActionRetractFact("z");

    model.rhs[0] = r0;
    model.rhs[1] = r1;
    model.rhs[2] = r2;

    model.removeRhsItem(1);

    assertEquals(2, model.rhs.length);
    assertEquals(r0, model.rhs[0]);
    assertEquals(r2, model.rhs[1]);
  }
View Full Code Here

  public void testScopedVariables() {

    // setup the data...

    final RuleModel model = new RuleModel();
    model.lhs = new IPattern[3];
    final FactPattern x = new FactPattern("Car");
    model.lhs[0] = x;
    x.boundName = "x";

    final FactPattern y = new FactPattern("Car");
    model.lhs[1] = y;
    y.boundName = "y";
    final SingleFieldConstraint[] cons = new SingleFieldConstraint[2];
    y.constraintList = new CompositeFieldConstraint();
    y.constraintList.constraints = cons;
    cons[0] = new SingleFieldConstraint("age");
    cons[1] = new SingleFieldConstraint("make");
    cons[0].fieldBinding = "qbc";
    cons[0].connectives = new ConnectiveConstraint[1];
    cons[0].connectives[0] = new ConnectiveConstraint("&", "x");
    cons[0].connectives[0].constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;

    final FactPattern other = new FactPattern("House");
    model.lhs[2] = other;
    other.boundName = "q";
    final SingleFieldConstraint[] cons2 = new SingleFieldConstraint[1];
    cons2[0] = new SingleFieldConstraint();
    other.constraintList = new CompositeFieldConstraint();
    other.constraintList.constraints = cons2;

    // check the results for correct scope
    List vars = model.getBoundVariablesInScope(cons[0]);
    assertEquals(1, vars.size());
    assertEquals("x", vars.get(0));

    vars = model.getBoundVariablesInScope(cons[0].connectives[0]);
    assertEquals(1, vars.size());
    assertEquals("x", vars.get(0));

    vars = model.getBoundVariablesInScope(cons[1]);
    assertEquals(2, vars.size());
    assertEquals("x", vars.get(0));
    assertEquals("qbc", vars.get(1));

    vars = model.getBoundVariablesInScope(cons[0]);
    assertEquals(1, vars.size());
    assertEquals("x", vars.get(0));

    vars = model.getBoundVariablesInScope(cons2[0]);
    assertEquals(3, vars.size());
    assertEquals("x", vars.get(0));
    assertEquals("qbc", vars.get(1));
    assertEquals("y", vars.get(2));
  }
View Full Code Here

    assertEquals("qbc", vars.get(1));
    assertEquals("y", vars.get(2));
  }

  public void testScopedVariablesWithCompositeFact() {
    RuleModel m = new RuleModel();
    FactPattern p = new FactPattern();
    CompositeFieldConstraint cf = new CompositeFieldConstraint();
    cf.addConstraint(new SingleFieldConstraint("x"));
    p.addConstraint(cf);
    SingleFieldConstraint sf = new SingleFieldConstraint("q");
    sf.fieldBinding = "abc";

    p.addConstraint(sf);
    SingleFieldConstraint sf2 = new SingleFieldConstraint("q");
    sf2.fieldBinding = "qed";
    cf.addConstraint(sf2);
    m.addLhsItem(p);

    List vars = m.getAllVariables();
    assertEquals(1, vars.size());
    assertEquals("abc", vars.get(0));
  }
View Full Code Here

  public void testAttribs() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] {"1", "desc", "a", ""};

    List<AttributeCol> attributeCols = new ArrayList<AttributeCol>();
    RuleModel rm = new RuleModel();
    RuleAttribute[] orig = rm.attributes;
    p.doAttribs(0,attributeCols, row, rm);

    assertSame(orig, rm.attributes);
View Full Code Here

  public void testMetaData() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] {"1", "desc", "bar", ""};

    List<MetadataCol> metadataCols = new ArrayList<MetadataCol>();
    RuleModel rm = new RuleModel();
    RuleMetadata[] orig = rm.metadataList;
//    RuleAttribute[] orig = rm.attributes;
    p.doMetadata(metadataCols, row, rm);
//    p.doAttribs(0,metadataCols, row, rm);
View Full Code Here

    col4.factField = "type";
    col4.operator = "==";
    col4.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
    cols.add(col4);

    RuleModel rm = new RuleModel();

    p.doConditions(1, cols, row, rm);
    assertEquals(2, rm.lhs.length);

    assertEquals("Person", ((FactPattern)rm.lhs[0]).factType);
View Full Code Here

TOP

Related Classes of org.drools.guvnor.client.modeldriven.brl.RuleModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.