Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / orchestration / AAIVnfResourcesTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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 package org.onap.so.client.orchestration;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Matchers.eq;
26 import static org.mockito.ArgumentMatchers.isA;
27 import static org.mockito.Mockito.doNothing;
28 import static org.mockito.Mockito.doReturn;
29 import static org.mockito.Mockito.times;
30 import static org.mockito.Mockito.verify;
31
32 import java.util.Optional;
33
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.ArgumentMatchers;
38 import org.mockito.InjectMocks;
39 import org.mockito.Mock;
40 import org.mockito.junit.MockitoJUnitRunner;
41 import org.onap.so.bpmn.common.data.TestDataSetup;
42 import org.onap.so.bpmn.common.InjectionHelper;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
47 import org.onap.so.client.aai.AAIResourcesClient;
48 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
49 import org.onap.so.client.aai.mapper.AAIObjectMapper;
50 import org.onap.so.db.catalog.beans.OrchestrationStatus;
51
52 @RunWith(MockitoJUnitRunner.Silent.class)
53 public class AAIVnfResourcesTest extends TestDataSetup {
54
55         private GenericVnf genericVnf;
56
57         private ServiceInstance serviceInstance;
58         @Mock
59         protected AAIResourcesClient MOCK_aaiResourcesClient;
60
61         @Mock
62         protected AAIObjectMapper MOCK_aaiObjectMapper;
63
64         @Mock
65         protected InjectionHelper MOCK_injectionHelper;
66         
67         @InjectMocks
68         AAIVnfResources aaiVnfResources = new AAIVnfResources();
69
70         @Before
71         public void before() {
72                 serviceInstance = buildServiceInstance();
73                 genericVnf = buildGenericVnf();
74                  doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
75         }
76
77         @Test
78         public void createVnfandConnectServiceInstanceTest() {
79                 doReturn(new org.onap.aai.domain.yang.GenericVnf()).when(MOCK_aaiObjectMapper).mapVnf(genericVnf);
80                 doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(isA(AAIResourceUri.class), any(Optional.class));
81                 doNothing().when(MOCK_aaiResourcesClient).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
82                 genericVnf.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
83
84                 aaiVnfResources.createVnfandConnectServiceInstance(genericVnf, serviceInstance);
85
86                 assertEquals(OrchestrationStatus.INVENTORIED, genericVnf.getOrchestrationStatus());
87                 verify(MOCK_aaiObjectMapper, times(1)).mapVnf(genericVnf);
88                 verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
89                 verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
90         }
91
92         @Test
93         public void createPlatformandConnectVnfTest() {
94                 Platform platform = new Platform();
95                 platform.setPlatformName("a123");
96                 doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class));
97                 doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(isA(AAIResourceUri.class), any(Optional.class));
98                 aaiVnfResources.createPlatformandConnectVnf(platform, genericVnf);
99                 verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class),isA(AAIResourceUri.class));
100         }
101         
102         @Test
103         public void createLineOfBusinessandConnectVnfTest() {
104                 LineOfBusiness lob = new LineOfBusiness();
105                 lob.setLineOfBusinessName("a123");
106                 doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class));
107                 doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(isA(AAIResourceUri.class), any(Optional.class));
108                 aaiVnfResources.createLineOfBusinessandConnectVnf(lob, genericVnf);
109                 verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class),isA(AAIResourceUri.class));
110         }
111         
112         @Test
113         public void deleteVnfTest() {
114                 doNothing().when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class));
115
116                 aaiVnfResources.deleteVnf(genericVnf);
117
118                 verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class));
119         }
120
121         @Test
122         public void updateOrchestrationStatusVnfTest() {
123                 doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Vnf.class));
124
125                 aaiVnfResources.updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
126
127                 verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), ArgumentMatchers.isNull());
128
129                 assertEquals(OrchestrationStatus.ACTIVE, genericVnf.getOrchestrationStatus());
130         }
131
132         @Test
133         public void updateObjectVnfTest() {
134                 doReturn(new org.onap.aai.domain.yang.GenericVnf()).when(MOCK_aaiObjectMapper).mapVnf(genericVnf);
135                 doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.GenericVnf.class));
136
137                 aaiVnfResources.updateObjectVnf(genericVnf);
138
139                 verify(MOCK_aaiObjectMapper, times(1)).mapVnf(genericVnf);
140                 verify(MOCK_aaiResourcesClient, times(1)).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.GenericVnf.class));
141         }
142
143         @Test
144         public void getGenericVnfTest () {
145                 Optional<org.onap.aai.domain.yang.GenericVnf> vnf = Optional.of(new org.onap.aai.domain.yang.GenericVnf());
146                 vnf.get().setVnfId("vnfId");
147                 doReturn(vnf).when(MOCK_aaiResourcesClient).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class));
148                 aaiVnfResources.getGenericVnf("vnfId");
149                 verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class));
150         }
151
152         @Test
153         public void checkInMaintFlagTest () {
154                 Optional<org.onap.aai.domain.yang.GenericVnf> vnf = Optional.of(new org.onap.aai.domain.yang.GenericVnf());
155                 vnf.get().setVnfId("vnfId");
156                 vnf.get().setInMaint(true);
157                 doReturn(vnf).when(MOCK_aaiResourcesClient).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class));
158                 boolean inMaintFlag = aaiVnfResources.checkInMaintFlag("vnfId");
159                 verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class));
160                 assertEquals(inMaintFlag, true);
161         }
162 }