From d0c9e06005c819b53970b72cf73ab814a3719109 Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Tue, 3 Oct 2017 08:42:05 -0400 Subject: Add unit tests for mdsal-resource Add unit tests for mdsal-resource component. Change-Id: I44ee079d43ee29e4d507abb5fc065188279b1ffe Issue-ID: CCSDK-106 Signed-off-by: Dan Timoney --- mdsal-resource/provider/pom.xml | 13 +++++++++- .../adaptors/resource/mdsal/ConfigResource.java | 8 ++++-- .../resource/mdsal/OperationalResource.java | 8 ++++-- .../resource/mdsal/TestConfigResource.java | 29 ++++++++++++++++++++++ .../resource/mdsal/TestOperationalResource.java | 29 ++++++++++++++++++++++ .../features/src/main/resources/features.xml | 2 +- 6 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestConfigResource.java create mode 100644 mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestOperationalResource.java diff --git a/mdsal-resource/provider/pom.xml b/mdsal-resource/provider/pom.xml index 5a61d762..ee0a3dc1 100755 --- a/mdsal-resource/provider/pom.xml +++ b/mdsal-resource/provider/pom.xml @@ -53,7 +53,18 @@ commons-codec ${commons.codec.version} - + + org.testng + testng + 6.11 + test + + + org.mockito + mockito-core + ${mockito.version} + test + diff --git a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.java b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.java index 9cade887..d02530fe 100644 --- a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.java +++ b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.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. @@ -42,6 +42,10 @@ public class ConfigResource implements SvcLogicResource { restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, RestService.PayloadType.XML); } + public ConfigResource(RestService restService) { + this.restService = restService; + } + @Override public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException { diff --git a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.java b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.java index 92a7b6be..63fe8c6a 100644 --- a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.java +++ b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.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. @@ -44,6 +44,10 @@ public class OperationalResource implements SvcLogicResource { } + public OperationalResource(RestService restService) { + this.restService = restService; + } + @Override public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException { diff --git a/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestConfigResource.java b/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestConfigResource.java new file mode 100644 index 00000000..a8f4d948 --- /dev/null +++ b/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestConfigResource.java @@ -0,0 +1,29 @@ +package org.onap.ccsdk.sli.adaptors.resource.mdsal; + +import junit.framework.TestCase; + +import static org.mockito.Mockito.mock; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +public class TestConfigResource extends TestCase { + + public void test() throws Exception { + + RestService restService = mock(RestService.class); + SvcLogicContext ctx = new SvcLogicContext(); + + ConfigResource res = new ConfigResource(restService); + + res.delete("my-resource", null, ctx); + res.notify("my-resource", "action", "key", ctx); + res.query("my-resource", false, "my-select", "mykey", "pfx", null, ctx); + res.release("my-resource", "mykey", ctx); + res.reserve("my-resource", "my-select", "mykey", "pfx", ctx); + res.exists("my-resource", "mykey", "pfx", ctx); + res.isAvailable("my-resource", "mykey", "pfx", ctx); + res.save("resource", false, false, null, null, null, ctx); + res.update("my-resource", "mykey", null, "pfx", ctx); + } + +} diff --git a/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestOperationalResource.java b/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestOperationalResource.java new file mode 100644 index 00000000..f5725e97 --- /dev/null +++ b/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestOperationalResource.java @@ -0,0 +1,29 @@ +package org.onap.ccsdk.sli.adaptors.resource.mdsal; + +import static org.mockito.Mockito.mock; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +import junit.framework.TestCase; + +public class TestOperationalResource extends TestCase { + + + public void test() throws Exception { + + RestService restService = mock(RestService.class); + SvcLogicContext ctx = new SvcLogicContext(); + + OperationalResource res = new OperationalResource(restService); + + res.delete("my-resource", null, ctx); + res.notify("my-resource", "action", "key", ctx); + res.query("my-resource", false, "my-select", "mykey", "pfx", null, ctx); + res.release("my-resource", "mykey", ctx); + res.reserve("my-resource", "my-select", "mykey", "pfx", ctx); + res.exists("my-resource", "mykey", "pfx", ctx); + res.isAvailable("my-resource", "mykey", "pfx", ctx); + res.save("resource", false, false, null, null, null, ctx); + res.update("my-resource", "mykey", null, "pfx", ctx); + } +} diff --git a/resource-assignment/features/src/main/resources/features.xml b/resource-assignment/features/src/main/resources/features.xml index ca1126d3..c9161a63 100644 --- a/resource-assignment/features/src/main/resources/features.xml +++ b/resource-assignment/features/src/main/resources/features.xml @@ -33,7 +33,7 @@ spring spring-jdbc spring-dm - mvn:org.onap.ccsdk.sli.adaptors/resource-assignment-provider/${project.version} + mvn:org.onap.ccsdk.sli.adaptors/resource-assignment-provider/${project.version} mvn:org.mariadb.jdbc/mariadb-java-client/${mariadb.connector.version} mvn:commons-lang/commons-lang/2.6 -- cgit 1.2.3-korg