2 * ============LICENSE_START=======================================================
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
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.vid.aai;
23 import com.fasterxml.jackson.core.JsonProcessingException;
24 import com.xebialabs.restito.semantics.Action;
25 import io.joshworks.restclient.http.HttpResponse;
26 import io.joshworks.restclient.http.mapper.ObjectMapper;
27 import org.assertj.core.api.Assertions;
28 import org.glassfish.grizzly.http.util.HttpStatus;
29 import org.json.simple.parser.JSONParser;
30 import org.json.simple.parser.ParseException;
31 import org.mockito.Mock;
32 import org.onap.vid.aai.model.ResourceType;
33 import org.onap.vid.client.SyncRestClient;
34 import org.onap.vid.model.SubscriberList;
35 import org.onap.vid.testUtils.StubServerUtil;
36 import org.testng.annotations.AfterClass;
37 import org.testng.annotations.BeforeClass;
38 import org.testng.annotations.BeforeMethod;
39 import org.testng.annotations.Test;
41 import java.io.IOException;
43 import static org.mockito.MockitoAnnotations.initMocks;
45 public class AaiOverTLSClientServerTest {
48 private AaiOverTLSPropertySupplier propertySupplier;
50 private static StubServerUtil serverUtil;
52 private String searchNodesQueryResponsePayload = "" +
54 "\"result-data\": [" +
56 " \"resource-type\": \"generic-vnf\"," +
57 " \"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/6eac8e69-c98d-4ac5-ab90-69fe0cabda76\"" +
62 private String subscribersResponsePayload =
66 + "\"global-customer-id\": \"DemoCust_752df078-d8e9-4731-abf6-8ae7348075bb\",\n"
67 + "\"subscriber-name\": \"DemoCust_752df078-d8e9-4731-abf6-8ae7348075bb\",\n"
68 + "\"subscriber-type\": \"INFRA\",\n"
69 + "\"resource-version\": \"1536158347585\"\n"
72 + "\"global-customer-id\": \"DemoCust_62bf43a3-4888-4c82-ae98-3ebc3d782761\",\n"
73 + "\"subscriber-name\": \"DemoCust_62bf43a3-4888-4c82-ae98-3ebc3d782761\",\n"
74 + "\"subscriber-type\": \"INFRA\",\n"
75 + "\"resource-version\": \"1536240894581\"\n"
78 + "\"global-customer-id\": \"DemoCust_e84256d6-ef3e-4a28-9741-9987019c3a8f\",\n"
79 + "\"subscriber-name\": \"DemoCust_e84256d6-ef3e-4a28-9741-9987019c3a8f\",\n"
80 + "\"subscriber-type\": \"INFRA\",\n"
81 + "\"resource-version\": \"1536330956393\"\n"
84 + "\"global-customer-id\": \"ETE_Customer_377bb124-2638-4025-a315-cdae04f52bce\",\n"
85 + "\"subscriber-name\": \"ETE_Customer_377bb124-2638-4025-a315-cdae04f52bce\",\n"
86 + "\"subscriber-type\": \"INFRA\",\n"
87 + "\"resource-version\": \"1536088625538\"\n"
93 public static void setUpClass(){
94 serverUtil = new StubServerUtil();
95 serverUtil.runServer();
99 public static void tearDown(){
100 serverUtil.stopServer();
109 public void shouldSearchNodeTypeByName() throws IOException, ParseException {
110 ObjectMapper objectMapper = getFasterXmlObjectMapper();
111 AaiOverTLSClient aaiOverTLSClient = new AaiOverTLSClient(new SyncRestClient(objectMapper), propertySupplier, serverUtil.constructTargetUrl("http", ""));
113 serverUtil.prepareGetCall("/nodes/generic-vnfs", new JSONParser().parse(searchNodesQueryResponsePayload), Action.status(HttpStatus.OK_200));
115 boolean aaiNodeQueryResponseHttpResponse = aaiOverTLSClient
116 .isNodeTypeExistsByName("any", ResourceType.GENERIC_VNF);
118 Assertions.assertThat(aaiNodeQueryResponseHttpResponse).isEqualTo(true);
122 public void shouldGetSubscribers() throws ParseException, JsonProcessingException {
123 ObjectMapper objectMapper = getFasterXmlObjectMapper();
124 AaiOverTLSClient aaiOverTLSClient = new AaiOverTLSClient(new SyncRestClient(objectMapper), propertySupplier, serverUtil.constructTargetUrl("http", ""));
126 serverUtil.prepareGetCall("/business/customers", new JSONParser().parse(subscribersResponsePayload), Action.status(HttpStatus.OK_200));
128 HttpResponse<SubscriberList> allSubscribers = aaiOverTLSClient.getAllSubscribers();
130 SubscriberList subscriberList = allSubscribers.getBody();
131 Assertions.assertThat(subscriberList.customer.size()).isEqualTo(4);
132 Assertions.assertThat(allSubscribers.getStatus()).isEqualTo(200);
135 private ObjectMapper getFasterXmlObjectMapper() {
136 return new ObjectMapper() {
138 com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper();
141 public <T> T readValue(String s, Class<T> aClass) {
143 return om.readValue(s, aClass);
144 } catch (IOException e) {
145 throw new RuntimeException(e);
150 public String writeValue(Object o) {
152 return om.writeValueAsString(o);
153 } catch (IOException e) {
154 throw new RuntimeException(e);