Reduce the number of problems in resources by removing unused imports
[aai/resources.git] / aai-resources / src / test / java / org / onap / aai / rest / PserverRelationshipTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 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
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
21 package org.onap.aai.rest;
22
23 import static org.hamcrest.CoreMatchers.not;
24 import static org.hamcrest.MatcherAssert.assertThat;
25 import static org.hamcrest.Matchers.containsInAnyOrder;
26 import static org.hamcrest.Matchers.containsString;
27 import static org.junit.Assert.assertEquals;
28
29 import java.util.HashMap;
30 import java.util.HashSet;
31 import java.util.Map;
32 import java.util.Set;
33
34 import org.junit.Test;
35 import org.onap.aai.PayloadUtil;
36 import org.springframework.http.HttpEntity;
37 import org.springframework.http.HttpMethod;
38 import org.springframework.http.HttpStatus;
39 import org.springframework.http.ResponseEntity;
40
41 public class PserverRelationshipTest extends AbstractSpringRestTest {
42
43     @Test
44     public void testGetRelationshipThrowUnrecognizedAAIObjectException() {
45
46         String endpoint = "/aai/v12/cloud-infrastructure/pservers/pserver/test/relationship-list/relationship";
47
48         ResponseEntity responseEntity = null;
49
50         responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntity, String.class);
51         String body = responseEntity.getBody().toString();
52
53         Set<HttpMethod> httpMethodSet = new HashSet<>();
54
55         httpMethodSet.add(HttpMethod.PUT);
56         httpMethodSet.add(HttpMethod.DELETE);
57         httpMethodSet.add(HttpMethod.OPTIONS);
58
59         assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
60         assertThat(body, containsString("Unrecognized AAI function"));
61         assertThat(responseEntity.getHeaders().getAllow(), containsInAnyOrder(httpMethodSet.toArray()));
62     }
63
64     @Test
65     public void testPutPserverAndCloudRegionAndReturnEdgesWithLabel() throws Exception {
66
67         String hostname = "test-pserver1";
68         String endpoint = "/aai/v12/cloud-infrastructure/pservers/pserver/" + hostname;
69
70         ResponseEntity responseEntity = null;
71
72         restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class);
73
74         String cloudRegionId = "test-region-1";
75         String cloudOwnerId = "test-owner-1";
76         endpoint = "/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/" + cloudOwnerId + "/" + cloudRegionId;
77
78         Map<String, String> map = new HashMap<>();
79         map.put("hostname", hostname);
80         map.put("cloud-region-id", cloudRegionId);
81         map.put("cloud-owner", cloudOwnerId);
82
83         String payload = PayloadUtil.getTemplatePayload("pserver-to-cloud-region.json", map);
84         httpEntity = new HttpEntity(payload, headers);
85         restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class);
86
87         httpEntity = new HttpEntity(headers);
88         responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntity, String.class);
89         assertThat(responseEntity.getBody().toString(), containsString("relationship-label"));
90
91         endpoint = "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/" + cloudOwnerId + "/" + cloudRegionId;
92
93         responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntity, String.class);
94         assertThat(responseEntity.getBody().toString(), not(containsString("relationship-label")));
95     }
96 }