1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2022 Huawei Canada Limited.
6 * ==============================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 *******************************************************************************/
22 package org.onap.slice.analysis.ms.service.ccvpn;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mockito;
29 import org.mockito.Spy;
30 import org.springframework.boot.test.context.SpringBootTest;
31 import org.springframework.test.context.junit4.SpringRunner;
33 import java.lang.reflect.Field;
34 import java.util.Arrays;
35 import java.util.concurrent.ConcurrentMap;
37 import static org.junit.Assert.assertEquals;
38 import static org.junit.Assert.assertTrue;
41 @RunWith(SpringRunner.class)
42 @SpringBootTest(classes = CCVPNPmDatastoreTest.class)
43 public class CCVPNPmDatastoreTest {
47 CCVPNPmDatastore datastore;
50 public void getUsedBwOfSvcTest() {
51 datastore.addUsedBwToEndpoint("cll-test", "uni-01", "100");
52 datastore.addUsedBwToEndpoint("cll-test", "uni-01", "100");
53 datastore.addUsedBwToEndpoint("cll-test", "uni-02", "100");
54 datastore.addUsedBwToEndpoint("cll-test2", "uni-01", "100");
55 assertEquals(datastore.getUsedBwOfSvc("cll-test").get(new Endpointkey("cll-test", "uni-01")).size(),
60 public void getMaxBwOfSvcTest() {
61 datastore.updateMaxBw("cll-test", 100, false);
62 assertEquals(datastore.getMaxBwOfSvc("cll-test"), Integer.valueOf(100));
66 public void getStatusOfSvcTest() {
67 datastore.updateSvcState("cll-01", ServiceState.RUNNING);
68 assertEquals(datastore.getStatusOfSvc("cll-01"), ServiceState.RUNNING);
72 public void getSvcStatusMapTest() {
73 datastore.updateSvcState("cll-01", ServiceState.RUNNING);
74 datastore.getSvcStatusMap();
75 Mockito.verify(datastore, Mockito.atLeastOnce()).getSvcStatusMap();
79 public void getUsedBwMapTest() {
80 datastore.updateSvcState("cll-01", ServiceState.RUNNING);
81 datastore.getUsedBwMap();
82 Mockito.verify(datastore, Mockito.atLeastOnce()).getUsedBwMap();
86 public void updateSvcStateTest() {
87 datastore.updateSvcState("cll-01", ServiceState.RUNNING);
88 assertEquals(datastore.getStatusOfSvc("cll-01"), ServiceState.RUNNING);
92 public void readToArrayTest() {
93 for(int i = 0; i < 5; i++){
94 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300");
96 assertTrue(Arrays.stream(datastore.readToArray("cll-01", "uni-n1"))
97 .mapToInt(o -> (int)o)
98 .allMatch(n -> n == 1));
102 public void updateMaxBwTest() throws NoSuchFieldException, IllegalAccessException {
103 datastore.updateMaxBw("cll-01", "300");
104 Mockito.verify(datastore, Mockito.atLeastOnce()).updateMaxBw(Mockito.any(String.class), Mockito.any(String.class));
108 public void addUsedBwToEndpointTest() {
109 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300Mb");
110 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300mb");
111 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300Gb");
112 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300kb");
113 assertTrue(datastore.readToArray("cll-01", "uni-n1") == null);
114 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300.00");
115 assertTrue(Arrays.stream(datastore.readToArray("cll-01", "uni-n1"))
116 .mapToInt(o -> (int)o)