2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Nokia 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
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=========================================================
21 package org.onap.so.client.orchestration;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.argThat;
26 import static org.mockito.ArgumentMatchers.eq;
27 import static org.mockito.Mockito.doReturn;
28 import static org.mockito.Mockito.times;
29 import static org.mockito.Mockito.verify;
30 import java.util.Optional;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.InjectMocks;
35 import org.mockito.Mock;
36 import org.mockito.junit.MockitoJUnitRunner;
37 import org.onap.so.bpmn.common.InjectionHelper;
38 import org.onap.so.bpmn.common.data.TestDataSetup;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
41 import org.onap.aaiclient.client.aai.AAIResourcesClient;
42 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
43 import org.onap.so.client.aai.mapper.AAIObjectMapper;
44 import org.onap.so.db.catalog.beans.OrchestrationStatus;
46 @RunWith(MockitoJUnitRunner.Silent.class)
47 public class AAIPnfResourcesTest extends TestDataSetup {
50 private ServiceInstance serviceInstance;
53 protected AAIObjectMapper aaiObjectMapperMock;
56 protected InjectionHelper injectionHelperMock;
59 protected AAIResourcesClient aaiResourcesClientMock;
62 AAIPnfResources aaiPnfResources = new AAIPnfResources();
67 pnf.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
68 serviceInstance = buildServiceInstance();
70 doReturn(aaiResourcesClientMock).when(injectionHelperMock).getAaiClient();
74 public void createPnfAndConnectServiceInstanceShouldSetInventoriedStatusAndCallConnectMethod() {
75 org.onap.aai.domain.yang.Pnf pnfYang = new org.onap.aai.domain.yang.Pnf();
77 doReturn(pnfYang).when(aaiObjectMapperMock).mapPnf(pnf);
78 doReturn(aaiResourcesClientMock).when(aaiResourcesClientMock).createIfNotExists(any(AAIResourceUri.class),
79 eq(Optional.of(pnfYang)));
81 aaiPnfResources.createPnfAndConnectServiceInstance(pnf, serviceInstance);
83 assertEquals(OrchestrationStatus.INVENTORIED, pnf.getOrchestrationStatus());
84 verify(aaiResourcesClientMock, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
88 public void updateOrchestrationStatusPnfShouldSetStatusAndUpdatePnfInAAI() {
89 org.onap.aai.domain.yang.Pnf pnfYang = new org.onap.aai.domain.yang.Pnf();
90 doReturn(pnfYang).when(aaiObjectMapperMock).mapPnf(pnf);
92 aaiPnfResources.updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE);
94 assertEquals(OrchestrationStatus.ACTIVE, pnf.getOrchestrationStatus());
95 verify(aaiObjectMapperMock, times(1))
96 .mapPnf(argThat(arg -> OrchestrationStatus.ACTIVE.equals(arg.getOrchestrationStatus())));
97 verify(aaiResourcesClientMock, times(1)).update(any(AAIResourceUri.class), eq(pnfYang));