From c8b3f59b0bc308e9b715ce88ac83d67959dc112d Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Mon, 10 May 2021 13:48:00 -0400 Subject: Adding network-prioritization-network Issue-ID: CCSDK-3292 Signed-off-by: Singal, Kapil (ks220y) Change-Id: I03fed97bd85040b62cd308d9c8166d9ed023efc6 --- .../lib/npm/api/NpmServiceCallbackHandler.java | 52 ++++++++++ .../lib/npm/api/NpmTransactionServiceTest.java | 114 +++++++++++++++++++++ .../ccsdk/features/lib/npm/utils/NpmUtilTest.java | 44 ++++++++ .../src/test/resources/log4j.xml | 36 +++++++ .../resources/properties/npm-config.properties | 11 ++ 5 files changed, 257 insertions(+) create mode 100644 lib/network-prioritization/src/test/java/org/onap/ccsdk/features/lib/npm/api/NpmServiceCallbackHandler.java create mode 100644 lib/network-prioritization/src/test/java/org/onap/ccsdk/features/lib/npm/api/NpmTransactionServiceTest.java create mode 100644 lib/network-prioritization/src/test/java/org/onap/ccsdk/features/lib/npm/utils/NpmUtilTest.java create mode 100644 lib/network-prioritization/src/test/resources/log4j.xml create mode 100644 lib/network-prioritization/src/test/resources/properties/npm-config.properties (limited to 'lib/network-prioritization/src/test') diff --git a/lib/network-prioritization/src/test/java/org/onap/ccsdk/features/lib/npm/api/NpmServiceCallbackHandler.java b/lib/network-prioritization/src/test/java/org/onap/ccsdk/features/lib/npm/api/NpmServiceCallbackHandler.java new file mode 100644 index 000000000..6682f8ed9 --- /dev/null +++ b/lib/network-prioritization/src/test/java/org/onap/ccsdk/features/lib/npm/api/NpmServiceCallbackHandler.java @@ -0,0 +1,52 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 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.lib.npm.api; + +import org.onap.ccsdk.features.lib.npm.models.NpmAck; +import org.onap.ccsdk.features.lib.npm.models.NpmTransaction; +import org.onap.ccsdk.features.lib.npm.utils.NpmUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class NpmServiceCallbackHandler implements NpmServiceCallbackApi { + private static final Logger logger = LoggerFactory.getLogger(NpmServiceCallbackApi.class); + + private final NpmTransactionService npmTransactionService; + + public NpmServiceCallbackHandler(NpmTransactionService npmTransactionService) { + this.npmTransactionService = npmTransactionService; + npmTransactionService.registerService("npmServiceCallbackHandler", this); + } + + @Override + public void process(NpmTransaction npmTransaction) { + logger.debug("Received NpmTransaction with npmTransactionId ({}) to process.", npmTransaction.getNpmTransactionId()); + logger.debug("NpmTransaction serviceRequest ({}).", NpmUtils.getJson(npmTransaction.getServiceRequest())); + removeTransactionsFromQueue(npmTransaction); + } + + private void removeTransactionsFromQueue(NpmTransaction npmTransaction) { + NpmAck npmAck = npmTransactionService.removeTransactionsFromQueue(npmTransaction); + logger.debug("Removed NpmTransaction with npmAck ({}) after processing.", npmAck); + } + +} diff --git a/lib/network-prioritization/src/test/java/org/onap/ccsdk/features/lib/npm/api/NpmTransactionServiceTest.java b/lib/network-prioritization/src/test/java/org/onap/ccsdk/features/lib/npm/api/NpmTransactionServiceTest.java new file mode 100644 index 000000000..ae7a9a6fc --- /dev/null +++ b/lib/network-prioritization/src/test/java/org/onap/ccsdk/features/lib/npm/api/NpmTransactionServiceTest.java @@ -0,0 +1,114 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 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.lib.npm.api; + +import org.junit.BeforeClass; +import org.onap.ccsdk.features.lib.npm.NpmConstants; +import org.onap.ccsdk.features.lib.npm.models.NpmAck; +import org.onap.ccsdk.features.lib.npm.models.NpmStatusEnum; +import org.onap.ccsdk.features.lib.npm.models.NpmTransaction; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +@RunWith(MockitoJUnitRunner.class) +public class NpmTransactionServiceTest { + + private static NpmTransactionServiceImpl npmTransactionService; + + private List npmTransactionList; + + @BeforeClass + public static void once() throws Exception { + System.setProperty(NpmConstants.SDNC_CONFIG_DIR, "src/test/resources/properties"); + npmTransactionService = new NpmTransactionServiceImpl(new NpmServiceManagerImpl()); + + npmTransactionService.registerService("npmServiceCallbackHandler", new NpmServiceCallbackHandler(npmTransactionService)); + } + + @Before + public void before() throws Exception { + + npmTransactionList = new ArrayList<>(); + npmTransactionList.add(npmTransactionService.formNpmTransaction(null, + "1.1.1.1", + "EMS_ERICSSON", + 0, + 1, + Instant.now(), + Instant.MAX, + "npmServiceCallbackHandler", + new ObjectMapper().readTree("{\"attr\": \"EMS_ERICSSON_1\"}"))); + npmTransactionList.add(npmTransactionService.formNpmTransaction(null, + "1.1.1.1", + "EMS_ERICSSON", + 0, + 1, + Instant.now(), + Instant.MAX, + "npmServiceCallbackHandler", + new ObjectMapper().readTree("{\"attr\": \"EMS_ERICSSON_2\"}"))); + + npmTransactionList.add(npmTransactionService.formNpmTransaction(null, + "2.2.2.2", + "EMS_NOKIA", + 0, + 1, + Instant.now(), + Instant.MAX, + "npmServiceCallbackHandler", + new ObjectMapper().readTree("{\"attr\": \"EMS_NOKIA_1\"}"))); + npmTransactionList.add(npmTransactionService.formNpmTransaction(null, + "2.2.2.2", + "EMS_NOKIA", + 0, + 1, + Instant.now(), + Instant.MAX, + "npmServiceCallbackHandler", + new ObjectMapper().readTree("{\"attr\": \"EMS_NOKIA_2\"}"))); + } + + @Test + public void addTransactionsToQueue_validTransaction() { + List npmAckList = npmTransactionService.addTransactionsToQueue(npmTransactionList); + assertEquals(npmTransactionList.size(), npmAckList.size()); + assertEquals(NpmStatusEnum.QUEUED, npmAckList.get(0).getStatus()); + assertEquals(NpmStatusEnum.QUEUED, npmAckList.get(1).getStatus()); + } + + @Test + public void addTransactionsToQueue_invalidTransaction() { + npmTransactionList.get(0).setServiceRequest(null); + NpmAck npmAck = npmTransactionService.addTransactionsToQueue(npmTransactionList.get(0)); + assertEquals(NpmStatusEnum.FAILED, npmAck.getStatus()); + } + +} \ No newline at end of file diff --git a/lib/network-prioritization/src/test/java/org/onap/ccsdk/features/lib/npm/utils/NpmUtilTest.java b/lib/network-prioritization/src/test/java/org/onap/ccsdk/features/lib/npm/utils/NpmUtilTest.java new file mode 100644 index 000000000..491984a18 --- /dev/null +++ b/lib/network-prioritization/src/test/java/org/onap/ccsdk/features/lib/npm/utils/NpmUtilTest.java @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 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.lib.npm.utils; + +import com.fasterxml.jackson.databind.JsonNode; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class NpmUtilTest { + + @Test + public void testGetListFromJsonString() { + String content = "{\"key\":\"value\"}"; + List jsonNodeForString = NpmUtils.getListFromJsonString(content, JsonNode.class); + assertEquals(1, jsonNodeForString.size()); + + content = "[{\"key\":\"value\"}, {\"key\":\"value2\"}]"; + jsonNodeForString = NpmUtils.getListFromJsonString(content, JsonNode.class); + assertEquals(2, jsonNodeForString.size()); + } + +} diff --git a/lib/network-prioritization/src/test/resources/log4j.xml b/lib/network-prioritization/src/test/resources/log4j.xml new file mode 100644 index 000000000..4289ba99f --- /dev/null +++ b/lib/network-prioritization/src/test/resources/log4j.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/network-prioritization/src/test/resources/properties/npm-config.properties b/lib/network-prioritization/src/test/resources/properties/npm-config.properties new file mode 100644 index 000000000..096d2d2ca --- /dev/null +++ b/lib/network-prioritization/src/test/resources/properties/npm-config.properties @@ -0,0 +1,11 @@ +Env_Type=solo +Priority_List=0,1,2 +Default_Priority=2 +EMS_ERICSSON=2 +EMS_NOKIA=2 +queue_capacity_0=10 +queue_capacity_1=7 +queue_capacity_2=5 +qsp_limit_0=5 +qsp_limit_1=3 +qsp_limit_2=2 -- cgit 1.2.3-korg