Merge "Turn role management off by default"
[vid.git] / vid-app-common / src / test / java / org / onap / vid / aai / AaiOverTLSClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2018 - 2019 Nokia 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.vid.aai;
22
23 import com.google.common.collect.ImmutableMap;
24 import org.mockito.Answers;
25 import org.mockito.Mock;
26 import org.mockito.Mockito;
27
28 import org.onap.vid.aai.model.ResourceType;
29 import org.onap.vid.client.SyncRestClient;
30 import org.onap.vid.model.SubscriberList;
31 import org.testng.annotations.BeforeMethod;
32 import org.testng.annotations.Test;
33
34 import java.util.Collections;
35 import java.util.Map;
36
37 import static org.mockito.ArgumentMatchers.contains;
38 import static org.mockito.ArgumentMatchers.eq;
39 import static org.mockito.MockitoAnnotations.initMocks;
40
41 public class AaiOverTLSClientTest {
42
43     private static final String SEARCH_NODES_QUERY_SEARCH_NODE_TYPE = "nodes/generic-vnfs?vnf-name=name";
44     private static final String SUBSCRIBERS = "business/customers?subscriber-type=INFRA&depth=0";
45     private AaiOverTLSClient aaiRestClient;
46
47     @Mock(answer = Answers.RETURNS_MOCKS)
48     private SyncRestClient syncRestClient;
49     @Mock
50     private AaiOverTLSPropertySupplier propertySupplier;
51
52     @BeforeMethod
53     public void setUp() {
54         initMocks(this);
55         aaiRestClient = new AaiOverTLSClient(syncRestClient,  propertySupplier);
56     }
57
58     @Test
59     public void testIsNodeTypeExistsByName() {
60         mockPropertyReader();
61
62         aaiRestClient.isNodeTypeExistsByName("name", ResourceType.GENERIC_VNF);
63         Mockito.verify(syncRestClient).get(contains(SEARCH_NODES_QUERY_SEARCH_NODE_TYPE),
64             eq(getHeaders()), eq(Collections.emptyMap()));
65     }
66
67     @Test
68     public void  testGetAllSubscribers(){
69         mockPropertyReader();
70
71         aaiRestClient.getAllSubscribers();
72         Mockito.verify(syncRestClient).get(contains(SUBSCRIBERS),
73             eq(getHeaders()), eq(Collections.emptyMap()), eq(SubscriberList.class));
74     }
75
76     private void mockPropertyReader() {
77         Mockito.when(propertySupplier.getPassword()).thenReturn("Pass");
78         Mockito.when(propertySupplier.getUsername()).thenReturn("User");
79         Mockito.when(propertySupplier.getRequestId()).thenReturn("1");
80         Mockito.when(propertySupplier.getRandomUUID()).thenReturn("2");
81     }
82
83     private Map<String,String> getHeaders(){
84         return ImmutableMap.<String, String>builder().put("Authorization", "Basic VXNlcjpQYXNz").
85             put("X-FromAppId", "VidAaiController").put("Accept", "application/json").put("X-ECOMP-RequestID", "1").
86             put("X-TransactionId", "2").put("Content-Type", "application/json").build();
87     }
88
89 }