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.aai;
23 import static org.mockito.ArgumentMatchers.isA;
24 import static org.mockito.Mockito.doReturn;
25 import static org.mockito.Mockito.spy;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
29 import java.util.Arrays;
30 import java.util.List;
32 import javax.ws.rs.core.Response;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.InjectMocks;
37 import org.mockito.Mock;
38 import org.mockito.junit.MockitoJUnitRunner;
39 import org.onap.so.client.RestClient;
40 import org.onap.so.client.aai.entities.CustomQuery;
41 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
42 import org.onap.so.client.aai.entities.uri.AAIUri;
43 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
44 import org.onap.so.client.graphinventory.Format;
45 import org.onap.so.client.graphinventory.GraphInventoryClient;
46 import org.onap.so.client.graphinventory.GraphInventorySubgraphType;
49 @RunWith(MockitoJUnitRunner.class)
50 public class AAIQueryClientTest {
56 RestClient restClient;
59 GraphInventoryClient client;
62 AAIQueryClient aaiQueryClient = new AAIQueryClient();
65 public void testQuery() {
66 List<AAIResourceUri> uris = Arrays.asList(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY));
68 Format format = Format.SIMPLE;
69 CustomQuery query = new CustomQuery(uris);
71 doReturn(restClient).when(client).createClient(isA(AAIUri.class));
72 aaiQueryClient.query(format, query);
73 verify(client, times(1)).createClient(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY).queryParam("format", format.toString()));
74 verify(restClient, times(1)).put(query, String.class);
78 public void testCreateClient() {
79 String depth = "testDepth";
80 GraphInventorySubgraphType subgraph = GraphInventorySubgraphType.STAR;
82 aaiQueryClient.depth(depth);
83 aaiQueryClient.nodesOnly();
84 aaiQueryClient.subgraph(subgraph);
86 AAIUri aaiUri = spy(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY));
87 doReturn(aaiUri).when(aaiUri).clone();
88 aaiQueryClient.setupQueryParams(aaiUri);
90 verify(aaiUri, times(1)).queryParam("depth", depth);
91 verify(aaiUri, times(1)).queryParam("nodesOnly", "");
92 verify(aaiUri, times(1)).queryParam("subgraph", subgraph.toString());