summaryrefslogtreecommitdiffstats
path: root/lib/network-prioritization/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'lib/network-prioritization/src/test/java')
-rw-r--r--lib/network-prioritization/src/test/java/org/onap/ccsdk/features/lib/npm/api/NpmServiceCallbackHandler.java52
-rw-r--r--lib/network-prioritization/src/test/java/org/onap/ccsdk/features/lib/npm/api/NpmTransactionServiceTest.java114
-rw-r--r--lib/network-prioritization/src/test/java/org/onap/ccsdk/features/lib/npm/utils/NpmUtilTest.java44
3 files changed, 210 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());
+ }
+
+}