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