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.openecomp.sdnc.sli;
27 import java.io.BufferedReader;
28 import java.io.InputStream;
29 import java.io.InputStreamReader;
31 import java.util.LinkedList;
33 import org.openecomp.sdnc.sli.SvcLogicParser;
34 import org.openecomp.sdnc.sli.SvcLogicParserException;
35 import org.openecomp.sdnc.sli.SvcLogicStore;
36 import org.openecomp.sdnc.sli.SvcLogicStoreFactory;
38 import junit.framework.TestCase;
44 public class SvcLogicParserTest extends TestCase {
47 * Test method for {@link org.openecomp.sdnc.sli.SvcLogicParser#parse(java.lang.String)}.
51 public void testParse() {
57 URL propUrl = getClass().getResource("/svclogic.properties");
59 InputStream propStr = getClass().getResourceAsStream("/svclogic.properties");
61 SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propStr);
65 store.registerNodeType("switch");
66 store.registerNodeType("block");
67 store.registerNodeType("get-resource");
68 store.registerNodeType("reserve");
69 store.registerNodeType("is-available");
70 store.registerNodeType("exists");
71 store.registerNodeType("configure");
72 store.registerNodeType("return");
73 store.registerNodeType("record");
74 store.registerNodeType("allocate");
75 store.registerNodeType("release");
76 store.registerNodeType("for");
77 store.registerNodeType("set");
80 InputStream testStr = getClass().getResourceAsStream("/parser-good.tests");
81 BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr));
82 String testCaseFile = null;
83 while ((testCaseFile = testsReader.readLine()) != null) {
85 testCaseFile = testCaseFile.trim();
87 if (testCaseFile.length() > 0)
89 if (!testCaseFile.startsWith("/"))
91 testCaseFile = "/"+testCaseFile;
93 URL testCaseUrl = getClass().getResource(testCaseFile);
94 if (testCaseUrl == null)
96 fail("Could not resolve test case file "+testCaseFile);
100 SvcLogicParser.validate(testCaseUrl.getPath(), store);
101 } catch (Exception e) {
102 fail("Validation failure ["+e.getMessage()+"]");
113 testStr = getClass().getResourceAsStream("/parser-bad.tests");
114 testsReader = new BufferedReader(new InputStreamReader(testStr));
116 while ((testCaseFile = testsReader.readLine()) != null) {
118 testCaseFile = testCaseFile.trim();
120 if (testCaseFile.length() > 0)
122 if (!testCaseFile.startsWith("/"))
124 testCaseFile = "/"+testCaseFile;
126 URL testCaseUrl = getClass().getResource(testCaseFile);
127 if (testCaseUrl == null)
129 fail("Could not resolve test case file "+testCaseFile);
132 boolean valid = true;
134 SvcLogicParser.load(testCaseUrl.getPath(), store);
135 } catch (Exception e) {
136 System.out.println(e.getMessage());
141 fail("Expected compiler error on "+testCaseFile+", but got success");
148 catch (SvcLogicParserException e)
150 fail("Parser error : "+e.getMessage());
155 fail("Caught exception processing test cases");