Get subscribers rewritten to new rest client
[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 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 java.util.Collections;
25 import java.util.Map;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.mockito.Matchers;
30 import org.mockito.Mock;
31 import org.mockito.Mockito;
32 import org.mockito.runners.MockitoJUnitRunner;
33 import org.onap.vid.aai.model.AaiNodeQueryResponse;
34 import org.onap.vid.aai.model.ResourceType;
35 import org.onap.vid.client.SyncRestClient;
36 import org.onap.vid.model.SubscriberList;
37
38 @RunWith(MockitoJUnitRunner.class)
39 public class AaiOverTLSClientTest {
40
41     private static final String SEARCH_NODES_QUERY_SEARCH_NODE_TYPE = "search/nodes-query?search-node-type=generic-vnf&filter=vnf-name:EQUALS:name";
42     private static final String SUBSCRIBERS = "business/customers?subscriber-type=INFRA&depth=0";
43     private AaiOverTLSClient aaiRestClient;
44
45     @Mock
46     private SyncRestClient syncRestClient;
47     @Mock
48     private AaiOverTLSPropertySupplier propertySupplier;
49
50     @Before
51     public void setUp() {
52         aaiRestClient = new AaiOverTLSClient(syncRestClient,  propertySupplier);
53     }
54
55     @Test
56     public void testSearchNodeTypeByName() {
57         mockPropertyReader();
58
59         aaiRestClient.searchNodeTypeByName("name", ResourceType.GENERIC_VNF);
60         Mockito.verify(syncRestClient).get(Matchers.contains(SEARCH_NODES_QUERY_SEARCH_NODE_TYPE),
61             Matchers.eq(getHeaders()), Matchers.eq(Collections.emptyMap()), Matchers.eq(AaiNodeQueryResponse.class));
62     }
63
64     @Test
65     public void  testGetAllSubscribers(){
66         mockPropertyReader();
67
68         aaiRestClient.getAllSubscribers();
69         Mockito.verify(syncRestClient).get(Matchers.contains(SUBSCRIBERS),
70             Matchers.eq(getHeaders()), Matchers.eq(Collections.emptyMap()), Matchers.eq(SubscriberList.class));
71     }
72
73     private void mockPropertyReader() {
74         Mockito.when(propertySupplier.getPassword()).thenReturn("Pass");
75         Mockito.when(propertySupplier.getUsername()).thenReturn("User");
76         Mockito.when(propertySupplier.getRequestId()).thenReturn("1");
77         Mockito.when(propertySupplier.getRandomUUID()).thenReturn("2");
78     }
79
80     private Map<String,String> getHeaders(){
81         return ImmutableMap.<String, String>builder().put("Authorization", "Basic VXNlcjpQYXNz").
82             put("X-FromAppId", "VidAaiController").put("Accept", "application/json").put("X-ECOMP-RequestID", "1").
83             put("X-TransactionId", "2").put("Content-Type", "application/json").build();
84     }
85
86 }