aef25e5dedbcadc61ea0b307455b1adbfda91bf7
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / orchestration / AAIInstanceGroupResourcesTest.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.mockito.Matchers.eq;
24 import static org.mockito.Matchers.isA;
25 import static org.mockito.Mockito.doReturn;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28
29 import java.util.Optional;
30
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.runners.MockitoJUnitRunner;
37 import org.onap.so.bpmn.common.data.TestDataSetup;
38 import org.onap.so.bpmn.common.InjectionHelper;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
41 import org.onap.so.client.aai.AAIObjectType;
42 import org.onap.so.client.aai.AAIResourcesClient;
43 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
44 import org.onap.so.client.aai.mapper.AAIObjectMapper;
45 @RunWith(MockitoJUnitRunner.class)
46 public class AAIInstanceGroupResourcesTest extends TestDataSetup{
47         
48         @InjectMocks
49         private AAIInstanceGroupResources aaiInstanceGroupResources = new AAIInstanceGroupResources();
50         
51         private InstanceGroup instanceGroup;
52         private GenericVnf vnf;
53         
54         @Mock
55         protected AAIResourcesClient MOCK_aaiResourcesClient;
56     
57     @Mock
58     protected AAIObjectMapper MOCK_aaiObjectMapper;
59     
60     @Mock
61     protected InjectionHelper MOCK_injectionHelper;
62         
63         @Before
64         public void before() {
65                 instanceGroup = buildInstanceGroup();
66                 vnf = buildGenericVnf();
67                  doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
68         }
69         
70         @Test
71         public void createInstanceGroupTest() throws Exception {
72                 doReturn(new org.onap.aai.domain.yang.InstanceGroup()).when(MOCK_aaiObjectMapper).mapInstanceGroup(instanceGroup);
73                 aaiInstanceGroupResources.createInstanceGroup(instanceGroup);
74                 verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(eq(AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId())), isA(Optional.class));
75         }
76         
77         @Test
78         public void deleteInstanceGroupTest() throws Exception {
79                 aaiInstanceGroupResources.deleteInstanceGroup(instanceGroup);
80                 verify(MOCK_aaiResourcesClient, times(1)).delete(eq(AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId())));
81         }
82         
83         @Test
84         public void connectInstanceGroupTest() throws Exception {
85                 aaiInstanceGroupResources.connectInstanceGroupToVnf(instanceGroup, vnf);
86                 verify(MOCK_aaiResourcesClient, times(1)).connect(eq(AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId())), eq(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId())));
87         }
88         
89         @Test
90         public void existsTest() throws Exception {
91                 aaiInstanceGroupResources.exists(instanceGroup);
92                 verify(MOCK_aaiResourcesClient, times(1)).exists(eq(AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId())));
93         }
94         
95 }