2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 - 2019 Nokia Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.vid.aai;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.MockitoAnnotations.initMocks;
26 import static org.onap.vid.utils.KotlinUtilsKt.JOSHWORKS_JACKSON_OBJECT_MAPPER;
28 import com.fasterxml.jackson.core.JsonProcessingException;
29 import com.xebialabs.restito.semantics.Action;
30 import io.joshworks.restclient.http.HttpResponse;
31 import java.io.IOException;
32 import org.assertj.core.api.Assertions;
33 import org.glassfish.grizzly.http.util.HttpStatus;
34 import org.jetbrains.annotations.NotNull;
35 import org.json.simple.parser.JSONParser;
36 import org.json.simple.parser.ParseException;
37 import org.mockito.Mock;
38 import org.onap.vid.aai.model.ResourceType;
39 import org.onap.vid.client.SyncRestClient;
40 import org.onap.vid.model.SubscriberList;
41 import org.onap.vid.testUtils.StubServerUtil;
42 import org.onap.vid.utils.Logging;
43 import org.testng.annotations.AfterClass;
44 import org.testng.annotations.BeforeClass;
45 import org.testng.annotations.BeforeMethod;
46 import org.testng.annotations.Test;
48 public class AaiOverTLSClientServerTest {
51 private AaiOverTLSPropertySupplier propertySupplier;
53 private static StubServerUtil serverUtil;
55 private String searchNodesQueryResponsePayload = "" +
57 "\"result-data\": [" +
59 " \"resource-type\": \"generic-vnf\"," +
60 " \"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/6eac8e69-c98d-4ac5-ab90-69fe0cabda76\"" +
65 private String subscribersResponsePayload =
69 + "\"global-customer-id\": \"DemoCust_752df078-d8e9-4731-abf6-8ae7348075bb\",\n"
70 + "\"subscriber-name\": \"DemoCust_752df078-d8e9-4731-abf6-8ae7348075bb\",\n"
71 + "\"subscriber-type\": \"INFRA\",\n"
72 + "\"resource-version\": \"1536158347585\"\n"
75 + "\"global-customer-id\": \"DemoCust_62bf43a3-4888-4c82-ae98-3ebc3d782761\",\n"
76 + "\"subscriber-name\": \"DemoCust_62bf43a3-4888-4c82-ae98-3ebc3d782761\",\n"
77 + "\"subscriber-type\": \"INFRA\",\n"
78 + "\"resource-version\": \"1536240894581\"\n"
81 + "\"global-customer-id\": \"DemoCust_e84256d6-ef3e-4a28-9741-9987019c3a8f\",\n"
82 + "\"subscriber-name\": \"DemoCust_e84256d6-ef3e-4a28-9741-9987019c3a8f\",\n"
83 + "\"subscriber-type\": \"INFRA\",\n"
84 + "\"resource-version\": \"1536330956393\"\n"
87 + "\"global-customer-id\": \"ETE_Customer_377bb124-2638-4025-a315-cdae04f52bce\",\n"
88 + "\"subscriber-name\": \"ETE_Customer_377bb124-2638-4025-a315-cdae04f52bce\",\n"
89 + "\"subscriber-type\": \"INFRA\",\n"
90 + "\"resource-version\": \"1536088625538\"\n"
96 public static void setUpClass(){
97 serverUtil = new StubServerUtil();
98 serverUtil.runServer();
102 public static void tearDown(){
103 serverUtil.stopServer();
112 public void shouldSearchNodeTypeByName() throws IOException, ParseException {
113 AaiOverTLSClient aaiOverTLSClient = createAaiOverTLSClient();
115 serverUtil.prepareGetCall("/nodes/generic-vnfs", new JSONParser().parse(searchNodesQueryResponsePayload), Action.status(HttpStatus.OK_200));
117 boolean aaiNodeQueryResponseHttpResponse = aaiOverTLSClient
118 .isNodeTypeExistsByName("any", ResourceType.GENERIC_VNF);
120 Assertions.assertThat(aaiNodeQueryResponseHttpResponse).isEqualTo(true);
124 private AaiOverTLSClient createAaiOverTLSClient() {
125 return new AaiOverTLSClient(
126 new SyncRestClient(JOSHWORKS_JACKSON_OBJECT_MAPPER, mock(Logging.class)),
128 serverUtil.constructTargetUrl("http", "")
133 public void shouldGetSubscribers() throws ParseException, JsonProcessingException {
134 AaiOverTLSClient aaiOverTLSClient = createAaiOverTLSClient();
136 serverUtil.prepareGetCall("/business/customers", new JSONParser().parse(subscribersResponsePayload), Action.status(HttpStatus.OK_200));
138 HttpResponse<SubscriberList> allSubscribers = aaiOverTLSClient.getAllSubscribers();
140 SubscriberList subscriberList = allSubscribers.getBody();
141 Assertions.assertThat(subscriberList.customer.size()).isEqualTo(4);
142 Assertions.assertThat(allSubscribers.getStatus()).isEqualTo(200);