2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
24 package org.onap.ccsdk.sli.core.sli;
26 import java.io.BufferedReader;
27 import java.io.InputStream;
28 import java.io.InputStreamReader;
30 import java.util.LinkedList;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicParser;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicParserException;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
37 import junit.framework.TestCase;
43 public class SvcLogicParserTest extends TestCase {
46 * Test method for {@link org.onap.ccsdk.sli.core.sli.SvcLogicParser#parse(java.lang.String)}.
50 public void testParse() {
56 URL propUrl = getClass().getResource("/svclogic.properties");
58 InputStream propStr = getClass().getResourceAsStream("/svclogic.properties");
60 SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propStr);
64 store.registerNodeType("switch");
65 store.registerNodeType("block");
66 store.registerNodeType("get-resource");
67 store.registerNodeType("reserve");
68 store.registerNodeType("is-available");
69 store.registerNodeType("exists");
70 store.registerNodeType("configure");
71 store.registerNodeType("return");
72 store.registerNodeType("record");
73 store.registerNodeType("allocate");
74 store.registerNodeType("release");
75 store.registerNodeType("for");
76 store.registerNodeType("set");
79 InputStream testStr = getClass().getResourceAsStream("/parser-good.tests");
80 BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr));
81 String testCaseFile = null;
82 while ((testCaseFile = testsReader.readLine()) != null) {
84 testCaseFile = testCaseFile.trim();
86 if (testCaseFile.length() > 0)
88 if (!testCaseFile.startsWith("/"))
90 testCaseFile = "/"+testCaseFile;
92 URL testCaseUrl = getClass().getResource(testCaseFile);
93 if (testCaseUrl == null)
95 fail("Could not resolve test case file "+testCaseFile);
99 SvcLogicParser.validate(testCaseUrl.getPath(), store);
100 } catch (Exception e) {
101 fail("Validation failure ["+e.getMessage()+"]");
112 testStr = getClass().getResourceAsStream("/parser-bad.tests");
113 testsReader = new BufferedReader(new InputStreamReader(testStr));
115 while ((testCaseFile = testsReader.readLine()) != null) {
117 testCaseFile = testCaseFile.trim();
119 if (testCaseFile.length() > 0)
121 if (!testCaseFile.startsWith("/"))
123 testCaseFile = "/"+testCaseFile;
125 URL testCaseUrl = getClass().getResource(testCaseFile);
126 if (testCaseUrl == null)
128 fail("Could not resolve test case file "+testCaseFile);
131 boolean valid = true;
133 SvcLogicParser.load(testCaseUrl.getPath(), store);
134 } catch (Exception e) {
135 System.out.println(e.getMessage());
140 fail("Expected compiler error on "+testCaseFile+", but got success");
147 catch (SvcLogicParserException e)
149 fail("Parser error : "+e.getMessage());
154 fail("Caught exception processing test cases");