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.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.InjectMocks;
27 import org.mockito.Mockito;
28 import org.mockito.Spy;
29 import org.springframework.boot.test.context.SpringBootTest;
30 import org.springframework.test.context.junit4.SpringRunner;
32 import java.util.Arrays;
34 import static org.junit.Assert.assertEquals;
35 import static org.junit.Assert.assertTrue;
38 @RunWith(SpringRunner.class)
39 @SpringBootTest(classes = CCVPNPmDatastoreTest.class)
40 public class CCVPNPmDatastoreTest {
44 CCVPNPmDatastore datastore;
47 public void getUsedBwOfSvcTest() {
48 datastore.addUsedBwToEndpoint("cll-test", "uni-01", "100");
49 datastore.addUsedBwToEndpoint("cll-test", "uni-01", "100");
50 datastore.addUsedBwToEndpoint("cll-test", "uni-02", "100");
51 datastore.addUsedBwToEndpoint("cll-test2", "uni-01", "100");
52 assertEquals(datastore.getUsedBwOfSvc("cll-test").get(new Endpointkey("cll-test", "uni-01")).size(),
57 public void getMaxBwOfSvcTest() {
58 datastore.updateProvBw("cll-test", 100, false);
59 assertEquals(datastore.getProvBwOfSvc("cll-test"), Integer.valueOf(100));
63 public void getStatusOfSvcTest() {
64 datastore.updateSvcState("cll-01", ServiceState.RUNNING);
65 assertEquals(datastore.getStatusOfSvc("cll-01"), ServiceState.RUNNING);
69 public void getSvcStatusMapTest() {
70 datastore.updateSvcState("cll-01", ServiceState.RUNNING);
71 datastore.getSvcStatusMap();
72 Mockito.verify(datastore, Mockito.atLeastOnce()).getSvcStatusMap();
76 public void getUsedBwMapTest() {
77 datastore.updateSvcState("cll-01", ServiceState.RUNNING);
78 datastore.getUsedBwMap();
79 Mockito.verify(datastore, Mockito.atLeastOnce()).getUsedBwMap();
83 public void updateSvcStateTest() {
84 datastore.updateSvcState("cll-01", ServiceState.RUNNING);
85 assertEquals(datastore.getStatusOfSvc("cll-01"), ServiceState.RUNNING);
89 public void readToArrayTest() {
90 for(int i = 0; i < 5; i++){
91 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300");
93 assertTrue(Arrays.stream(datastore.readToArray("cll-01", "uni-n1"))
94 .mapToInt(o -> (int)o)
95 .allMatch(n -> n == 1));
99 public void updateMaxBwTest() throws NoSuchFieldException, IllegalAccessException {
100 datastore.updateProvBw("cll-01", "300");
101 Mockito.verify(datastore, Mockito.atLeastOnce()).updateProvBw(Mockito.any(String.class), Mockito.any(String.class));
105 public void updateUpperBoundBwTest() throws NoSuchFieldException, IllegalAccessException {
106 datastore.updateUpperBoundBw("cll-01", 300);
107 Mockito.verify(datastore, Mockito.atLeastOnce()).updateUpperBoundBw(Mockito.any(String.class), Mockito.any(Integer.class));
111 public void addUsedBwToEndpointTest() {
112 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300Mb");
113 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300mb");
114 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300Gb");
115 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300kb");
116 assertTrue(datastore.readToArray("cll-01", "uni-n1") == null);
117 datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300.00");
118 assertTrue(Arrays.stream(datastore.readToArray("cll-01", "uni-n1"))
119 .mapToInt(o -> (int)o)