2 * ============LICENSE_START=======================================================
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
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.aai.rest;
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;
29 import java.util.HashMap;
30 import java.util.HashSet;
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;
41 public class PserverRelationshipTest extends AbstractSpringRestTest {
44 public void testGetRelationshipThrowUnrecognizedAAIObjectException() {
46 String endpoint = "/aai/v12/cloud-infrastructure/pservers/pserver/test/relationship-list/relationship";
48 ResponseEntity responseEntity = null;
50 responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntity, String.class);
51 String body = responseEntity.getBody().toString();
53 Set<HttpMethod> httpMethodSet = new HashSet<>();
55 httpMethodSet.add(HttpMethod.PUT);
56 httpMethodSet.add(HttpMethod.DELETE);
57 httpMethodSet.add(HttpMethod.OPTIONS);
59 assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
60 assertThat(body, containsString("Unrecognized AAI function"));
61 assertThat(responseEntity.getHeaders().getAllow(), containsInAnyOrder(httpMethodSet.toArray()));
65 public void testPutPserverAndCloudRegionAndReturnEdgesWithLabel() throws Exception {
67 String hostname = "test-pserver1";
68 String endpoint = "/aai/v12/cloud-infrastructure/pservers/pserver/" + hostname;
70 ResponseEntity responseEntity = null;
72 restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class);
74 String cloudRegionId = "test-region-1";
75 String cloudOwnerId = "test-owner-1";
76 endpoint = "/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/" + cloudOwnerId + "/" + cloudRegionId;
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);
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);
87 httpEntity = new HttpEntity(headers);
88 responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntity, String.class);
89 assertThat(responseEntity.getBody().toString(), containsString("relationship-label"));
91 endpoint = "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/" + cloudOwnerId + "/" + cloudRegionId;
93 responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntity, String.class);
94 assertThat(responseEntity.getBody().toString(), not(containsString("relationship-label")));