From a0ab49e6c1ea41af18656d6e9efb3377051f2528 Mon Sep 17 00:00:00 2001 From: "Timoney, Dan (dt5972)" Date: Sat, 24 Mar 2018 19:11:10 -0400 Subject: Add unit tests for sli Added unit tests for ccsdk/sli/core/sli Change-Id: I0d2408c43b9e56a78f3e01e87985aedb6cad5953 Issue-ID: CCSDK-213 Signed-off-by: Timoney, Dan (dt5972) --- .gitignore | 2 + .../ccsdk/sli/core/dblib/CachedDataSource.java | 7 +- filters/provider/pom.xml | 8 + .../filters/RequestResponseDbLoggingFilter.java | 5 +- .../onap/ccsdk/sli/core/filters/TestLogFilter.java | 71 +++++++ .../filters/TestRequestResponseLoggingFilter.java | 129 +++++++++++++ sli/common/pom.xml | 12 +- .../org/onap/ccsdk/sli/core/sli/MessageWriter.java | 6 +- .../ccsdk/sli/core/sli/SvcLogicDblibStore.java | 13 ++ .../onap/ccsdk/sli/core/sli/SvcLogicJdbcStore.java | 1 - .../onap/ccsdk/sli/core/sli/SvcLogicParser.java | 6 +- .../ccsdk/sli/core/sli/ITCaseSvcLogicParser.java | 139 ++++++++++++-- .../ccsdk/sli/core/sli/PrintYangToPropTest.java | 22 +++ .../onap/ccsdk/sli/core/sli/TestMetricLogger.java | 135 +++++++++++++ .../ccsdk/sli/core/sli/TestSvcLogicLoader.java | 38 ++++ sli/common/src/test/resources/dblib.properties | 14 ++ .../test/resources/graphs/sliapi/graph.versions | 1 + .../resources/graphs/sliapi/sli_healthcheck.xml | 27 +++ sli/common/src/test/resources/l3sdn_logic_v10.xml | 208 +++++++++++++++++++++ sli/common/src/test/resources/parser-good.tests | 1 + sli/common/src/test/resources/svclogic.properties | 7 +- sli/common/src/test/resources/svclogic.xsd | 11 ++ sli/provider/pom.xml | 96 +++++----- .../src/main/resources/svclogic.properties | 25 --- .../sli/provider/ITCaseSvcLogicGraphExecutor.java | 29 +-- sli/provider/src/test/resources/executor.tests | 4 +- .../src/test/resources/l3sdn_logic_v10.xml | 23 +++ .../src/test/resources/svclogic.properties | 4 +- sliapi/provider/pom.xml | 143 ++++++++------ .../onap/ccsdk/sli/core/sliapi/sliapiProvider.java | 23 ++- .../ccsdk/sli/core/sliapi/TestSliapiProvider.java | 171 +++++++++++++++++ .../src/test/resources/sli_healthcheck.xml | 27 +++ .../src/test/resources/svclogic.properties | 27 +++ 33 files changed, 1241 insertions(+), 194 deletions(-) create mode 100644 filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestLogFilter.java create mode 100644 filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestRequestResponseLoggingFilter.java create mode 100644 sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java create mode 100644 sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestSvcLogicLoader.java create mode 100755 sli/common/src/test/resources/dblib.properties create mode 100644 sli/common/src/test/resources/graphs/sliapi/graph.versions create mode 100644 sli/common/src/test/resources/graphs/sliapi/sli_healthcheck.xml create mode 100644 sli/common/src/test/resources/l3sdn_logic_v10.xml delete mode 100644 sli/provider/src/main/resources/svclogic.properties create mode 100644 sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java create mode 100644 sliapi/provider/src/test/resources/sli_healthcheck.xml create mode 100644 sliapi/provider/src/test/resources/svclogic.properties diff --git a/.gitignore b/.gitignore index a36bed32..a5a0d80e 100755 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,5 @@ sdnc-core_bdio.jsonld blackDuckHubProjectName.txt blackDuckHubProjectVersionName.txt +# Derby log +derby.log diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java index 02cce3cf..97380f58 100755 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java @@ -342,11 +342,16 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito } protected boolean testConnection(boolean errorLevel) { + + String testQuery = "SELECT @@global.read_only, @@global.hostname"; + if (isDerby) { + testQuery = "SELECT 'false', 'localhost' FROM SYSIBM.SYSDUMMY1"; + } ResultSet rs = null; try (Connection conn = this.getConnection(); Statement stmt = conn.createStatement()) { Boolean readOnly; String hostname; - rs = stmt.executeQuery("SELECT @@global.read_only, @@global.hostname"); // ("SELECT 1 FROM DUAL"); //"select + rs = stmt.executeQuery(testQuery); // ("SELECT 1 FROM DUAL"); //"select // BANNER from SYS.V_$VERSION" while (rs.next()) { readOnly = rs.getBoolean(1); diff --git a/filters/provider/pom.xml b/filters/provider/pom.xml index 4fdd8328..a60c0be0 100755 --- a/filters/provider/pom.xml +++ b/filters/provider/pom.xml @@ -19,6 +19,8 @@ UTF-8 + + **/RequestResponseDbLoggingFilter.java @@ -28,6 +30,12 @@ ${junit.version} test + + + org.mockito + mockito-core + test + javax.servlet javax.servlet-api diff --git a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/RequestResponseDbLoggingFilter.java b/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/RequestResponseDbLoggingFilter.java index 8b67276b..35913656 100644 --- a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/RequestResponseDbLoggingFilter.java +++ b/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/RequestResponseDbLoggingFilter.java @@ -8,9 +8,9 @@ * 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. @@ -47,6 +47,7 @@ import org.onap.ccsdk.sli.core.sli.MessageWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated public class RequestResponseDbLoggingFilter implements Filter { private static Logger log = LoggerFactory.getLogger(RequestResponseDbLoggingFilter.class); diff --git a/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestLogFilter.java b/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestLogFilter.java new file mode 100644 index 00000000..a900b246 --- /dev/null +++ b/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestLogFilter.java @@ -0,0 +1,71 @@ +/** + * + */ +package org.onap.ccsdk.sli.core.filters; + +import static org.junit.Assert.*; +import org.apache.commons.codec.binary.Base64; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; +import java.io.IOException; +import java.util.UUID; +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @author dt5972 + * + */ +public class TestLogFilter { + + LogFilter logFilter; + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + logFilter = new LogFilter(); + logFilter.init(null); + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + logFilter.destroy(); + } + + /** + * Test method for {@link org.onap.ccsdk.sli.core.filters.LogFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)}. + * @throws ServletException + * @throws IOException + */ + @Test + public void testDoFilter() throws IOException, ServletException { + + // Test failed request with minimal headers + HttpServletRequest servletReq = mock(HttpServletRequest.class); + when(servletReq.getRequestURL()).thenReturn(new StringBuffer("SLI-API:healthcheck")); + when(servletReq.getPathInfo()).thenReturn("/hello:world"); + HttpServletResponse servletResp = mock(HttpServletResponse.class); + when(servletResp.getStatus()).thenReturn(400); + FilterChain filterChain = mock(FilterChain.class); + logFilter.doFilter(servletReq, servletResp, filterChain); + + // Test successful request with valid header + when(servletReq.getHeader(LogFilter.REQUEST_ID)).thenReturn(UUID.randomUUID().toString()); + when(servletReq.getHeader("Authorization")).thenReturn("Basic "+Base64.encodeBase64String("username:password".getBytes())); + when(servletResp.getStatus()).thenReturn(200); + logFilter.doFilter(servletReq, servletResp, filterChain); + + + } + +} diff --git a/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestRequestResponseLoggingFilter.java b/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestRequestResponseLoggingFilter.java new file mode 100644 index 00000000..9f36fe11 --- /dev/null +++ b/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestRequestResponseLoggingFilter.java @@ -0,0 +1,129 @@ +/** + * + */ +package org.onap.ccsdk.sli.core.filters; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.StringBufferInputStream; +import java.io.StringReader; +import java.util.LinkedList; +import java.util.UUID; +import java.util.Vector; +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.commons.codec.binary.Base64; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * @author dt5972 + * + */ +public class TestRequestResponseLoggingFilter { + + RequestResponseLoggingFilter filter; + + private class DummyServletInputStream extends ServletInputStream { + + InputStream stream; + + public DummyServletInputStream(InputStream stream) { + this.stream = stream; + } + + + @Override + public void close() throws IOException { + super.close(); + stream.close(); + } + + + @Override + public int read() throws IOException { + return stream.read(); + } + + + + } + + private class DummyServletOutputStream extends ServletOutputStream { + + OutputStream ostr; + + public DummyServletOutputStream(OutputStream ostr) { + this.ostr = ostr; + } + + @Override + public void write(int b) throws IOException { + ostr.write(b); + } + + } + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + filter = new RequestResponseLoggingFilter(); + filter.init(null); + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception {} + + /** + * Test method for {@link org.onap.ccsdk.sli.core.filters.RequestResponseLoggingFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)}. + * @throws IOException + * @throws ServletException + */ + @Test + public void testDoFilter() throws IOException, ServletException { + + HttpServletRequest request = mock(HttpServletRequest.class); + String msgBody = "hello world"; + InputStream reqInputStream = new ByteArrayInputStream(msgBody.getBytes()); + when(request.getInputStream()).thenReturn(new DummyServletInputStream(reqInputStream)); + when(request.getMethod()).thenReturn("POST"); + when(request.getRequestURL()).thenReturn(new StringBuffer("/HELLO:world")); + when(request.getPathInfo()).thenReturn("/hello:world"); + Vector headerList = new Vector<>(); + headerList.add(LogFilter.REQUEST_ID); + headerList.add("Authorization"); + when(request.getHeaderNames()).thenReturn(headerList.elements()); + + when(request.getHeader(LogFilter.REQUEST_ID)).thenReturn(UUID.randomUUID().toString()); + when(request.getHeader("Authorization")).thenReturn("Basic "+Base64.encodeBase64String("username:password".getBytes())); + + HttpServletResponse response = mock(HttpServletResponse.class); + OutputStream outStr = new ByteArrayOutputStream(); + when(response.getOutputStream()).thenReturn(new DummyServletOutputStream(outStr)); + + FilterChain filterChain = mock(FilterChain.class); + + filter.doFilter(request, response, filterChain); + + + + } + +} diff --git a/sli/common/pom.xml b/sli/common/pom.xml index 1d35dfb1..c22c1ae6 100755 --- a/sli/common/pom.xml +++ b/sli/common/pom.xml @@ -18,6 +18,12 @@ ccsdk-sli-core :: sli :: ${project.artifactId} The SLI Common package includes common classes used by the various SLI subcomponents, as well as classes used by clients to interface with the service logic interpreter + + + **/MessageWriter.java + + + @@ -31,9 +37,9 @@ - ch.vorburger.mariaDB4j - mariaDB4j - 2.2.3 + org.apache.derby + derby + 10.11.1.1 test diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MessageWriter.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MessageWriter.java index c75873eb..0e39896e 100644 --- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MessageWriter.java +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MessageWriter.java @@ -8,9 +8,9 @@ * 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. @@ -38,7 +38,7 @@ import org.osgi.framework.ServiceReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - +@Deprecated public class MessageWriter { private static final Logger LOG = LoggerFactory.getLogger(MessageWriter.class); diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java index ee3bcca5..864652b4 100644 --- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java @@ -66,6 +66,19 @@ public class SvcLogicDblibStore implements SvcLogicStore { this.dbSvc = dbsvc; } + public SvcLogicDblibStore(Properties props) { + try { + dbSvc = new DBResourceManager(props); + JavaSingleton.setInstance(dbSvc); + } catch (Exception e) { + LOG.warn("Caught exception trying to create DBResourceManager", e); + } + } + + public Connection getConnection() throws SQLException { + return(dbSvc.getConnection()); + } + @Override public void init(Properties props) throws ConfigurationException { diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicJdbcStore.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicJdbcStore.java index e2fbdf72..0e7d05a6 100644 --- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicJdbcStore.java +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicJdbcStore.java @@ -38,7 +38,6 @@ import java.util.Properties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class SvcLogicJdbcStore implements SvcLogicStore { private static final Logger LOG = LoggerFactory.getLogger(SvcLogicJdbcStore.class); diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicParser.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicParser.java index 3d9caffb..2804f620 100644 --- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicParser.java +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicParser.java @@ -437,7 +437,7 @@ public class SvcLogicParser { } - + public static void load(String xmlfile, SvcLogicStore store) throws SvcLogicException { File xmlFile = new File(xmlfile); if (!xmlFile.canRead()) { @@ -531,7 +531,7 @@ public class SvcLogicParser { } - private static void activate(String module, String rpc, String version, String mode, SvcLogicStore store) { + public static void activate(String module, String rpc, String version, String mode, SvcLogicStore store) { String details = "(module:" + module + ", rpc:" + rpc + ", version:" + version + ", mode:" + mode + ")"; try { @@ -560,7 +560,7 @@ public class SvcLogicParser { System.exit(1); } - + protected SAXParser initParser() throws ParserConfigurationException, SAXException { URL xsdUrl = null; Schema schema = null; 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 index 368d9f95..6ee18e92 100644 --- 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 @@ -32,11 +32,13 @@ 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 ch.vorburger.mariadb4j.DB; -import ch.vorburger.mariadb4j.DBConfigurationBuilder; - import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -67,17 +69,9 @@ public class ITCaseSvcLogicParser { props.load(propStr); + store = SvcLogicStoreFactory.getSvcLogicStore(props); - // Start MariaDB4j database - DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder(); - config.setPort(0); // 0 => autom. detect free port - DB db = DB.newEmbeddedDB(config.build()); - db.start(); - - - // Override jdbc URL and database name - props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); - props.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test")); + assertNotNull(store); } @@ -120,8 +114,123 @@ public class ITCaseSvcLogicParser { } try { - SvcLogicParser.validate(testCaseUrl.getPath(), store); + 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(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," + + "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() + "]"); } } @@ -152,7 +261,7 @@ public class ITCaseSvcLogicParser { if (testCaseUrl == null) { fail("Could not resolve test case file " + testCaseFile); } - SvcLogicParser.load(testCaseUrl.getPath(), store); + SvcLogicParser.validate(testCaseUrl.getPath(), store); } } } diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/PrintYangToPropTest.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/PrintYangToPropTest.java index 21d3e59c..fb6eaf70 100644 --- a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/PrintYangToPropTest.java +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/PrintYangToPropTest.java @@ -15,6 +15,9 @@ import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.Exe import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.ExecuteGraphInputBuilder; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.execute.graph.input.SliParameter; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.execute.graph.input.SliParameterBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefixBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,6 +53,22 @@ public class PrintYangToPropTest { pBuilder.setIntValue(null); pBuilder.setBooleanValue(true); pList.add(pBuilder.build()); + pBuilder.setParameterName("ipaddress-value1"); + pBuilder.setBooleanValue(null); + pBuilder.setIpaddressValue(IpAddressBuilder.getDefaultInstance("127.0.0.1")); + pList.add(pBuilder.build()); + pBuilder.setParameterName("ipaddress-value1"); + pBuilder.setIpaddressValue(IpAddressBuilder.getDefaultInstance("::1")); + pList.add(pBuilder.build()); + pBuilder.setParameterName("ipprefix-value1"); + pBuilder.setIpaddressValue(null); + pBuilder.setIpprefixValue(IpPrefixBuilder.getDefaultInstance("192.168.0.0/16")); + pList.add(pBuilder.build()); + pBuilder.setParameterName("ipprefix-value2"); + pBuilder.setIpprefixValue(IpPrefixBuilder.getDefaultInstance("2001:db8:3c4d::/48")); + pList.add(pBuilder.build()); + + egBuilder.setSliParameter(pList); @@ -64,6 +83,9 @@ public class PrintYangToPropTest { LOG.info("Property {} = {}", propName, props.getProperty(propName)); } + // Generate builder from properties just generated + PrintYangToProp.toBuilder(props, pBuilder); + } } 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 100644 index 00000000..31a419bb --- /dev/null +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java @@ -0,0 +1,135 @@ +package org.onap.ccsdk.sli.core.sli; + +import static org.junit.Assert.*; +import java.util.Date; +import org.junit.Before; +import org.junit.Test; + +public class TestMetricLogger { + + MetricLogger logger; + + @Before + public void setUp() throws Exception { + + logger = new MetricLogger(); + logger.resetContext(); + logger.logRequest("svcInstance1", "svcName", "svcPartner", "targetEntity", "targetServiceName", "targetVirtualEntity", "hello-world"); + logger.logResponse("200", "200", "SUCCESS"); + + } + + @Test + public final void testGetBeginTimestamp() { + logger.getBeginTimestamp(); + } + + @Test + public final void testGetEndTimestamp() { + logger.getEndTimestamp(); + } + + @Test + public final void testGetRequestID() { + logger.getRequestID(); + } + + @Test + public final void testGetServiceInstanceID() { + logger.getServiceInstanceID(); + } + + @Test + public final void testGetServiceName() { + logger.getServiceName(); + } + + @Test + public final void testGetPartnerName() { + logger.getPartnerName(); + } + + @Test + public final void testGetTargetEntity() { + logger.getTargetEntity(); + } + + @Test + public final void testGetTargetServiceName() { + logger.getTargetServiceName(); + } + + @Test + public final void testGetStatusCode() { + logger.getStatusCode(); + } + + @Test + public final void testGetResponseCode() { + logger.getResponseCode(); + } + + @Test + public final void testGetResponseDescription() { + logger.getResponseDescription(); + } + + @Test + public final void testGetInstanceUUID() { + logger.getInstanceUUID(); + } + + @Test + public final void testGetCategoryLogLevel() { + logger.getCategoryLogLevel(); + } + + @Test + public final void testGetSeverity() { + logger.getSeverity(); + } + + @Test + public final void testGetServerIpAddress() { + logger.getServerIpAddress(); + } + + @Test + public final void testGetElapsedTime() { + logger.getElapsedTime(); + } + + @Test + public final void testGetServer() { + logger.getServer(); + } + + @Test + public final void testGetClientIp() { + logger.getClientIp(); + } + + @Test + public final void testGetClassName() { + logger.getClassName(); + } + + @Test + public final void testGetTargetVirtualEntity() { + logger.getTargetVirtualEntity(); + } + + @Test + public final void testAsIso8601Date() { + logger.asIso8601(new Date()); + } + + @Test + public final void testAsIso8601Long() { + logger.asIso8601(System.currentTimeMillis()); + } + + + + +} 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 00000000..8998382e --- /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.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); + + URL graphUrl = TestSvcLogicLoader.class.getClassLoader().getResource("graphs"); + + if (graphUrl == null) { + fail("Cannot find graphs directory"); + } + + SvcLogicLoader loader = new SvcLogicLoader(graphUrl.getPath(), store); + loader.loadAndActivate(); + + + } + + + +} diff --git a/sli/common/src/test/resources/dblib.properties b/sli/common/src/test/resources/dblib.properties new file mode 100755 index 00000000..f08dce7a --- /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/graphs/sliapi/graph.versions b/sli/common/src/test/resources/graphs/sliapi/graph.versions new file mode 100644 index 00000000..d72920a4 --- /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 00000000..d512f546 --- /dev/null +++ b/sli/common/src/test/resources/graphs/sliapi/sli_healthcheck.xml @@ -0,0 +1,27 @@ + + + + + + + + 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 00000000..58a420f9 --- /dev/null +++ b/sli/common/src/test/resources/l3sdn_logic_v10.xml @@ -0,0 +1,208 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sli/common/src/test/resources/parser-good.tests b/sli/common/src/test/resources/parser-good.tests index 06543126..4147fdb6 100755 --- a/sli/common/src/test/resources/parser-good.tests +++ b/sli/common/src/test/resources/parser-good.tests @@ -1,2 +1,3 @@ ReleasePortSvcLogic_v101.xml neutron_logic_v10.xml +l3sdn_logic_v10.xml diff --git a/sli/common/src/test/resources/svclogic.properties b/sli/common/src/test/resources/svclogic.properties index 33d7ae6e..426960f7 100644 --- a/sli/common/src/test/resources/svclogic.properties +++ b/sli/common/src/test/resources/svclogic.properties @@ -20,7 +20,8 @@ ### org.onap.ccsdk.sli.dbtype = jdbc -org.onap.ccsdk.sli.jdbc.url = jdbc:mysql://localhost:3306/test -org.onap.ccsdk.sli.jdbc.database = test +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 = test123 +org.onap.ccsdk.sli.jdbc.password = test diff --git a/sli/common/src/test/resources/svclogic.xsd b/sli/common/src/test/resources/svclogic.xsd index a63758f7..2704de88 100755 --- a/sli/common/src/test/resources/svclogic.xsd +++ b/sli/common/src/test/resources/svclogic.xsd @@ -30,6 +30,7 @@ + @@ -320,4 +321,14 @@ + + + + + + + + + + diff --git a/sli/provider/pom.xml b/sli/provider/pom.xml index 4a90ae00..1b21b002 100755 --- a/sli/provider/pom.xml +++ b/sli/provider/pom.xml @@ -1,44 +1,40 @@ - - 4.0.0 + + 4.0.0 - + org.onap.ccsdk.parent binding-parent 1.0.1-SNAPSHOT - + - org.onap.ccsdk.sli.core - sli-provider - 0.2.1-SNAPSHOT - bundle + org.onap.ccsdk.sli.core + sli-provider + 0.2.1-SNAPSHOT + bundle - ccsdk-sli-core :: sli :: ${project.artifactId} - SLI Provider is the OSGi bundle that exposes the service logic interpreter as a service. + ccsdk-sli-core :: sli :: ${project.artifactId} + SLI Provider is the OSGi bundle that exposes the service logic interpreter as a service. - + UTF-8 - - - - org.opendaylight.controller - mdsal-artifacts - 1.6.1 - pom - import - - - - - - ch.vorburger.mariaDB4j - mariaDB4j - 2.2.3 - test - + + + + org.opendaylight.controller + mdsal-artifacts + 1.6.1 + pom + import + + + + + org.onap.ccsdk.sli.core sli-model @@ -61,11 +57,6 @@ slf4j-api ${slf4j.version} - - org.slf4j - jcl-over-slf4j - ${slf4j.version} - commons-lang commons-lang @@ -74,23 +65,28 @@ - - org.opendaylight.controller - sal-binding-api - - - - - junit - junit - test - + + org.opendaylight.controller + sal-binding-api + - - org.mockito - mockito-core - test - + + + junit + junit + test + + + org.mockito + mockito-core + test + + + org.apache.derby + derby + 10.11.1.1 + test + diff --git a/sli/provider/src/main/resources/svclogic.properties b/sli/provider/src/main/resources/svclogic.properties deleted file mode 100644 index 49d39ab4..00000000 --- a/sli/provider/src/main/resources/svclogic.properties +++ /dev/null @@ -1,25 +0,0 @@ -### -# ============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 = dblib -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 diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java index 4c112ab2..0a8bf71a 100644 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java @@ -24,8 +24,7 @@ package org.onap.ccsdk.sli.core.sli.provider; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; -import ch.vorburger.mariadb4j.DB; -import ch.vorburger.mariadb4j.DBConfigurationBuilder; + import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; @@ -40,6 +39,7 @@ 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.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicGraph; import org.onap.ccsdk.sli.core.sli.SvcLogicParser; @@ -74,6 +74,7 @@ public class ITCaseSvcLogicGraphExecutor { put("set", new SetNodeExecutor()); put("switch", new SwitchNodeExecutor()); put("update", new UpdateNodeExecutor()); + put("while", new WhileNodeExecutor()); } }; @@ -88,16 +89,6 @@ public class ITCaseSvcLogicGraphExecutor { Properties svcprops = new Properties(); svcprops.load(propStr); - // Start MariaDB4j database - DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder(); - config.setPort(0); // 0 => autom. detect free port - DB db = DB.newEmbeddedDB(config.build()); - db.start(); - - // Override jdbc URL and database name - svcprops.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); - svcprops.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test")); - SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(svcprops); assertNotNull(store); @@ -144,18 +135,9 @@ public class ITCaseSvcLogicGraphExecutor { Properties svcprops = new Properties(); svcprops.load(propStr); - // Start MariaDB4j database - DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder(); - config.setPort(0); // 0 => autom. detect free port - DB db = DB.newEmbeddedDB(config.build()); - db.start(); - - // Override jdbc URL and database name - svcprops.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); - svcprops.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test")); - SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(svcprops); + assertNotNull(store); @@ -214,10 +196,13 @@ public class ITCaseSvcLogicGraphExecutor { fail("Could not resolve test case file " + testCaseFile); } + LinkedList graphs = parser.parse(testCaseUrl.getPath()); assertNotNull(graphs); + // Load grqphs into db to support call node + parser.load(testCaseUrl.getPath(), store); for (SvcLogicGraph graph : graphs) { if (graph.getRpc().equals(testCaseMethod)) { Properties props = ctx.toProperties(); diff --git a/sli/provider/src/test/resources/executor.tests b/sli/provider/src/test/resources/executor.tests index e4e60208..5468c8d6 100755 --- a/sli/provider/src/test/resources/executor.tests +++ b/sli/provider/src/test/resources/executor.tests @@ -1,6 +1,8 @@ l3sdn_logic_v10.xml:switchTester:test-value="" l3sdn_logic_v10.xml:switchTester:test-value="hi" l3sdn_logic_v10.xml:forRecordTester +l3sdn_logic_v10.xml:whileNodeTester l3sdn_logic_v10.xml:resourceTester l3sdn_logic_v10.xml:configureTester -l3sdn_logic_v10.xml:javaPluginTester \ No newline at end of file +l3sdn_logic_v10.xml:javaPluginTester +l3sdn_logic_v10.xml:allNodesTester \ No newline at end of file diff --git a/sli/provider/src/test/resources/l3sdn_logic_v10.xml b/sli/provider/src/test/resources/l3sdn_logic_v10.xml index 1386df10..cbb5db1b 100644 --- a/sli/provider/src/test/resources/l3sdn_logic_v10.xml +++ b/sli/provider/src/test/resources/l3sdn_logic_v10.xml @@ -49,6 +49,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -167,6 +188,8 @@ + + diff --git a/sli/provider/src/test/resources/svclogic.properties b/sli/provider/src/test/resources/svclogic.properties index 49d39ab4..426960f7 100644 --- a/sli/provider/src/test/resources/svclogic.properties +++ b/sli/provider/src/test/resources/svclogic.properties @@ -19,7 +19,9 @@ # ============LICENSE_END========================================================= ### -org.onap.ccsdk.sli.dbtype = dblib +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/sliapi/provider/pom.xml b/sliapi/provider/pom.xml index cb4dfc89..5650416d 100755 --- a/sliapi/provider/pom.xml +++ b/sliapi/provider/pom.xml @@ -1,73 +1,94 @@ - - 4.0.0 + + 4.0.0 - - org.onap.ccsdk.parent - binding-parent - 1.0.1-SNAPSHOT - - + + org.onap.ccsdk.parent + binding-parent + 1.0.1-SNAPSHOT + + - org.onap.ccsdk.sli.core - sliapi-provider - 0.2.1-SNAPSHOT - bundle + org.onap.ccsdk.sli.core + sliapi-provider + 0.2.1-SNAPSHOT + bundle - ccsdk-sli-core :: sliapi :: ${project.artifactId} + ccsdk-sli-core :: sliapi :: ${project.artifactId} - - - - org.opendaylight.controller - mdsal-artifacts - 1.6.1 - pom - import - - - - - - org.onap.ccsdk.sli.core - sliapi-model - ${project.version} - + + + + org.opendaylight.controller + mdsal-artifacts + 1.6.1 + pom + import + + + + + + org.onap.ccsdk.sli.core + sliapi-model + ${project.version} + - - org.opendaylight.controller - sal-binding-config - + + org.opendaylight.controller + sal-binding-config + - - org.opendaylight.controller - sal-binding-api - + + org.opendaylight.controller + sal-binding-api + - - org.opendaylight.controller - sal-common-util - + + org.opendaylight.controller + sal-common-util + - - org.onap.ccsdk.sli.core - sli-common - ${project.version} - - - org.onap.ccsdk.sli.core - sli-provider - ${project.version} - - - org.opendaylight.controller - sal-core-api - - - org.opendaylight.yangtools - yang-data-impl - - + + org.onap.ccsdk.sli.core + sli-common + ${project.version} + + + org.onap.ccsdk.sli.core + sli-provider + ${project.version} + + + org.opendaylight.controller + sal-core-api + + + org.opendaylight.yangtools + yang-data-impl + + + + junit + junit + ${junit.version} + test + + + + org.mockito + mockito-core + test + + + + org.apache.derby + derby + 10.11.1.1 + test + + diff --git a/sliapi/provider/src/main/java/org/onap/ccsdk/sli/core/sliapi/sliapiProvider.java b/sliapi/provider/src/main/java/org/onap/ccsdk/sli/core/sliapi/sliapiProvider.java index 3ff2f52d..e9a2b8eb 100644 --- a/sliapi/provider/src/main/java/org/onap/ccsdk/sli/core/sliapi/sliapiProvider.java +++ b/sliapi/provider/src/main/java/org/onap/ccsdk/sli/core/sliapi/sliapiProvider.java @@ -114,14 +114,16 @@ import com.google.common.util.concurrent.Futures; */ public class sliapiProvider implements AutoCloseable, SLIAPIService{ - private final Logger LOG = LoggerFactory.getLogger( sliapiProvider.class ); - private final String appName = "slitester"; + private static final Logger LOG = LoggerFactory.getLogger( sliapiProvider.class ); + private static final String appName = "slitester"; protected DataBroker dataBroker; protected DOMDataBroker domDataBroker; protected NotificationPublishService notificationService; protected RpcProviderRegistry rpcRegistry; + private SvcLogicService svcLogic; + protected BindingAwareBroker.RpcRegistration rpcRegistration; private static String SLIAPI_NAMESPACE = "org:onap:ccsdk:sli:core:sliapi"; @@ -142,15 +144,23 @@ public class sliapiProvider implements AutoCloseable, SLIAPIService{ RESULTS_QNAME = QName.create(TEST_RESULT_QNAME, "results"); } + public sliapiProvider( + DataBroker dataBroker, + NotificationPublishService notificationPublishService, + RpcProviderRegistry rpcProviderRegistry) { + this(dataBroker, notificationPublishService, rpcProviderRegistry, findSvcLogicService()); + } public sliapiProvider( DataBroker dataBroker, NotificationPublishService notificationPublishService, - RpcProviderRegistry rpcProviderRegistry) { + RpcProviderRegistry rpcProviderRegistry, + SvcLogicService svcLogic) { this.LOG.info( "Creating provider for " + appName ); this.dataBroker = dataBroker; this.notificationService = notificationPublishService; this.rpcRegistry = rpcProviderRegistry; + this.svcLogic = svcLogic; initialize(); } @@ -357,6 +367,13 @@ public class sliapiProvider implements AutoCloseable, SLIAPIService{ private SvcLogicService getSvcLogicService() { + if (svcLogic == null) { + svcLogic = findSvcLogicService(); + } + + return(svcLogic); + } + private static SvcLogicService findSvcLogicService() { BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class).getBundleContext(); SvcLogicService svcLogic = null; diff --git a/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java b/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java new file mode 100644 index 00000000..38cbd40c --- /dev/null +++ b/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java @@ -0,0 +1,171 @@ +/** + * + */ +package org.onap.ccsdk.sli.core.sliapi; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.*; +import java.io.InputStream; +import java.net.URL; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicParser; +import org.onap.ccsdk.sli.core.sli.SvcLogicStore; +import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory; +import org.onap.ccsdk.sli.core.sli.provider.BlockNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.CallNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.ConfigureNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.DeleteNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.ExecuteNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.ExistsNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.ForNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.GetResourceNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.IsAvailableNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.NotifyNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.RecordNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.ReleaseNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.ReserveNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.ReturnNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.SaveNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.SetNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicPropertiesProviderImpl; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicServiceImpl; +import org.onap.ccsdk.sli.core.sli.provider.SwitchNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.UpdateNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.WhileNodeExecutor; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.ExecuteGraphInput; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.ExecuteGraphInputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.SLIAPIService; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.execute.graph.input.SliParameter; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.execute.graph.input.SliParameterBuilder; + +/** + * @author dt5972 + * + */ +public class TestSliapiProvider { + + private sliapiProvider provider; + + private static final String HEALTHCHECK_DG = "sli_healthcheck.xml"; + + private static final Map BUILTIN_NODES = new HashMap() { + { + put("block", new BlockNodeExecutor()); + put("call", new CallNodeExecutor()); + put("configure", new ConfigureNodeExecutor()); + put("delete", new DeleteNodeExecutor()); + put("execute", new ExecuteNodeExecutor()); + put("exists", new ExistsNodeExecutor()); + put("for", new ForNodeExecutor()); + put("get-resource", new GetResourceNodeExecutor()); + put("is-available", new IsAvailableNodeExecutor()); + put("notify", new NotifyNodeExecutor()); + put("record", new RecordNodeExecutor()); + put("release", new ReleaseNodeExecutor()); + put("reserve", new ReserveNodeExecutor()); + put("return", new ReturnNodeExecutor()); + put("save", new SaveNodeExecutor()); + put("set", new SetNodeExecutor()); + put("switch", new SwitchNodeExecutor()); + put("update", new UpdateNodeExecutor()); + put("while", new WhileNodeExecutor()); + + } + }; + + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + DataBroker dataBroker = mock(DataBroker.class); + NotificationPublishService notifyService = mock(NotificationPublishService.class); + RpcProviderRegistry rpcRegistry = mock(RpcProviderRegistry.class); + BindingAwareBroker.RpcRegistration rpcRegistration = (BindingAwareBroker.RpcRegistration) mock(BindingAwareBroker.RpcRegistration.class); + when(rpcRegistry.addRpcImplementation(any(Class.class), any(SLIAPIService.class))).thenReturn(rpcRegistration); + + + // Load svclogic.properties and get a SvcLogicStore + InputStream propStr = TestSliapiProvider.class.getResourceAsStream("/svclogic.properties"); + Properties svcprops = new Properties(); + svcprops.load(propStr); + + SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(svcprops); + + assertNotNull(store); + + // Load the DG for the healthcheck api + URL testCaseUrl = TestSliapiProvider.class.getClassLoader().getResource(HEALTHCHECK_DG); + if (testCaseUrl == null) { + fail("Cannot find "+HEALTHCHECK_DG); + } + SvcLogicParser.load(testCaseUrl.getPath(), store); + SvcLogicParser.activate("sli", "healthcheck", "1.0.0", "sync", store); + + // Create a ServiceLogicService and initialize it + SvcLogicServiceImpl svc = new SvcLogicServiceImpl(new SvcLogicPropertiesProviderImpl()); + for (String nodeType : BUILTIN_NODES.keySet()) { + svc.registerExecutor(nodeType, BUILTIN_NODES.get(nodeType)); + } + + // Finally ready to create sliapiProvider + provider = new sliapiProvider(dataBroker, notifyService, rpcRegistry, svc); + provider.setDataBroker(dataBroker); + provider.setNotificationService(notifyService); + provider.setRpcRegistry(rpcRegistry); + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + provider.close(); + } + + /** + * Test method for {@link org.onap.ccsdk.sli.core.sliapi.sliapiProvider#executeGraph(org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.ExecuteGraphInput)}. + */ + @Test + public void testExecuteGraph() { + ExecuteGraphInputBuilder inputBuilder = new ExecuteGraphInputBuilder(); + + inputBuilder.setMode(ExecuteGraphInput.Mode.Sync); + inputBuilder.setModuleName("sli"); + inputBuilder.setRpcName("healthcheck"); + List pList = new LinkedList<>(); + SliParameterBuilder pBuilder = new SliParameterBuilder(); + pBuilder.setParameterName("int-parameter"); + pBuilder.setIntValue(1); + pList.add(pBuilder.build()); + inputBuilder.setSliParameter(pList); + + + + + provider.executeGraph(inputBuilder.build()); + } + + /** + * Test method for {@link org.onap.ccsdk.sli.core.sliapi.sliapiProvider#healthcheck()}. + */ + @Test + public void testHealthcheck() { + provider.healthcheck(); + } + +} diff --git a/sliapi/provider/src/test/resources/sli_healthcheck.xml b/sliapi/provider/src/test/resources/sli_healthcheck.xml new file mode 100644 index 00000000..d512f546 --- /dev/null +++ b/sliapi/provider/src/test/resources/sli_healthcheck.xml @@ -0,0 +1,27 @@ + + + + + + + + diff --git a/sliapi/provider/src/test/resources/svclogic.properties b/sliapi/provider/src/test/resources/svclogic.properties new file mode 100644 index 00000000..426960f7 --- /dev/null +++ b/sliapi/provider/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 -- cgit 1.2.3-korg