1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2022 Huawei Canada Limited.
6 * Copyright (C) 2022 Huawei Technologies Co., Ltd.
7 * ==============================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 *******************************************************************************/
23 package org.onap.slice.analysis.ms.service.ccvpn;
25 import java.util.HashSet;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.mockito.InjectMocks;
30 import org.mockito.Mockito;
31 import org.mockito.Spy;
32 import org.springframework.boot.test.context.SpringBootTest;
33 import org.springframework.test.context.junit4.SpringRunner;
35 import java.util.Arrays;
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.updateProvBw("cll-test", 100, false);
62 assertEquals(datastore.getProvBwOfSvc("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.updateProvBw("cll-01", "300");
104 Mockito.verify(datastore, Mockito.atLeastOnce()).updateProvBw(Mockito.any(String.class), Mockito.any(String.class));
108 public void updateUpperBoundBwTest() throws NoSuchFieldException, IllegalAccessException {
109 datastore.updateUpperBoundBw("cll-01", 300);
110 Mockito.verify(datastore, Mockito.atLeastOnce()).updateUpperBoundBw(Mockito.any(String.class), Mockito.any(Integer.class));
114 public void addUsedBwToEndpointTest() {
115 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300Mb");
116 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300mb");
117 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300Gb");
118 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300kb");
119 assertTrue(datastore.readToArray("cll-01", "uni-n1") == null);
120 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300.00");
121 assertTrue(Arrays.stream(datastore.readToArray("cll-01", "uni-n1"))
122 .mapToInt(o -> (int)o)
127 public void updateCllInstancesTest() {
128 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300Mb");
129 datastore.updateUpperBoundBw("cll-01", 300);
130 datastore.updateProvBw("cll-01", "300");
131 datastore.updateSvcState("cll-01", ServiceState.RUNNING);
132 datastore.updateOriginalBw("cll-01", 1000);
133 datastore.updateClosedloopStatus("cll-01", true);
134 datastore.addUsedBwToEndpoint("cll-02", "uni-n2", "300Mb");
135 datastore.updateUpperBoundBw("cll-02", 300);
136 datastore.updateProvBw("cll-02", "300");
137 datastore.updateSvcState("cll-02", ServiceState.RUNNING);
138 datastore.updateOriginalBw("cll-02", 1000);
139 datastore.updateClosedloopStatus("cll-02", true);
140 Set<String> cllId = new HashSet<>();
142 datastore.updateCllInstances(cllId);
143 assertEquals(datastore.getEndpointToUsedBw().keySet().size(), 1);
144 assertEquals(datastore.getUpperBoundBw().keySet().equals(cllId), true);
145 assertEquals(datastore.getEndpointToProvBw().keySet().equals(cllId), true);
146 assertEquals(datastore.getSvcStatus().keySet().equals(cllId), true);
147 assertEquals(datastore.getEndpointToOriginalBw().keySet().equals(cllId), true);