diff options
Diffstat (limited to 'components/slice-analysis-ms/src/test/java')
9 files changed, 644 insertions, 34 deletions
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<String, String> input = null; - OnsetMessage output = null; - String expected = ""; - String actual = ""; - Map<String, Map<String, Integer>> ricToThroughputMapping = new HashMap<>(); - Map<String, Integer> ric1 = new HashMap<>(); - Map<String, Integer> 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<Map<String,String>>(){}); - 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<String, String> input = null; + OnsetMessage output = null; + String expected = ""; + String actual = ""; + Map<String, Map<String, Integer>> ricToThroughputMapping = new HashMap<>(); + Map<String, Integer> ric1 = new HashMap<>(); + Map<String, Integer> 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<Map<String,String>>(){}); + 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<Map<String, Map<String, Integer>>> 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 ); + } +} |