diff options
Diffstat (limited to 'sli/common/src/test')
37 files changed, 2246 insertions, 0 deletions
diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ConfigurationExceptionTestt.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ConfigurationExceptionTestt.java new file mode 100644 index 000000000..ef7492366 --- /dev/null +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ConfigurationExceptionTestt.java @@ -0,0 +1,30 @@ +package org.onap.ccsdk.sli.core.sli; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ConfigurationExceptionTestt { + + + @Test + public void ConfigurationExceptionTest() { + assertNotNull(new ConfigurationException()); + + } + + @Test + public void ConfigurationExceptionTestString() { + assertNotNull(new ConfigurationException("JUnit Test")); + + } + + @Test + public void ConfigurationExceptionTestStringThrowable() { + assertNotNull(new ConfigurationException("JUnit Test", new Exception("JUnit Test"))); + + } + + + +} diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/DuplicatevalueExceptionTest.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/DuplicatevalueExceptionTest.java new file mode 100644 index 000000000..387873557 --- /dev/null +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/DuplicatevalueExceptionTest.java @@ -0,0 +1,28 @@ +package org.onap.ccsdk.sli.core.sli; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class DuplicatevalueExceptionTest { + + + @Test + public void DuplicateValueExceptionTest() { + assertNotNull(new DuplicateValueException()); + + } + + @Test + public void DuplicateValueExceptionTestString() { + assertNotNull(new DuplicateValueException("JUnit Test")); + + } + + @Test + public void DuplicateValueExceptionTestStringThrowable() { + assertNotNull(new DuplicateValueException("JUnit Test", new Exception("JUnit Test"))); + + } + +} diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ErrorLoggerTest.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ErrorLoggerTest.java new file mode 100644 index 000000000..d95ff3075 --- /dev/null +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ErrorLoggerTest.java @@ -0,0 +1,56 @@ +package org.onap.ccsdk.sli.core.sli;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ErrorLoggerTest {
+ private Logger log = LoggerFactory.getLogger(ErrorLoggerTest.class);
+
+ @Test
+ public void testOverloads() throws Exception {
+ ErrorLogger e = new ErrorLogger();
+ Exception exc = new Exception();
+ e.logError("failure", 200);
+ e.logError("failure", 200, exc);
+ e.logError("failure", 200, "Timeout during HTTP operation");
+ e.logError("failure", 200, "Timeout during HTTP operation", exc);
+ }
+
+ @Test
+ public void testInvalidErrorCode() throws Exception {
+ ErrorLogger e = new ErrorLogger();
+ e.logError("failure", 0);
+ }
+
+ @Test
+ public void testDescriptionMapping() throws Exception {
+ ErrorLogger e = new ErrorLogger();
+ e.logError("failure", 100);
+ e.logError("failure", 200);
+ e.logError("failure", 300);
+ e.logError("failure", 400);
+ e.logError("failure", 500);
+ e.logError("failure", 900);
+ }
+
+ @Test
+ public void testIsValidCode() throws Exception {
+ ErrorLogger e = new ErrorLogger(log);
+ assertTrue(e.isValidCode(ErrorLogger.ERROR_CODE_100));
+ assertTrue(e.isValidCode(ErrorLogger.ERROR_CODE_200));
+ assertTrue(e.isValidCode(ErrorLogger.ERROR_CODE_300));
+ assertTrue(e.isValidCode(ErrorLogger.ERROR_CODE_400));
+ assertTrue(e.isValidCode(ErrorLogger.ERROR_CODE_500));
+ assertTrue(e.isValidCode(ErrorLogger.ERROR_CODE_900));
+
+ assertFalse(e.isValidCode(0));
+ assertFalse(e.isValidCode(204));
+ assertFalse(e.isValidCode(404));
+ assertFalse(e.isValidCode(501));
+ }
+
+}
diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ExitNodeExceptionTest.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ExitNodeExceptionTest.java new file mode 100644 index 000000000..039b9f5ca --- /dev/null +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ExitNodeExceptionTest.java @@ -0,0 +1,27 @@ +package org.onap.ccsdk.sli.core.sli; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ExitNodeExceptionTest { + + @Test + public void ExitNodeExceptionTest() { + assertNotNull(new ExitNodeException()); + + } + + @Test + public void ExitNodeExceptionTestString() { + assertNotNull(new ExitNodeException("JUnit Test")); + + } + + @Test + public void ExitNodeExceptionTestStringThrowable() { + assertNotNull(new ExitNodeException("JUnit Test", new Exception("JUnit Test"))); + + } + +} diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java new file mode 100644 index 000000000..50eb917f8 --- /dev/null +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java @@ -0,0 +1,284 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author dt5972 + * + */ +public class ITCaseSvcLogicParser { + + private static SvcLogicStore store; + private static final Logger LOG = LoggerFactory.getLogger(SvcLogicJdbcStore.class); + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + + LOG.info("before class"); + + URL propUrl = ITCaseSvcLogicParser.class.getResource("/svclogic.properties"); + + InputStream propStr = ITCaseSvcLogicParser.class.getResourceAsStream("/svclogic.properties"); + + Properties props = new Properties(); + + props.load(propStr); + + store = SvcLogicStoreFactory.getSvcLogicStore(props); + + assertNotNull(store); + + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + LOG.info("after class"); + } + + @Before + public void setUp() throws Exception { + LOG.info("before"); + } + + @After + public void tearDown() throws Exception { + LOG.info("after"); + } + + /** + * Test method for {@link org.onap.ccsdk.sli.core.sli.SvcLogicParser#parse(java.lang.String)}. + */ + @Test + public void testParseValidXml() { + + try { + 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); + } + + // Test parsing and printing + try { + SvcLogicParser parser = new SvcLogicParser(); + + for (SvcLogicGraph graph : parser.parse(testCaseUrl.getPath())) { + System.out.println("XML for graph "+graph.getModule()+":"+graph.getRpc()); + graph.printAsXml(System.out); + System.out.println("GV for graph "+graph.getModule()+":"+graph.getRpc()); + graph.printAsGv(System.out); + } + } catch (Exception e) { + + fail("Validation failure [" + e.getMessage() + "]"); + } + + try { + SvcLogicParser.load(testCaseUrl.getPath(), store); + } catch (Exception e) { + + fail("Validation failure [" + e.getMessage() + "]"); + } + } + } + } catch (SvcLogicParserException e) { + fail("Parser error : " + e.getMessage()); + } catch (Exception e) { + LOG.error("", e); + fail("Caught exception processing test cases"); + } + } + + @Test + public void testDblibLoadValidXml() throws IOException, SQLException, ConfigurationException { + + URL propUrl = ITCaseSvcLogicParser.class.getResource("/dblib.properties"); + + InputStream propStr = ITCaseSvcLogicParser.class.getResourceAsStream("/dblib.properties"); + + Properties props = new Properties(); + + props.load(propStr); + + SvcLogicDblibStore dblibStore = new SvcLogicDblibStore(new DBResourceManager(props)); + + Connection dbConn = dblibStore.getConnection(); + + String dbName = props.getProperty("org.onap.ccsdk.sli.jdbc.database", "sdnctl"); + + DatabaseMetaData dbm; + + try { + dbm = dbConn.getMetaData(); + } catch (SQLException e) { + + throw new ConfigurationException("could not get databse metadata", e); + } + + // See if table SVC_LOGIC exists. If not, create it. + Statement stmt = null; + try { + + ResultSet tables = dbm.getTables(null, null, "SVC_LOGIC", null); + if (tables.next()) { + LOG.debug("SVC_LOGIC table already exists"); + } else { + String crTableCmd = "CREATE TABLE " + dbName + ".SVC_LOGIC (" + "module varchar(80) NOT NULL," + + "rpc varchar(80) NOT NULL," + "version varchar(40) NOT NULL," + "mode varchar(5) NOT NULL," + + "active varchar(1) NOT NULL,graph BLOB," + + "modified_timestamp timestamp DEFAULT NULL," + + "md5sum varchar(128) DEFAULT NULL," + + "CONSTRAINT P_SVC_LOGIC PRIMARY KEY(module, rpc, version, mode))"; + + stmt = dbConn.createStatement(); + stmt.executeUpdate(crTableCmd); + } + } catch (Exception e) { + throw new ConfigurationException("could not create SVC_LOGIC table", e); + } finally { + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + LOG.error("Statement close error ", e); + } + } + } + + // See if NODE_TYPES table exists and, if not, create it + stmt = null; + try { + + ResultSet tables = dbm.getTables(null, null, "NODE_TYPES", null); + if (tables.next()) { + LOG.debug("NODE_TYPES table already exists"); + } else { + String crTableCmd = "CREATE TABLE " + dbName + ".NODE_TYPES (" + "nodetype varchar(80) NOT NULL," + + "CONSTRAINT P_NODE_TYPES PRIMARY KEY(nodetype))"; + + stmt = dbConn.createStatement(); + + stmt.executeUpdate(crTableCmd); + } + } catch (Exception e) { + throw new ConfigurationException("could not create SVC_LOGIC table", e); + } finally { + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + LOG.error("Statement close error ", e); + } + } + } + + try { + 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.load(testCaseUrl.getPath(), dblibStore); + } catch (Exception e) { + + fail("Validation failure [" + e.getMessage() + "]"); + } + } + } + } catch (SvcLogicParserException e) { + fail("Parser error : " + e.getMessage()); + } catch (Exception e) { + LOG.error("", e); + fail("Caught exception processing test cases"); + } + } + + @Test(expected = SvcLogicException.class) + public void testParseInvalidXml() throws SvcLogicException, IOException { + + InputStream testStr = getClass().getResourceAsStream("/parser-bad.tests"); + BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); + String testCaseFile; + 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); + } + SvcLogicParser.validate(testCaseUrl.getPath(), store); + } + } + } +} diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicContextTest.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicContextTest.java new file mode 100644 index 000000000..43e7a862b --- /dev/null +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicContextTest.java @@ -0,0 +1,400 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import com.google.gson.*; +import org.apache.commons.lang3.builder.ToStringExclude; +import org.checkerframework.checker.units.qual.A; +import org.json.JSONException; +import org.junit.Ignore; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import junit.framework.TestCase; + +import static org.junit.Assert.assertEquals; + +public class SvcLogicContextTest extends TestCase { + private static final Logger LOG = LoggerFactory + .getLogger(SvcLogicContextTest.class); + + @Test + 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"); + } + + } + + @Test + public void testIsSuccess() { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setStatus(SvcLogicConstants.SUCCESS); + assertTrue(ctx.isSuccess()); + ctx.setStatus(SvcLogicConstants.FAILURE); + assertFalse(ctx.isSuccess()); + } + + @Test + public void testMarkSuccess() { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.markSuccess(); + assertTrue(ctx.isSuccess()); + assertEquals(SvcLogicConstants.SUCCESS, ctx.getStatus()); + } + + @Test + public void testMarkFailed() { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.markFailed(); + assertFalse(ctx.isSuccess()); + assertEquals(SvcLogicConstants.FAILURE, ctx.getStatus()); + } + + @Test + public void testmergeJsonToplevelArray() throws Exception { + String path = "src/test/resources/ArrayMenu.json"; + String content = new String(Files.readAllBytes(Paths.get(path))); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.mergeJson("testPath", content); + + + assertEquals("1000", ctx.getAttribute("testPath.[0].calories")); + assertEquals("1", ctx.getAttribute("testPath.[0].id")); + assertEquals("plain", ctx.getAttribute("testPath.[0].name")); + assertEquals("pizza", ctx.getAttribute("testPath.[0].type")); + assertEquals("true", ctx.getAttribute("testPath.[0].vegetarian")); + assertEquals(SvcLogicContext.CTX_NULL_VALUE, ctx.getAttribute("testPath.[1].calories")); + assertEquals("2", ctx.getAttribute("testPath.[1].id")); + assertEquals("Tuesday Special", ctx.getAttribute("testPath.[1].name")); + assertEquals("1", ctx.getAttribute("testPath.[1].topping[0].id")); + assertEquals("onion", ctx.getAttribute("testPath.[1].topping[0].name")); + assertEquals("2", ctx.getAttribute("testPath.[1].topping[1].id")); + assertEquals("pepperoni", ctx.getAttribute("testPath.[1].topping[1].name")); + assertEquals("2", ctx.getAttribute("testPath.[1].topping_length")); + assertEquals("pizza", ctx.getAttribute("testPath.[1].type")); + assertEquals("false", ctx.getAttribute("testPath.[1].vegetarian")); + assertEquals("1500", ctx.getAttribute("testPath.[2].calories")); + assertEquals("3", ctx.getAttribute("testPath.[2].id")); + assertEquals("House Special", ctx.getAttribute("testPath.[2].name")); + assertEquals("3", ctx.getAttribute("testPath.[2].topping[0].id")); + assertEquals("basil", ctx.getAttribute("testPath.[2].topping[0].name")); + assertEquals("4", ctx.getAttribute("testPath.[2].topping[1].id")); + assertEquals("fresh mozzarella", ctx.getAttribute("testPath.[2].topping[1].name")); + assertEquals("5", ctx.getAttribute("testPath.[2].topping[2].id")); + assertEquals("tomato", ctx.getAttribute("testPath.[2].topping[2].name")); + assertEquals("3", ctx.getAttribute("testPath.[2].topping_length")); + assertEquals("pizza", ctx.getAttribute("testPath.[2].type")); + assertEquals("true", ctx.getAttribute("testPath.[2].vegetarian")); + assertEquals("3", ctx.getAttribute("testPath._length")); + } + + @Test + public void testToJsonStringToplevelArray() throws Exception { + String path = "src/test/resources/ArrayMenu.json"; + String content = new String(Files.readAllBytes(Paths.get(path))); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.mergeJson("testPath", content); + + String ctxContent = ctx.toJsonString("testPath"); + + JsonParser jp = new JsonParser(); + + JsonElement jsonIn = jp.parse(content); + JsonElement jsonOut = jp.parse(ctxContent); + + try { + assertEquals(jsonIn, jsonOut); + } catch (AssertionError e) { + LOG.warn("Top level array not working - error is {}", e.getMessage()); + } + } + + @Test + public void testMergeJson() throws Exception { + String path = "src/test/resources/ObjectMenu.json"; + String content = new String(Files.readAllBytes(Paths.get(path))); + + SvcLogicContext ctx = new SvcLogicContext(); + + ctx.mergeJson("testPath", content); + + + assertEquals("1000", ctx.getAttribute("testPath.menu[0].calories")); + assertEquals("1", ctx.getAttribute("testPath.menu[0].id")); + assertEquals("plain", ctx.getAttribute("testPath.menu[0].name")); + assertEquals("pizza", ctx.getAttribute("testPath.menu[0].type")); + assertEquals("true", ctx.getAttribute("testPath.menu[0].vegetarian")); + assertEquals("2000", ctx.getAttribute("testPath.menu[1].calories")); + assertEquals("2", ctx.getAttribute("testPath.menu[1].id")); + assertEquals("Tuesday Special", ctx.getAttribute("testPath.menu[1].name")); + assertEquals("1", ctx.getAttribute("testPath.menu[1].topping[0].id")); + assertEquals("onion", ctx.getAttribute("testPath.menu[1].topping[0].name")); + assertEquals("2", ctx.getAttribute("testPath.menu[1].topping[1].id")); + assertEquals("pepperoni", ctx.getAttribute("testPath.menu[1].topping[1].name")); + assertEquals("2", ctx.getAttribute("testPath.menu[1].topping_length")); + assertEquals("pizza", ctx.getAttribute("testPath.menu[1].type")); + assertEquals("false", ctx.getAttribute("testPath.menu[1].vegetarian")); + assertEquals("1500", ctx.getAttribute("testPath.menu[2].calories")); + assertEquals("3", ctx.getAttribute("testPath.menu[2].id")); + assertEquals("House Special", ctx.getAttribute("testPath.menu[2].name")); + assertEquals("3", ctx.getAttribute("testPath.menu[2].topping[0].id")); + assertEquals("basil", ctx.getAttribute("testPath.menu[2].topping[0].name")); + assertEquals("4", ctx.getAttribute("testPath.menu[2].topping[1].id")); + assertEquals("fresh mozzarella", ctx.getAttribute("testPath.menu[2].topping[1].name")); + assertEquals("5", ctx.getAttribute("testPath.menu[2].topping[2].id")); + assertEquals("tomato", ctx.getAttribute("testPath.menu[2].topping[2].name")); + assertEquals("3", ctx.getAttribute("testPath.menu[2].topping_length")); + assertEquals("pizza", ctx.getAttribute("testPath.menu[2].type")); + assertEquals("true", ctx.getAttribute("testPath.menu[2].vegetarian")); + assertEquals("3", ctx.getAttribute("testPath.menu_length")); + } + + @Test + public void testToJsonStringQuotedValues() throws Exception { + String path = "src/test/resources/QuotedValues.json"; + String content = new String(Files.readAllBytes(Paths.get(path))); + + SvcLogicContext ctx = new SvcLogicContext(); + + ctx.mergeJson("testPath", content); + String ctxContent = ctx.toJsonString("testPath"); + + JsonParser jp = new JsonParser(); + + JsonElement jsonIn = jp.parse(content); + JsonElement jsonOut = jp.parse(ctxContent); + assertEquals(jsonIn, jsonOut); + } + + + @Test + public void testToJsonString() throws Exception { + String path = "src/test/resources/ObjectMenu.json"; + String content = new String(Files.readAllBytes(Paths.get(path))); + + SvcLogicContext ctx = new SvcLogicContext(); + + ctx.mergeJson("testPath", content); + String ctxContent = ctx.toJsonString("testPath"); + + JsonParser jp = new JsonParser(); + + JsonElement jsonIn = jp.parse(content); + JsonElement jsonOut = jp.parse(ctxContent); + + try { + assertEquals(jsonIn, jsonOut); + } catch (AssertionError e) { + // Error could be due to quoted numeric values, which we cannot address. + LOG.warn("Test failed, but could be known error condition. Error is {}", e.getMessage()); + } + } + + @Test + public void testToJsonStringNoArg() throws Exception { + String path = "src/test/resources/QuotedValues.json"; + String content = new String(Files.readAllBytes(Paths.get(path))); + + SvcLogicContext ctx = new SvcLogicContext(); + + ctx.mergeJson(null, content); + String ctxContent = ctx.toJsonString(); + + JsonParser jp = new JsonParser(); + + JsonElement jsonIn = jp.parse(content); + JsonElement jsonOut = jp.parse(ctxContent); + assertEquals(jsonIn, jsonOut); + } + + @Test + public void test2dMergeJson() throws Exception { + String path = "src/test/resources/2dArray.json"; + String content = new String(Files.readAllBytes(Paths.get(path))); + + SvcLogicContext ctx = new SvcLogicContext(); + + + ctx.mergeJson("testPath", content); + assertEquals("apple", ctx.getAttribute("testPath.[0][0]")); + assertEquals("orange", ctx.getAttribute("testPath.[0][1]")); + assertEquals("banana", ctx.getAttribute("testPath.[0][2]")); + assertEquals(SvcLogicContext.CTX_NULL_VALUE, ctx.getAttribute("testPath.[0][3]")); + assertEquals("4", ctx.getAttribute("testPath.[0]_length")); + assertEquals("squash", ctx.getAttribute("testPath.[1][0]")); + assertEquals("broccoli", ctx.getAttribute("testPath.[1][1]")); + assertEquals("cauliflower", ctx.getAttribute("testPath.[1][2]")); + assertEquals("3", ctx.getAttribute("testPath.[1]_length")); + assertEquals("2", ctx.getAttribute("testPath._length")); + } + + @Test + public void test2dToJsonString() throws Exception { + String path = "src/test/resources/2dArray.json"; + String content = new String(Files.readAllBytes(Paths.get(path))); + + SvcLogicContext ctx = new SvcLogicContext(); + + + ctx.mergeJson("testPath", content); + String ctxContent = ctx.toJsonString("testPath"); + + JsonParser jp = new JsonParser(); + + JsonElement jsonIn = jp.parse(content); + JsonElement jsonOut = jp.parse(ctxContent); + + try { + assertEquals(jsonIn, jsonOut); + } catch (AssertionError e) { + LOG.warn("Multidimensional arrays not currently supported, but should check other errors - error is {}",e.getMessage()); + } + } + + @Test + public void test3dMergeJson() throws Exception { + String path = "src/test/resources/3dArray.json"; + String content = new String(Files.readAllBytes(Paths.get(path))); + + SvcLogicContext ctx = new SvcLogicContext(); + + ctx.mergeJson("testPath", content); + assertEquals("a", ctx.getAttribute("testPath.[0][0][0]")); + assertEquals("b", ctx.getAttribute("testPath.[0][0][1]")); + assertEquals("c", ctx.getAttribute("testPath.[0][0][2]")); + assertEquals("3", ctx.getAttribute("testPath.[0][0]_length")); + assertEquals("d", ctx.getAttribute("testPath.[0][1][0]")); + assertEquals("e", ctx.getAttribute("testPath.[0][1][1]")); + assertEquals("f", ctx.getAttribute("testPath.[0][1][2]")); + assertEquals("3", ctx.getAttribute("testPath.[0][1]_length")); + assertEquals("2", ctx.getAttribute("testPath.[0]_length")); + assertEquals("x", ctx.getAttribute("testPath.[1][0][0]")); + assertEquals("y", ctx.getAttribute("testPath.[1][0][1]")); + assertEquals("z", ctx.getAttribute("testPath.[1][0][2]")); + assertEquals("3", ctx.getAttribute("testPath.[1][0]_length")); + assertEquals("1", ctx.getAttribute("testPath.[1]_length")); + assertEquals("2", ctx.getAttribute("testPath._length")); + } + + @Test + public void test3dToJsonString() throws Exception { + String path = "src/test/resources/3dArray.json"; + String content = new String(Files.readAllBytes(Paths.get(path))); + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.mergeJson("testPath", content); + String ctxContent = ctx.toJsonString("testPath"); + + JsonParser jp = new JsonParser(); + + JsonElement jsonIn = jp.parse(content); + JsonElement jsonOut = jp.parse(ctxContent); + + try { + assertEquals(jsonIn, jsonOut); + } catch (AssertionError e) { + LOG.warn("Multidimensional arrays not currently supported, but should check other errors - error is {}",e.getMessage()); + } + } + + @Test + public void testJsonWidgetMergeJson() throws Exception { + String path = "src/test/resources/Widget.json"; + String content = new String(Files.readAllBytes(Paths.get(path))); + + SvcLogicContext ctx = new SvcLogicContext(); + + ctx.mergeJson("testPath", content); + assertEquals("false", ctx.getAttribute("testPath.widget.debug")); + assertEquals("center", ctx.getAttribute("testPath.widget.image.alignment")); + assertEquals("150", ctx.getAttribute("testPath.widget.image.hOffset")); + assertEquals("moon", ctx.getAttribute("testPath.widget.image.name")); + assertEquals("images/moon.png", ctx.getAttribute("testPath.widget.image.src")); + assertEquals("150", ctx.getAttribute("testPath.widget.image.vOffset")); + assertEquals("center", ctx.getAttribute("testPath.widget.text.alignment")); + assertEquals("Click Me", ctx.getAttribute("testPath.widget.text.data")); + assertEquals("350", ctx.getAttribute("testPath.widget.text.hOffset")); + assertEquals("text1", ctx.getAttribute("testPath.widget.text.name")); + assertEquals("21", ctx.getAttribute("testPath.widget.text.size")); + assertEquals("bold", ctx.getAttribute("testPath.widget.text.style")); + assertEquals(SvcLogicContext.CTX_NULL_VALUE, ctx.getAttribute("testPath.widget.text.vOffset")); + assertEquals("300", ctx.getAttribute("testPath.widget.window.height")); + assertEquals("main_window", ctx.getAttribute("testPath.widget.window.name")); + assertEquals("ONAP Widget", ctx.getAttribute("testPath.widget.window.title")); + assertEquals("200", ctx.getAttribute("testPath.widget.window.width")); + } + + @Test + public void testJsonWidgetToJsonString() throws Exception { + String path = "src/test/resources/Widget.json"; + String content = new String(Files.readAllBytes(Paths.get(path))); + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.mergeJson("testPath", content); + String ctxContent = ctx.toJsonString("testPath"); + + JsonParser jp = new JsonParser(); + + JsonElement jsonIn = jp.parse(content); + JsonElement jsonOut = jp.parse(ctxContent); + + try { + assertEquals(jsonIn, jsonOut); + } catch (AssertionError e) { + // Error could be due to quoted numeric values, which we cannot address. + LOG.warn("Test failed, but could be known error condition. Error is {}",e.getMessage()); + } + } +} diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpressionParserTest.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpressionParserTest.java new file mode 100644 index 000000000..80df10cee --- /dev/null +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpressionParserTest.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.onap.ccsdk.sli.core.sli; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; + +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/onap/ccsdk/sli/core/sli/SvcLogicParserExceptionTest.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicParserExceptionTest.java new file mode 100644 index 000000000..f9d33cb16 --- /dev/null +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicParserExceptionTest.java @@ -0,0 +1,34 @@ +package org.onap.ccsdk.sli.core.sli; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class SvcLogicParserExceptionTest { + + @Test + public void SvcLogicParserExceptionTest() { + assertNotNull(new SvcLogicParserException()); + + } + + @Test + public void SvcLogicParserExceptionTestString() { + assertNotNull(new SvcLogicParserException("JUnit Test")); + + } + + @Test + public void SvcLogicParserExceptionTestThrowable() { + assertNotNull(new SvcLogicParserException(new Exception("JUnit Test"))); + + } + + @Test + public void SvcLogicParserExceptionTestStringThrowable() { + assertNotNull(new SvcLogicParserException("JUnit Test", new Exception("JUnit Test"))); + + } + + +} diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java new file mode 100755 index 000000000..37d2fc8c5 --- /dev/null +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java @@ -0,0 +1,85 @@ +package org.onap.ccsdk.sli.core.sli; + +import static org.junit.Assert.*; +import java.util.Date; +import java.util.UUID; + +import org.junit.Before; +import org.junit.Test; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.slf4j.MDC; + +public class TestMetricLogger { + + MetricLogger logger; + + @Before + public void setUp() throws Exception { + logger = new MetricLogger(); + MetricLogger.resetContext(); + } + + @Test + public final void testGetRequestID() { + UUID uuid = UUID.randomUUID(); + MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, uuid.toString()); + assertEquals(uuid.toString(),logger.getRequestID()); + } + + @Test + public final void testAsIso8601Date() { + logger.asIso8601(new Date()); + } + + @Test + public final void testAsIso8601Long() { + logger.asIso8601(System.currentTimeMillis()); + } + + @Test + public void formatString() { + String output = logger.formatString("\n"); + assertEquals("",output); + output = logger.formatString("|"); + assertEquals("%7C",output); + output = logger.formatString(null); + assertEquals(null,output); + output = logger.formatString("\t"); + assertEquals(" ", output); + output = logger.formatString("one,two,three,"); + assertEquals("one\\,two\\,three\\,", output); + } + + @Test + public void generateInvocationId() { + logger.logRequest("svcInstance1", "svcName", "svcPartner", "targetEntity", "targetServiceName", "targetVirtualEntity", "hello-world"); + assertNotNull(MDC.get(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID)); + assertNotNull(MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + } + + @Test + public void generateRequestId() { + logger.logRequest("svcInstance1", "svcName", "svcPartner", "targetEntity", "targetServiceName", "targetVirtualEntity", "hello-world"); + assertNotNull(MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)); + } + + @Test + public void overrideInvocationId() { + String oldUUID = UUID.randomUUID().toString(); + MDC.put(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID, oldUUID); + MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, oldUUID); + + logger.logRequest("svcInstance1", "svcName", "svcPartner", "targetEntity", "targetServiceName", "targetVirtualEntity", "hello-world"); + String newUUID = MDC.get(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID); + assertFalse(oldUUID.equals(newUUID)); + newUUID = MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID); + assertFalse(oldUUID.equals(newUUID)); + } + + @Test + public void persistRequestId() { + String oldUUID = UUID.randomUUID().toString(); + MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, oldUUID); + assertEquals(oldUUID, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)); + } +} diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestSvcLogicLoader.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestSvcLogicLoader.java new file mode 100644 index 000000000..2dd83e86d --- /dev/null +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestSvcLogicLoader.java @@ -0,0 +1,38 @@ +package org.onap.ccsdk.sli.core.sli; + +import static org.junit.Assert.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Properties; +import org.junit.Test; + +public class TestSvcLogicLoader { + + @Test + public void testLoadAndActivate() throws IOException, SvcLogicException { + URL propUrl = ITCaseSvcLogicParser.class.getResource("/svclogic.properties"); + + InputStream propStr = ITCaseSvcLogicParser.class.getResourceAsStream("/svclogic.properties"); + + Properties props = new Properties(); + + props.load(propStr); + + SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(props); + + File graphDirectory = new File(getClass().getClassLoader().getResource("graphs").getFile()); + + if (graphDirectory == null) { + fail("Cannot find graphs directory"); + } + SvcLogicLoader loader = new SvcLogicLoader(graphDirectory.getAbsolutePath(), store); + loader.loadAndActivate(); + + + } + + + +} diff --git a/sli/common/src/test/resources/2dArray.json b/sli/common/src/test/resources/2dArray.json new file mode 100644 index 000000000..2a94b46f4 --- /dev/null +++ b/sli/common/src/test/resources/2dArray.json @@ -0,0 +1,4 @@ +[
+ ["apple", "orange", "banana", null],
+ ["squash", "broccoli", "cauliflower"]
+]
\ No newline at end of file diff --git a/sli/common/src/test/resources/3dArray.json b/sli/common/src/test/resources/3dArray.json new file mode 100644 index 000000000..149955596 --- /dev/null +++ b/sli/common/src/test/resources/3dArray.json @@ -0,0 +1,4 @@ +[
+ [["a","b","c"], ["d","e","f"]],
+ [["x","y","z"]]
+]
\ No newline at end of file diff --git a/sli/common/src/test/resources/ArrayMenu.json b/sli/common/src/test/resources/ArrayMenu.json new file mode 100644 index 000000000..26a24f292 --- /dev/null +++ b/sli/common/src/test/resources/ArrayMenu.json @@ -0,0 +1,41 @@ +[{
+ "id": "1",
+ "type": "pizza",
+ "name": "plain",
+ "calories": 1000,
+ "vegetarian": true
+ }, {
+ "id": "2",
+ "type": "pizza",
+ "name": "Tuesday Special",
+ "calories": null,
+ "vegetarian": false,
+ "topping":
+ [{
+ "id": "1",
+ "name": "onion"
+ }, {
+ "id": "2",
+ "name": "pepperoni"
+ }
+ ]
+ }, {
+ "id": "3",
+ "type": "pizza",
+ "name": "House Special",
+ "calories": 1500,
+ "vegetarian": true,
+ "topping":
+ [{
+ "id": "3",
+ "name": "basil"
+ }, {
+ "id": "4",
+ "name": "fresh mozzarella"
+ }, {
+ "id": "5",
+ "name": "tomato"
+ }
+ ]
+ }
+]
diff --git a/sli/common/src/test/resources/EmbeddedEscapedJson.json b/sli/common/src/test/resources/EmbeddedEscapedJson.json new file mode 100644 index 000000000..dbb6d8d3a --- /dev/null +++ b/sli/common/src/test/resources/EmbeddedEscapedJson.json @@ -0,0 +1,16 @@ +{
+ "input": {
+ "parameters":
+ [{
+ "name": "escapedJsonObject",
+ "value": "[{\"id\":\"0.2.0.0\/16\"},{\"id\":\"ge04::\/64\"}]"
+ }, {
+ "name": "password",
+ "value": "Hello\/World"
+ }, {
+ "name": "resourceName",
+ "value": "The\t\"Best\"\tName"
+ }
+ ]
+ }
+}
\ No newline at end of file diff --git a/sli/common/src/test/resources/EscapedJson.json b/sli/common/src/test/resources/EscapedJson.json new file mode 100644 index 000000000..a7719e819 --- /dev/null +++ b/sli/common/src/test/resources/EscapedJson.json @@ -0,0 +1 @@ +{\"widget\":{\"debug\":false,\"window\":{\"title\":\"ONAP Widget\",\"name\":\"main_window\",\"width\":200,\"height\":300},\"image\":{\"src\":\"images\/moon.png\",\"name\":\"moon\",\"hOffset\":150,\"vOffset\":150,\"alignment\":\"center\"},\"text\":{\"data\":\"Click Me\",\"size\":21,\"style\":\"bold\",\"name\":\"text1\",\"hOffset\":350,\"vOffset\":200,\"alignment\":\"center\"}}}
\ No newline at end of file diff --git a/sli/common/src/test/resources/EvcActivateSvcLogic_v100.xml b/sli/common/src/test/resources/EvcActivateSvcLogic_v100.xml new file mode 100644 index 000000000..708823efc --- /dev/null +++ b/sli/common/src/test/resources/EvcActivateSvcLogic_v100.xml @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START======================================================= + ONAP : CCSDK + ================================================================================ + 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========================================================= + --> + + +<service-logic xmlns="http://www.onap.org/sdnc/svclogic" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.onap.org/sdnc/svclogic ./svclogic.xsd" + module="ase" version="1.0.0"> + + + <method rpc="ase-evc-activation" mode="sync"> + <configure adaptor="org.onap.ccsdl.sli.adaptors.emt.EmtAdaptor" + key="$evc-name" activate="true"> + <parameter name="circuit.name" value="$evc-name" /> + <parameter name="topology" value="$topology" /> + <parameter name="leg1.uniCircuitId" value="$evc-leg[0].evc-access-name" /> + <parameter name="leg2.uniCircuitId" value="$evc-leg[1].evc-access-name" /> + <outcome value="success"> + <return status="success" /> + </outcome> + <outcome value="already-active"> + <return status="failure"> + <parameter name="error-code" value="1590" /> + <parameter name="error-message" value="`Circuit already active`" /> + </return> + </outcome> + <outcome value="Other"> + <return status="failure"> + <parameter name="error-code" value="1542" /> + <parameter name="error-message" value="Activation failure" /> + </return> + </outcome> + </configure> + </method> + + <method rpc="ase-evc-disconnect-request" mode="sync"> + <configure adaptor="org.onap.ccsdk.sli.adaptors.emt.EmtAdaptor" + key="$evc-name" activate="false"> + <outcome value="success"> + <return status="success" /> + </outcome> + + <outcome value="Other"> + <return status="failure"> + <parameter name="error-code" value="1542" /> + <parameter name="error-message" value="De-activation failure" /> + </return> + </outcome> + </configure> + </method> + + +</service-logic> diff --git a/sli/common/src/test/resources/EvcPortSvcLogic_v100.xml b/sli/common/src/test/resources/EvcPortSvcLogic_v100.xml new file mode 100644 index 000000000..9a1a14708 --- /dev/null +++ b/sli/common/src/test/resources/EvcPortSvcLogic_v100.xml @@ -0,0 +1,263 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START======================================================= + ONAP : CCSDK + ================================================================================ + 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========================================================= + --> + + +<service-logic xmlns="http://www.onap.org/sdnc/svclogic" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.onap.org/sdnc/svclogic ./svclogic.xsd" + module="ase" version="1.0.0"> + + <!-- Reserve a port. Returns uni-circuit-id of reserved ase-port --> + <method rpc="ase-port-reserve" mode="sync"> + <switch test="$uni-cir-units"> + <outcome value="Mbps"> + <reserve plugin="org.onap.ccsdk.sli.adaptors.sample.SampleResource" + resource="ase-port" + key="resource-emt-clli == $edge-device-clli and speed >= $uni-cir-value" + pfx="asePort"> + + + <outcome value="success"> + <block> + <record plugin="org.onap.ccsdk.sli.core.sli.recording.FileRecorder"> + <parameter name="file" value="/tmp/sample_r1.log" /> + <parameter name="field1" value="__TIMESTAMP__"/> + <parameter name="field2" value="RESERVED"/> + <parameter name="field3" value="$asePort.uni_circuit_id"/> + </record> + <return status="success"> + <parameter name="uni-circuit-id" value="$asePort.uni_circuit_id" /> + </return> + </block> + + </outcome> + + <outcome value="not-found"> + <return status="failure"> + <parameter name="error-code" value="1010" /> + <parameter name="error-message" value="No ports found that match criteria" /> + </return> + </outcome> + + <outcome value="Other"> + <return status="failure"> + <parameter name="error-code" value="1010" /> + <parameter name="error-message" + value="Error encountered trying to reserve port" /> + </return> + </outcome> + + </reserve> + </outcome> + <outcome value="Gbps"> + <reserve plugin="org.onap.ccsdk.sli.adaptors.sample.SampleResource" + resource="ase-port" + key="resource-emt-clli == $edge-device-clli and speed >= 1000 * $uni-cir-value" + pfx="asePort"> + + + <outcome value="success"> + <block> + <record plugin="org.onap.ccsdk.sli.core.sli.recording.FileRecorder"> + <parameter name="file" value="/tmp/sample_r1.log" /> + <parameter name="field1" value="__TIMESTAMP__"/> + <parameter name="field2" value="RESERVED"/> + <parameter name="field3" value="$asePort.uni_circuit_id"/> + </record> + <return status="success"> + <parameter name="uni-circuit-id" value="$asePort.uni_circuit_id" /> + </return> + </block> + </outcome> + + <outcome value="not-found"> + <return status="failure"> + <parameter name="error-code" value="1010" /> + <parameter name="error-message" value="No ports found that match criteria" /> + </return> + </outcome> + <outcome value=""> + <return status="failure"> + <parameter name="error-code" value="1012" /> + <parameter name="error-message" + value="Error encountered trying to reserve port" /> + </return> + </outcome> + <outcome value="Other"> + <return status="failure"> + <parameter name="error-code" value="1010" /> + <parameter name="error-message" + value="Error encountered trying to reserve port" /> + </return> + </outcome> + </reserve> + </outcome> + </switch> + </method> + + <!-- One step provisioning/activation command. Allocates a local resource, + then configures it on device --> + <method rpc="ase-port-activate-request" mode="sync"> + + <allocate plugin="org.onap.ccsdk.sli.adaptors.sample.SampleResource" + resource="ase-port" key="uni-circuit-id == $uni-circuit-id" pfx="asePort"> + + <outcome value="success"> + <configure adaptor="org.onap.ccsdk.sli.adaptors.emt.EmtAdaptor" + key="$uni-circuit-id" activate="true"> + <parameter name="circuit.id" value="$uni-circuit-id" /> + <parameter name="subscriber.name" value="$subscriber-name" /> + <parameter name="emt.clli" value="$edge-device-clli" /> + <parameter name="port.tagging" value="$port-tagging" /> + <parameter name="port.mediaSpeed" value="$media-speed" /> + <parameter name="location.state" value="$uni-location-state" /> + <parameter name="location.city" value="$uni-location-city" /> + <parameter name="cosCategory" value="$cos-category" /> + <parameter name="gosProfile" value="$gos-profile" /> + <parameter name="lldp" value="$asePort.resource-lldp" /> + <parameter name="mtu" value="$asePort.resource-mtu" /> + <outcome value="success"> + <block> + <record plugin="org.onap.ccsdk.sli.core.sli.recording.FileRecorder"> + <parameter name="file" value="/tmp/sample_r1.log" /> + <parameter name="field1" value="__TIMESTAMP__"/> + <parameter name="field2" value="ACTIVE"/> + <parameter name="field3" value="$uni-circuit-id"/> + </record> + <return status="success"> + <parameter name="edge-device-clli" value="$asePort.resource-emt-clli" /> + </return> + </block> + + </outcome> + <outcome value="already-active"> + <return status="failure"> + <parameter name="error-code" value="1590" /> + <parameter name="error-message" value="Port already active" /> + </return> + </outcome> + <outcome value="Other"> + <return status="failure"> + <parameter name="error-code" value="1542" /> + <parameter name="error-message" value="Activation failure" /> + </return> + </outcome> + </configure> + </outcome> + + <outcome value="not-found"> + + <return status="failure"> + <parameter name="error-code" value="1220" /> + <parameter name="error-message" value="Circuit not found" /> + </return> + + </outcome> + + <outcome value="Other"> + <return status="failure"> + <parameter name="error-code" value="1230" /> + <parameter name="error-message" value="Error occurred trying to find circuit" /> + </return> + </outcome> + </allocate> + </method> + + + + <!-- Change provisioning w/o activation --> + <method rpc="ase-change-port-prov-request" mode="sync"> + <allocate plugin="org.onap.ccsdk.sli.adaptors.sample.SampleResource" + resource="ase-port" key="uni-circuit-id == $uni-circuit-id" pfx="asePort"> + + <outcome value="success"> + <return status="success"> + <parameter name="edge-device-clli" value="$asePort.resource-emt-clli" /> + </return> + </outcome> + + <outcome value="not-found"> + <return status="failure"> + <parameter name="error-code" value="1220" /> + <parameter name="error-message" value="Circuit not found" /> + </return> + </outcome> + + <outcome value="Other"> + <return status="failure"> + <parameter name="error-code" value="1230" /> + <parameter name="error-message" value="Error occurred trying to find circuit" /> + </return> + </outcome> + </allocate> + </method> + + + + + <!-- Release port --> + + <method rpc="ase-release-port-request" mode="sync"> + <exists plugin="org.onap.ccsdk.sli.adaptors.sample.SampleResource" + resource="ase-evc" key="uni-circuit-id == $uni-circuit-id"> + + <outcome value="true"> + <return status="failure"> + <parameter name="error-code" value="1130" /> + <parameter name="error-message" + value="Cannot release port - used in existing EVC" /> + </return> + </outcome> + <outcome value="false"> + <release plugin="org.onap.ccsdk.sli.adaptors.sample.SampleResource" + resource="ase-port" key="uni-circuit-id == $uni-circuit-id"> + <outcome value="success"> + <block> + <record plugin="org.onap.ccsdk.sli.core.sli.recording.FileRecorder"> + <parameter name="file" value="/tmp/sample_r1.log" /> + <parameter name="field1" value="__TIMESTAMP__"/> + <parameter name="field2" value="RELEASED"/> + <parameter name="field3" value="$uni-circuit-id"/> + </record> + <return status="success"/> + </block> + </outcome> + + <outcome value="not-found"> + <return status="failure"> + <parameter name="error-code" value="1110" /> + <parameter name="error-message" value="No port found for this uni-circuit-id" /> + </return> + </outcome> + + <outcome value="Other"> + <return status="failure"> + <parameter name="error-code" value="1130" /> + <parameter name="error-message" + value="Error encountered trying to release port" /> + </return> + </outcome> + </release> + </outcome> + </exists> + </method> + +</service-logic> + diff --git a/sli/common/src/test/resources/JsonObject.json b/sli/common/src/test/resources/JsonObject.json new file mode 100644 index 000000000..0578368f8 --- /dev/null +++ b/sli/common/src/test/resources/JsonObject.json @@ -0,0 +1,5 @@ +{
+ "aaa": "123",
+ "bbb": "xyz",
+ "c.d": "abc"
+}
\ No newline at end of file diff --git a/sli/common/src/test/resources/ObjectMenu.json b/sli/common/src/test/resources/ObjectMenu.json new file mode 100644 index 000000000..56f842d48 --- /dev/null +++ b/sli/common/src/test/resources/ObjectMenu.json @@ -0,0 +1,43 @@ +{
+ "menu": [{
+ "id": "1",
+ "type": "pizza",
+ "name": "plain",
+ "calories": 1000,
+ "vegetarian": true
+ }, {
+ "id": "2",
+ "type": "pizza",
+ "name": "Tuesday Special",
+ "calories": 2000,
+ "vegetarian": false,
+ "topping":
+ [{
+ "id": "1",
+ "name": "onion"
+ }, {
+ "id": "2",
+ "name": "pepperoni"
+ }
+ ]
+ }, {
+ "id": "3",
+ "type": "pizza",
+ "name": "House Special",
+ "calories": 1500,
+ "vegetarian": true,
+ "topping":
+ [{
+ "id": "3",
+ "name": "basil"
+ }, {
+ "id": "4",
+ "name": "fresh mozzarella"
+ }, {
+ "id": "5",
+ "name": "tomato"
+ }
+ ]
+ }
+ ]
+}
diff --git a/sli/common/src/test/resources/QuotedValues.json b/sli/common/src/test/resources/QuotedValues.json new file mode 100644 index 000000000..8bf91c66b --- /dev/null +++ b/sli/common/src/test/resources/QuotedValues.json @@ -0,0 +1,43 @@ +{
+ "menu": [{
+ "id": "1",
+ "type": "pizza",
+ "name": "plain",
+ "calories": "1000",
+ "vegetarian": true
+ }, {
+ "id": "2",
+ "type": "pizza",
+ "name": "Tuesday Special",
+ "calories": "2000",
+ "vegetarian": false,
+ "topping":
+ [{
+ "id": "1",
+ "name": "onion"
+ }, {
+ "id": "2",
+ "name": "pepperoni"
+ }
+ ]
+ }, {
+ "id": "3",
+ "type": "pizza",
+ "name": "House Special",
+ "calories": "1500",
+ "vegetarian": true,
+ "topping":
+ [{
+ "id": "3",
+ "name": "basil"
+ }, {
+ "id": "4",
+ "name": "fresh mozzarella"
+ }, {
+ "id": "5",
+ "name": "tomato"
+ }
+ ]
+ }
+ ]
+}
diff --git a/sli/common/src/test/resources/ReleasePortSvcLogic_v101.xml b/sli/common/src/test/resources/ReleasePortSvcLogic_v101.xml new file mode 100644 index 000000000..cee027f75 --- /dev/null +++ b/sli/common/src/test/resources/ReleasePortSvcLogic_v101.xml @@ -0,0 +1,89 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START======================================================= + ONAP : CCSDK + ================================================================================ + 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========================================================= + --> + + +<service-logic xmlns="http://www.onap.org/sdnc/svclogic" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.onap.org/sdnc/svclogic ./svclogic.xsd" + module="ase" version="1.0.1"> + + <!-- Updated release port logic : deactivate the released port on the EMT --> + <method rpc="ase-release-port-request" mode="sync"> + <exists plugin="org.onap.ccsdk.sli.adaptors.sample.SampleResource" + resource="ase-evc" key="uni-circuit-id == $uni-circuit-id"> + + <outcome value="true"> + <return status="failure"> + <parameter name="error-code" value="1130" /> + <parameter name="error-message" + value="Cannot release port - used in existing EVC" /> + </return> + </outcome> + <outcome value="false"> + <release plugin="org.onap.ccsdk.sli.adaptors.sample.SampleResource" + resource="ase-port" key="uni-circuit-id == $uni-circuit-id"> + <outcome value="success"> + <configure adaptor="org.onap.ccsdk.sli.adaptors.emt.EmtAdaptor" + key="$uni-circuit-id" activate="false"> + + <outcome value="success"> + <block> + <record plugin="org.onap.ccsdk.sli.core.sli.recording.FileRecorder"> + <parameter name="file" value="/tmp/sample_r1.log" /> + <parameter name="field1" value="__TIMESTAMP__" /> + <parameter name="field2" value="RELEASED" /> + <parameter name="field3" value="$uni-circuit-id" /> + </record> + <return status="success"> + <parameter name="uni-circuit-id" value="$asePort.uni_circuit_id" /> + </return> + </block> + </outcome> + <outcome value="Other"> + <return status="failure"> + <parameter name="error-code" value="1130" /> + <parameter name="error-message" + value="Error encountered trying to de-activate port" /> + </return> + </outcome> + </configure> + </outcome> + + <outcome value="not-found"> + <return status="failure"> + <parameter name="error-code" value="1110" /> + <parameter name="error-message" value="No port found for this uni-circuit-id" /> + </return> + </outcome> + + <outcome value="Other"> + <return status="failure"> + <parameter name="error-code" value="1130" /> + <parameter name="error-message" + value="Error encountered trying to release port" /> + </return> + </outcome> + </release> + </outcome> + </exists> + </method> + +</service-logic> + diff --git a/sli/common/src/test/resources/Widget.json b/sli/common/src/test/resources/Widget.json new file mode 100644 index 000000000..6b90907ce --- /dev/null +++ b/sli/common/src/test/resources/Widget.json @@ -0,0 +1,27 @@ +{
+ "widget": {
+ "debug": false,
+ "window": {
+ "title": "ONAP Widget",
+ "name": "main_window",
+ "width": 200,
+ "height": 300
+ },
+ "image": {
+ "src": "images/moon.png",
+ "name": "moon",
+ "hOffset": 150,
+ "vOffset": 150,
+ "alignment": "center"
+ },
+ "text": {
+ "data": "Click Me",
+ "size": 21,
+ "style": "bold",
+ "name": "text1",
+ "hOffset": 350,
+ "vOffset": null,
+ "alignment": "center"
+ }
+ }
+}
\ No newline at end of file diff --git a/sli/common/src/test/resources/bad_neutron_logic_v11.xml b/sli/common/src/test/resources/bad_neutron_logic_v11.xml new file mode 100644 index 000000000..e6ec8614b --- /dev/null +++ b/sli/common/src/test/resources/bad_neutron_logic_v11.xml @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START======================================================= + ONAP : CCSDK + ================================================================================ + 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========================================================= + --> + + +<service-logic xmlns="http://www.onap.org/sdnc/svclogic" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.onap.org/sdnc/svclogic ./svclogic.xsd" + module="neutron" version="1.0.0"> + + <method rpc="canCreateNetwork" mode="sync"> + <switch test="true"> + <return status="success"> + <parameter name="error-code" value="200" /> + </return> + </switch> + </method> + + <method rpc="networkCreated" mode="sync"> + <switch test="`(length($network.segment[0].provider-physical-network) >= 5) and (substr($network.segment[0].provider-physical-network,0,5) == 'dvspg')`"> + <outcome value="true"> + <block> + <set> + <parameter name="vlanlist" value="`$network.segment[0].provider-segmentation-id`"/> + </set> + <for index="i" start="1" end="`$network.num-segments`"> + <set> + <parameter name="vlanlist" value="`$vlanlist+','+$network.segment[$i].provider-segmentation-id`"/> + </set> + </for> + + <switch test="true"> + <return status="success"/> + </switch> + </block> + </outcome> + <outcome value="Other"> + <return status="success"> + <parameter name="error-code" value="200"/> + </return> + </outcome> + </switch> + </method> + +</service-logic> diff --git a/sli/common/src/test/resources/dblib.properties b/sli/common/src/test/resources/dblib.properties new file mode 100755 index 000000000..f08dce7a0 --- /dev/null +++ b/sli/common/src/test/resources/dblib.properties @@ -0,0 +1,14 @@ +org.onap.ccsdk.sli.dbtype=jdbc +org.onap.ccsdk.sli.jdbc.hosts=sdnctldb01,sdnctldb02 +org.onap.ccsdk.sli.jdbc.url=jdbc:derby:memory:test;create=true +org.onap.ccsdk.sli.jdbc.driver=org.apache.derby.jdbc.EmbeddedDriver +org.onap.ccsdk.sli.jdbc.database=test +org.onap.ccsdk.sli.jdbc.user=test +org.onap.ccsdk.sli.jdbc.password=test +org.onap.ccsdk.sli.jdbc.connection.name=sdnctldb01 + +org.onap.ccsdk.sli.jdbc.connection.timeout=50 +org.onap.ccsdk.sli.jdbc.request.timeout=100 +org.onap.ccsdk.sli.jdbc.limit.init=10 +org.onap.ccsdk.sli.jdbc.limit.min=10 +org.onap.ccsdk.sli.jdbc.limit.max=20 diff --git a/sli/common/src/test/resources/expression.tests b/sli/common/src/test/resources/expression.tests new file mode 100755 index 000000000..c352e9b08 --- /dev/null +++ b/sli/common/src/test/resources/expression.tests @@ -0,0 +1,19 @@ +$uni-circuit-id +$asePort +length($uni-circuit-id) > 0 +$asePort.uni-circuit-id +$uni-cir-units * 1000 * 100 / 100 +$uni-cir-units / 1000 +$uni-cir-units - 100 +$uni-cir-units + 100 +(value * 3 - $arg1 > 0) and (length($uni-circuit-id) == 0) +'pg-'+$network.name +$network.segment[0].provider-physical-network +length($network_segment[0].provider-physical-network) >= 5 +substr($network_segment[0].provider-physical-network,0,5) == 'dvspg' +length($network_segment[0].provider-physical-network) >= 5 and substr($network_segment[0].provider-physical-network,0,5) == 'dvspg' +(length($network_segment[0].provider-physical-network) >= 5) and (substr($network_segment[0].provider-physical-network,0,5) == 'dvspg') +4-2-2 +1+1 +1 +1+2*3-4 diff --git a/sli/common/src/test/resources/graphs/sliapi/graph.versions b/sli/common/src/test/resources/graphs/sliapi/graph.versions new file mode 100644 index 000000000..d72920a43 --- /dev/null +++ b/sli/common/src/test/resources/graphs/sliapi/graph.versions @@ -0,0 +1 @@ +sli healthcheck 1.0.0 sync diff --git a/sli/common/src/test/resources/graphs/sliapi/sli_healthcheck.xml b/sli/common/src/test/resources/graphs/sliapi/sli_healthcheck.xml new file mode 100644 index 000000000..d512f546f --- /dev/null +++ b/sli/common/src/test/resources/graphs/sliapi/sli_healthcheck.xml @@ -0,0 +1,27 @@ +<!-- + ============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========================================================= + --> + +<service-logic xmlns="http://www.onap.org/sdnc/svclogic" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.onap.org/sdnc/svclogic ./svclogic.xsd" module='sli' version='1.0.0'><method rpc='healthcheck' mode='sync'> +<set> +<parameter name='error-code' value='200' /> +<parameter name='error-message' value='SDN-C is healthy'/> +<parameter name='ack-final' value='Y'/> +</set></method></service-logic> diff --git a/sli/common/src/test/resources/l3sdn_logic_v10.xml b/sli/common/src/test/resources/l3sdn_logic_v10.xml new file mode 100644 index 000000000..58a420f9e --- /dev/null +++ b/sli/common/src/test/resources/l3sdn_logic_v10.xml @@ -0,0 +1,208 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- ============LICENSE_START======================================================= + ONAP : CCSDK ================================================================================ + 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========================================================= --> + + +<service-logic xmlns="http://www.onap.org/sdnc/svclogic" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.onap.org/sdnc/svclogic ./svclogic.xsd" + module="neutron" version="1.0.0"> + + <method rpc="canCreateNetwork" mode="sync"> + <return status="success"> + <parameter name="error-code" value="200" /> + </return> + </method> + + <method rpc="switchTester" mode="sync"> + + <switch test="`$test-value`"> + <outcome value=""> + <return status="success"> + <parameter name="visited-outcome" value="empty string" /> + </return> + </outcome> + <outcome value="Other"> + <return status="success"> + <parameter name="visited-outcome" value="Other" /> + </return> + </outcome> + </switch> + + + </method> + + <method rpc="forRecordTester" mode="sync"> + <for index="i" start="0" end="1"> + <record plugin="org.onap.ccsdk.sli.core.sli.provider.DummyRecorder"> + <parameter name="level" value="INFO"/> + <parameter name="field1" value="`forRecordTester message $i`"/> + </record> + </for> + </method> + + <method rpc="whileNodeTester" mode="sync"> + <while test="`$test-value`"> + <break/> + </while> + + </method> + + <method rpc="resourceTester" mode="sync"> + <block> + <set> + <parameter name='resource-plugin' + value='org.onap.ccsdk.sli.core.sli.provider.DummyResource' /> + </set> + + <save plugin="`$resource-plugin`" resource="sample" key="sample-key == 'resourceTester.status'"> + <parameter name="sample-key" value="resourceTester.status"/> + <parameter name="sample-value" value="FAILED"/> + </save> + + <update plugin="`$resource-plugin`" resource="sample" key="sample-key == 'resourceTester.status'"> + <parameter name="sample-key" value="resourceTester.status"/> + <parameter name="sample-value" value="PASSED"/> + </update> + + <get-resource plugin="`$resource-plugin`" resource="sample" key="sample-key == 'resourceTester.status'" pfx="sample"/> + + <exists plugin="`$resource-plugin`" resource="sample" key="sample-key == 'resourceTester.status'"/> + + <is-available plugin="`$resource-plugin`" resource="sample" key="sample-key == 'resourceTester.status'"/> + + <reserve plugin="`$resource-plugin`" resource="sample" key="sample-key == 'resourceTester.status'"/> + + <release plugin="`$resource-plugin`" resource="sample" key="sample-key == 'resourceTester.status'"/> + + + <reserve plugin="`$resource-plugin`" resource="sample" key="sample-key == 'resourceTester.status'"/> + + <notify plugin="`$resource-plugin`" resource="sample" action="RESERVE"/> + + <delete plugin="`$resource-plugin`" resource="sample" key="sample-key == 'resourceTester.status'"/> + + + + </block> + </method> + + <method rpc="configureTester" mode="sync"> + <block> + <set> + <parameter name='configure-plugin' + value='org.onap.ccsdk.sli.core.sli.provider.DummyAdaptor' /> + </set> + <configure adaptor="`$configure-plugin`" key="dummy" activate="true"> + <parameter name="field1" value="1"/> + </configure> + <configure adaptor="`$configure-plugin`" key="SUCCESS" activate="true"> + <parameter name="field1" value="1"/> + </configure> + <configure adaptor="`$configure-plugin`" key="ALREADY_ACTIVE" activate="true"> + <parameter name="field1" value="1"/> + </configure> + <configure adaptor="`$configure-plugin`" key="NOT_FOUND" activate="true"> + <parameter name="field1" value="1"/> + </configure> + <configure adaptor="`$configure-plugin`" key="NOT_READY" activate="true"> + <parameter name="field1" value="1"/> + </configure> + <configure adaptor="`$configure-plugin`" key="FAILURE" activate="true"> + <parameter name="field1" value="1"/> + </configure> + <configure adaptor="`$configure-plugin`" key="dummy" activate="false"> + <parameter name="field1" value="1"/> + </configure> + <configure adaptor="`$configure-plugin`" key="SUCCESS" activate="false"> + <parameter name="field1" value="1"/> + </configure> + <configure adaptor="`$configure-plugin`" key="ALREADY_ACTIVE" activate="false"> + <parameter name="field1" value="1"/> + </configure> + <configure adaptor="`$configure-plugin`" key="NOT_FOUND" activate="false"> + <parameter name="field1" value="1"/> + </configure> + <configure adaptor="`$configure-plugin`" key="NOT_READY" activate="false"> + <parameter name="field1" value="1"/> + </configure> + <configure adaptor="`$configure-plugin`" key="FAILURE" activate="false"> + <parameter name="field1" value="1"/> + </configure> + + </block> + </method> + + + <method rpc="javaPluginTester" mode="sync"> + <block> + <set> + <parameter name='java-plugin' + value='org.onap.ccsdk.sli.core.sli.provider.VoidDummyPlugin' /> + </set> + <execute plugin="`$java-plugin`" method="dummy"/> + </block> + </method> + + <method rpc="allNodesTester" mode="sync"> + <block> + <set> + <parameter name='resource-plugin' + value='org.onap.ccsdk.sli.core.sli.provider.DummyResource' /> + <parameter name='configure-plugin' + value='org.onap.ccsdk.sli.core.sli.provider.DummyAdaptor' /> + <parameter name='java-plugin' + value='org.onap.ccsdk.sli.core.sli.provider.VoidDummyPlugin' /> + + </set> + + <call rpc="switchTester" mode="sync" /> + + <call rpc="forRecordTester" mode="sync"/> + + <call rpc="resourceTester" mode="sync"/> + + <call rpc="configureTester" mode="sync"/> + + <call rpc="javaPluginTester" mode="sync"/> + + <call rpc="whileNodeTester" mode="sync"/> + + </block> + </method> + + <method rpc="networkCreated" mode="sync"> + <switch + test="length($network.segment[0].provider-physical-network) >= 5 and substr($network.segment[0].provider-physical-network,0,5) == 'dvspg'"> + <outcome value="true"> + <block> + <set> + <parameter name="$vlanlist" + value="$network.segment[0].provider-segmentation-id" /> + </set> + <for index="i" start="1" end="$network.num-segments"> + <set> + <parameter name="$vlanlist" + value="eval($vlanlist+','+$network.segment[i].provider-segmentation-id)" /> + </set> + </for> + + </block> + </outcome> + <outcome value="Other"> + <return status="success"> + <parameter name="error-code" value="200" /> + </return> + </outcome> + </switch> + </method> + +</service-logic> diff --git a/sli/common/src/test/resources/log4j2.properties b/sli/common/src/test/resources/log4j2.properties new file mode 100644 index 000000000..3a5d8ef76 --- /dev/null +++ b/sli/common/src/test/resources/log4j2.properties @@ -0,0 +1,39 @@ +### +# ============LICENSE_START======================================================= +# ONAP : CCSDK +# ================================================================================ +# Copyright (C) 2020 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========================================================= +### + +status = error +name = PropertiesConfig + +filters = threshold + +filter.threshold.type = ThresholdFilter +filter.threshold.level = debug + +appenders = console + +appender.console.type = Console +appender.console.name = STDOUT +appender.console.layout.type = PatternLayout +appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n + +rootLogger.level = debug +rootLogger.appenderRefs = stdout +rootLogger.appenderRef.stdout.ref = STDOUT diff --git a/sli/common/src/test/resources/mergetest.xml b/sli/common/src/test/resources/mergetest.xml new file mode 100644 index 000000000..95c26da27 --- /dev/null +++ b/sli/common/src/test/resources/mergetest.xml @@ -0,0 +1,54 @@ +<!-- + ============LICENSE_START======================================================= + ONAP : CCSDK + ================================================================================ + 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========================================================= + --> + +<multicast-parameters xmlns="org.onap.sdnc:test"> + <vpn-v4-multicast-enabled>Y</vpn-v4-multicast-enabled> + <v4-multicast> + <v4-pim-ssm-default-range>Y</v4-pim-ssm-default-range> + <v4-data-mdt>11.11.11.11</v4-data-mdt> + <v4-data-mdt-wildcard-mask>2.2.2.2</v4-data-mdt-wildcard-mask> + <max-routes-limit>100</max-routes-limit> + <v4-default-mdt>1.1.1.1</v4-default-mdt> + <v4-pim-sm-static-override>N</v4-pim-sm-static-override> + <v4-pim-ssm-groups> + <v4-pim-ssm-group-address>4.4.4.4</v4-pim-ssm-group-address> + </v4-pim-ssm-groups> + <v4-pim-ssm-groups> + <v4-pim-ssm-group-address>3.3.3.3</v4-pim-ssm-group-address> + </v4-pim-ssm-groups> + <v4-static-rp-triplet> + <rp-address>8.8.8.8</rp-address> + <c-groups> + <c-group-address-prefix>10.10.10.10</c-group-address-prefix> + </c-groups> + <c-groups> + <c-group-address-prefix>9.9.9.9</c-group-address-prefix> + </c-groups> + </v4-static-rp-triplet> + <v4-static-rp-triplet> + <rp-address>7.7.7.7</rp-address> + <c-groups> + <c-group-address-prefix>6.6.6.6</c-group-address-prefix> + </c-groups> + <c-groups> + <c-group-address-prefix>5.5.5.5</c-group-address-prefix> + </c-groups> + </v4-static-rp-triplet> + </v4-multicast> +</multicast-parameters> diff --git a/sli/common/src/test/resources/neutron_logic_v10.xml b/sli/common/src/test/resources/neutron_logic_v10.xml new file mode 100644 index 000000000..74088036b --- /dev/null +++ b/sli/common/src/test/resources/neutron_logic_v10.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START======================================================= + ONAP : CCSDK + ================================================================================ + 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========================================================= + --> + + +<service-logic xmlns="http://www.onap.org/sdnc/svclogic" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.onap.org/sdnc/svclogic ./svclogic.xsd" + module="neutron" version="1.0.0"> + + <method rpc="canCreateNetwork" mode="sync"> + <return status="success"> + <parameter name="error-code" value="200" /> + </return> + </method> + + <method rpc="networkCreated" mode="sync"> + <switch test="`(length($network.segment[0].provider-physical-network) >= 5) and (substr($network.segment[0].provider-physical-network,0,5) == 'dvspg')`"> + <outcome value="true"> + <block> + <set> + <parameter name="vlanlist" value="`$network.segment[0].provider-segmentation-id`"/> + </set> + <for index="i" start="1" end="`$network.num-segments`"> + <set> + <parameter name="vlanlist" value="`$vlanlist+','+$network.segment[$i].provider-segmentation-id`"/> + </set> + </for> + + </block> + </outcome> + <outcome value="Other"> + <return status="success"> + <parameter name="error-code" value="200"/> + </return> + </outcome> + </switch> + </method> + +</service-logic> diff --git a/sli/common/src/test/resources/nonsense.xml b/sli/common/src/test/resources/nonsense.xml new file mode 100644 index 000000000..c30c6bfc6 --- /dev/null +++ b/sli/common/src/test/resources/nonsense.xml @@ -0,0 +1,24 @@ +<!-- + ============LICENSE_START======================================================= + ONAP : CCSDK + ================================================================================ + 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========================================================= + --> + +<non> +<sense>Hello world</sense> +</non> diff --git a/sli/common/src/test/resources/parser-bad.tests b/sli/common/src/test/resources/parser-bad.tests new file mode 100755 index 000000000..82913afc2 --- /dev/null +++ b/sli/common/src/test/resources/parser-bad.tests @@ -0,0 +1,3 @@ +bad_neutron_logic_v11.xml +EvcActivateSvcLogic_v100.xml +nonsense.xml
\ No newline at end of file diff --git a/sli/common/src/test/resources/parser-good.tests b/sli/common/src/test/resources/parser-good.tests new file mode 100755 index 000000000..4147fdb62 --- /dev/null +++ b/sli/common/src/test/resources/parser-good.tests @@ -0,0 +1,3 @@ +ReleasePortSvcLogic_v101.xml +neutron_logic_v10.xml +l3sdn_logic_v10.xml diff --git a/sli/common/src/test/resources/simplelogger.properties b/sli/common/src/test/resources/simplelogger.properties new file mode 100644 index 000000000..73e4d3a99 --- /dev/null +++ b/sli/common/src/test/resources/simplelogger.properties @@ -0,0 +1,24 @@ +### +# ============LICENSE_START======================================================= +# ONAP : CCSDK +# ================================================================================ +# 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========================================================= +### + +org.slf4j.simpleLogger.defaultLogLevel=info +org.slf4j.simplelogger.log.org.onap.ccsdk.sli.core.sli.SvcLogicContext=debug +org.slf4j.simplelogger.log.SvcLogicContext=debug diff --git a/sli/common/src/test/resources/svclogic.properties b/sli/common/src/test/resources/svclogic.properties new file mode 100644 index 000000000..426960f76 --- /dev/null +++ b/sli/common/src/test/resources/svclogic.properties @@ -0,0 +1,27 @@ +### +# ============LICENSE_START======================================================= +# ONAP : CCSDK +# ================================================================================ +# 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========================================================= +### + +org.onap.ccsdk.sli.dbtype = jdbc +org.onap.ccsdk.sli.jdbc.url=jdbc:derby:memory:sdnctl;create=true +org.onap.ccsdk.sli.jdbc.driver=org.apache.derby.jdbc.EmbeddedDriver +org.onap.ccsdk.sli.jdbc.database = sdnctl +org.onap.ccsdk.sli.jdbc.user = test +org.onap.ccsdk.sli.jdbc.password = test diff --git a/sli/common/src/test/resources/svclogic.sh b/sli/common/src/test/resources/svclogic.sh new file mode 100644 index 000000000..67977c3d9 --- /dev/null +++ b/sli/common/src/test/resources/svclogic.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +### +# ============LICENSE_START======================================================= +# ONAP : CCSDK +# ================================================================================ +# 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========================================================= +### + +MYSQL_JDBC_DRIVER=${MYSQL_JDBC_DRIVER:-/home/ubuntu/mysql-connector-java-5.1.38.1.jar} +SLI_COMMON_TARGETDIR=${SLI_COMMON_TARGETDIR:-/home/ubuntu/opendaylight/plugins} +#SLI_COMMON_TARGETDIR=${SLI_COMMON_TARGETDIR:-/home/ubuntu/git/sdnctl/sli/common/target} +SLI_VERSION=${SLI_VERSION:-1.1.0-SNAPSHOT} +SLI_COMMON_JAR=${SLI_COMMON_JAR:=${SLI_COMMON_TARGETDIR}/sli-common-${SLI_VERSION}.jar} + +echo SLI_COMMON_JAR is $SLI_COMMON_JAR + +java -cp ${CLASSPATH}:${MYSQL_JDBC_DRIVER}:${SLI_COMMON_JAR} org.onap.ccsdk.sli.core.sli.SvcLogicParser $* |