diff options
author | Sandeep Shah <sandeeplinux1068@gmail.com> | 2020-03-02 10:31:48 -0600 |
---|---|---|
committer | Sandeep Shah <sandeeplinux1068@gmail.com> | 2020-03-02 10:31:48 -0600 |
commit | 4fdab1fe391c2ecf3ea8bcb0fefb563ba8af042c (patch) | |
tree | 5f82e1a690f6600023a400ef899c49e47ea87016 /sdnr/northbound/CMNotify/provider/src/test | |
parent | c6f4d650f2652a30aa4d951459e294e37394c559 (diff) |
ORAN CMNotify Karaf Feature Development
CMNotify Karaf feature development as part of SDNR
meta-feature. This feature relates to receiving
VES message for nbrListChangeNotification via
DMAAP and making updates to RuntimeDB/ConfigDB
Issue-ID: CCSDK-2130
Signed-off-by: SandeepLinux <Sandeep.Shah@ibm.com>
Change-Id: Iad5f0bfe855986a202a264b50e1a0591c7015fce
Diffstat (limited to 'sdnr/northbound/CMNotify/provider/src/test')
2 files changed, 190 insertions, 0 deletions
diff --git a/sdnr/northbound/CMNotify/provider/src/test/java/org/onap/ccsdk/features/sdnr/northbound/CMNotify/CMNotifyClientTest.java b/sdnr/northbound/CMNotify/provider/src/test/java/org/onap/ccsdk/features/sdnr/northbound/CMNotify/CMNotifyClientTest.java new file mode 100644 index 000000000..06955838e --- /dev/null +++ b/sdnr/northbound/CMNotify/provider/src/test/java/org/onap/ccsdk/features/sdnr/northbound/CMNotify/CMNotifyClientTest.java @@ -0,0 +1,85 @@ +/*- + * ============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.features.sdnr.northbound.CMNotify; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import java.util.Properties; + +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService; + +import org.onap.ccsdk.features.sdnr.northbound.CMNotify.CMNotifyClient; + +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationInput; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationInputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationOutput; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationOutputBuilder; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CMNotifyClientTest { + + SvcLogicService mockSvcLogicService; + String module = "test-module"; + String rpc = "test-rpc"; + String version = "test-version"; + String mode = "test-mode"; + Properties localProp = new Properties(); + + @Before + public void setUp() throws Exception { + mockSvcLogicService = mock(SvcLogicService.class); + when(mockSvcLogicService.hasGraph(module, rpc, version, mode)).thenReturn(true); + } + + @Test + public void testCMNotifyClientConstructor() { + CMNotifyClient CMNotifyClient = new CMNotifyClient(mockSvcLogicService); + assertNotNull(CMNotifyClient); + } + + @Test + public void testHasGraph() throws SvcLogicException { + CMNotifyClient CMNotifyClient = new CMNotifyClient(mockSvcLogicService); + boolean result = CMNotifyClient.hasGraph(module, rpc, version, mode); + assertTrue(result); + } + + @Test + public void testExecuteSvcLogicStatusFailure() throws SvcLogicException { + NbrlistChangeNotificationOutputBuilder serviceData = mock(NbrlistChangeNotificationOutputBuilder.class); + Properties parms = mock(Properties.class); + SvcLogicService svcLogicService = mock(SvcLogicService.class); + Properties properties = new Properties(); + properties.setProperty("SvcLogic.status", "failure"); + when(svcLogicService.execute(module, rpc, version, mode, properties)).thenReturn(properties); + CMNotifyClient sliClient = new CMNotifyClient(svcLogicService); + Properties prop = sliClient.execute(module, rpc, version, mode, serviceData, properties); + assertTrue(prop != null); + } +} diff --git a/sdnr/northbound/CMNotify/provider/src/test/java/org/onap/ccsdk/features/sdnr/northbound/CMNotify/TestCMNotify.java b/sdnr/northbound/CMNotify/provider/src/test/java/org/onap/ccsdk/features/sdnr/northbound/CMNotify/TestCMNotify.java new file mode 100644 index 000000000..060d39949 --- /dev/null +++ b/sdnr/northbound/CMNotify/provider/src/test/java/org/onap/ccsdk/features/sdnr/northbound/CMNotify/TestCMNotify.java @@ -0,0 +1,105 @@ +/*- + * ============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.features.sdnr.northbound.CMNotify; + +import org.junit.Before; +import org.junit.Test; + +import org.onap.ccsdk.features.sdnr.northbound.CMNotify.CMNotifyClient; +import org.onap.ccsdk.features.sdnr.northbound.CMNotify.CMNotifyProvider; + +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; + +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; + +import java.math.*; + +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationInput; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationInputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationOutput; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationOutputBuilder; + +import com.google.common.util.concurrent.ListenableFuture; + + + +public class TestCMNotify extends AbstractConcurrentDataBrokerTest { + + private CMNotifyProvider cMNotifyProvider; + private static final Logger LOG = LoggerFactory.getLogger(CMNotifyProvider.class); + + @Before + public void setUp() throws Exception { + if (null == cMNotifyProvider) { + DataBroker dataBroker = getDataBroker(); + NotificationPublishService mockNotification = mock(NotificationPublishService.class); + RpcProviderRegistry mockRpcRegistry = mock(RpcProviderRegistry.class); + CMNotifyClient mockSliClient = mock(CMNotifyClient.class); + cMNotifyProvider = new CMNotifyProvider(dataBroker, mockNotification, mockRpcRegistry, mockSliClient); + } + } + + //Testcase should return error 503 when No service logic active for NbrlistChangeNotification + @Test + public void testNbrlistChangeNotification() { + + NbrlistChangeNotificationInputBuilder inputBuilder = new NbrlistChangeNotificationInputBuilder(); + + inputBuilder.setFapServiceNumberOfEntriesChanged(new BigInteger("1")); + + // TODO: currently initialize SvcLogicServiceClient is failing, need to fix + ListenableFuture<RpcResult<NbrlistChangeNotificationOutput>> future = cMNotifyProvider + .nbrlistChangeNotification(inputBuilder.build()); + RpcResult<NbrlistChangeNotificationOutput> rpcResult = null; + try { + rpcResult = future.get(); + } catch (Exception e) { + fail("Error : " + e); + } + LOG.info("result: {}", rpcResult); + assertEquals("503", rpcResult.getResult().getResponseCode()); + } + + //Input parameter validation + @Test + public void testvValidation() { + + ListenableFuture<RpcResult<NbrlistChangeNotificationOutput>> future = cMNotifyProvider + .nbrlistChangeNotification(null); + RpcResult<NbrlistChangeNotificationOutput> rpcResult = null; + try { + rpcResult = future.get(); + } catch (Exception e) { + fail("Error : " + e); + } + LOG.info("result: {}", rpcResult); + assertEquals("Input is null", rpcResult.getResult().getResponseCode()); + } +} |