Ejemplo n.º 1
0
        public void TestValidate()
        {
            // Must have exactly 2 subnodes
            try
            {
                _bitWiseNode.Validate(ExprValidationContextFactory.MakeEmpty());
                Assert.Fail();
            }
            catch (ExprValidationException)
            {
                // Expected
                Log.Debug("No nodes in the expression");
            }

            // Must have only number or boolean-type subnodes
            _bitWiseNode.AddChildNode(new SupportExprNode(typeof(string)));
            _bitWiseNode.AddChildNode(new SupportExprNode(typeof(int)));
            try
            {
                _bitWiseNode.Validate(ExprValidationContextFactory.MakeEmpty());
                Assert.Fail();
            }
            catch (ExprValidationException)
            {
                // Expected
            }
        }
Ejemplo n.º 2
0
        public void TestValidate()
        {
            ExprCoalesceNode coalesceNode = new ExprCoalesceNode();

            coalesceNode.AddChildNode(new SupportExprNode(1));

            // Test too few nodes under this node
            try
            {
                coalesceNode.Validate(ExprValidationContextFactory.MakeEmpty());
                Assert.Fail();
            }
            catch (ExprValidationException ex)
            {
                // Expected
            }

            // Test node result type not fitting
            coalesceNode.AddChildNode(new SupportExprNode("s"));
            try
            {
                coalesceNode.Validate(ExprValidationContextFactory.MakeEmpty());
                Assert.Fail();
            }
            catch (ExprValidationException ex)
            {
                // Expected
            }
        }
Ejemplo n.º 3
0
        private void runAssertionThreading(ConfigurationEngineDefaults.ThreadingProfile threadingProfile)
        {
            _concatNode = new ExprConcatNode();
            var textA = "This is the first text";
            var textB = "Second text";
            var textC = "Third text, some more";

            foreach (var text in new[] { textA, textB, textC })
            {
                _concatNode.AddChildNode(new ExprConstantNodeImpl(text));
            }
            _concatNode.Validate(ExprValidationContextFactory.MakeEmpty(threadingProfile));

            var numThreads = 4;
            var numLoop    = 10000;

            var threads = new List <SupportConcatThread>(numThreads);

            for (var i = 0; i < numThreads; i++)
            {
                var thread = new SupportConcatThread(_concatNode, numLoop, textA + textB + textC);
                threads.Add(thread);
                thread.Start();
            }

            foreach (var thread in threads)
            {
                thread.Join();
                Assert.IsFalse(thread.IsFail);
            }
        }
Ejemplo n.º 4
0
        public void TestGetValidatedSubtree()
        {
            SupportExprNode.SetValidateCount(0);

            // Confirms all child nodes validated
            // Confirms depth-first validation
            SupportExprNode topNode = new SupportExprNode(typeof(Boolean));

            SupportExprNode parent_1 = new SupportExprNode(typeof(Boolean));
            SupportExprNode parent_2 = new SupportExprNode(typeof(Boolean));

            topNode.AddChildNode(parent_1);
            topNode.AddChildNode(parent_2);

            SupportExprNode supportNode1_1 = new SupportExprNode(typeof(Boolean));
            SupportExprNode supportNode1_2 = new SupportExprNode(typeof(Boolean));
            SupportExprNode supportNode2_1 = new SupportExprNode(typeof(Boolean));
            SupportExprNode supportNode2_2 = new SupportExprNode(typeof(Boolean));

            parent_1.AddChildNode(supportNode1_1);
            parent_1.AddChildNode(supportNode1_2);
            parent_2.AddChildNode(supportNode2_1);
            parent_2.AddChildNode(supportNode2_2);

            ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.SELECT, topNode, ExprValidationContextFactory.MakeEmpty());

            Assert.AreEqual(1, supportNode1_1.ValidateCountSnapshot);
            Assert.AreEqual(2, supportNode1_2.ValidateCountSnapshot);
            Assert.AreEqual(3, parent_1.ValidateCountSnapshot);
            Assert.AreEqual(4, supportNode2_1.ValidateCountSnapshot);
            Assert.AreEqual(5, supportNode2_2.ValidateCountSnapshot);
            Assert.AreEqual(6, parent_2.ValidateCountSnapshot);
            Assert.AreEqual(7, topNode.ValidateCountSnapshot);
        }
Ejemplo n.º 5
0
        public void TestValidate()
        {
            _identNodes[0].Validate(ExprValidationContextFactory.Make(_streamTypeService));
            Assert.AreEqual(2, _identNodes[0].StreamId);
            Assert.AreEqual(typeof(string), _identNodes[0].ExprEvaluator.ReturnType);
            Assert.AreEqual("Mapped('a')", _identNodes[0].ResolvedPropertyName);

            _identNodes[1].Validate(ExprValidationContextFactory.Make(_streamTypeService));
            Assert.AreEqual(2, _identNodes[1].StreamId);
            Assert.AreEqual(typeof(string), _identNodes[1].ExprEvaluator.ReturnType);
            Assert.AreEqual("Nested.NestedValue", _identNodes[1].ResolvedPropertyName);

            _identNodes[2].Validate(ExprValidationContextFactory.Make(_streamTypeService));
            Assert.AreEqual(2, _identNodes[2].StreamId);
            Assert.AreEqual(typeof(int?), _identNodes[2].ExprEvaluator.ReturnType);
            Assert.AreEqual("Indexed[1]", _identNodes[2].ResolvedPropertyName);

            _identNodes[3].Validate(ExprValidationContextFactory.Make(_streamTypeService));
            Assert.AreEqual(0, _identNodes[3].StreamId);
            Assert.AreEqual(typeof(int?), _identNodes[3].ExprEvaluator.ReturnType);
            Assert.AreEqual("IntPrimitive", _identNodes[3].ResolvedPropertyName);

            TryInvalidValidate(new ExprIdentNodeImpl(""));
            TryInvalidValidate(new ExprIdentNodeImpl("dummy"));
            TryInvalidValidate(new ExprIdentNodeImpl("Nested", "s0"));
            TryInvalidValidate(new ExprIdentNodeImpl("dummy", "s2"));
            TryInvalidValidate(new ExprIdentNodeImpl("IntPrimitive", "s2"));
            TryInvalidValidate(new ExprIdentNodeImpl("IntPrimitive", "s3"));
        }
Ejemplo n.º 6
0
        public void TestValidate()
        {
            // Must have 2 or more subnodes
            try
            {
                _minMaxNode.Validate(ExprValidationContextFactory.MakeEmpty());
                Assert.Fail();
            }
            catch (ExprValidationException ex)
            {
                // Expected
            }

            // Must have only number-type subnodes
            _minMaxNode.AddChildNode(new SupportExprNode(typeof(String)));
            _minMaxNode.AddChildNode(new SupportExprNode(typeof(int)));
            try
            {
                _minMaxNode.Validate(ExprValidationContextFactory.MakeEmpty());
                Assert.Fail();
            }
            catch (ExprValidationException ex)
            {
                // Expected
            }
        }
Ejemplo n.º 7
0
        public void SetUp()
        {
            _arrayNodes    = new ExprArrayNode[4];
            _arrayNodes[0] = new ExprArrayNode();

            // no coercion array
            _arrayNodes[1] = new ExprArrayNode();
            _arrayNodes[1].AddChildNode(new SupportExprNode(2));
            _arrayNodes[1].AddChildNode(new SupportExprNode(3));

            // coercion
            _arrayNodes[2] = new ExprArrayNode();
            _arrayNodes[2].AddChildNode(new SupportExprNode(1.5D));
            _arrayNodes[2].AddChildNode(new SupportExprNode(1));

            // mixed types
            _arrayNodes[3] = new ExprArrayNode();
            _arrayNodes[3].AddChildNode(new SupportExprNode("a"));
            _arrayNodes[3].AddChildNode(new SupportExprNode(1));

            for (int i = 0; i < _arrayNodes.Length; i++)
            {
                _arrayNodes[i].Validate(ExprValidationContextFactory.MakeEmpty());
            }
        }
Ejemplo n.º 8
0
        public void TestValidate()
        {
            // Must have exactly 1 subnodes
            try
            {
                _minNode.Validate(ExprValidationContextFactory.MakeEmpty());
                Assert.Fail();
            }
            catch (ExprValidationException ex)
            {
                // Expected
            }

            // Must have only number-type subnodes
            _minNode = new ExprMinMaxAggrNode(false, MinMaxTypeEnum.MIN, true, false);
            _minNode.AddChildNode(new SupportExprNode(typeof(string)));
            _minNode.AddChildNode(new SupportExprNode(typeof(int)));
            try
            {
                _minNode.Validate(ExprValidationContextFactory.Make(new SupportStreamTypeSvc3Stream()));
                Assert.Fail();
            }
            catch (ExprValidationException ex)
            {
                // Expected
            }
        }
Ejemplo n.º 9
0
        public void TestValidate()
        {
            // test success
            _orNode.AddChildNode(new SupportExprNode(typeof(Boolean)));
            _orNode.AddChildNode(new SupportExprNode(typeof(Boolean)));
            _orNode.Validate(ExprValidationContextFactory.MakeEmpty());

            // test failure, type mismatch
            _orNode.AddChildNode(new SupportExprNode(typeof(string)));
            try
            {
                _orNode.Validate(ExprValidationContextFactory.MakeEmpty());
                Assert.Fail();
            }
            catch (ExprValidationException ex)
            {
                // Expected
            }

            // test failed - with just one child
            _orNode = new ExprOrNode();
            _orNode.AddChildNode(new SupportExprNode(typeof(Boolean)));
            try
            {
                _orNode.Validate(ExprValidationContextFactory.MakeEmpty());
                Assert.Fail();
            }
            catch (ExprValidationException ex)
            {
                // Expected
            }
        }
Ejemplo n.º 10
0
        public void TestValidate()
        {
            // Must have exactly 2 subnodes
            try
            {
                _arithNode.Validate(ExprValidationContextFactory.MakeEmpty());
                Assert.Fail();
            }
            catch (ExprValidationException)
            {
                // Expected
            }

            // Must have only number-type subnodes
            _arithNode.AddChildNode(new SupportExprNode(typeof(string)));
            _arithNode.AddChildNode(new SupportExprNode(typeof(int)));
            try
            {
                _arithNode.Validate(ExprValidationContextFactory.MakeEmpty());
                Assert.Fail();
            }
            catch (ExprValidationException)
            {
                // Expected
            }
        }
Ejemplo n.º 11
0
        public void TestValidate()
        {
            ExprCaseNode caseNode = SupportExprNodeFactory.MakeCaseSyntax1Node();

            caseNode.Validate(ExprValidationContextFactory.MakeEmpty());

            caseNode = SupportExprNodeFactory.MakeCaseSyntax2Node();
            caseNode.Validate(ExprValidationContextFactory.MakeEmpty());

            // No subnodes: Exception is thrown.
            TryInvalidValidate(new ExprCaseNode(false));
            TryInvalidValidate(new ExprCaseNode(true));

            // singe child node not possible, must be 2 at least
            caseNode = new ExprCaseNode(false);
            caseNode.AddChildNode(new SupportExprNode(4));
            TryInvalidValidate(caseNode);

            // in a case 1 expression (e.g. case when a=b then 1 else 2) the when child nodes must return boolean
            caseNode.AddChildNode(new SupportExprNode(2));
            TryInvalidValidate(caseNode);

            // in a case 2 expression (e.g. case a when b then 1 else 2) then a and b types must be comparable
            caseNode = new ExprCaseNode(true);
            caseNode.AddChildNode(new SupportExprNode("a"));
            caseNode.AddChildNode(new SupportExprNode(1));
            caseNode.AddChildNode(new SupportExprNode(2));
            TryInvalidValidate(caseNode);
        }
Ejemplo n.º 12
0
 public void TestGetType()
 {
     _arithNode.AddChildNode(new SupportExprNode(typeof(double?)));
     _arithNode.AddChildNode(new SupportExprNode(typeof(int)));
     _arithNode.Validate(ExprValidationContextFactory.MakeEmpty());
     Assert.AreEqual(typeof(double?), _arithNode.ReturnType);
 }
Ejemplo n.º 13
0
        public void TestEvaluateEquals()
        {
            var eparams = new EvaluateParams(null, false, null);

            _equalsNodes[0] = MakeNode(true, false, false);
            Assert.IsFalse(_equalsNodes[0].ExprEvaluator.Evaluate(eparams).AsBoolean());

            _equalsNodes[0] = MakeNode(false, false, false);
            Assert.IsTrue(_equalsNodes[0].ExprEvaluator.Evaluate(eparams).AsBoolean());

            _equalsNodes[0] = MakeNode(true, true, false);
            Assert.IsTrue(_equalsNodes[0].ExprEvaluator.Evaluate(eparams).AsBoolean());

            _equalsNodes[0] = MakeNode(true, typeof(bool), null, typeof(bool), false);
            Assert.IsNull(_equalsNodes[0].ExprEvaluator.Evaluate(eparams));

            _equalsNodes[0] = MakeNode(null, typeof(String), "ss", typeof(String), false);
            Assert.IsNull(_equalsNodes[0].ExprEvaluator.Evaluate(eparams));

            _equalsNodes[0] = MakeNode(null, typeof(String), null, typeof(String), false);
            Assert.IsNull(_equalsNodes[0].ExprEvaluator.Evaluate(eparams));

            // try a long and int
            _equalsNodes[1].Validate(ExprValidationContextFactory.MakeEmpty());
            Assert.IsTrue(_equalsNodes[1].ExprEvaluator.Evaluate(eparams).AsBoolean());

            // try a double and int
            _equalsNodes[2].Validate(ExprValidationContextFactory.MakeEmpty());
            Assert.IsTrue(_equalsNodes[2].ExprEvaluator.Evaluate(eparams).AsBoolean());

            _equalsNodes[3].Validate(ExprValidationContextFactory.MakeEmpty());
            Assert.IsTrue(_equalsNodes[3].ExprEvaluator.Evaluate(eparams).AsBoolean());
        }
Ejemplo n.º 14
0
        public void TestEvaluate()
        {
            SupportExprNode childOne = new SupportExprNode("d");
            SupportExprNode childTwo = new SupportExprNode("c");

            _opNode.AddChildNode(childOne);
            _opNode.AddChildNode(childTwo);
            _opNode.Validate(ExprValidationContextFactory.MakeEmpty());       // Type initialization

            var eparams = new EvaluateParams(null, false, null);

            Assert.AreEqual(true, _opNode.Evaluate(eparams));

            childOne.Value = "c";
            Assert.AreEqual(true, _opNode.Evaluate(eparams));

            childOne.Value = "b";
            Assert.AreEqual(false, _opNode.Evaluate(eparams));

            _opNode = MakeNode(null, typeof(int), 2, typeof(int));
            Assert.AreEqual(null, _opNode.Evaluate(eparams));
            _opNode = MakeNode(1, typeof(int), null, typeof(int));
            Assert.AreEqual(null, _opNode.Evaluate(eparams));
            _opNode = MakeNode(null, typeof(int), null, typeof(int));
            Assert.AreEqual(null, _opNode.Evaluate(eparams));
        }
Ejemplo n.º 15
0
        public void TestValidate()
        {
            ExprPropertyExistsNode castNode = new ExprPropertyExistsNode();

            // Test too few nodes under this node
            try
            {
                castNode.Validate(ExprValidationContextFactory.MakeEmpty());
                Assert.Fail();
            }
            catch (ExprValidationException ex)
            {
                // Expected
            }

            castNode.AddChildNode(new SupportExprNode(1));
            try
            {
                castNode.Validate(ExprValidationContextFactory.MakeEmpty());
                Assert.Fail();
            }
            catch (ExprValidationException ex)
            {
                // Expected
            }
        }
Ejemplo n.º 16
0
 public void TestGetType()
 {
     for (int i = 0; i < _isNodes.Length; i++)
     {
         _isNodes[i].Validate(ExprValidationContextFactory.MakeEmpty());
         Assert.AreEqual(typeof(bool?), _isNodes[i].ReturnType);
     }
 }
Ejemplo n.º 17
0
 public void TestEqualsNode()
 {
     _identNodes[0].Validate(ExprValidationContextFactory.Make(_streamTypeService));
     _identNodes[2].Validate(ExprValidationContextFactory.Make(_streamTypeService));
     _identNodes[3].Validate(ExprValidationContextFactory.Make(_streamTypeService));
     Assert.IsTrue(_identNodes[3].EqualsNode(_identNodes[3]));
     Assert.IsFalse(_identNodes[0].EqualsNode(_identNodes[2]));
 }
Ejemplo n.º 18
0
 public void TestEvaluate()
 {
     Log.Debug(".testEvaluate");
     _bitWiseNode.AddChildNode(new SupportExprNode(10));
     _bitWiseNode.AddChildNode(new SupportExprNode(12));
     ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.SELECT, _bitWiseNode, ExprValidationContextFactory.MakeEmpty());
     Assert.AreEqual(8, _bitWiseNode.Evaluate(new EvaluateParams(null, false, null)));
 }
Ejemplo n.º 19
0
        public void TestEvaluate()
        {
            EventBean[] events = new EventBean[] { MakeEvent(10) };

            _identNodes[3].Validate(ExprValidationContextFactory.Make(_streamTypeService));
            Assert.AreEqual(10, _identNodes[3].ExprEvaluator.Evaluate(new EvaluateParams(events, false, null)));
            Assert.IsNull(_identNodes[3].ExprEvaluator.Evaluate(new EvaluateParams(new EventBean[2], false, null)));
        }
Ejemplo n.º 20
0
        public void TestEvaluate()
        {
            EventBean theEvent = MakeEvent(10);

            EventBean[] events = new EventBean[] { theEvent };

            _node.Validate(ExprValidationContextFactory.Make(_streamTypeService));
            Assert.AreEqual(theEvent.Underlying, _node.Evaluate(new EvaluateParams(events, false, null)));
        }
Ejemplo n.º 21
0
        public void TestValidate()
        {
            _node.Validate(ExprValidationContextFactory.Make(_streamTypeService));
            Assert.AreEqual(0, _node.StreamId);
            Assert.AreEqual(typeof(SupportBean), _node.ReturnType);

            TryInvalidValidate(new ExprStreamUnderlyingNodeImpl("", false));
            TryInvalidValidate(new ExprStreamUnderlyingNodeImpl("dummy", false));
        }
Ejemplo n.º 22
0
        public void TestGetType()
        {
            for (int i = 0; i < _castNodes.Length; i++)
            {
                _castNodes[i].Validate(ExprValidationContextFactory.MakeEmpty());
            }

            Assert.AreEqual(typeof(long?), _castNodes[0].TargetType);
            Assert.AreEqual(typeof(int?), _castNodes[1].TargetType);
        }
Ejemplo n.º 23
0
        public void TestEvaluate()
        {
            for (int i = 0; i < _castNodes.Length; i++)
            {
                _castNodes[i].Validate(ExprValidationContextFactory.MakeEmpty());
            }

            Assert.AreEqual(10L, _castNodes[0].ExprEvaluator.Evaluate(new EvaluateParams(null, false, null)));
            Assert.AreEqual(16, _castNodes[1].ExprEvaluator.Evaluate(new EvaluateParams(null, false, null)));
        }
Ejemplo n.º 24
0
 private static void SetupNode(ExprMinMaxRowNode nodeMin, int intValue, double doubleValue, float?floatValue)
 {
     nodeMin.AddChildNode(new SupportExprNode(intValue));
     nodeMin.AddChildNode(new SupportExprNode(doubleValue));
     if (floatValue != null)
     {
         nodeMin.AddChildNode(new SupportExprNode(floatValue));
     }
     nodeMin.Validate(ExprValidationContextFactory.MakeEmpty());
 }
Ejemplo n.º 25
0
 public void TestToExpressionString()
 {
     for (int i = 0; i < _identNodes.Length; i++)
     {
         _identNodes[i].Validate(ExprValidationContextFactory.Make(_streamTypeService));
     }
     Assert.AreEqual("Mapped('a')", _identNodes[0].ToExpressionStringMinPrecedenceSafe());
     Assert.AreEqual("Nested.NestedValue", _identNodes[1].ToExpressionStringMinPrecedenceSafe());
     Assert.AreEqual("s2.Indexed[1]", _identNodes[2].ToExpressionStringMinPrecedenceSafe());
     Assert.AreEqual("s0.IntPrimitive", _identNodes[3].ToExpressionStringMinPrecedenceSafe());
 }
Ejemplo n.º 26
0
 private void TryInvalidValidate(ExprLikeNode exprLikeRegexpNode)
 {
     try {
         exprLikeRegexpNode.Validate(ExprValidationContextFactory.MakeEmpty());
         Assert.Fail();
     }
     catch (ExprValidationException ex)
     {
         // expected
     }
 }
Ejemplo n.º 27
0
 private void TryInvalidValidate(ExprPreviousNode exprPrevNode)
 {
     try {
         exprPrevNode.Validate(ExprValidationContextFactory.MakeEmpty());
         Assert.Fail();
     }
     catch (ExprValidationException)
     {
         // expected
     }
 }
Ejemplo n.º 28
0
        private ExprMinMaxRowNode MakeNode(Object valueOne, Type typeOne,
                                           Object valueTwo, Type typeTwo,
                                           Object valueThree, Type typeThree)
        {
            var maxNode = new ExprMinMaxRowNode(MinMaxTypeEnum.MAX);

            maxNode.AddChildNode(new SupportExprNode(valueOne, typeOne));
            maxNode.AddChildNode(new SupportExprNode(valueTwo, typeTwo));
            maxNode.AddChildNode(new SupportExprNode(valueThree, typeThree));
            maxNode.Validate(ExprValidationContextFactory.MakeEmpty());
            return(maxNode);
        }
Ejemplo n.º 29
0
 private void TryInvalidValidate(ExprIdentNode identNode)
 {
     try
     {
         identNode.Validate(ExprValidationContextFactory.Make(_streamTypeService));
         Assert.Fail();
     }
     catch (ExprValidationException ex)
     {
         // expected
     }
 }
Ejemplo n.º 30
0
        public void TestGetType()
        {
            for (int i = 0; i < _coalesceNodes.Length; i++)
            {
                _coalesceNodes[i].Validate(ExprValidationContextFactory.MakeEmpty());
            }

            Assert.AreEqual(typeof(long?), _coalesceNodes[0].ReturnType);
            Assert.AreEqual(typeof(string), _coalesceNodes[1].ReturnType);
            Assert.AreEqual(typeof(bool?), _coalesceNodes[2].ReturnType);
            Assert.AreEqual(typeof(char?), _coalesceNodes[3].ReturnType);
            Assert.AreEqual(typeof(double?), _coalesceNodes[4].ReturnType);
        }