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.junit.Assert.assertNotNull;
24 import static org.mockito.Matchers.eq;
25 import static org.mockito.ArgumentMatchers.isA;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.spy;
29 import static org.mockito.Mockito.times;
30 import static org.mockito.Mockito.verify;
32 import java.util.Arrays;
33 import java.util.List;
35 import javax.ws.rs.core.Response;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.mockito.Mock;
40 import org.mockito.Mockito;
41 import org.mockito.Spy;
42 import org.mockito.junit.MockitoJUnitRunner;
43 import org.onap.so.client.RestClient;
44 import org.onap.so.client.aai.entities.CustomQuery;
45 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
46 import org.onap.so.client.aai.entities.uri.AAIUri;
47 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
48 import org.onap.so.client.graphinventory.Format;
51 @RunWith(MockitoJUnitRunner.class)
52 public class AAIQueryClientTest {
58 RestClient restClient;
61 AAIQueryClient aaiQueryClient = new AAIQueryClient();
64 public void testQuery() {
65 List<AAIResourceUri> uris = Arrays.asList(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY));
67 Format format = Format.SIMPLE;
68 CustomQuery query = new CustomQuery(uris);
70 doReturn(restClient).when(aaiQueryClient).createClient(isA(AAIUri.class));
71 aaiQueryClient.query(format, query);
72 verify(aaiQueryClient, times(1)).createClient(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY).queryParam("format", format.toString()));
73 verify(restClient, times(1)).put(query, String.class);
77 public void testCreateClient() {
78 String depth = "testDepth";
79 AAISubgraphType subgraph = AAISubgraphType.STAR;
81 aaiQueryClient.depth(depth);
82 aaiQueryClient.nodesOnly();
83 aaiQueryClient.subgraph(subgraph);
85 AAIUri aaiUri = spy(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY));
86 doReturn(aaiUri).when(aaiUri).clone();
87 aaiQueryClient.setupQueryParams(aaiUri);
89 verify(aaiUri, times(1)).queryParam("depth", depth);
90 verify(aaiUri, times(1)).queryParam("nodesOnly", "");
91 verify(aaiUri, times(1)).queryParam("subgraph", subgraph.toString());