Add simplified local setup
[aai/test-config.git] / local-setup / src / test / java / onap / aai / AaiResourcesIT.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package onap.aai;
21
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;
29
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;
35
36 public class AaiResourcesIT {
37
38     private String id;
39
40     @After
41     public void tearDown() {
42         if (id != null && !id.isEmpty()) {
43             AaiRequest.delete(v14("/cloud-infrastructure/complexes/complex/clli2?resource-version=" + id));
44         }
45     }
46
47     @Test
48     public void aai_resources_docker_test() {
49         System.out.println("Get complexes...");
50         assert_getComplexes_returns_notFound();
51
52         System.out.println("Adding complex...");
53         assert_putComplex_returns_created();
54
55         System.out.println("Get complexes...");
56         id = assert_getComplexes_returns_complex();
57
58         System.out.println("Remove complex...");
59         assert_deleteComplex_returns_noContent(id);
60
61         System.out.println("Get complex...");
62         assert_getComplexes_returns_notFound();
63     }
64
65     private void assert_getComplexes_returns_notFound() {
66         HttpRequest request = AaiRequest.get(v14("/cloud-infrastructure/complexes"));
67
68         assertThat(request.code()).isEqualTo(HTTP_NOT_FOUND);
69         assertThat(request.body()).contains("requestError");
70     }
71
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"));
76
77         assertThat(request.code()).isEqualTo(HTTP_CREATED);
78     }
79
80     private String assert_getComplexes_returns_complex() {
81         HttpRequest request = AaiRequest.get(v14("/cloud-infrastructure/complexes"))
82             .acceptJson();
83
84         assertThat(request.code()).isEqualTo(HTTP_OK);
85         String body = request.body();
86
87         assertThat(body).contains("clli2").contains("resource-version");
88
89         return JsonPath.read(body, "$.complex.[0].resource-version");
90     }
91
92     private void assert_deleteComplex_returns_noContent(String id) {
93         HttpRequest request = AaiRequest
94             .delete(v14("/cloud-infrastructure/complexes/complex/clli2?resource-version=" + id));
95
96         assertThat(request.code()).isEqualTo(HTTP_NO_CONTENT);
97     }
98 }