Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / orchestration / AAIVpnBindingResourcesTest.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.junit.Assert.assertNotNull;
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 import static org.mockito.Mockito.when;
32
33 import java.util.Optional;
34
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.mockito.InjectMocks;
38 import org.onap.aai.domain.yang.VpnBindings;
39 import org.onap.so.bpmn.BaseTaskTest;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding;
42 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
43
44
45 public class AAIVpnBindingResourcesTest extends BaseTaskTest{
46         
47         @InjectMocks
48         private AAIVpnBindingResources aaiVpnBindingResources = new AAIVpnBindingResources();
49         
50         private Customer customer;
51
52         @Before
53         public void before() {
54                 customer = buildCustomer();
55                 doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
56         }
57
58         @Test
59         public void createCustomerTest() {
60                 org.onap.aai.domain.yang.Customer mappedCustomer = new org.onap.aai.domain.yang.Customer();
61                 mappedCustomer.setGlobalCustomerId(customer.getGlobalCustomerId());
62                 
63                 doReturn(mappedCustomer).when(MOCK_aaiObjectMapper).mapCustomer(customer);
64                 doNothing().when(MOCK_aaiResourcesClient).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Customer.class));
65                 
66                 aaiVpnBindingResources.createCustomer(customer);
67                 
68                 verify(MOCK_aaiResourcesClient, times(1)).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Customer.class));
69                 verify(MOCK_aaiObjectMapper, times(1)).mapCustomer(customer);
70         }
71
72         @Test
73         public void getVpnBindingTest () {
74                 org.onap.aai.domain.yang.VpnBinding vpnBinding = new org.onap.aai.domain.yang.VpnBinding();
75                 vpnBinding.setVpnId("vnfId");
76                 when(MOCK_aaiResourcesClient.get(eq(org.onap.aai.domain.yang.VpnBinding.class),isA(AAIResourceUri.class))).thenReturn(Optional.of(vpnBinding));
77                 aaiVpnBindingResources.getVpnBinding("vpnId");
78                 verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.VpnBinding.class),isA(AAIResourceUri.class));
79         }
80
81     @Test
82     public void existsCustomerTest() {
83                 when(MOCK_aaiResourcesClient.exists(isA(AAIResourceUri.class))).thenReturn(true);
84                 boolean isCustomerExist = aaiVpnBindingResources.existsCustomer(customer);
85                 verify(MOCK_aaiResourcesClient, times(1)).exists(isA(AAIResourceUri.class));
86                 assertEquals(true,isCustomerExist);
87         }
88
89     @Test
90     public void getVpnBindingByCustomerVpnIdTest() {
91                 when(MOCK_aaiResourcesClient.get(eq(VpnBindings.class),isA(AAIResourceUri.class))).thenReturn(Optional.of(new VpnBindings()));
92                 Optional<VpnBindings> vpnBindings = aaiVpnBindingResources.getVpnBindingByCustomerVpnId("testCustomerVpnId");
93                 assertNotNull(vpnBindings.get());
94                 verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.VpnBindings.class),isA(AAIResourceUri.class));
95         }
96
97         @Test
98         public void createVpnBindingTest() {
99                 doNothing().when(MOCK_aaiResourcesClient).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VpnBinding.class));
100                 org.onap.aai.domain.yang.VpnBinding mappedVpnBinding = new org.onap.aai.domain.yang.VpnBinding();
101                 mappedVpnBinding.setVpnName("test");
102
103                 doReturn(mappedVpnBinding).when(MOCK_aaiObjectMapper).mapVpnBinding(isA(VpnBinding.class));
104                 VpnBinding vpnBinding = buildVpnBinding();
105                 aaiVpnBindingResources.createVpnBinding(vpnBinding);
106
107                 verify(MOCK_aaiResourcesClient, times(1)).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VpnBinding.class));
108                 verify(MOCK_aaiObjectMapper, times(1)).mapVpnBinding(isA(VpnBinding.class));
109         }
110
111         @Test
112         public void connectCustomerToVpnBinding() {
113                 doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class));
114                 aaiVpnBindingResources.connectCustomerToVpnBinding("testCustId","testVpnId");
115                 verify(MOCK_aaiResourcesClient,times(1)).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class));
116         }
117 }