2 * ============LICENSE_START=======================================================
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
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.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;
33 import java.util.Optional;
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;
50 @RunWith(MockitoJUnitRunner.class)
51 public class AAIVpnBindingResourcesTest extends TestDataSetup{
54 protected AAIResourcesClient MOCK_aaiResourcesClient;
57 protected AAIObjectMapper MOCK_aaiObjectMapper;
60 protected InjectionHelper MOCK_injectionHelper;
63 private AAIVpnBindingResources aaiVpnBindingResources = new AAIVpnBindingResources();
65 private Customer customer;
68 public void before() {
69 customer = buildCustomer();
70 doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
74 public void createCustomerTest() {
75 org.onap.aai.domain.yang.Customer mappedCustomer = new org.onap.aai.domain.yang.Customer();
76 mappedCustomer.setGlobalCustomerId(customer.getGlobalCustomerId());
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));
81 aaiVpnBindingResources.createCustomer(customer);
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);
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));
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);
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));
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");
118 doReturn(mappedVpnBinding).when(MOCK_aaiObjectMapper).mapVpnBinding(isA(VpnBinding.class));
119 VpnBinding vpnBinding = buildVpnBinding();
120 aaiVpnBindingResources.createVpnBinding(vpnBinding);
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));
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));