Examples of BaseCondition


Examples of org.emftrace.metamodel.RuleModel.BaseCondition

        rule.getElements().add(e2);
       
        e1.setAlias("number_1");
        e2.setAlias("number_2");
       
        BaseCondition baseCondition = RuleModelFactory.eINSTANCE.createBaseCondition();
        LogicCondition logicCondition = RuleModelFactory.eINSTANCE.createLogicCondition();
        accessLayer.addElement(project, baseCondition);
        accessLayer.addElement(project, logicCondition);
       
        rule.setConditions(logicCondition);
        logicCondition.getBaseConditions().add(baseCondition);
        logicCondition.setType(LogicConditionType.AND);
        baseCondition.setSource("number_1::Id");
        baseCondition.setTarget("number_2::Id");
       
        List<EObject[]> tuples = new ArrayList<EObject[]>();
       
        // test "EQUALS":
        baseCondition.setType(BaseConditionType.VALUE_EQUALS);       
        assertTrue(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        assertEquals(1, result.get(0).size()); // test this once...
        assertEquals(1, result.get(1).size());
        c1.setId("test_addition");
        assertFalse(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        assertEquals(0, result.get(0).size());
        assertEquals(0, result.get(1).size());
        result.get(0).clear();
        result.get(0).add(c1);
        result.get(1).clear();
        result.get(1).add(c2);
       
        // test "STARTS_WITH":
        c1.setId("test_bla");
        baseCondition.setType(BaseConditionType.VALUE_STARTS_WITH);       
        assertTrue(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        c1.setId("bla");
        assertFalse(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        result.get(0).clear();
        result.get(0).add(c1);
        result.get(1).clear();
        result.get(1).add(c2);
       
        // test "ENDS_WITH":
        c1.setId("test");
        baseCondition.setType(BaseConditionType.VALUE_ENDS_WITH);       
        assertTrue(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        c1.setId("test_bla");
        assertFalse(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        result.get(0).clear();
        result.get(0).add(c1);
        result.get(1).clear();
        result.get(1).add(c2);
       
        // test "CONTAINS":
        c1.setId("test_addition");
        baseCondition.setType(BaseConditionType.VALUE_CONTAINS);       
        assertTrue(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        c1.setId("tes");
        assertFalse(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        result.get(0).clear();
        result.get(0).add(c1);
        result.get(1).clear();
        result.get(1).add(c2);
       
        // test "SIMILAR_TO"
        conditionProcessor.setCorrelation(0.5f);
        c1.setId("test1");
        baseCondition.setType(BaseConditionType.VALUE_SIMILAR_TO);       
        assertTrue(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        c1.setId("tast");
        assertFalse(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        result.get(0).clear();
        result.get(0).add(c1);
        result.get(1).clear();
        result.get(1).add(c2);
               
        // test "LESSER_THAN":
        c1.setId("1");
        c2.setId("2");
        baseCondition.setType(BaseConditionType.VALUE_LESSER_THAN);
        assertTrue(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        c1.setId("2");
        c2.setId("1");
        assertFalse(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        result.get(0).clear();
        result.get(0).add(c1);
        result.get(1).clear();
        result.get(1).add(c2);
       
        // test "GREATER_THAN":
        c1.setId("2");
        c2.setId("1");
        baseCondition.setType(BaseConditionType.VALUE_GREATER_THAN);
        assertTrue(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        c1.setId("1");
        c2.setId("2");
        assertFalse(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
       
        // test "IS_PARENT":
        result.get(0).clear();
        result.get(0).add(rule);
        result.get(1).clear();
        result.get(1).add(baseCondition);
        baseCondition.setSource("number_1");
        baseCondition.setTarget("number_2");
        baseCondition.setType(BaseConditionType.MODEL_PARENT_OF);
        assertTrue(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        baseCondition.setSource("number_2");
        baseCondition.setTarget("number_1");
        assertFalse(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
       
        // test "MODEL_EQUALS":
        baseCondition.setType(BaseConditionType.MODEL_EQUALS);
        baseCondition.setSource("e1::Source");
        baseCondition.setTarget("e2");
       
        e1.setAlias("e1");
        e2.setAlias("e2");
        e1.setType("TraceLink");
        e2.setType("Actor");
       
        TraceLink link  = LinkModelFactory.eINSTANCE.createTraceLink();
        Actor     actor = URNModelFactory.eINSTANCE.createActor();
       
        accessLayer.addElement(project, link);
        accessLayer.addElement(project, actor);
             
        link.setSource(actor);
       
        result.get(0).clear();
        result.get(1).clear();
        result.get(0).add(link);
        result.get(1).add(actor);
               
        assertEquals(1, result.get(0).size());
        assertEquals(1, result.get(1).size());
        assertTrue(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        assertEquals(1, result.get(0).size());
        assertEquals(1, result.get(1).size());
       
        baseCondition.setSource("e1::Target");
        assertFalse(conditionProcessor.executeBaseCondition(rule, result, baseCondition, tuples));
        assertEquals(0, result.get(0).size());
        assertEquals(0, result.get(1).size());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.