From 1cb7623802f69bdf23dd285d67bd662f94d9f2d3 Mon Sep 17 00:00:00 2001 From: surya-huawei Date: Thu, 28 Sep 2017 17:59:53 +0530 Subject: Add a unit test for mdsal *Add a negative unit test case for ConfigResource This is to check availability of query and improve sonar code coverage Issue-Id: CCSDK-106 Change-Id: Ic276d1cfacce3aea7444adcb7bf09d6cdffb294e Signed-off-by: surya-huawei --- .../resource/mdsal/ConfigResourceTest.java | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResourceTest.java (limited to 'mdsal-resource/provider/src/test/java/org') diff --git a/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResourceTest.java b/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResourceTest.java new file mode 100644 index 000000000..f5b0bcf0c --- /dev/null +++ b/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResourceTest.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.resource.mdsal; + +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; + +import static org.junit.Assert.assertEquals; + +public class ConfigResourceTest { + ConfigResource configResource = new ConfigResource("http", "local", + "10001", "admin", + "password"); + + @Test + public void isAvailableNegativeTest() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + assertEquals(QueryStatus.NOT_FOUND, configResource.isAvailable + ("xyz", "key", "prefix", ctx)); + } +} + -- cgit 1.2.3-korg 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 (limited to 'mdsal-resource/provider/src/test/java/org') diff --git a/mdsal-resource/provider/pom.xml b/mdsal-resource/provider/pom.xml index 5a61d7624..ee0a3dc14 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 9cade887b..d02530fe6 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 92a7b6be0..63fe8c6ad 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 000000000..a8f4d9483 --- /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 000000000..f5725e971 --- /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 ca1126d37..c9161a635 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 From a55115b004330a638cdf3b2a93abbe04ed9be2cc Mon Sep 17 00:00:00 2001 From: Ganesh Chandrasekaran Date: Fri, 7 Sep 2018 15:02:53 +0900 Subject: Mdsal properties test case added Issue-ID: CCSDK-521 Change-Id: Ic71469cdcbacb2253e45091c29d893e025fd398b Signed-off-by: Ganesh Chandrasekaran --- .../TestMdsalResourcePropertiesProviderImpl.java | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourcePropertiesProviderImpl.java (limited to 'mdsal-resource/provider/src/test/java/org') diff --git a/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourcePropertiesProviderImpl.java b/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourcePropertiesProviderImpl.java new file mode 100644 index 000000000..9af5b59b3 --- /dev/null +++ b/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourcePropertiesProviderImpl.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2018 Samsung. 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.adaptors.resource.mdsal; + +import org.junit.Before; +import org.junit.Test; + +import java.util.Properties; + +import static org.junit.Assert.assertEquals; + +public class TestMdsalResourcePropertiesProviderImpl { + + MdsalResourcePropertiesProviderImpl mdsal; + + @Before + public void setup() { + mdsal = new MdsalResourcePropertiesProviderImpl(); + } + + + @Test + public void testGetProperties() { + Properties prop = mdsal.getProperties(); + + System.out.println("All Default Properties : " + prop); + + assertEquals("localhost",prop.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-host")); + assertEquals("Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U",prop.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-passwd")); + assertEquals("http",prop.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-protocol")); + assertEquals("8181",prop.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-port")); + assertEquals("admin",prop.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-user")); + } + + + @Test + public void testGetPropertie() throws IllegalStateException, IllegalArgumentException { + MdsalResourcePropertiesProviderImpl test = new MdsalResourcePropertiesProviderImpl(); + + mdsal.determinePropertiesFile(test); + + } +} -- cgit 1.2.3-korg From fc5c5f80898cc3e5c06c1596c34d9e210710dc29 Mon Sep 17 00:00:00 2001 From: Ganesh Chandrasekaran Date: Fri, 7 Sep 2018 15:22:05 +0900 Subject: Mdsal resource activator coverage Issue-ID: CCSDK-521 Change-Id: I88534c476337fbfbeb66a542780a3474a982f219 Signed-off-by: Ganesh Chandrasekaran --- .../resource/mdsal/TestMdsalResourceActivator.java | 328 +++++++++++++++++++++ 1 file changed, 328 insertions(+) create mode 100644 mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourceActivator.java (limited to 'mdsal-resource/provider/src/test/java/org') diff --git a/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourceActivator.java b/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourceActivator.java new file mode 100644 index 000000000..397915d08 --- /dev/null +++ b/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourceActivator.java @@ -0,0 +1,328 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2018 Samsung. 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.adaptors.resource.mdsal; + +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.osgi.framework.BundleListener; +import org.osgi.framework.Filter; +import org.osgi.framework.FrameworkListener; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceListener; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; + +import org.onap.ccsdk.sli.core.sli.ConfigurationException; +import java.io.File; +import java.io.InputStream; +import java.util.Collection; +import java.util.Dictionary; + +public class TestMdsalResourceActivator { + + MdsalResourceActivator mdsal; + + @Before + public void setup() { + mdsal = new MdsalResourceActivator(); + } + + + @Test (expected = ConfigurationException.class) + public void testStartResource() throws Exception { + BundleContext ctx = new BundleContext() { + @Override + public String getProperty(String key) { + return null; + } + + @Override + public Bundle getBundle() { + return null; + } + + @Override + public Bundle installBundle(String location, InputStream input) throws BundleException { + return null; + } + + @Override + public Bundle installBundle(String location) throws BundleException { + return null; + } + + @Override + public Bundle getBundle(long id) { + return null; + } + + @Override + public Bundle[] getBundles() { + return new Bundle[0]; + } + + @Override + public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException { + + } + + @Override + public void addServiceListener(ServiceListener listener) { + + } + + @Override + public void removeServiceListener(ServiceListener listener) { + + } + + @Override + public void addBundleListener(BundleListener listener) { + + } + + @Override + public void removeBundleListener(BundleListener listener) { + + } + + @Override + public void addFrameworkListener(FrameworkListener listener) { + + } + + @Override + public void removeFrameworkListener(FrameworkListener listener) { + + } + + @Override + public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties) { + return null; + } + + @Override + public ServiceRegistration registerService(String clazz, Object service, Dictionary properties) { + return null; + } + + @Override + public ServiceRegistration registerService(Class clazz, S service, Dictionary properties) { + return null; + } + + @Override + public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException { + return new ServiceReference[0]; + } + + @Override + public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException { + return new ServiceReference[0]; + } + + @Override + public ServiceReference getServiceReference(String clazz) { + return null; + } + + @Override + public ServiceReference getServiceReference(Class clazz) { + return null; + } + + @Override + public Collection> getServiceReferences(Class clazz, String filter) throws InvalidSyntaxException { + return null; + } + + @Override + public S getService(ServiceReference reference) { + return null; + } + + @Override + public boolean ungetService(ServiceReference reference) { + return false; + } + + @Override + public File getDataFile(String filename) { + return null; + } + + @Override + public Filter createFilter(String filter) throws InvalidSyntaxException { + return null; + } + + @Override + public Bundle getBundle(String location) { + return null; + } + }; + + mdsal.start(ctx); + + } + + @Test + public void testStopResource() throws Exception { + BundleContext ctx = new BundleContext() { + @Override + public String getProperty(String key) { + return null; + } + + @Override + public Bundle getBundle() { + return null; + } + + @Override + public Bundle installBundle(String location, InputStream input) throws BundleException { + return null; + } + + @Override + public Bundle installBundle(String location) throws BundleException { + return null; + } + + @Override + public Bundle getBundle(long id) { + return null; + } + + @Override + public Bundle[] getBundles() { + return new Bundle[0]; + } + + @Override + public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException { + + } + + @Override + public void addServiceListener(ServiceListener listener) { + + } + + @Override + public void removeServiceListener(ServiceListener listener) { + + } + + @Override + public void addBundleListener(BundleListener listener) { + + } + + @Override + public void removeBundleListener(BundleListener listener) { + + } + + @Override + public void addFrameworkListener(FrameworkListener listener) { + + } + + @Override + public void removeFrameworkListener(FrameworkListener listener) { + + } + + @Override + public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties) { + return null; + } + + @Override + public ServiceRegistration registerService(String clazz, Object service, Dictionary properties) { + return null; + } + + @Override + public ServiceRegistration registerService(Class clazz, S service, Dictionary properties) { + return null; + } + + @Override + public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException { + return new ServiceReference[0]; + } + + @Override + public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException { + return new ServiceReference[0]; + } + + @Override + public ServiceReference getServiceReference(String clazz) { + return null; + } + + @Override + public ServiceReference getServiceReference(Class clazz) { + return null; + } + + @Override + public Collection> getServiceReferences(Class clazz, String filter) throws InvalidSyntaxException { + return null; + } + + @Override + public S getService(ServiceReference reference) { + return null; + } + + @Override + public boolean ungetService(ServiceReference reference) { + return false; + } + + @Override + public File getDataFile(String filename) { + return null; + } + + @Override + public Filter createFilter(String filter) throws InvalidSyntaxException { + return null; + } + + @Override + public Bundle getBundle(String location) { + return null; + } + }; + + mdsal.stop(ctx); + + } +} -- cgit 1.2.3-korg From a19d05b4c780b5fbedf9724a60fa82786924901a Mon Sep 17 00:00:00 2001 From: Rupinder Date: Wed, 27 May 2020 15:11:12 +0530 Subject: added assert statements in 7 test files Issue-ID: CCSDK-2232 Change-Id: I07e3806cac9a317130ad1d5fe4c9af4fb1a17a5d Signed-off-by: Rupinder --- .../test/java/org/onap/ccsdk/sli/adaptors/aai/RegressionTest.java | 5 +++++ .../onap/ccsdk/sli/adaptors/resource/mdsal/TestConfigResource.java | 2 ++ .../resource/mdsal/TestMdsalResourcePropertiesProviderImpl.java | 2 ++ .../ccsdk/sli/adaptors/resource/mdsal/TestOperationalResource.java | 2 ++ .../consumer/provider/impl/AbstractBaseConsumerTest.java | 1 + .../java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestLockHelper.java | 2 ++ .../test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java | 5 +++++ 7 files changed, 19 insertions(+) (limited to 'mdsal-resource/provider/src/test/java/org') diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RegressionTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RegressionTest.java index 0e81e5b52..eb8dbc4a8 100755 --- a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RegressionTest.java +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RegressionTest.java @@ -121,6 +121,7 @@ public class RegressionTest { QueryStatus resp = client.save("connector", false, false, "resource-instance-id = '12345'", data, "aaidata", ctx); LOG.info("AAIResponse: " + resp.toString()); + assertNotNull(ctx); } catch (Exception e) { @@ -158,6 +159,7 @@ public class RegressionTest { QueryStatus resp = client.save("connector", false, false, "resource-instance-id = '11012345'", data, "aaidata", ctx); LOG.info("AAIResponse: " + resp.toString()); + assertNotNull(ctx); } catch (Exception e) { @@ -210,6 +212,7 @@ public class RegressionTest { QueryStatus resp = client.save("logical-link", false, false, "link-name = '1252541'", data, "aaidata", ctx); LOG.info("AAIResponse: " + resp.toString()); + assertNotNull(data); } catch (Exception e) { @@ -241,6 +244,7 @@ public class RegressionTest { QueryStatus resp = client.save("virtual-data-center", false, false, "vdc-id = '1252541'", data, "aaidata", ctx); LOG.info("AAIResponse: " + resp.toString()); + assertNotNull(data); } catch (Exception e) { @@ -408,6 +412,7 @@ public class RegressionTest { // assertTrue(response == QueryStatus.SUCCESS); LOG.info("AAIResponse: " + datum.toString()); + assertNotNull(nameValues); } catch (Exception e) { 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 index a8f4d9483..80563b96b 100644 --- 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 @@ -5,6 +5,7 @@ import junit.framework.TestCase; import static org.mockito.Mockito.mock; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import static org.junit.Assert.assertNotNull; public class TestConfigResource extends TestCase { @@ -24,6 +25,7 @@ public class TestConfigResource extends TestCase { res.isAvailable("my-resource", "mykey", "pfx", ctx); res.save("resource", false, false, null, null, null, ctx); res.update("my-resource", "mykey", null, "pfx", ctx); + assertNotNull(res); } } diff --git a/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourcePropertiesProviderImpl.java b/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourcePropertiesProviderImpl.java index 9af5b59b3..7f05d1e5f 100644 --- a/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourcePropertiesProviderImpl.java +++ b/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourcePropertiesProviderImpl.java @@ -27,6 +27,7 @@ import org.junit.Test; import java.util.Properties; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; public class TestMdsalResourcePropertiesProviderImpl { @@ -57,6 +58,7 @@ public class TestMdsalResourcePropertiesProviderImpl { MdsalResourcePropertiesProviderImpl test = new MdsalResourcePropertiesProviderImpl(); mdsal.determinePropertiesFile(test); + assertNotNull(test); } } 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 index f5725e971..2e9798df1 100644 --- 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 @@ -5,6 +5,7 @@ import static org.mockito.Mockito.mock; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import junit.framework.TestCase; +import static org.junit.Assert.assertNotNull; public class TestOperationalResource extends TestCase { @@ -25,5 +26,6 @@ public class TestOperationalResource extends TestCase { res.isAvailable("my-resource", "mykey", "pfx", ctx); res.save("resource", false, false, null, null, null, ctx); res.update("my-resource", "mykey", null, "pfx", ctx); + assertNotNull(restService); } } diff --git a/message-router/consumer/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/consumer/provider/impl/AbstractBaseConsumerTest.java b/message-router/consumer/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/consumer/provider/impl/AbstractBaseConsumerTest.java index 99a4f3ff7..75873385b 100644 --- a/message-router/consumer/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/consumer/provider/impl/AbstractBaseConsumerTest.java +++ b/message-router/consumer/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/consumer/provider/impl/AbstractBaseConsumerTest.java @@ -58,6 +58,7 @@ public class AbstractBaseConsumerTest { public void callClose() throws Exception { DummyConsumer dummy = getAuthDummy(); dummy.close(); + assertNotNull(dummy); } @Test diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestLockHelper.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestLockHelper.java index 6564dc3d1..a9389b279 100644 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestLockHelper.java +++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestLockHelper.java @@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:test-context.xml" }) @@ -34,6 +35,7 @@ public class TestLockHelper { t1.join(); t2.join(); t3.join(); + assertNotNull(t1); } private class LockThread extends Thread { diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java index f42ef9c3a..b159127b8 100644 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java +++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java @@ -28,6 +28,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestTable; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:test-context.xml" }) @@ -231,6 +232,7 @@ public class TestReserve { rsList.forEach(r -> { StrUtil.info(log, r); }); + assertNotNull(rsList); } @@ -269,6 +271,7 @@ public class TestReserve { rsList.forEach(r -> { StrUtil.info(log, r); }); + assertNotNull(sd); } @@ -316,6 +319,7 @@ public class TestReserve { rsList.forEach(r -> { StrUtil.info(log, r); }); + assertNotNull(rr); } @@ -478,6 +482,7 @@ public class TestReserve { rsList.forEach(r -> { StrUtil.info(log, r); }); + assertNotNull(rsList); } -- cgit 1.2.3-korg From 6fb8dfad11c84c0833e842183ec43a4ee95e81de Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Tue, 14 Jul 2020 08:55:33 -0400 Subject: Update adaptors to sodium Update sli/adaptors to OpenDaylight Sodium release. 2 changes were needed: - mdsal-resource : needed to add unimplemented abstract methods in inner anonymous BundleContext class in test case. - resource-assignment: needed to correct unit test problems that were ignored in earlier versions of h2 Change-Id: Ice63bfce64768e46c4376db55e3e9e97d0b934ad Issue-ID: CCSDK-2551 Signed-off-by: Dan Timoney --- .gitignore | 1 + .../adaptors/aai/AAIClientRESTExecutorTest.java | 3 ++ features/ccsdk-ansible-adapter/pom.xml | 6 +++ features/ccsdk-saltstack-adapter/pom.xml | 10 ++++- .../resource/mdsal/TestMdsalResourceActivator.java | 49 ++++++++++++++++++---- .../onap/ccsdk/sli/adaptors/ra/TestReserve.java | 8 ++++ .../provider/src/test/resources/sql/schema.sql | 2 +- 7 files changed, 69 insertions(+), 10 deletions(-) (limited to 'mdsal-resource/provider/src/test/java/org') diff --git a/.gitignore b/.gitignore index cc576b7b2..42cca13bb 100755 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ classes out/ .DS_STORE .metadata +.vscode provider/src/main/java/META-INF/ provider/src/main/java/inventory/ logs/ diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutorTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutorTest.java index b0272f5d0..f60b2da64 100644 --- a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutorTest.java +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutorTest.java @@ -11,6 +11,8 @@ import static org.junit.Assert.assertNotNull; public class AAIClientRESTExecutorTest { private static AAIClientRESTExecutor aaiExecute; + private static AAIService aaiService; + @BeforeClass public static void setUpBeforeClass() throws Exception { Properties properties = new Properties(); @@ -22,6 +24,7 @@ public class AAIClientRESTExecutorTest { properties.setProperty("connection.timeout", "60000"); properties.setProperty("read.timeout", "60000"); aaiExecute = new AAIClientRESTExecutor(properties); + aaiService = new AAIService(properties); } diff --git a/features/ccsdk-ansible-adapter/pom.xml b/features/ccsdk-ansible-adapter/pom.xml index 32ec5058f..da497f56f 100644 --- a/features/ccsdk-ansible-adapter/pom.xml +++ b/features/ccsdk-ansible-adapter/pom.xml @@ -36,6 +36,12 @@ ${project.groupId} ansible-adapter-bundle ${project.version} + + + powermock-api-mockito + org.powermock + + diff --git a/features/ccsdk-saltstack-adapter/pom.xml b/features/ccsdk-saltstack-adapter/pom.xml index ffc43e152..2e51c83be 100644 --- a/features/ccsdk-saltstack-adapter/pom.xml +++ b/features/ccsdk-saltstack-adapter/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 @@ -33,6 +34,13 @@ ${project.groupId} saltstack-adapter-provider ${project.version} + + + + powermock-api-mockito + org.powermock + + diff --git a/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourceActivator.java b/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourceActivator.java index 397915d08..6174bc84d 100644 --- a/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourceActivator.java +++ b/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourceActivator.java @@ -30,7 +30,9 @@ import org.osgi.framework.BundleListener; import org.osgi.framework.Filter; import org.osgi.framework.FrameworkListener; import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceFactory; import org.osgi.framework.ServiceListener; +import org.osgi.framework.ServiceObjects; import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; @@ -49,8 +51,7 @@ public class TestMdsalResourceActivator { mdsal = new MdsalResourceActivator(); } - - @Test (expected = ConfigurationException.class) + @Test(expected = ConfigurationException.class) public void testStartResource() throws Exception { BundleContext ctx = new BundleContext() { @Override @@ -119,27 +120,32 @@ public class TestMdsalResourceActivator { } @Override - public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties) { + public ServiceRegistration registerService(String[] clazzes, Object service, + Dictionary properties) { return null; } @Override - public ServiceRegistration registerService(String clazz, Object service, Dictionary properties) { + public ServiceRegistration registerService(String clazz, Object service, + Dictionary properties) { return null; } @Override - public ServiceRegistration registerService(Class clazz, S service, Dictionary properties) { + public ServiceRegistration registerService(Class clazz, S service, + Dictionary properties) { return null; } @Override - public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException { + public ServiceReference[] getServiceReferences(String clazz, String filter) + throws InvalidSyntaxException { return new ServiceReference[0]; } @Override - public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException { + public ServiceReference[] getAllServiceReferences(String clazz, String filter) + throws InvalidSyntaxException { return new ServiceReference[0]; } @@ -154,7 +160,8 @@ public class TestMdsalResourceActivator { } @Override - public Collection> getServiceReferences(Class clazz, String filter) throws InvalidSyntaxException { + public Collection> getServiceReferences(Class clazz, String filter) + throws InvalidSyntaxException { return null; } @@ -182,6 +189,19 @@ public class TestMdsalResourceActivator { public Bundle getBundle(String location) { return null; } + + @Override + public ServiceRegistration registerService(Class clazz, ServiceFactory factory, + Dictionary properties) { + // TODO Auto-generated method stub + return null; + } + + @Override + public ServiceObjects getServiceObjects(ServiceReference reference) { + // TODO Auto-generated method stub + return null; + } }; mdsal.start(ctx); @@ -320,6 +340,19 @@ public class TestMdsalResourceActivator { public Bundle getBundle(String location) { return null; } + + @Override + public ServiceRegistration registerService(Class clazz, ServiceFactory factory, + Dictionary properties) { + // TODO Auto-generated method stub + return null; + } + + @Override + public ServiceObjects getServiceObjects(ServiceReference reference) { + // TODO Auto-generated method stub + return null; + } }; mdsal.stop(ctx); diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java index ab2d936cf..dbf0c4aac 100644 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java +++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java @@ -216,6 +216,7 @@ public class TestReserve { rr.requestType = "New"; rr.rangeMaxOverride = -1; rr.rangeMinOverride = -1; + rr.applicationId = "myapp"; List rsList = new ArrayList<>(); @@ -513,6 +514,7 @@ public class TestReserve { rr.endPointPosition = "VPE-Cust"; rr.rangeMaxOverride = -1; rr.rangeMinOverride = -1; + rr.applicationId = "myapp"; List rsList = new ArrayList<>(); resourceAllocator.reserve(sd, rt, rr, rsList); @@ -533,6 +535,7 @@ public class TestReserve { rr.endPointPosition = "VPE-Core1"; rr.rangeMaxOverride = -1; rr.rangeMinOverride = -1; + rr.applicationId = "myapp"; rsList = new ArrayList<>(); resourceAllocator.reserve(sd, rt, rr, rsList); @@ -553,6 +556,7 @@ public class TestReserve { rr.endPointPosition = "VPE-Core2"; rr.rangeMaxOverride = -1; rr.rangeMinOverride = -1; + rr.applicationId = "myapp"; rsList = new ArrayList<>(); resourceAllocator.reserve(sd, rt, rr, rsList); @@ -573,6 +577,7 @@ public class TestReserve { rr.endPointPosition = "VPE-Core3"; rr.rangeMaxOverride = -1; rr.rangeMinOverride = -1; + rr.applicationId = "myapp"; rsList = new ArrayList<>(); resourceAllocator.reserve(sd, rt, rr, rsList); @@ -720,6 +725,7 @@ public class TestReserve { rr.rangeMaxOverride = 3901; rr.rangeMinOverride = 3900; rr.resourceType = ResourceType.Range; + rr.applicationId = "myapp"; List rsList = new ArrayList<>(); resourceAllocator.reserve(sd, rt, rr, rsList); @@ -748,6 +754,7 @@ public class TestReserve { rr.rangeMinOverride = -1; rr.rangeOverrideList = Arrays.asList(range); rr.resourceType = ResourceType.Range; + rr.applicationId = "myapp"; rsList = new ArrayList<>(); resourceAllocator.reserve(sd, rt, rr, rsList); @@ -781,6 +788,7 @@ public class TestReserve { rr.rangeOverrideList = new ArrayList<>(); rr.rangeOverrideList.add(range1); rr.rangeOverrideList.add(range2); + rr.applicationId = "myapp"; rr.resourceType = ResourceType.Range; rsList = new ArrayList<>(); diff --git a/resource-assignment/provider/src/test/resources/sql/schema.sql b/resource-assignment/provider/src/test/resources/sql/schema.sql index ed123ddd6..275337e44 100644 --- a/resource-assignment/provider/src/test/resources/sql/schema.sql +++ b/resource-assignment/provider/src/test/resources/sql/schema.sql @@ -124,7 +124,7 @@ CREATE TABLE SERVICE_RESOURCE ( service_status VARCHAR(10) NOT NULL, service_change_number SMALLINT NOT NULL, resource_set_id VARCHAR(100) NOT NULL, - resource_union_id VARCHAR(100) NOT NULL, + resource_union_id VARCHAR(100) NOT NULL ); ALTER TABLE SERVICE_RESOURCE ADD CONSTRAINT C1_SERVICE_RESOURCE CHECK (service_status IN ('Active', 'Pending')); -- cgit 1.2.3-korg From 684ff7064739851f66483df77d6578966ee4b6a3 Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Mon, 19 Oct 2020 10:11:15 -0400 Subject: Address security issues Removed unused Mdsal activator class. Added file name validation for ConnectionBuilder in ansible adaptor Change-Id: I00d6a0c1edccae263520738f7a4685b1ad71b943 Issue-ID: CCSDK-2918 Signed-off-by: Dan Timoney --- .../adaptors/ansible/impl/ConnectionBuilder.java | 6 + .../resource/mdsal/MdsalResourceActivator.java | 108 ------ .../resource/mdsal/TestMdsalResourceActivator.java | 361 --------------------- 3 files changed, 6 insertions(+), 469 deletions(-) delete mode 100644 mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourceActivator.java delete mode 100644 mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourceActivator.java (limited to 'mdsal-resource/provider/src/test/java/org') diff --git a/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/ConnectionBuilder.java b/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/ConnectionBuilder.java index 6295a2557..672e0df67 100644 --- a/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/ConnectionBuilder.java +++ b/ansible-adapter/ansible-adapter-bundle/src/main/java/org/onap/ccsdk/sli/adaptors/ansible/impl/ConnectionBuilder.java @@ -53,6 +53,8 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResult; import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResultCodes; +import org.onap.ccsdk.sli.core.utils.PathValidator; + import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; @@ -104,6 +106,10 @@ public class ConnectionBuilder { public ConnectionBuilder(String trustStoreFile, char[] trustStorePasswd) throws KeyStoreException, IOException, KeyManagementException, NoSuchAlgorithmException, CertificateException { + if (!PathValidator.isValidFilePath(trustStoreFile)) { + throw new IOException("Invalid trust store file path"); + } + /* Load the specified trustStore */ KeyStore keystore = KeyStore.getInstance("JKS"); FileInputStream readStream = new FileInputStream(trustStoreFile); diff --git a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourceActivator.java b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourceActivator.java deleted file mode 100644 index 53ed65725..000000000 --- a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourceActivator.java +++ /dev/null @@ -1,108 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Modifications Copyright (C) 2018 IBM. - * ================================================================================ - * 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.adaptors.resource.mdsal; - -import java.io.File; -import java.io.FileInputStream; -import java.util.LinkedList; -import java.util.Properties; - -import org.onap.ccsdk.sli.core.sli.ConfigurationException; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class MdsalResourceActivator implements BundleActivator { - - - - private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; - - public LinkedList registrations = new LinkedList<>(); - - private static final Logger LOG = LoggerFactory - .getLogger(MdsalResourceActivator.class); - - @Override - public void start(BundleContext ctx) throws Exception { - - // Read properties - Properties props = new Properties(); - - String propDir = System.getenv(SDNC_CONFIG_DIR); - if (propDir == null) { - - propDir = "/opt/sdnc/data/properties"; - } - String propPath = propDir + "/mdsal-resource.properties"; - - - File propFile = new File(propPath); - - if (!propFile.exists()) { - - throw new ConfigurationException( - "Missing configuration properties file : " - + propFile); - } - try { - - props.load(new FileInputStream(propFile)); - } catch (Exception e) { - throw new ConfigurationException( - "Could not load properties file " + propPath, e); - - } - - String sdncUser = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-user", "admin"); - String sdncPasswd = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-passwd", "admin"); - String sdncHost = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-host", "localhost"); - String sdncProtocol = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-protocol", "https"); - String sdncPort = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-port", "8443"); - - // Advertise MD-SAL resource adaptors - SvcLogicResource impl = new ConfigResource(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd); - - LOG.debug("Registering MdsalResource service "+impl.getClass().getName()); - registrations.add(ctx.registerService(impl.getClass().getName(), impl, null)); - - impl = new OperationalResource(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd); - - LOG.debug("Registering MdsalResource service "+impl.getClass().getName()); - registrations.add(ctx.registerService(impl.getClass().getName(), impl, null)); - } - - @Override - public void stop(BundleContext ctx) throws Exception { - - for (ServiceRegistration registration : registrations) - { - registration.unregister(); - } - } - -} diff --git a/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourceActivator.java b/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourceActivator.java deleted file mode 100644 index 6174bc84d..000000000 --- a/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestMdsalResourceActivator.java +++ /dev/null @@ -1,361 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2018 Samsung. 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.adaptors.resource.mdsal; - -import org.junit.Before; -import org.junit.Test; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; -import org.osgi.framework.BundleListener; -import org.osgi.framework.Filter; -import org.osgi.framework.FrameworkListener; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceFactory; -import org.osgi.framework.ServiceListener; -import org.osgi.framework.ServiceObjects; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; - -import org.onap.ccsdk.sli.core.sli.ConfigurationException; -import java.io.File; -import java.io.InputStream; -import java.util.Collection; -import java.util.Dictionary; - -public class TestMdsalResourceActivator { - - MdsalResourceActivator mdsal; - - @Before - public void setup() { - mdsal = new MdsalResourceActivator(); - } - - @Test(expected = ConfigurationException.class) - public void testStartResource() throws Exception { - BundleContext ctx = new BundleContext() { - @Override - public String getProperty(String key) { - return null; - } - - @Override - public Bundle getBundle() { - return null; - } - - @Override - public Bundle installBundle(String location, InputStream input) throws BundleException { - return null; - } - - @Override - public Bundle installBundle(String location) throws BundleException { - return null; - } - - @Override - public Bundle getBundle(long id) { - return null; - } - - @Override - public Bundle[] getBundles() { - return new Bundle[0]; - } - - @Override - public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException { - - } - - @Override - public void addServiceListener(ServiceListener listener) { - - } - - @Override - public void removeServiceListener(ServiceListener listener) { - - } - - @Override - public void addBundleListener(BundleListener listener) { - - } - - @Override - public void removeBundleListener(BundleListener listener) { - - } - - @Override - public void addFrameworkListener(FrameworkListener listener) { - - } - - @Override - public void removeFrameworkListener(FrameworkListener listener) { - - } - - @Override - public ServiceRegistration registerService(String[] clazzes, Object service, - Dictionary properties) { - return null; - } - - @Override - public ServiceRegistration registerService(String clazz, Object service, - Dictionary properties) { - return null; - } - - @Override - public ServiceRegistration registerService(Class clazz, S service, - Dictionary properties) { - return null; - } - - @Override - public ServiceReference[] getServiceReferences(String clazz, String filter) - throws InvalidSyntaxException { - return new ServiceReference[0]; - } - - @Override - public ServiceReference[] getAllServiceReferences(String clazz, String filter) - throws InvalidSyntaxException { - return new ServiceReference[0]; - } - - @Override - public ServiceReference getServiceReference(String clazz) { - return null; - } - - @Override - public ServiceReference getServiceReference(Class clazz) { - return null; - } - - @Override - public Collection> getServiceReferences(Class clazz, String filter) - throws InvalidSyntaxException { - return null; - } - - @Override - public S getService(ServiceReference reference) { - return null; - } - - @Override - public boolean ungetService(ServiceReference reference) { - return false; - } - - @Override - public File getDataFile(String filename) { - return null; - } - - @Override - public Filter createFilter(String filter) throws InvalidSyntaxException { - return null; - } - - @Override - public Bundle getBundle(String location) { - return null; - } - - @Override - public ServiceRegistration registerService(Class clazz, ServiceFactory factory, - Dictionary properties) { - // TODO Auto-generated method stub - return null; - } - - @Override - public ServiceObjects getServiceObjects(ServiceReference reference) { - // TODO Auto-generated method stub - return null; - } - }; - - mdsal.start(ctx); - - } - - @Test - public void testStopResource() throws Exception { - BundleContext ctx = new BundleContext() { - @Override - public String getProperty(String key) { - return null; - } - - @Override - public Bundle getBundle() { - return null; - } - - @Override - public Bundle installBundle(String location, InputStream input) throws BundleException { - return null; - } - - @Override - public Bundle installBundle(String location) throws BundleException { - return null; - } - - @Override - public Bundle getBundle(long id) { - return null; - } - - @Override - public Bundle[] getBundles() { - return new Bundle[0]; - } - - @Override - public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException { - - } - - @Override - public void addServiceListener(ServiceListener listener) { - - } - - @Override - public void removeServiceListener(ServiceListener listener) { - - } - - @Override - public void addBundleListener(BundleListener listener) { - - } - - @Override - public void removeBundleListener(BundleListener listener) { - - } - - @Override - public void addFrameworkListener(FrameworkListener listener) { - - } - - @Override - public void removeFrameworkListener(FrameworkListener listener) { - - } - - @Override - public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties) { - return null; - } - - @Override - public ServiceRegistration registerService(String clazz, Object service, Dictionary properties) { - return null; - } - - @Override - public ServiceRegistration registerService(Class clazz, S service, Dictionary properties) { - return null; - } - - @Override - public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException { - return new ServiceReference[0]; - } - - @Override - public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException { - return new ServiceReference[0]; - } - - @Override - public ServiceReference getServiceReference(String clazz) { - return null; - } - - @Override - public ServiceReference getServiceReference(Class clazz) { - return null; - } - - @Override - public Collection> getServiceReferences(Class clazz, String filter) throws InvalidSyntaxException { - return null; - } - - @Override - public S getService(ServiceReference reference) { - return null; - } - - @Override - public boolean ungetService(ServiceReference reference) { - return false; - } - - @Override - public File getDataFile(String filename) { - return null; - } - - @Override - public Filter createFilter(String filter) throws InvalidSyntaxException { - return null; - } - - @Override - public Bundle getBundle(String location) { - return null; - } - - @Override - public ServiceRegistration registerService(Class clazz, ServiceFactory factory, - Dictionary properties) { - // TODO Auto-generated method stub - return null; - } - - @Override - public ServiceObjects getServiceObjects(ServiceReference reference) { - // TODO Auto-generated method stub - return null; - } - }; - - mdsal.stop(ctx); - - } -} -- cgit 1.2.3-korg