Search in sources :

Example 16 with MethodInfo

use of org.kie.soup.project.datamodel.oracle.MethodInfo in project drools by kiegroup.

the class RuleModelDRLPersistenceUnmarshallingTest method testFunctionCalls4_MultiParameterSetter.

@Test
public void testFunctionCalls4_MultiParameterSetter() {
    String drl = "package org.mortgages;\n" + "import org.mortgages.classes.MyClass;\n" + "rule \"rule1\"\n" + "dialect \"mvel\"\n" + "when\n" + "  $c : MyClass()\n" + "then\n" + "  $c.setSomething(0, 1);\n" + "end\n";
    Map<String, List<MethodInfo>> methodInformation = new HashMap<>();
    List<MethodInfo> mapMethodInformation = new ArrayList<>();
    mapMethodInformation.add(new MethodInfo("setSomething", Arrays.asList(DataType.TYPE_NUMERIC_INTEGER, DataType.TYPE_NUMERIC_INTEGER), "void", null, DataType.TYPE_STRING));
    methodInformation.put("org.mortgages.classes.MyClass", mapMethodInformation);
    when(dmo.getModuleMethodInformation()).thenReturn(methodInformation);
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(1, m.rhs.length);
    assertTrue(m.rhs[0] instanceof ActionCallMethod);
    ActionCallMethod actionCallMethod1 = (ActionCallMethod) m.rhs[0];
    assertEquals(1, actionCallMethod1.getState());
    assertEquals("setSomething", actionCallMethod1.getMethodName());
    assertEquals("$c", actionCallMethod1.getVariable());
    assertEquals(2, actionCallMethod1.getFieldValues().length);
    assertEquals("setSomething", actionCallMethod1.getFieldValues()[0].getField());
    assertEquals("0", actionCallMethod1.getFieldValues()[0].getValue());
    assertEquals(FieldNatureType.TYPE_LITERAL, actionCallMethod1.getFieldValues()[0].getNature());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, actionCallMethod1.getFieldValues()[0].getType());
    assertEquals("setSomething", actionCallMethod1.getFieldValues()[1].getField());
    assertEquals("1", actionCallMethod1.getFieldValues()[1].getValue());
    assertEquals(FieldNatureType.TYPE_LITERAL, actionCallMethod1.getFieldValues()[1].getNature());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, actionCallMethod1.getFieldValues()[1].getType());
    assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) List(java.util.List) ArrayList(java.util.ArrayList) MethodInfo(org.kie.soup.project.datamodel.oracle.MethodInfo) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Aggregations

MethodInfo (org.kie.soup.project.datamodel.oracle.MethodInfo)16 ArrayList (java.util.ArrayList)12 List (java.util.List)12 HashMap (java.util.HashMap)11 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)11 Test (org.junit.Test)11 ActionCallMethod (org.drools.workbench.models.datamodel.rule.ActionCallMethod)9 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)3 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)3 ExpressionMethod (org.drools.workbench.models.datamodel.rule.ExpressionMethod)3 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)3 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)3 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)3 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)3 ExpressionField (org.drools.workbench.models.datamodel.rule.ExpressionField)2 ExpressionUnboundFact (org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact)2 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)2 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)2 AccumulateDescr (org.drools.compiler.lang.descr.AccumulateDescr)1 CollectDescr (org.drools.compiler.lang.descr.CollectDescr)1