Exemple #1
0
        public void If_OneMatchApplicationEqualsConditionAndDateCondition_ThenReturnCorrectSequence()
        {
            // ARRANGE
            string lqlQuery = @"MATCH (app = 'MyApp')
BETWEEN '2016-01-01 00:00:00' AND '2016-01-01 00:00:00'";

            // ACT
            var lexer = new LqlLexer();
            var tokenSeq = lexer.Tokenize(lqlQuery);

            // ASSERT
            Assert.AreEqual(TokenType.Match, tokenSeq[0].TokenType);
            Assert.AreEqual(TokenType.OpenParenthesis, tokenSeq[1].TokenType);
            Assert.AreEqual(TokenType.Application, tokenSeq[2].TokenType);
            Assert.AreEqual(TokenType.Equals, tokenSeq[3].TokenType);
            Assert.AreEqual(TokenType.StringValue, tokenSeq[4].TokenType);
            Assert.AreEqual("'MyApp'", tokenSeq[4].Value);
            Assert.AreEqual(TokenType.CloseParenthesis, tokenSeq[5].TokenType);
            Assert.AreEqual(TokenType.Between, tokenSeq[6].TokenType);
            Assert.AreEqual(TokenType.DateTimeValue, tokenSeq[7].TokenType);
            Assert.AreEqual("'2016-01-01 00:00:00'", tokenSeq[7].Value);
            Assert.AreEqual(TokenType.And, tokenSeq[8].TokenType);
            Assert.AreEqual(TokenType.DateTimeValue, tokenSeq[9].TokenType);
            Assert.AreEqual("'2016-01-01 00:00:00'", tokenSeq[9].Value);
            Assert.AreEqual(TokenType.SequenceTerminator, tokenSeq[10].TokenType);
        }
Exemple #2
0
        public void If_OneMatchApplicationLikeConditionAndDateCondition_ThenReturnCorrectMatchConditionSequence()
        {
            // ARRANGE
            string lqlQuery = @"MATCH (app LIKE 'My App')
BETWEEN '2016-01-01 00:00:00' AND '2016-01-01 00:00:00'";

            // ACT
            var lexer = new LqlLexer();
            var tokenSeq = lexer.Tokenize(lqlQuery);

            // ASSERT
            Assert.AreEqual(TokenType.Match, tokenSeq[0].TokenType);
            Assert.AreEqual(TokenType.OpenParenthesis, tokenSeq[1].TokenType);
            Assert.AreEqual(TokenType.Application, tokenSeq[2].TokenType);
            Assert.AreEqual(TokenType.Like, tokenSeq[3].TokenType);
            Assert.AreEqual(TokenType.StringValue, tokenSeq[4].TokenType);
            Assert.AreEqual(TokenType.CloseParenthesis, tokenSeq[5].TokenType);
        }
Exemple #3
0
        public void If_Misspelling_ThenReturnInvalidTokensInSequence()
        {
            // ARRANGE
            string lqlQuery = @"MATCH (ap = 'MyApp')
BETWEE '2016-01-01 00:00:00' AND '2016-01-01 00:00:00'";

            // ACT
            var lexer = new LqlLexer();
            var tokenSeq = lexer.Tokenize(lqlQuery);

            // ASSERT
            Assert.AreEqual(TokenType.Match, tokenSeq[0].TokenType);
            Assert.AreEqual(TokenType.OpenParenthesis, tokenSeq[1].TokenType);
            Assert.AreEqual(TokenType.Invalid, tokenSeq[2].TokenType);
            Assert.AreEqual("ap", tokenSeq[2].Value);
            Assert.AreEqual(TokenType.Equals, tokenSeq[3].TokenType);
            Assert.AreEqual(TokenType.StringValue, tokenSeq[4].TokenType);
            Assert.AreEqual(TokenType.CloseParenthesis, tokenSeq[5].TokenType);
            Assert.AreEqual(TokenType.Invalid, tokenSeq[6].TokenType);
            Assert.AreEqual("BETWEE", tokenSeq[6].Value);
            Assert.AreEqual(TokenType.DateTimeValue, tokenSeq[7].TokenType);
            Assert.AreEqual(TokenType.And, tokenSeq[8].TokenType);
            Assert.AreEqual(TokenType.DateTimeValue, tokenSeq[9].TokenType);
            Assert.AreEqual(TokenType.SequenceTerminator, tokenSeq[10].TokenType);
        }
Exemple #4
0
        public void If_MatchConditionsDateConditionFrequencyConditionAndCountByIntegerOfHour_ThenReturnCorrectSequence()
        {
            // ARRANGE
            string lqlQuery = @"MATCH (APP = 'MyApp')
BETWEEN '2016-01-01 00:00:00' AND '2016-01-01 00:00:00'
FREQUENCY > 1000
COUNT BY 10h";

            // ACT
            var lexer = new LqlLexer();
            var tokenSeq = lexer.Tokenize(lqlQuery);

            // ASSERT
            Assert.AreEqual(TokenType.CountBy, tokenSeq[12].TokenType);
            Assert.AreEqual(TokenType.CountByValue, tokenSeq[13].TokenType);
            Assert.AreEqual("10h", tokenSeq[13].Value);
            Assert.AreEqual(TokenType.SequenceTerminator, tokenSeq[14].TokenType);
        }
Exemple #5
0
        public void If_MatchConditionsDateConditionFrequencyConditionAndCountByFractionOfDay_ThenReturnCorrectSequence()
        {
            // ARRANGE
            string lqlQuery = @"MATCH (APP = 'MyApp')
BETWEEN '2016-01-01 00:00:00' AND '2016-01-01 00:00:00'
FREQUENCY > 1000
COUNT BY 0.5d";

            // ACT
            var lexer = new LqlLexer();
            var tokenSeq = lexer.Tokenize(lqlQuery);

            // ASSERT
            Assert.AreEqual(TokenType.Match, tokenSeq[0].TokenType);
            Assert.AreEqual(TokenType.OpenParenthesis, tokenSeq[1].TokenType);
            Assert.AreEqual(TokenType.Application, tokenSeq[2].TokenType);
            Assert.AreEqual(TokenType.Equals, tokenSeq[3].TokenType);
            Assert.AreEqual(TokenType.StringValue, tokenSeq[4].TokenType);
            Assert.AreEqual(TokenType.CloseParenthesis, tokenSeq[5].TokenType);
            Assert.AreEqual(TokenType.Between, tokenSeq[6].TokenType);
            Assert.AreEqual(TokenType.DateTimeValue, tokenSeq[7].TokenType);
            Assert.AreEqual(TokenType.And, tokenSeq[8].TokenType);
            Assert.AreEqual(TokenType.DateTimeValue, tokenSeq[9].TokenType);
            Assert.AreEqual(TokenType.FrequencyGreaterThan, tokenSeq[10].TokenType);
            Assert.AreEqual(TokenType.Number, tokenSeq[11].TokenType);
            Assert.AreEqual(TokenType.CountBy, tokenSeq[12].TokenType);
            Assert.AreEqual(TokenType.CountByValue, tokenSeq[13].TokenType);
            Assert.AreEqual("0.5d", tokenSeq[13].Value);
            Assert.AreEqual(TokenType.SequenceTerminator, tokenSeq[14].TokenType);
        }
Exemple #6
0
        public void If_MultipleOrMatchConditionsAndDateCondition_ThenReturnCorrectSequence()
        {
            // ARRANGE
            string lqlQuery = @"MATCH (APP = 'MyApp'
OR MSG = 'An error occurred')
BETWEEN '2016-01-01 00:00:00' AND '2016-01-01 00:00:00'";

            // ACT
            var lexer = new LqlLexer();
            var tokenSeq = lexer.Tokenize(lqlQuery);

            // ASSERT
            Assert.AreEqual(TokenType.Match, tokenSeq[0].TokenType);
            Assert.AreEqual(TokenType.OpenParenthesis, tokenSeq[1].TokenType);
            Assert.AreEqual(TokenType.Application, tokenSeq[2].TokenType);
            Assert.AreEqual(TokenType.Equals, tokenSeq[3].TokenType);
            Assert.AreEqual(TokenType.StringValue, tokenSeq[4].TokenType);
            Assert.AreEqual(TokenType.Or, tokenSeq[5].TokenType);
            Assert.AreEqual(TokenType.Message, tokenSeq[6].TokenType);
            Assert.AreEqual(TokenType.Equals, tokenSeq[7].TokenType);
            Assert.AreEqual(TokenType.StringValue, tokenSeq[8].TokenType);
            Assert.AreEqual(TokenType.CloseParenthesis, tokenSeq[9].TokenType);
            Assert.AreEqual(TokenType.Between, tokenSeq[10].TokenType);
            Assert.AreEqual(TokenType.DateTimeValue, tokenSeq[11].TokenType);
            Assert.AreEqual(TokenType.And, tokenSeq[12].TokenType);
            Assert.AreEqual(TokenType.DateTimeValue, tokenSeq[13].TokenType);
            Assert.AreEqual(TokenType.SequenceTerminator, tokenSeq[14].TokenType);
        }
Exemple #7
0
        public void If_OneMatchMessageEqualsConditionAndDateCondition_ThenReturnCorrectMatchConditionSequence()
        {
            // ARRANGE
            string lqlQuery = @"MATCH (MSG = 'An error occurred')
BETWEEN '2016-01-01 00:00:00' AND '2016-01-01 00:00:00'";

            // ACT
            var lexer = new LqlLexer();
            var tokenSeq = lexer.Tokenize(lqlQuery);

            // ASSERT
            Assert.AreEqual(TokenType.Match, tokenSeq[0].TokenType);
            Assert.AreEqual(TokenType.OpenParenthesis, tokenSeq[1].TokenType);
            Assert.AreEqual(TokenType.Message, tokenSeq[2].TokenType);
            Assert.AreEqual(TokenType.Equals, tokenSeq[3].TokenType);
            Assert.AreEqual(TokenType.StringValue, tokenSeq[4].TokenType);
            Assert.AreEqual(TokenType.CloseParenthesis, tokenSeq[5].TokenType);
        }