aboutsummaryrefslogtreecommitdiffstats
path: root/sli/common/src/test/java/org/openecomp
diff options
context:
space:
mode:
Diffstat (limited to 'sli/common/src/test/java/org/openecomp')
-rw-r--r--sli/common/src/test/java/org/openecomp/sdnc/sli/SvcLogicContextTest.java69
-rw-r--r--sli/common/src/test/java/org/openecomp/sdnc/sli/SvcLogicExpressionParserTest.java69
-rw-r--r--sli/common/src/test/java/org/openecomp/sdnc/sli/SvcLogicParserTest.java163
3 files changed, 301 insertions, 0 deletions
diff --git a/sli/common/src/test/java/org/openecomp/sdnc/sli/SvcLogicContextTest.java b/sli/common/src/test/java/org/openecomp/sdnc/sli/SvcLogicContextTest.java
new file mode 100644
index 0000000..ea6e1e1
--- /dev/null
+++ b/sli/common/src/test/java/org/openecomp/sdnc/sli/SvcLogicContextTest.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+
+import junit.framework.TestCase;
+
+public class SvcLogicContextTest extends TestCase {
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SvcLogicContext.class);
+
+ public void testMerge() {
+
+ try {
+ InputStream testStr = getClass().getResourceAsStream("/mergetest.xml");
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ Document theDocument = db.parse(testStr);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.mergeDocument("test-merge", theDocument);
+ Properties props = ctx.toProperties();
+ LOG.info("SvcLogicContext contains the following : ");
+ for (Enumeration e = props.propertyNames(); e.hasMoreElements() ; ) {
+ String propName = (String) e.nextElement();
+ LOG.info(propName+" = "+props.getProperty(propName));
+
+ }
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to merge", e);
+ fail("Caught exception trying to merge");
+ }
+
+ }
+
+}
diff --git a/sli/common/src/test/java/org/openecomp/sdnc/sli/SvcLogicExpressionParserTest.java b/sli/common/src/test/java/org/openecomp/sdnc/sli/SvcLogicExpressionParserTest.java
new file mode 100644
index 0000000..6ebd6df
--- /dev/null
+++ b/sli/common/src/test/java/org/openecomp/sdnc/sli/SvcLogicExpressionParserTest.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.openecomp.sdnc.sli.SvcLogicExprListener;
+import org.openecomp.sdnc.sli.SvcLogicExpression;
+import org.openecomp.sdnc.sli.SvcLogicExpressionFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.TestCase;
+
+public class SvcLogicExpressionParserTest extends TestCase {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SvcLogicExprListener.class);
+
+ public void testParse() {
+ try
+ {
+ InputStream testStr = getClass().getResourceAsStream("/expression.tests");
+ BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr));
+
+ String testExpr = null;
+ while ((testExpr = testsReader.readLine()) != null) {
+
+ SvcLogicExpression parsedExpr = SvcLogicExpressionFactory.parse(testExpr);
+ if (parsedExpr == null)
+ {
+ fail("parse("+testExpr+") returned null");
+ }
+ else
+ {
+ LOG.info("test expression = ["+testExpr+"] ; parsed expression = ["+parsedExpr.asParsedExpr()+"]");
+
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("Caught exception processing test cases");
+ }
+ }
+
+}
diff --git a/sli/common/src/test/java/org/openecomp/sdnc/sli/SvcLogicParserTest.java b/sli/common/src/test/java/org/openecomp/sdnc/sli/SvcLogicParserTest.java
new file mode 100644
index 0000000..2ee65f5
--- /dev/null
+++ b/sli/common/src/test/java/org/openecomp/sdnc/sli/SvcLogicParserTest.java
@@ -0,0 +1,163 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+/**
+ *
+ */
+package org.openecomp.sdnc.sli;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.LinkedList;
+
+import org.openecomp.sdnc.sli.SvcLogicParser;
+import org.openecomp.sdnc.sli.SvcLogicParserException;
+import org.openecomp.sdnc.sli.SvcLogicStore;
+import org.openecomp.sdnc.sli.SvcLogicStoreFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * @author dt5972
+ *
+ */
+public class SvcLogicParserTest extends TestCase {
+
+ /**
+ * Test method for {@link org.openecomp.sdnc.sli.SvcLogicParser#parse(java.lang.String)}.
+ */
+
+
+ public void testParse() {
+
+
+ try
+ {
+
+ URL propUrl = getClass().getResource("/svclogic.properties");
+
+ InputStream propStr = getClass().getResourceAsStream("/svclogic.properties");
+
+ SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propStr);
+
+ assertNotNull(store);
+
+ store.registerNodeType("switch");
+ store.registerNodeType("block");
+ store.registerNodeType("get-resource");
+ store.registerNodeType("reserve");
+ store.registerNodeType("is-available");
+ store.registerNodeType("exists");
+ store.registerNodeType("configure");
+ store.registerNodeType("return");
+ store.registerNodeType("record");
+ store.registerNodeType("allocate");
+ store.registerNodeType("release");
+ store.registerNodeType("for");
+ store.registerNodeType("set");
+
+
+ InputStream testStr = getClass().getResourceAsStream("/parser-good.tests");
+ BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr));
+ String testCaseFile = null;
+ while ((testCaseFile = testsReader.readLine()) != null) {
+
+ testCaseFile = testCaseFile.trim();
+
+ if (testCaseFile.length() > 0)
+ {
+ if (!testCaseFile.startsWith("/"))
+ {
+ testCaseFile = "/"+testCaseFile;
+ }
+ URL testCaseUrl = getClass().getResource(testCaseFile);
+ if (testCaseUrl == null)
+ {
+ fail("Could not resolve test case file "+testCaseFile);
+ }
+
+ try {
+ SvcLogicParser.validate(testCaseUrl.getPath(), store);
+ } catch (Exception e) {
+ fail("Validation failure ["+e.getMessage()+"]");
+
+ }
+
+
+
+
+
+ }
+ }
+
+ testStr = getClass().getResourceAsStream("/parser-bad.tests");
+ testsReader = new BufferedReader(new InputStreamReader(testStr));
+ testCaseFile = null;
+ while ((testCaseFile = testsReader.readLine()) != null) {
+
+ testCaseFile = testCaseFile.trim();
+
+ if (testCaseFile.length() > 0)
+ {
+ if (!testCaseFile.startsWith("/"))
+ {
+ testCaseFile = "/"+testCaseFile;
+ }
+ URL testCaseUrl = getClass().getResource(testCaseFile);
+ if (testCaseUrl == null)
+ {
+ fail("Could not resolve test case file "+testCaseFile);
+ }
+
+ boolean valid = true;
+ try {
+ SvcLogicParser.load(testCaseUrl.getPath(), store);
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ valid = false;
+ }
+
+ if (valid) {
+ fail("Expected compiler error on "+testCaseFile+", but got success");
+ }
+
+
+ }
+ }
+ }
+ catch (SvcLogicParserException e)
+ {
+ fail("Parser error : "+e.getMessage());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("Caught exception processing test cases");
+ }
+
+
+ }
+
+
+
+}