673ec6a83d418da451f7f206574fb52b7a844d06
[dcaegen2/services.git] /
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  slice-analysis-ms
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
10  *
11  *          http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  *
20  *******************************************************************************/
21
22 package org.onap.slice.analysis.ms.service.ccvpn;
23
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;
31
32 import java.util.Arrays;
33
34 import static org.junit.Assert.assertEquals;
35 import static org.junit.Assert.assertTrue;
36
37
38 @RunWith(SpringRunner.class)
39 @SpringBootTest(classes = CCVPNPmDatastoreTest.class)
40 public class CCVPNPmDatastoreTest {
41
42     @Spy
43     @InjectMocks
44     CCVPNPmDatastore datastore;
45
46     @Test
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(),
53         2);
54     }
55
56     @Test
57     public void getMaxBwOfSvcTest() {
58         datastore.updateProvBw("cll-test", 100, false);
59         assertEquals(datastore.getProvBwOfSvc("cll-test"), Integer.valueOf(100));
60     }
61
62     @Test
63     public void getStatusOfSvcTest() {
64         datastore.updateSvcState("cll-01", ServiceState.RUNNING);
65         assertEquals(datastore.getStatusOfSvc("cll-01"), ServiceState.RUNNING);
66     }
67
68     @Test
69     public void getSvcStatusMapTest() {
70         datastore.updateSvcState("cll-01", ServiceState.RUNNING);
71         datastore.getSvcStatusMap();
72         Mockito.verify(datastore, Mockito.atLeastOnce()).getSvcStatusMap();
73     }
74
75     @Test
76     public void getUsedBwMapTest() {
77         datastore.updateSvcState("cll-01", ServiceState.RUNNING);
78         datastore.getUsedBwMap();
79         Mockito.verify(datastore, Mockito.atLeastOnce()).getUsedBwMap();
80     }
81
82     @Test
83     public void updateSvcStateTest() {
84         datastore.updateSvcState("cll-01", ServiceState.RUNNING);
85         assertEquals(datastore.getStatusOfSvc("cll-01"), ServiceState.RUNNING);
86     }
87
88     @Test
89     public void readToArrayTest() {
90         for(int i = 0; i < 5; i++){
91             datastore.addUsedBwToEndpoint("cll-01", "uni-n1", "300");
92         }
93         assertTrue(Arrays.stream(datastore.readToArray("cll-01", "uni-n1"))
94                 .mapToInt(o -> (int)o)
95                 .allMatch(n -> n == 1));
96     }
97
98     @Test
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));
102     }
103
104     @Test
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));
108     }
109
110     @Test
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)
120                 .sum() == 300602 );
121     }
122 }