2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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.so.adapters.catalogdb.catalogrest;
23 import static org.junit.Assert.assertEquals;
24 import javax.transaction.Transactional;
25 import javax.ws.rs.core.MediaType;
26 import javax.ws.rs.core.Response;
27 import org.junit.Test;
28 import org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest;
29 import org.onap.so.db.catalog.beans.AuthenticationType;
30 import org.onap.so.db.catalog.beans.CloudIdentity;
31 import org.onap.so.db.catalog.beans.CloudSite;
32 import org.onap.so.db.catalog.beans.ServerType;
33 import org.springframework.boot.web.server.LocalServerPort;
34 import org.springframework.boot.test.web.client.TestRestTemplate;
35 import org.springframework.http.HttpEntity;
36 import org.springframework.http.HttpHeaders;
37 import org.springframework.http.HttpMethod;
38 import org.springframework.http.ResponseEntity;
39 import org.springframework.web.util.UriComponentsBuilder;
40 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
41 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
43 public class CloudConfigTest extends CatalogDbAdapterBaseTest {
45 protected TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
47 protected HttpHeaders headers = new HttpHeaders();
54 public void createCloudSiteRest_TEST() {
55 headers.set("Accept", MediaType.APPLICATION_JSON);
56 headers.set("Content-Type", MediaType.APPLICATION_JSON);
58 CloudSite cloudSite = new CloudSite();
59 cloudSite.setId("MTN7");
60 cloudSite.setClli("TESTCLLI");
61 cloudSite.setRegionId("regionId");
62 cloudSite.setCloudVersion("VERSION");
63 cloudSite.setPlatform("PLATFORM");
65 CloudIdentity cloudIdentity = new CloudIdentity();
66 cloudIdentity.setId("RANDOMID-test");
67 cloudIdentity.setIdentityUrl("URL");
68 cloudIdentity.setMsoId("MSO_ID");
69 cloudIdentity.setMsoPass("MSO_PASS");
70 cloudIdentity.setAdminTenant("ADMIN_TENANT");
71 cloudIdentity.setMemberRole("ROLE");
72 cloudIdentity.setIdentityServerType(ServerType.KEYSTONE);
73 cloudIdentity.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
74 cloudSite.setIdentityService(cloudIdentity);
75 String uri = "/cloudSite";
76 UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:" + port + uri);
77 HttpEntity<CloudSite> request = new HttpEntity<CloudSite>(cloudSite, headers);
78 ResponseEntity<String> response =
79 restTemplate.exchange(builder.toUriString(), HttpMethod.POST, request, String.class);
80 assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusCode().value());
82 builder = UriComponentsBuilder.fromHttpUrl("http://localhost:" + port + uri + "/" + cloudSite.getId());
83 HttpEntity<String> entity = new HttpEntity<String>(null, headers);
84 ResponseEntity<CloudSite> actualCloudSite =
85 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, CloudSite.class);
86 builder = UriComponentsBuilder.fromHttpUrl("http://localhost:" + port + uri);
87 ResponseEntity<String> cloudSiteString =
88 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
89 System.out.println(cloudSiteString.getBody());
90 assertEquals(Response.Status.OK.getStatusCode(), actualCloudSite.getStatusCode().value());
91 assertThat(actualCloudSite.getBody(), sameBeanAs(cloudSite).ignoring("created").ignoring("updated")
92 .ignoring("identityService.created").ignoring("identityService.updated"));