From 32fb53c13342d5ad353c839b7ffd0ca85d14bd48 Mon Sep 17 00:00:00 2001 From: Jessica Wagantall Date: Tue, 1 Dec 2020 11:48:20 -0800 Subject: Migrate sli-core files Migrate sli-core repo files into new directory "core". Signed-off-by: Jessica Wagantall --- .../ccsdk/sli/core/sliapi/SliapiHelperTest.java | 35 ++++ .../ccsdk/sli/core/sliapi/TestSliapiProvider.java | 209 +++++++++++++++++++++ .../src/test/resources/simplelogger.properties | 23 +++ .../src/test/resources/sli_healthcheck.xml | 27 +++ .../src/test/resources/svclogic.properties | 27 +++ 5 files changed, 321 insertions(+) create mode 100644 core/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/SliapiHelperTest.java create mode 100644 core/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java create mode 100644 core/sliapi/provider/src/test/resources/simplelogger.properties create mode 100644 core/sliapi/provider/src/test/resources/sli_healthcheck.xml create mode 100644 core/sliapi/provider/src/test/resources/svclogic.properties (limited to 'core/sliapi/provider/src/test') diff --git a/core/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/SliapiHelperTest.java b/core/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/SliapiHelperTest.java new file mode 100644 index 000000000..228f6127e --- /dev/null +++ b/core/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/SliapiHelperTest.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 IBM. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sliapi; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +public class SliapiHelperTest { + + @Test + public void TestSliapiHelper() + { + SliapiHelper sliapiHelper= new SliapiHelper(); + assertNotNull(sliapiHelper); + } +} diff --git a/core/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java b/core/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java new file mode 100644 index 000000000..f48cf783b --- /dev/null +++ b/core/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java @@ -0,0 +1,209 @@ +/** + * + */ +package org.onap.ccsdk.sli.core.sliapi; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +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 java.util.concurrent.Future; +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.SvcLogicClassResolver; +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.base.AbstractSvcLogicNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.BlockNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.CallNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ConfigureNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.DeleteNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ExecuteNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ExistsNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ForNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.GetResourceNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.IsAvailableNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.NotifyNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.RecordNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ReleaseNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ReserveNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.ReturnNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.SaveNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.SetNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.SwitchNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.UpdateNodeExecutor; +import org.onap.ccsdk.sli.core.sli.provider.base.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.HealthcheckInput; +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.VlbcheckInput; +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(), + new SvcLogicClassResolver()); + 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 SliapiProvider#executeGraph(org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.ExecuteGraphInput)}. + */ + @Test + public void testExecuteGraph() { + ExecuteGraphInputBuilder inputBuilder = new ExecuteGraphInputBuilder(); + + // Valid test - graph exists + 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()); + pBuilder.setParameterName("bool-parameter"); + pBuilder.setIntValue(null); + pBuilder.setBooleanValue(true); + pList.add(pBuilder.build()); + pBuilder.setParameterName("str-parameter"); + pBuilder.setBooleanValue(null); + pBuilder.setStringValue("value"); + pList.add(pBuilder.build()); + inputBuilder.setSliParameter(pList); + provider.executeGraph(inputBuilder.build()); + + + // Invalid test - graph does not exist + inputBuilder.setMode(ExecuteGraphInput.Mode.Sync); + inputBuilder.setModuleName("sli"); + inputBuilder.setRpcName("no-such-graph"); + pList = new LinkedList<>(); + pBuilder = new SliParameterBuilder(); + pBuilder.setParameterName("int-parameter"); + pBuilder.setIntValue(1); + pList.add(pBuilder.build()); + pBuilder.setParameterName("bool-parameter"); + pBuilder.setIntValue(null); + pBuilder.setBooleanValue(true); + pList.add(pBuilder.build()); + pBuilder.setParameterName("str-parameter"); + pBuilder.setBooleanValue(null); + pBuilder.setStringValue("value"); + pList.add(pBuilder.build()); + inputBuilder.setSliParameter(pList); + provider.executeGraph(inputBuilder.build()); + + assertTrue(provider.vlbcheck(mock(VlbcheckInput.class)) instanceof Future); + } + + /** + * Test method for + * {@link SliapiProvider#healthcheck()}. + */ + @Test + public void testHealthcheck() { + provider.healthcheck(mock(HealthcheckInput.class)); + } + +} diff --git a/core/sliapi/provider/src/test/resources/simplelogger.properties b/core/sliapi/provider/src/test/resources/simplelogger.properties new file mode 100644 index 000000000..2f7d8ea0b --- /dev/null +++ b/core/sliapi/provider/src/test/resources/simplelogger.properties @@ -0,0 +1,23 @@ +### +# ============LICENSE_START======================================================= +# ONAP : CCSDK +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights +# reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +org.slf4j.simpleLogger.defaultLogLevel=info +org.slf4j.simplelogger.log.org.onap.ccsdk.sli.core.sliapi.SliapiProvider=debug diff --git a/core/sliapi/provider/src/test/resources/sli_healthcheck.xml b/core/sliapi/provider/src/test/resources/sli_healthcheck.xml new file mode 100644 index 000000000..d512f546f --- /dev/null +++ b/core/sliapi/provider/src/test/resources/sli_healthcheck.xml @@ -0,0 +1,27 @@ + + + + + + + + diff --git a/core/sliapi/provider/src/test/resources/svclogic.properties b/core/sliapi/provider/src/test/resources/svclogic.properties new file mode 100644 index 000000000..426960f76 --- /dev/null +++ b/core/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