public ConnectiveConstraint( final String factType, final String fieldName, final String fieldType, final String opr, final String val ) { this.factType = factType; this.fieldName = fieldName; this.fieldType = fieldType; this.operator = opr; this.setValue( val ); }
private ConnectiveConstraint visitConnectiveConstraint(ConnectiveConstraint cc) { ConnectiveConstraint clone = new ConnectiveConstraint(); clone.setConstraintValueType(cc.getConstraintValueType()); clone.setExpressionValue((ExpressionFormLine) visit(cc.getExpressionValue())); clone.setFactType(cc.getFactType()); clone.setFieldName(cc.getFieldName()); clone.setFieldType(cc.getFieldType()); clone.setOperator(cc.getOperator()); for (Map.Entry<String, String> entry : cc.getParameters().entrySet()) { clone.setParameter(entry.getKey(), entry.getValue()); } clone.setValue(cc.getValue()); return clone; }
private ConnectiveConstraint visitConnectiveConstraint(ConnectiveConstraint cc) { ConnectiveConstraint clone = new ConnectiveConstraint(); clone.setConstraintValueType(cc.getConstraintValueType()); clone.setExpressionValue((ExpressionFormLine) visit(cc.getExpressionValue())); clone.setFactType(cc.getFactType()); clone.setFieldName(cc.getFieldName()); clone.setFieldType(cc.getFieldType()); clone.setOperator(cc.getOperator()); for (Map.Entry<String, String> entry : cc.getParameters().entrySet()) { clone.setParameter(entry.getKey(), entry.getValue()); } clone.setValue(cc.getValue()); return clone; }
@Test public void testConnectiveConstraintSecondValue() { TemplateModel m = new TemplateModel(); m.name = "t1"; FactPattern p1 = new FactPattern("Person"); m.addLhsItem(p1); final SingleFieldConstraint X = new SingleFieldConstraint(); X.setFieldName("field1"); X.setFieldType(DataType.TYPE_STRING); X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE); X.setValue("$f1"); X.setOperator("=="); p1.addConstraint(X); ConnectiveConstraint connective = new ConnectiveConstraint(); connective.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE); connective.setFieldType(DataType.TYPE_STRING); connective.setOperator("|| =="); connective.setValue("$f2"); X.setConnectives(new ConnectiveConstraint[1]); X.getConnectives()[0] = connective; String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"bar\" )\n" + "then\n" + "end\n"; m.addRow(new String[]{null, "bar"}); checkMarshall(expected, m); }
@Test public void testConnectiveConstraintFirstValue() { TemplateModel m = new TemplateModel(); m.name = "t1"; FactPattern p1 = new FactPattern("Person"); m.addLhsItem(p1); final SingleFieldConstraint X = new SingleFieldConstraint(); X.setFieldName("field1"); X.setFieldType(DataType.TYPE_STRING); X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE); X.setValue("$f1"); X.setOperator("=="); p1.addConstraint(X); ConnectiveConstraint connective = new ConnectiveConstraint(); connective.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE); connective.setFieldType(DataType.TYPE_STRING); connective.setOperator("|| =="); connective.setValue("$f2"); X.setConnectives(new ConnectiveConstraint[1]); X.getConnectives()[0] = connective; String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" )\n" + "then\n" + "end\n"; m.addRow(new String[]{"foo", null}); checkMarshall(expected, m); }
@Test public void testConnectiveConstraintBothValues() { TemplateModel m = new TemplateModel(); m.name = "t1"; FactPattern p1 = new FactPattern("Person"); m.addLhsItem(p1); final SingleFieldConstraint X = new SingleFieldConstraint(); X.setFieldName("field1"); X.setFieldType(DataType.TYPE_STRING); X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE); X.setValue("$f1"); X.setOperator("=="); p1.addConstraint(X); ConnectiveConstraint connective = new ConnectiveConstraint(); connective.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE); connective.setFieldType(DataType.TYPE_STRING); connective.setOperator("|| =="); connective.setValue("$f2"); X.setConnectives(new ConnectiveConstraint[1]); X.getConnectives()[0] = connective; String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" || == \"bar\" )\n" + "then\n" + "end\n"; m.addRow(new String[]{"foo", "bar"}); checkMarshall(expected, m); }
connective.setFieldType(DataType.TYPE_STRING); connective.setOperator("|| =="); connective.setValue("goo");
connective.setFieldType(DataType.TYPE_STRING); connective.setOperator("|| =="); connective.setValue("goo");
connective.setFieldType(DataType.TYPE_STRING); connective.setOperator("|| =="); connective.setValue("goo");
X.getConnectives()[0].setConstraintValueType(ConnectiveConstraint.TYPE_LITERAL); X.getConnectives()[0].setOperator("|| =="); X.getConnectives()[0].setValue("bar"); comp.addConstraint(X);