From 7f2e4aa47f56085be6c95cb81b6a8bea8126d56d Mon Sep 17 00:00:00 2001 From: decheng zhang Date: Mon, 28 Feb 2022 11:15:20 -0500 Subject: Jakarta changes in slice-analysis-ms for IBN Cloud leased line update and CCVPN closed-loop. This commit contains work in sub-task: 1) AAI monitor thread; 2) bandwidth evaluator; 3) policy notification code. Issue-ID: DCAEGEN2-3063 Signed-off-by: decheng zhang Change-Id: I9029ffd7563e65be59f7fd76adc2a749ff624172 Signed-off-by: decheng zhang --- .../ms/dmaap/AaiEventNotificationCallbackTest.java | 62 +++++++++++ .../analysis/ms/dmaap/MRTopicMonitorTest.java | 102 ++++++++++++++++++ .../slice/analysis/ms/dmaap/MRTopicParamsTest.java | 96 +++++++++++++++++ .../ms/dmaap/VesNotificationCallbackTest.java | 63 +++++++++++ .../analysis/ms/models/ConfigurationTest.java | 13 +++ .../ms/models/vesnotification/VesModelsTest.java | 64 +++++++++++ .../analysis/ms/service/PolicyServiceTest.java | 92 ++++++++++------ .../ms/service/ccvpn/BandwidthEvaluatorTest.java | 67 ++++++++++++ .../ms/service/ccvpn/CCVPNPmDatastoreTest.java | 119 +++++++++++++++++++++ .../src/test/resources/aaiEventDmaapMsg.json | 25 +++++ .../src/test/resources/config_all.json | 72 +++++++++++-- .../src/test/resources/onsetMessage2.json | 18 ++++ .../src/test/resources/vesCCVPNNotiModel.json | 34 ++++++ 13 files changed, 786 insertions(+), 41 deletions(-) create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/AaiEventNotificationCallbackTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/MRTopicMonitorTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/MRTopicParamsTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallbackTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/vesnotification/VesModelsTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluatorTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastoreTest.java create mode 100644 components/slice-analysis-ms/src/test/resources/aaiEventDmaapMsg.json create mode 100644 components/slice-analysis-ms/src/test/resources/onsetMessage2.json create mode 100644 components/slice-analysis-ms/src/test/resources/vesCCVPNNotiModel.json (limited to 'components/slice-analysis-ms/src/test') diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/AaiEventNotificationCallbackTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/AaiEventNotificationCallbackTest.java new file mode 100644 index 00000000..eb88d537 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/AaiEventNotificationCallbackTest.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Huawei Canada Limited. + * ============================================================================== + * 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.slice.analysis.ms.dmaap; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = VesNotificationCallbackTest.class) +public class AaiEventNotificationCallbackTest { + + @Spy + @InjectMocks + AaiEventNotificationCallback aaiEventNotificationCallback; + + @Test + public void initTest() { + aaiEventNotificationCallback.init(); + Mockito.verify(aaiEventNotificationCallback, Mockito.atLeastOnce()).init(); + } + + @Test + public void activateCallBackTest() { + String input = null; + try { + input = new String(Files.readAllBytes(Paths.get("src/test/resources/aaiEventDmaapMsg.json"))); + } catch (IOException e) { + e.printStackTrace(); + } + aaiEventNotificationCallback.activateCallBack(input); + Mockito.verify(aaiEventNotificationCallback, Mockito.atLeastOnce()).activateCallBack(Mockito.anyString()); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/MRTopicMonitorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/MRTopicMonitorTest.java new file mode 100644 index 00000000..ce920a0e --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/MRTopicMonitorTest.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Huawei Canada Limited. + * ============================================================================== + * 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.slice.analysis.ms.dmaap; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.mockito.stubbing.Answer; +import org.onap.slice.analysis.ms.models.Configuration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.Map; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = MRTopicMonitorTest.class) +public class MRTopicMonitorTest { + + @Spy + @InjectMocks + MRTopicMonitor mrTopicMonitor; + + @Mock + AaiEventNotificationCallback aaiEventNotificationCallback; + + @Before + public void before(){ + Configuration configuration = Configuration.getInstance(); + String configAllJson = readFromFile("src/test/resources/config_all.json"); + JsonObject configAll = new Gson().fromJson(configAllJson, JsonObject.class); + JsonObject config = configAll.getAsJsonObject("config"); + configuration.updateConfigurationFromJsonObject(config); + + mrTopicMonitor = new MRTopicMonitor("aai_subscriber", aaiEventNotificationCallback); + MockitoAnnotations.initMocks(this); + } + + @Test + public void start() { + mrTopicMonitor.start(); + Mockito.verify(mrTopicMonitor, Mockito.times(1)).start(); + } + + @Test + public void run() { + mrTopicMonitor.run(); + Mockito.verify(mrTopicMonitor, Mockito.times(1)).run(); + } + + @Test + public void stop() { + mrTopicMonitor.start(); + mrTopicMonitor.stop(); + Mockito.verify(mrTopicMonitor, Mockito.times(1)).stop(); + } + + private static String readFromFile(String file) { + String content = ""; + try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { + content = bufferedReader.readLine(); + String temp; + while ((temp = bufferedReader.readLine()) != null) { + content = content.concat(temp); + } + content = content.trim(); + } catch (Exception e) { + content = null; + } + return content; + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/MRTopicParamsTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/MRTopicParamsTest.java new file mode 100644 index 00000000..a5066b17 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/MRTopicParamsTest.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Huawei Canada Limited. + * ============================================================================== + * 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.slice.analysis.ms.dmaap; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +public class MRTopicParamsTest { + private static final String TEST_TOPIC = "test-topic"; + private static final String TEST_HOST = "test-host"; + private static final String MY_CLIENT = "my-client"; + private static final String MY_CG = "my-cg"; + private static final String MY_CI = "my-ci"; + private static final String MY_API_SEC = "my-api-sec"; + private static final String MY_API_KEY = "my-api-key"; + private static final int MY_FETCH_LIMIT = 100; + private static final int MY_FETCH_TIMEOUT = 1000; + private static final String MY_PASS = "my-pass"; + private static final String MY_USERNAME = "my-username"; + private static final int MY_PORT = 5555; + + @Test + public void builderTest() { + MRTopicParams params = MRTopicParams.builder() + .topic(TEST_TOPIC) + .hostname(TEST_HOST) + .clientName(MY_CLIENT) + .consumerGroup(MY_CG) + .consumerInstance(MY_CI) + .apiSecret(MY_API_SEC) + .apiKey(MY_API_KEY) + .fetchLimit(MY_FETCH_LIMIT) + .fetchTimeout(MY_FETCH_TIMEOUT) + .password(MY_PASS) + .userName(MY_USERNAME) + .port(MY_PORT) + .build(); + + assertEquals(TEST_TOPIC, params.getTopic()); + assertEquals(TEST_HOST, params.getHostname()); + assertEquals(MY_CLIENT, params.getClientName()); + assertEquals(MY_CG, params.getConsumerGroup()); + assertEquals(MY_CI, params.getConsumerInstance()); + assertEquals(MY_API_SEC, params.getApiSecret()); + assertEquals(MY_API_KEY, params.getApiKey()); + assertEquals(MY_FETCH_LIMIT, params.getFetchLimit()); + assertEquals(MY_FETCH_TIMEOUT, params.getFetchTimeout()); + assertEquals(MY_PASS, params.getPassword()); + assertEquals(MY_USERNAME, params.getUserName()); + assertEquals(MY_PORT, params.getPort()); + } + + @Test + public void testGetterSetterMRTopicParams() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MRTopicParams.class); + validateMd(pojoclass); + } + + public void validateMd(PojoClass pojoclass) { + Validator validator = ValidatorBuilder + .create() + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + validator.validate(pojoclass); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallbackTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallbackTest.java new file mode 100644 index 00000000..74f75a8c --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallbackTest.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * Copyright (C) 2022 Huawei Canada Limited. + * ============================================================================== + * 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.slice.analysis.ms.dmaap; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = VesNotificationCallbackTest.class) +public class VesNotificationCallbackTest { + ObjectMapper obj = new ObjectMapper(); + + @Spy + @InjectMocks + VesNotificationCallback vesNotificationCallback; + + @Test + public void initTest() { + vesNotificationCallback.init(); + Mockito.verify(vesNotificationCallback, Mockito.atLeastOnce()).init(); + } + + @Test + public void activateCallBackTest() { + String input = null; + try { + input = new String(Files.readAllBytes(Paths.get("src/test/resources/vesCCVPNNotiModel.json"))); + } catch (IOException e) { + e.printStackTrace(); + } + vesNotificationCallback.activateCallBack(input); + Mockito.verify(vesNotificationCallback, Mockito.atLeastOnce()).activateCallBack(Mockito.anyString()); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java index ed583cad..3d9b58d4 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java @@ -3,6 +3,7 @@ * slice-analysis-ms * ================================================================================ * Copyright (C) 2020-2021 Wipro Limited. + * Copyright (C) 2022 Huawei Canada Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,6 +53,12 @@ public class ConfigurationTest { configuration.setSamples(10); configuration.setMinPercentageChange(50); configuration.setInitialDelaySeconds(1000); + configuration.setVesNotifPollingInterval(5); + configuration.setVesNotifChangeIdentifier("PM_BW_UPDATE"); + configuration.setVesNotifChangeType("BandwidthChanged"); + configuration.setCcvpnEvalInterval(5); + configuration.setCcvpnEvalPrecision(100); + configuration.setCcvpnEvalThreshold(0.8); assertEquals(true,configuration.isSecured()); assertEquals("user", configuration.getAafUsername()); assertEquals("password", configuration.getAafPassword()); @@ -73,5 +80,11 @@ public class ConfigurationTest { assertEquals(10,configuration.getSamples()); assertEquals(50,configuration.getMinPercentageChange()); assertEquals(1000,configuration.getInitialDelaySeconds()); + assertEquals(5, configuration.getVesNotifPollingInterval()); + assertEquals("PM_BW_UPDATE", configuration.getVesNotifChangeIdentifier()); + assertEquals("BandwidthChanged", configuration.getVesNotifChangeType()); + assertEquals(5, configuration.getCcvpnEvalInterval()); + assertEquals(100.0, configuration.getCcvpnEvalPrecision(), 0.001); + assertEquals(0.8, configuration.getCcvpnEvalThreshold(), 0.001); } } diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/vesnotification/VesModelsTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/vesnotification/VesModelsTest.java new file mode 100644 index 00000000..78cb635c --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/vesnotification/VesModelsTest.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Huawei Canada Limited. + * ============================================================================== + * 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.slice.analysis.ms.models.vesnotification; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import org.junit.Test; +import org.onap.slice.analysis.ms.models.policy.Payload; + +public class VesModelsTest { + + @Test + public void testGetterSetterArrayOfNamedHashMap() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(ArrayOfNamedHashMap.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterHashMap() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(HashMap.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterNotificationFields() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(NotificationFields.class); + validateMd(pojoclass); + } + + public void validateMd(PojoClass pojoclass) { + Validator validator = ValidatorBuilder + .create() + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + validator.validate(pojoclass); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PolicyServiceTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PolicyServiceTest.java index fef9eb35..d9bf7617 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PolicyServiceTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PolicyServiceTest.java @@ -3,6 +3,7 @@ * slice-analysis-ms * ================================================================================ * Copyright (C) 2020 Wipro Limited. + * Copyright (C) 2022 Huawei Canada Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +35,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.onap.slice.analysis.ms.models.policy.AdditionalProperties; import org.onap.slice.analysis.ms.models.policy.OnsetMessage; +import org.onap.slice.analysis.ms.service.ccvpn.RequestOwner; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -44,41 +46,63 @@ import com.google.gson.Gson; @RunWith(SpringRunner.class) @SpringBootTest(classes = PolicyServiceTest.class) public class PolicyServiceTest { - ObjectMapper obj = new ObjectMapper(); - - @InjectMocks - PolicyService policyService; - - @Test - public void formPolicyOnsetMessageTest() { - String snssai = "001-100001"; - Map input = null; - OnsetMessage output = null; - String expected = ""; - String actual = ""; - Map> ricToThroughputMapping = new HashMap<>(); - Map ric1 = new HashMap<>(); - Map ric2 = new HashMap<>(); - ric1.put("dLThptPerSlice",50); - ric1.put("uLThptPerSlice",40); - ric2.put("dLThptPerSlice",50); - ric2.put("uLThptPerSlice",30); - ricToThroughputMapping.put("1", ric1); - ricToThroughputMapping.put("2", ric2); - try { - input = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/serviceDetails.json"))), new TypeReference>(){}); - output = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/onsetMessage.json"))), OnsetMessage.class); - expected = obj.writeValueAsString(output); - } - catch (IOException e) { - e.printStackTrace(); - } + ObjectMapper obj = new ObjectMapper(); + + @InjectMocks + PolicyService policyService; + + @Test + public void formPolicyOnsetMessageTest() { + String snssai = "001-100001"; + Map input = null; + OnsetMessage output = null; + String expected = ""; + String actual = ""; + Map> ricToThroughputMapping = new HashMap<>(); + Map ric1 = new HashMap<>(); + Map ric2 = new HashMap<>(); + ric1.put("dLThptPerSlice",50); + ric1.put("uLThptPerSlice",40); + ric2.put("dLThptPerSlice",50); + ric2.put("uLThptPerSlice",30); + ricToThroughputMapping.put("1", ric1); + ricToThroughputMapping.put("2", ric2); + try { + input = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/serviceDetails.json"))), new TypeReference>(){}); + output = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/onsetMessage.json"))), OnsetMessage.class); + expected = obj.writeValueAsString(output); + } + catch (IOException e) { + e.printStackTrace(); + } AdditionalProperties>> addProps = new AdditionalProperties<>(); - addProps.setResourceConfig(ricToThroughputMapping); + addProps.setResourceConfig(ricToThroughputMapping); actual = new Gson().toJson(policyService.formPolicyOnsetMessage(snssai,addProps,input)); - + + assertThatJson(actual) + .whenIgnoringPaths("requestID","payload","closedLoopAlarmStart", "AAI", "target_type", "aai", "targetType") + .isEqualTo(expected); + } + + @Test + public void formPolicyOnsetMessageForCCVPNTest() { + String cllId = "cll-instance-01"; + OnsetMessage output = null; + String expected = ""; + String actual = ""; + try { + output = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/onsetMessage2.json"))), OnsetMessage.class); + expected = obj.writeValueAsString(output); + + String msg = obj.writeValueAsString(policyService + .formPolicyOnsetMessageForCCVPN(cllId, 3000, RequestOwner.UUI)); + actual = new Gson().toJson(msg); + } + catch (IOException e) { + e.printStackTrace(); + } assertThatJson(actual) - .whenIgnoringPaths("requestID","payload","closedLoopAlarmStart", "AAI", "target_type", "aai", "targetType") - .isEqualTo(expected); - } + .whenIgnoringPaths("requestID","payload","closedLoopAlarmStart", "AAI", "target_type", "aai", "targetType") + .isEqualTo(expected); + } } diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluatorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluatorTest.java new file mode 100644 index 00000000..c80a1495 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluatorTest.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Huawei Canada Limited. + * ============================================================================== + * 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.slice.analysis.ms.service.ccvpn; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import static org.mockito.Mockito.mock; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = BandwidthEvaluatorTest.class) +public class BandwidthEvaluatorTest { + + @Spy + @InjectMocks + BandwidthEvaluator bandwidthEvaluator; + + @Before + public void setup(){ + MockitoAnnotations.initMocks(this); + } + + @Test + public void initTest(){ + bandwidthEvaluator.init(); + Mockito.verify(bandwidthEvaluator, Mockito.atLeastOnce()).init(); + } + + @Test + public void stopTest(){ + bandwidthEvaluator.init(); + bandwidthEvaluator.stop(); + Mockito.verify(bandwidthEvaluator, Mockito.atLeastOnce()).stop(); + } + + @Test + public void postTest() { + Event evt = mock(SimpleEvent.class); + bandwidthEvaluator.post(evt); + Mockito.verify(bandwidthEvaluator, Mockito.atLeastOnce()).post(Mockito.any(Event.class)); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastoreTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastoreTest.java new file mode 100644 index 00000000..1b03de06 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastoreTest.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Huawei Canada Limited. + * ============================================================================== + * 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.slice.analysis.ms.service.ccvpn; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.concurrent.ConcurrentMap; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = CCVPNPmDatastoreTest.class) +public class CCVPNPmDatastoreTest { + + @Spy + @InjectMocks + CCVPNPmDatastore datastore; + + @Test + public void getUsedBwOfSvcTest() { + datastore.addUsedBwToEndpoint("cll-test", "uni-01", "100"); + datastore.addUsedBwToEndpoint("cll-test", "uni-01", "100"); + datastore.addUsedBwToEndpoint("cll-test", "uni-02", "100"); + datastore.addUsedBwToEndpoint("cll-test2", "uni-01", "100"); + assertEquals(datastore.getUsedBwOfSvc("cll-test").get(new Endpointkey("cll-test", "uni-01")).size(), + 2); + } + + @Test + public void getMaxBwOfSvcTest() { + datastore.updateMaxBw("cll-test", 100, false); + assertEquals(datastore.getMaxBwOfSvc("cll-test"), Integer.valueOf(100)); + } + + @Test + public void getStatusOfSvcTest() { + datastore.updateSvcState("cll-01", ServiceState.RUNNING); + assertEquals(datastore.getStatusOfSvc("cll-01"), ServiceState.RUNNING); + } + + @Test + public void getSvcStatusMapTest() { + datastore.updateSvcState("cll-01", ServiceState.RUNNING); + datastore.getSvcStatusMap(); + Mockito.verify(datastore, Mockito.atLeastOnce()).getSvcStatusMap(); + } + + @Test + public void getUsedBwMapTest() { + datastore.updateSvcState("cll-01", ServiceState.RUNNING); + datastore.getUsedBwMap(); + Mockito.verify(datastore, Mockito.atLeastOnce()).getUsedBwMap(); + } + + @Test + public void updateSvcStateTest() { + datastore.updateSvcState("cll-01", ServiceState.RUNNING); + assertEquals(datastore.getStatusOfSvc("cll-01"), ServiceState.RUNNING); + } + + @Test + public void readToArrayTest() { + for(int i = 0; i < 5; i++){ + datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300"); + } + assertTrue(Arrays.stream(datastore.readToArray("cll-01", "uni-n1")) + .mapToInt(o -> (int)o) + .allMatch(n -> n == 1)); + } + + @Test + public void updateMaxBwTest() throws NoSuchFieldException, IllegalAccessException { + datastore.updateMaxBw("cll-01", "300"); + Mockito.verify(datastore, Mockito.atLeastOnce()).updateMaxBw(Mockito.any(String.class), Mockito.any(String.class)); + } + + @Test + public void addUsedBwToEndpointTest() { + datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300Mb"); + datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300mb"); + datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300Gb"); + datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300kb"); + assertTrue(datastore.readToArray("cll-01", "uni-n1") == null); + datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300.00"); + assertTrue(Arrays.stream(datastore.readToArray("cll-01", "uni-n1")) + .mapToInt(o -> (int)o) + .sum() == 300602 ); + } +} diff --git a/components/slice-analysis-ms/src/test/resources/aaiEventDmaapMsg.json b/components/slice-analysis-ms/src/test/resources/aaiEventDmaapMsg.json new file mode 100644 index 00000000..82faeeb4 --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/aaiEventDmaapMsg.json @@ -0,0 +1,25 @@ +{ + "cambria.partition":"AAI", + "event-header":{ + "severity":"NORMAL", + "entity-type":"service-instance", + "top-entity-type":"service-instance", + "entity-link":"/aai/v24/business/customers/customer/IBNCustomer/service-subscriptions/service-subscription/IBN/service-instances/service-instance/cll-01", + "event-type":"AAI-EVENT","domain":"dev","action":"UPDATE", + "sequence-number":"0","id":"51a99267-83ec-4f4f-a676-690ba527bf78", + "source-name":"UUI","version":"v23","timestamp":"20210705-15:18:37:452" + }, + "entity":{ + "service-instance-id":"0835fd19-6726-4081-befb-cc8932c47767", + "service-instance-name":"sa1", + "service-instance-location-id" : "cll-01", + "service-type":"embb", + "service-role":"service-profile", + "environment-context":"01-06E442", + "model-invariant-id":"8b94b147-2233-4e9f-b939-55c1b0e618ac", + "model-version-id":"961ec436-7b16-4d71-9d62-9c4ca5dd94bf", + "resource-version":"1645003055191", + "orchestration-status":"deactivated", + "bandwidth-total" : 8000 + } +} diff --git a/components/slice-analysis-ms/src/test/resources/config_all.json b/components/slice-analysis-ms/src/test/resources/config_all.json index 79d70202..b2998703 100644 --- a/components/slice-analysis-ms/src/test/resources/config_all.json +++ b/components/slice-analysis-ms/src/test/resources/config_all.json @@ -22,6 +22,35 @@ "client_id": "sdnr-sliceanalysis-1" }, "aaf_username": null + }, + "ves_ccvpn_notification_topic": { + "aaf_password": null, + "type": "message-router", + "dmaap_info": { + "topic_url": "http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.VES_NOTIFICATION_OUTPUT", + "client_role": "sliceanalysis-subscriber", + "location": "onap", + "client_id": "sdnr-sliceanalysis-1" + }, + "aaf_username": null + }, + "aai_subscriber":{ + "type":"message_router", + "aaf_username": null, + "aaf_password": null, + "api_key" : null, + "api_secret" : null, + "servers" : ["message-router"], + "consumer_group" : "dcae_ccvpn_cl", + "consumer_instance" : "dcae_ccvpn_cl_aaievent", + "fetch_timeout" : 15000, + "fetch_limit" : 100, + "dmaap_info":{ + "topic_url":"https://message-router:3905/events/AAI_EVENT", + "client_role":"org.onap.dcae.aaiSub", + "location":"onap", + "client_id":"sdnr-sliceanalysis-1" + } } }, "streams_publishes": { @@ -47,17 +76,46 @@ "cbsPollingInterval": 60, "sliceanalysisms.cg": "sliceanalysisms-cg", "sliceanalysisms.pollingInterval": 20, + "sliceanalysisms.samples": 3, + "sliceanalysisms.minPercentageChange": 5, + "sliceanalysisms.initialDelaySeconds": 300000, + "sliceanalysisms.pollingTimeout": 60, "sliceanalysisms.cid": "sliceanalysisms-cid", - "sliceanalysisms.configDb.service": "http://sdnc.onap:8181", - "sliceanalysisms.pollingTimeout":4, - "sliceanalysisms.samples": 5, - "sliceanalysisms.minPercentageChange":4, - "sliceanalysisms.initialDelaySeconds": 60000, + "sliceanalysisms.configDb.service": "http://configdb_sim:5000", + "sliceanalysisms.aai.url": "https://aai-resources:8447/aai/v21", + "sliceanalysisms.cps.url": "http://cps-tbdmt:8080/execute/ran-network", + "sliceanalysisms.configDbEnabled": "false", + "sliceanalysisms.rannfnssiDetailsTemplateId": "get-rannfnssiid-details", + "sliceanalysisms.desUrl": "http://dl-des:1681/datalake/v1/exposure/pm_data", + "sliceanalysisms.pmDataDurationInWeeks": 4, + "sliceanalysisms.vesNotifPollingInterval": 5, + "sliceanalysisms.vesNotifChangeIdentifier": "PM_BW_UPDATE", + "sliceanalysisms.vesNotifChangeType": "BandwidthChanged", + "sliceanalysisms.aaiNotif.targetAction" : "UPDATE", + "sliceanalysisms.aaiNotif.targetSource" : "UUI", + "sliceanalysisms.aaiNotif.targetEntity" : "service-instance", + "sliceanalysisms.ccvpnEvalInterval": 5, + "sliceanalysisms.ccvpnEvalThreshold": 0.8, + "sliceanalysisms.ccvpnEvalPrecision": 100.0, + "sliceanalysisms.ccvpnEvalPeriodicCheckOn": true, + "sliceanalysisms.ccvpnEvalOnDemandCheckOn": true, "service_calls": { "policy-req": [] - } + }, + "trust_store_path": "/opt/app/sliceanalysisms/etc/cert/trust.jks", + "trust_store_pass_path": "/opt/app/sliceanalysisms/etc/cert/trust.pass" }, "policies": { - + "event": { + "action": "gathered", + "timestamp": "2019-09-18T14:57:55.320Z", + "update_id": "dbb88da8-8df1-489d-b51d-8d5cbbfbcd99", + "policies_count": 1 + }, + "items": [ + { + "policyName": "com.Config_PCIMS_CONFIG_POLICY.1.xml" + } + ] } } diff --git a/components/slice-analysis-ms/src/test/resources/onsetMessage2.json b/components/slice-analysis-ms/src/test/resources/onsetMessage2.json new file mode 100644 index 00000000..530c831f --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/onsetMessage2.json @@ -0,0 +1,18 @@ +{ + "closedLoopControlName": "ControlLoop-CCVPN-CLL-227e8b00-dbeb-4d03-8719-d0a658fb846c", + "closedLoopAlarmStart": 1605691996370, + "closedLoopEventClient": "microservice.sliceAnalysisMS", + "closedLoopEventStatus": "ONSET", + "requestID": "1e946480-1232-46d4-a39b-614ac534400f", + "target": "generic-vnf.vnf-id", + "payload": "{\"name\": \"cloud-leased-line-101\",\"serviceInstanceID\": \"cll-instance-01\",\"globalSubscriberId\": \"IBNCustomer\",\"subscriptionServiceType\": \"IBN\",\"serviceType\": \"CLL\",\"additionalProperties\": {\"modifyAction\": \"bandwdith\",\"enableSdnc\": \"true\",\"transportNetworks\": [{ \"id\": \"cll-101-network-001\", \"sla\": { \"latency\": 2, \"maxBandwidth\": 8000 }}]}}", + "from": "DCAE", + "version": "1.0.2", + "target_type": "VNF", + "AAI": { + "generic-vnf.is-closed-loop-disabled": "true", + "generic-vnf.prov-status": "ACTIVE", + "generic-vnf.vnf-id": "3f2f23fa-c567-4dd8-8f15-f95ae3e6fd82", + "generic-vnf.vnf-name": "76543" + } +} diff --git a/components/slice-analysis-ms/src/test/resources/vesCCVPNNotiModel.json b/components/slice-analysis-ms/src/test/resources/vesCCVPNNotiModel.json new file mode 100644 index 00000000..270c0779 --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/vesCCVPNNotiModel.json @@ -0,0 +1,34 @@ +{ + "event": { + "commonEventHeader": { + "version": "4.0.1", + "vesEventListenerVersion": "7.0.1", + "domain": "notification", + "eventName": "ccvpnNotification_CloudLeaseLine_BandwidthChanged", + "eventId": "BandwidthChanged_1797490e-10ae-4d48-9ea7-3d7d790b25e1", + "lastEpochMicrosec": 8745745764578, + "priority": "Normal", + "reportingEntityName": "onap-sdnc", + "sequence": 0, + "sourceName": "onap-sdnc", + "startEpochMicrosec": 8745745764578, + "timeZoneOffset": "UTC-05.00" + }, + "notificationFields": { + "changeIdentifier": "PM_BW_UPDATE", + "changeType": "BandwidthChanged", + "notificationFieldsVersion": "2.0", + "arrayOfNamedHashMap": [ + { + "name": "DomainId-1-cll-instance-01-uni-01-8745745764578", + "hashMap": { + "cllId": "cll-instance-01", + "uniId": "uni-01", + "bandwidthValue": "4000", + "time": "2022-02-08T11:13:34.781-05:00" + } + } + ] + } + } +} -- cgit 1.2.3-korg