From 3fa9671f720dd95bf15a5a4668aa89a7c3dd93e7 Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Wed, 13 Sep 2017 16:32:45 -0400 Subject: Use oparent-odlparent in sli/core Update sli/core to use oparent-odlparent. To prevent verify builds from failing due to unit test errors, also changed unit tests that require database access to use MariaDB4j to start up a local MariaDB database. Change-Id: I928b7e1e83bdb328ca9e0785c8b81f67f982eeda Issue-ID: CCSDK-43 Signed-off-by: Dan Timoney --- .../DblibDefaultFileResolverTest.java | 24 ++ .../DblibEnvVarFileResolverTest.java | 23 ++ .../DblibJREFileResolverTest.java | 15 ++ .../DblibKarafRootFileResolverTest.java | 14 + .../DblibDefaultFileResolverTest.java | 24 -- .../DblibEnvVarFileResolverTest.java | 23 -- .../DblibJREFileResolverTest.java | 15 -- .../DblibKarafRootFileResolverTest.java | 14 - pom.xml | 2 +- sli/common/pom.xml | 297 +++++++++++---------- .../ccsdk/sli/core/sli/ITCaseSvcLogicParser.java | 78 ++++-- sli/common/src/test/resources/svclogic.properties | 12 +- sli/provider/pom.xml | 6 + .../sli/provider/ITCaseSvcLogicGraphExecutor.java | 100 ++++--- 14 files changed, 340 insertions(+), 307 deletions(-) create mode 100644 dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java create mode 100644 dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java create mode 100644 dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java create mode 100644 dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java delete mode 100644 dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java delete mode 100644 dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java delete mode 100644 dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java delete mode 100644 dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java diff --git a/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java new file mode 100644 index 00000000..41011e55 --- /dev/null +++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java @@ -0,0 +1,24 @@ +package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver; + +import static org.junit.Assert.*; + +import java.io.File; +import java.util.Optional; +import org.junit.Test; + +public class DblibDefaultFileResolverTest { + + @Test + public void resolveFile() throws Exception { + final DblibPropertiesFileResolver resolver = new DblibDefaultFileResolver("success"); + final Optional file = resolver.resolveFile("doesnotexist.cfg"); + assertFalse(file.isPresent()); + } + + @Test + public void getSuccessfulResolutionMessage() throws Exception { + final DblibPropertiesFileResolver resolver = new DblibDefaultFileResolver("success"); + assertEquals("success", resolver.getSuccessfulResolutionMessage()); + } + +} \ No newline at end of file diff --git a/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java new file mode 100644 index 00000000..77589893 --- /dev/null +++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java @@ -0,0 +1,23 @@ +package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver; + +import static org.junit.Assert.*; + +import java.io.File; +import java.util.Optional; +import org.junit.Test; + +public class DblibEnvVarFileResolverTest { + @Test + public void resolveFile() throws Exception { + final DblibPropertiesFileResolver resolver = new DblibEnvVarFileResolver("success"); + final Optional file = resolver.resolveFile("doesnotexist.cfg"); + assertFalse(file.isPresent()); + } + + @Test + public void getSuccessfulResolutionMessage() throws Exception { + final DblibPropertiesFileResolver resolver = new DblibEnvVarFileResolver("success"); + assertEquals("success", resolver.getSuccessfulResolutionMessage()); + } + +} \ No newline at end of file diff --git a/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java new file mode 100644 index 00000000..65ebfbae --- /dev/null +++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java @@ -0,0 +1,15 @@ +package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class DblibJREFileResolverTest { + + @Test + public void getSuccessfulResolutionMessage() throws Exception { + final DblibPropertiesFileResolver resolver = new DblibJREFileResolver("success"); + assertEquals("success", resolver.getSuccessfulResolutionMessage()); + } + +} \ No newline at end of file diff --git a/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java new file mode 100644 index 00000000..0a032e8b --- /dev/null +++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java @@ -0,0 +1,14 @@ +package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class DblibKarafRootFileResolverTest { + @Test + public void getSuccessfulResolutionMessage() throws Exception { + final DblibPropertiesFileResolver resolver = new DblibKarafRootFileResolver("success", null); + assertEquals("success", resolver.getSuccessfulResolutionMessage()); + } + +} \ No newline at end of file diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java b/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java deleted file mode 100644 index 41011e55..00000000 --- a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver; - -import static org.junit.Assert.*; - -import java.io.File; -import java.util.Optional; -import org.junit.Test; - -public class DblibDefaultFileResolverTest { - - @Test - public void resolveFile() throws Exception { - final DblibPropertiesFileResolver resolver = new DblibDefaultFileResolver("success"); - final Optional file = resolver.resolveFile("doesnotexist.cfg"); - assertFalse(file.isPresent()); - } - - @Test - public void getSuccessfulResolutionMessage() throws Exception { - final DblibPropertiesFileResolver resolver = new DblibDefaultFileResolver("success"); - assertEquals("success", resolver.getSuccessfulResolutionMessage()); - } - -} \ No newline at end of file diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java b/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java deleted file mode 100644 index 77589893..00000000 --- a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver; - -import static org.junit.Assert.*; - -import java.io.File; -import java.util.Optional; -import org.junit.Test; - -public class DblibEnvVarFileResolverTest { - @Test - public void resolveFile() throws Exception { - final DblibPropertiesFileResolver resolver = new DblibEnvVarFileResolver("success"); - final Optional file = resolver.resolveFile("doesnotexist.cfg"); - assertFalse(file.isPresent()); - } - - @Test - public void getSuccessfulResolutionMessage() throws Exception { - final DblibPropertiesFileResolver resolver = new DblibEnvVarFileResolver("success"); - assertEquals("success", resolver.getSuccessfulResolutionMessage()); - } - -} \ No newline at end of file diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java b/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java deleted file mode 100644 index 65ebfbae..00000000 --- a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver; - -import static org.junit.Assert.*; - -import org.junit.Test; - -public class DblibJREFileResolverTest { - - @Test - public void getSuccessfulResolutionMessage() throws Exception { - final DblibPropertiesFileResolver resolver = new DblibJREFileResolver("success"); - assertEquals("success", resolver.getSuccessfulResolutionMessage()); - } - -} \ No newline at end of file diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java b/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java deleted file mode 100644 index 0a032e8b..00000000 --- a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver; - -import static org.junit.Assert.*; - -import org.junit.Test; - -public class DblibKarafRootFileResolverTest { - @Test - public void getSuccessfulResolutionMessage() throws Exception { - final DblibPropertiesFileResolver resolver = new DblibKarafRootFileResolver("success", null); - assertEquals("success", resolver.getSuccessfulResolutionMessage()); - } - -} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3bf8b1e6..469a2a69 100755 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.onap.ccsdk.parent odlparent-carbon-sr1 - 0.0.1-SNAPSHOT + 0.0.2-SNAPSHOT diff --git a/sli/common/pom.xml b/sli/common/pom.xml index f71ca35f..c367dd77 100755 --- a/sli/common/pom.xml +++ b/sli/common/pom.xml @@ -1,150 +1,157 @@ - - 4.0.0 - - sli - org.onap.ccsdk.sli.core - 0.1.2-SNAPSHOT - - sli-common - bundle + + 4.0.0 + + sli + org.onap.ccsdk.sli.core + 0.1.2-SNAPSHOT + + sli-common + bundle - SLI - Common Classes - 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 + SLI - Common Classes + 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 - - - junit - junit - 3.8.1 - test - - - org.antlr - antlr4 - ${antlr.version} - jar - compile - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.slf4j - slf4j-simple - 1.7.5 - compile - - - org.apache.commons - commons-lang3 - ${commons.lang3.version} - - - org.opendaylight.mdsal - yang-binding - ${odl.mdsal.yang.binding.version} - - - org.opendaylight.yangtools - yang-common - ${odl.yangtools.version} - - - org.opendaylight.mdsal.model - ietf-inet-types - ${odl.ietf-inet-types.version} - - - org.opendaylight.mdsal.model - ietf-yang-types - ${odl.ietf-yang-types.version} - - - org.opendaylight.controller - sal-core-api - ${odl.mdsal.version} - - - org.opendaylight.yangtools - yang-data-impl - ${odl.yangtools.version} - - - equinoxSDK381 - org.eclipse.osgi - ${equinox.osgi.version} - - - mysql - mysql-connector-java - ${mysql.connector.version} - jar - compile - - - org.onap.ccsdk.sli.core - dblib-provider - ${sdnctl.dblib.version} - - + + + junit + junit + 3.8.1 + test + + + ch.vorburger.mariaDB4j + mariaDB4j + 2.2.3 + test + + + org.antlr + antlr4 + ${antlr.version} + jar + compile + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + slf4j-simple + 1.7.5 + compile + + + org.apache.commons + commons-lang3 + ${commons.lang3.version} + + + org.opendaylight.mdsal + yang-binding + ${odl.mdsal.yang.binding.version} + + + org.opendaylight.yangtools + yang-common + ${odl.yangtools.version} + + + org.opendaylight.mdsal.model + ietf-inet-types + ${odl.ietf-inet-types.version} + + + org.opendaylight.mdsal.model + ietf-yang-types + ${odl.ietf-yang-types.version} + + + org.opendaylight.controller + sal-core-api + ${odl.mdsal.version} + + + org.opendaylight.yangtools + yang-data-impl + ${odl.yangtools.version} + + + equinoxSDK381 + org.eclipse.osgi + ${equinox.osgi.version} + + + mysql + mysql-connector-java + ${mysql.connector.version} + jar + compile + + + org.onap.ccsdk.sli.core + dblib-provider + ${sdnctl.dblib.version} + + - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.7 - 1.7 - - - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - **/*.xsd - - - org.onap.ccsdk.sli.core.sli.SvcLogicParser - org.onap.ccsdk.sli.core.sli - true - - - - - - org.apache.felix - maven-bundle-plugin - true - - - org.onap.ccsdk.sli.core.sli;version=${project.version} - * - *;scope=compile;artifactId=commons-lang|commons-lang3 - true - - - - - org.antlr - antlr4-maven-plugin - ${antlr.version} - - - - ${project.basedir}/src/main/java/ - - antlr - - antlr4 - - - - - - + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + **/*.xsd + + + org.onap.ccsdk.sli.core.sli.SvcLogicParser + org.onap.ccsdk.sli.core.sli + true + + + + + + org.apache.felix + maven-bundle-plugin + true + + + org.onap.ccsdk.sli.core.sli;version=${project.version} + * + *;scope=compile;artifactId=commons-lang|commons-lang3 + true + + + + + org.antlr + antlr4-maven-plugin + ${antlr.version} + + + + ${project.basedir}/src/main/java/ + + antlr + + antlr4 + + + + + + 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 0e6000fb..07f40a2e 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 @@ -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. @@ -20,7 +20,7 @@ */ /** - * + * */ package org.onap.ccsdk.sli.core.sli; @@ -28,7 +28,10 @@ import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; +import java.util.Properties; +import ch.vorburger.mariadb4j.DB; +import ch.vorburger.mariadb4j.DBConfigurationBuilder; import junit.framework.TestCase; /** @@ -40,22 +43,43 @@ public class ITCaseSvcLogicParser extends TestCase { /** * Test method for {@link org.onap.ccsdk.sli.core.sli.SvcLogicParser#parse(java.lang.String)}. */ - - + + public void testParse() { - + try { + + URL propUrl = getClass().getResource("/svclogic.properties"); - + InputStream propStr = getClass().getResourceAsStream("/svclogic.properties"); - - SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propStr); - + + Properties props = new Properties(); + + props.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 + props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); + props.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test")); + + + + SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(props); + assertNotNull(store); - + store.registerNodeType("switch"); store.registerNodeType("block"); store.registerNodeType("get-resource"); @@ -69,15 +93,15 @@ public class ITCaseSvcLogicParser extends TestCase { store.registerNodeType("release"); store.registerNodeType("for"); store.registerNodeType("set"); - - + + InputStream testStr = getClass().getResourceAsStream("/parser-good.tests"); BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); String testCaseFile = null; while ((testCaseFile = testsReader.readLine()) != null) { - + testCaseFile = testCaseFile.trim(); - + if (testCaseFile.length() > 0) { if (!testCaseFile.startsWith("/")) @@ -94,23 +118,23 @@ public class ITCaseSvcLogicParser extends TestCase { SvcLogicParser.validate(testCaseUrl.getPath(), store); } catch (Exception e) { fail("Validation failure ["+e.getMessage()+"]"); - + } - - - + + + } } - + testStr = getClass().getResourceAsStream("/parser-bad.tests"); testsReader = new BufferedReader(new InputStreamReader(testStr)); testCaseFile = null; while ((testCaseFile = testsReader.readLine()) != null) { - + testCaseFile = testCaseFile.trim(); - + if (testCaseFile.length() > 0) { if (!testCaseFile.startsWith("/")) @@ -134,7 +158,7 @@ public class ITCaseSvcLogicParser extends TestCase { if (valid) { fail("Expected compiler error on "+testCaseFile+", but got success"); } - + } } @@ -148,10 +172,10 @@ public class ITCaseSvcLogicParser extends TestCase { e.printStackTrace(); fail("Caught exception processing test cases"); } - - + + } - - + + } diff --git a/sli/common/src/test/resources/svclogic.properties b/sli/common/src/test/resources/svclogic.properties index 25eb3bd4..33d7ae6e 100644 --- a/sli/common/src/test/resources/svclogic.properties +++ b/sli/common/src/test/resources/svclogic.properties @@ -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. @@ -20,7 +20,7 @@ ### org.onap.ccsdk.sli.dbtype = jdbc -org.onap.ccsdk.sli.jdbc.url = jdbc:mysql://localhost:3306/sdnctl -org.onap.ccsdk.sli.jdbc.database = sdnctl -org.onap.ccsdk.sli.jdbc.user = sdnctl -org.onap.ccsdk.sli.jdbc.password = gamma +org.onap.ccsdk.sli.jdbc.url = jdbc:mysql://localhost:3306/test +org.onap.ccsdk.sli.jdbc.database = test +org.onap.ccsdk.sli.jdbc.user = test +org.onap.ccsdk.sli.jdbc.password = test123 diff --git a/sli/provider/pom.xml b/sli/provider/pom.xml index f665c56a..529f9769 100755 --- a/sli/provider/pom.xml +++ b/sli/provider/pom.xml @@ -19,6 +19,12 @@ 3.8.1 test + + ch.vorburger.mariaDB4j + mariaDB4j + 2.2.3 + test + org.onap.ccsdk.sli.core sli-common 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 5e895aa3..cdf837af 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 @@ -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. @@ -31,43 +31,22 @@ import java.util.LinkedList; import java.util.Map; import java.util.Properties; -import org.onap.ccsdk.sli.core.sli.MetricLogger; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicGraph; -import org.onap.ccsdk.sli.core.sli.SvcLogicNode; 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.SvcLogicServiceImpl; -import org.onap.ccsdk.sli.core.sli.provider.SwitchNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.UpdateNodeExecutor; -import org.osgi.framework.ServiceRegistration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ch.vorburger.mariadb4j.DB; +import ch.vorburger.mariadb4j.DBConfigurationBuilder; import junit.framework.TestCase; public class ITCaseSvcLogicGraphExecutor extends TestCase { private static final Logger LOG = LoggerFactory .getLogger(SvcLogicGraph.class); - + private static final Map BUILTIN_NODES = new HashMap() { { put("block", new BlockNodeExecutor()); @@ -91,19 +70,36 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase { } }; - + public void testExecute() { - + try { InputStream testStr = getClass().getResourceAsStream("/executor.tests"); BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); - + InputStream propStr = getClass().getResourceAsStream("/svclogic.properties"); - - SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propStr); - + + 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); - + store.registerNodeType("switch"); store.registerNodeType("block"); store.registerNodeType("get-resource"); @@ -118,26 +114,26 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase { store.registerNodeType("for"); store.registerNodeType("set"); SvcLogicParser parser = new SvcLogicParser(store); - + // Loop through executor tests SvcLogicServiceImpl svc = new SvcLogicServiceImpl(); - + for (String nodeType : BUILTIN_NODES.keySet()) { LOG.info("SLI - registering node executor for node type "+nodeType); - + svc.registerExecutor(nodeType, BUILTIN_NODES.get(nodeType)); } String testCaseLine = null; while ((testCaseLine = testsReader.readLine()) != null) { - + String[] testCaseFields = testCaseLine.split(":"); String testCaseFile = testCaseFields[0]; String testCaseMethod = testCaseFields[1]; String testCaseParameters = null; - + if (testCaseFields.length > 2) { testCaseParameters = testCaseFields[2]; } @@ -145,7 +141,7 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase { SvcLogicContext ctx = new SvcLogicContext(); if (testCaseParameters != null) { String[] testCaseParameterSettings = testCaseParameters.split(","); - + for (int i = 0 ; i < testCaseParameterSettings.length ; i++) { String[] nameValue = testCaseParameterSettings[i].split("="); if (nameValue != null) { @@ -154,14 +150,14 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase { if (nameValue.length > 1) { value = nameValue[1]; } - + ctx.setAttribute(name, value); } } } - + testCaseFile = testCaseFile.trim(); - + if (testCaseFile.length() > 0) { if (!testCaseFile.startsWith("/")) { testCaseFile = "/"+testCaseFile; @@ -170,12 +166,12 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase { if (testCaseUrl == null) { fail("Could not resolve test case file "+testCaseFile); } - + LinkedList graphs = parser.parse(testCaseUrl.getPath()); - + assertNotNull(graphs); - + for (SvcLogicGraph graph: graphs) { if (graph.getRpc().equals(testCaseMethod)) { Properties props = ctx.toProperties(); @@ -184,9 +180,9 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase { String propName = (String) e1.nextElement(); LOG.info(propName+" = "+props.getProperty(propName)); } - + svc.execute(graph, ctx); - + props = ctx.toProperties(); LOG.info("SvcLogicContext after executing "+testCaseMethod+":"); for (Enumeration e2 = props.propertyNames(); e2.hasMoreElements() ; ) { @@ -197,16 +193,16 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase { } } - - + + } - - + + } catch (Exception e) { LOG.error("Caught exception executing directed graphs", e); fail("Exception executing graphs"); } } - + } -- cgit 1.2.3-korg