Refactor dblib
[ccsdk/sli/core.git] / sli / common / src / test / java / org / onap / ccsdk / sli / core / sli / SvcLogicExpressionParserTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
4  * ================================================================================
5  * Copyright (C) 2017 ONAP
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.ccsdk.sli.core.sli;
22
23 import java.io.BufferedReader;
24 import java.io.InputStream;
25 import java.io.InputStreamReader;
26
27 import org.onap.ccsdk.sli.core.sli.SvcLogicExprListener;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicExpressionFactory;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 import junit.framework.TestCase;
34
35 public class SvcLogicExpressionParserTest extends TestCase {
36
37         private static final Logger LOG = LoggerFactory
38                         .getLogger(SvcLogicExprListener.class);
39         
40         public void testParse() {
41                 try
42                 {
43                         InputStream testStr = getClass().getResourceAsStream("/expression.tests");
44                         BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr));
45                         
46                         String testExpr = null;
47                         while ((testExpr = testsReader.readLine()) != null) {
48                                 
49                                 SvcLogicExpression parsedExpr = SvcLogicExpressionFactory.parse(testExpr);
50                                 if (parsedExpr == null)
51                                 {
52                                         fail("parse("+testExpr+") returned null");
53                                 }
54                                 else
55                                 {
56                                         LOG.info("test expression = ["+testExpr+"] ; parsed expression = ["+parsedExpr.asParsedExpr()+"]");
57                                         
58                                 }
59                         }
60                 }
61                 catch (Exception e)
62                 {
63                         e.printStackTrace();
64                         fail("Caught exception processing test cases");
65                 }
66         }
67
68 }