2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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=========================================================
22 import static java.net.HttpURLConnection.HTTP_CREATED;
23 import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
24 import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
25 import static java.net.HttpURLConnection.HTTP_OK;
26 import static onap.aai.util.AaiRequest.v14;
27 import static onap.aai.util.Resources.inputStreamFrom;
28 import static org.assertj.core.api.Assertions.assertThat;
30 import com.github.kevinsawicki.http.HttpRequest;
31 import com.jayway.jsonpath.JsonPath;
32 import onap.aai.util.AaiRequest;
33 import org.junit.After;
34 import org.junit.Test;
36 public class AaiResourcesIT {
41 public void tearDown() {
42 if (id != null && !id.isEmpty()) {
43 AaiRequest.delete(v14("/cloud-infrastructure/complexes/complex/clli2?resource-version=" + id));
48 public void aai_resources_docker_test() {
49 System.out.println("Get complexes...");
50 assert_getComplexes_returns_notFound();
52 System.out.println("Adding complex...");
53 assert_putComplex_returns_created();
55 System.out.println("Get complexes...");
56 id = assert_getComplexes_returns_complex();
58 System.out.println("Remove complex...");
59 assert_deleteComplex_returns_noContent(id);
61 System.out.println("Get complex...");
62 assert_getComplexes_returns_notFound();
65 private void assert_getComplexes_returns_notFound() {
66 HttpRequest request = AaiRequest.get(v14("/cloud-infrastructure/complexes"));
68 assertThat(request.code()).isEqualTo(HTTP_NOT_FOUND);
69 assertThat(request.body()).contains("requestError");
72 private void assert_putComplex_returns_created() {
73 HttpRequest request = AaiRequest
74 .put(v14("/cloud-infrastructure/complexes/complex/clli2"))
75 .send(inputStreamFrom("complex_data.json"));
77 assertThat(request.code()).isEqualTo(HTTP_CREATED);
80 private String assert_getComplexes_returns_complex() {
81 HttpRequest request = AaiRequest.get(v14("/cloud-infrastructure/complexes"))
84 assertThat(request.code()).isEqualTo(HTTP_OK);
85 String body = request.body();
87 assertThat(body).contains("clli2").contains("resource-version");
89 return JsonPath.read(body, "$.complex.[0].resource-version");
92 private void assert_deleteComplex_returns_noContent(String id) {
93 HttpRequest request = AaiRequest
94 .delete(v14("/cloud-infrastructure/complexes/complex/clli2?resource-version=" + id));
96 assertThat(request.code()).isEqualTo(HTTP_NO_CONTENT);