2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
25 package org.onap.ccsdk.sli.core.sli;
27 import java.io.BufferedReader;
28 import java.io.InputStream;
29 import java.io.InputStreamReader;
32 import junit.framework.TestCase;
38 public class ITCaseSvcLogicParser extends TestCase {
41 * Test method for {@link org.onap.ccsdk.sli.core.sli.SvcLogicParser#parse(java.lang.String)}.
45 public void testParse() {
51 URL propUrl = getClass().getResource("/svclogic.properties");
53 InputStream propStr = getClass().getResourceAsStream("/svclogic.properties");
55 SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propStr);
59 store.registerNodeType("switch");
60 store.registerNodeType("block");
61 store.registerNodeType("get-resource");
62 store.registerNodeType("reserve");
63 store.registerNodeType("is-available");
64 store.registerNodeType("exists");
65 store.registerNodeType("configure");
66 store.registerNodeType("return");
67 store.registerNodeType("record");
68 store.registerNodeType("allocate");
69 store.registerNodeType("release");
70 store.registerNodeType("for");
71 store.registerNodeType("set");
74 InputStream testStr = getClass().getResourceAsStream("/parser-good.tests");
75 BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr));
76 String testCaseFile = null;
77 while ((testCaseFile = testsReader.readLine()) != null) {
79 testCaseFile = testCaseFile.trim();
81 if (testCaseFile.length() > 0)
83 if (!testCaseFile.startsWith("/"))
85 testCaseFile = "/"+testCaseFile;
87 URL testCaseUrl = getClass().getResource(testCaseFile);
88 if (testCaseUrl == null)
90 fail("Could not resolve test case file "+testCaseFile);
94 SvcLogicParser.validate(testCaseUrl.getPath(), store);
95 } catch (Exception e) {
96 fail("Validation failure ["+e.getMessage()+"]");
107 testStr = getClass().getResourceAsStream("/parser-bad.tests");
108 testsReader = new BufferedReader(new InputStreamReader(testStr));
110 while ((testCaseFile = testsReader.readLine()) != null) {
112 testCaseFile = testCaseFile.trim();
114 if (testCaseFile.length() > 0)
116 if (!testCaseFile.startsWith("/"))
118 testCaseFile = "/"+testCaseFile;
120 URL testCaseUrl = getClass().getResource(testCaseFile);
121 if (testCaseUrl == null)
123 fail("Could not resolve test case file "+testCaseFile);
126 boolean valid = true;
128 SvcLogicParser.load(testCaseUrl.getPath(), store);
129 } catch (Exception e) {
130 System.out.println(e.getMessage());
135 fail("Expected compiler error on "+testCaseFile+", but got success");
142 catch (SvcLogicParserException e)
144 fail("Parser error : "+e.getMessage());
149 fail("Caught exception processing test cases");