diff options
author | Singal, Kapil (ks220y) <ks220y@att.com> | 2021-05-10 13:48:00 -0400 |
---|---|---|
committer | Singal, Kapil (ks220y) <ks220y@att.com> | 2021-05-10 13:48:34 -0400 |
commit | c8b3f59b0bc308e9b715ce88ac83d67959dc112d (patch) | |
tree | 0434de5bd69e2e64c6e777c611182ad51e1a0353 /lib/network-prioritization/src/test | |
parent | 2c1f3727a703634cf62c63cfc4a3d4bb30fe2d9c (diff) |
Adding network-prioritization-network
Issue-ID: CCSDK-3292
Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
Change-Id: I03fed97bd85040b62cd308d9c8166d9ed023efc6
Diffstat (limited to 'lib/network-prioritization/src/test')
5 files changed, 257 insertions, 0 deletions
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<NpmTransaction> 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<NpmAck> 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<JsonNode> 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 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + ~ ============LICENSE_START======================================================= + ~ ONAP : ccsdk features + ~ ================================================================================ + ~ Update Copyright (C) 2021 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======================================================= + ~ + --> + +<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> + +<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> + <appender name="console" class="org.apache.log4j.ConsoleAppender"> + <param name="Target" value="System.out"/> + <layout class="org.apache.log4j.PatternLayout"> + <param name="ConversionPattern" value="%-5p %c{1} - %m%n"/> + </layout> + </appender> + <root> + <priority value="trace" /> + <appender-ref ref="console" /> + </root> +</log4j:configuration>
\ 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 |