7c31040f1d102ac7a59ebd17325553d412d41d4c
[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.Matchers.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.junit.runner.RunWith;
38 import org.mockito.InjectMocks;
39 import org.mockito.Mock;
40 import org.mockito.runners.MockitoJUnitRunner;
41 import org.onap.aai.domain.yang.VpnBindings;
42 import org.onap.so.bpmn.common.data.TestDataSetup;
43 import org.onap.so.bpmn.common.InjectionHelper;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding;
46 import org.onap.so.client.aai.AAIResourcesClient;
47 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
48 import org.onap.so.client.aai.mapper.AAIObjectMapper;
49
50 @RunWith(MockitoJUnitRunner.class)
51 public class AAIVpnBindingResourcesTest extends TestDataSetup{
52
53         @Mock
54         protected AAIResourcesClient MOCK_aaiResourcesClient;
55
56         @Mock
57         protected AAIObjectMapper MOCK_aaiObjectMapper;
58
59         @Mock
60         protected InjectionHelper MOCK_injectionHelper;
61         
62         @InjectMocks
63         private AAIVpnBindingResources aaiVpnBindingResources = new AAIVpnBindingResources();
64         
65         private Customer customer;
66
67         @Before
68         public void before() {
69                 customer = buildCustomer();
70                  doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
71         }
72
73         @Test
74         public void createCustomerTest() {
75                 org.onap.aai.domain.yang.Customer mappedCustomer = new org.onap.aai.domain.yang.Customer();
76                 mappedCustomer.setGlobalCustomerId(customer.getGlobalCustomerId());
77                 
78                 doReturn(mappedCustomer).when(MOCK_aaiObjectMapper).mapCustomer(customer);
79                 doNothing().when(MOCK_aaiResourcesClient).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Customer.class));
80                 
81                 aaiVpnBindingResources.createCustomer(customer);
82                 
83                 verify(MOCK_aaiResourcesClient, times(1)).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Customer.class));
84                 verify(MOCK_aaiObjectMapper, times(1)).mapCustomer(customer);
85         }
86
87         @Test
88         public void getVpnBindingTest () {
89                 org.onap.aai.domain.yang.VpnBinding vpnBinding = new org.onap.aai.domain.yang.VpnBinding();
90                 vpnBinding.setVpnId("vnfId");
91                 when(MOCK_aaiResourcesClient.get(eq(org.onap.aai.domain.yang.VpnBinding.class),isA(AAIResourceUri.class))).thenReturn(Optional.of(vpnBinding));
92                 aaiVpnBindingResources.getVpnBinding("vpnId");
93                 verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.VpnBinding.class),isA(AAIResourceUri.class));
94         }
95
96     @Test
97     public void existsCustomerTest() {
98                 when(MOCK_aaiResourcesClient.exists(isA(AAIResourceUri.class))).thenReturn(true);
99                 boolean isCustomerExist = aaiVpnBindingResources.existsCustomer(customer);
100                 verify(MOCK_aaiResourcesClient, times(1)).exists(isA(AAIResourceUri.class));
101                 assertEquals(true,isCustomerExist);
102         }
103
104     @Test
105     public void getVpnBindingByCustomerVpnIdTest() {
106                 when(MOCK_aaiResourcesClient.get(eq(VpnBindings.class),isA(AAIResourceUri.class))).thenReturn(Optional.of(new VpnBindings()));
107                 Optional<VpnBindings> vpnBindings = aaiVpnBindingResources.getVpnBindingByCustomerVpnId("testCustomerVpnId");
108                 assertNotNull(vpnBindings.get());
109                 verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.VpnBindings.class),isA(AAIResourceUri.class));
110         }
111
112         @Test
113         public void createVpnBindingTest() {
114                 doNothing().when(MOCK_aaiResourcesClient).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VpnBinding.class));
115                 org.onap.aai.domain.yang.VpnBinding mappedVpnBinding = new org.onap.aai.domain.yang.VpnBinding();
116                 mappedVpnBinding.setVpnName("test");
117
118                 doReturn(mappedVpnBinding).when(MOCK_aaiObjectMapper).mapVpnBinding(isA(VpnBinding.class));
119                 VpnBinding vpnBinding = buildVpnBinding();
120                 aaiVpnBindingResources.createVpnBinding(vpnBinding);
121
122                 verify(MOCK_aaiResourcesClient, times(1)).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VpnBinding.class));
123                 verify(MOCK_aaiObjectMapper, times(1)).mapVpnBinding(isA(VpnBinding.class));
124         }
125
126         @Test
127         public void connectCustomerToVpnBinding() {
128                 doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class));
129                 aaiVpnBindingResources.connectCustomerToVpnBinding("testCustId","testVpnId");
130                 verify(MOCK_aaiResourcesClient,times(1)).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class));
131         }
132 }