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.junit.runner.RunWith;
29 import org.onap.so.adapters.catalogdb.CatalogDBApplication;
30 import org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest;
31 import org.onap.so.db.catalog.beans.AuthenticationType;
32 import org.onap.so.db.catalog.beans.CloudIdentity;
33 import org.onap.so.db.catalog.beans.CloudSite;
34 import org.onap.so.db.catalog.beans.ServerType;
35 import org.springframework.boot.web.server.LocalServerPort;
36 import org.springframework.boot.test.context.SpringBootTest;
37 import org.springframework.boot.test.web.client.TestRestTemplate;
38 import org.springframework.http.HttpEntity;
39 import org.springframework.http.HttpHeaders;
40 import org.springframework.http.HttpMethod;
41 import org.springframework.http.ResponseEntity;
42 import org.springframework.test.context.ActiveProfiles;
43 import org.springframework.test.context.junit4.SpringRunner;
44 import org.springframework.web.util.UriComponentsBuilder;
45 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
46 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
48 public class CloudConfigTest extends CatalogDbAdapterBaseTest {
50 protected TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
52 protected HttpHeaders headers = new HttpHeaders();
59 public void createCloudSiteRest_TEST() {
60 headers.set("Accept", MediaType.APPLICATION_JSON);
61 headers.set("Content-Type",MediaType.APPLICATION_JSON);
63 CloudSite cloudSite = new CloudSite();
64 cloudSite.setId("MTN7");
65 cloudSite.setClli("TESTCLLI");
66 cloudSite.setRegionId("regionId");
67 cloudSite.setCloudVersion("VERSION");
68 cloudSite.setPlatform("PLATFORM");
70 CloudIdentity cloudIdentity = new CloudIdentity();
71 cloudIdentity.setId("RANDOMID-test");
72 cloudIdentity.setIdentityUrl("URL");
73 cloudIdentity.setMsoId("MSO_ID");
74 cloudIdentity.setMsoPass("MSO_PASS");
75 cloudIdentity.setAdminTenant("ADMIN_TENANT");
76 cloudIdentity.setMemberRole("ROLE");
77 cloudIdentity.setIdentityServerType(ServerType.KEYSTONE);
78 cloudIdentity.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
79 cloudSite.setIdentityService(cloudIdentity);
80 String uri = "/cloudSite";
81 UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:"+ port + uri);
82 HttpEntity<CloudSite> request = new HttpEntity<CloudSite>(cloudSite, headers);
83 ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(),
84 HttpMethod.POST, request, String.class);
85 assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusCode().value());
87 builder = UriComponentsBuilder.fromHttpUrl("http://localhost:"+ port + uri +"/" + cloudSite.getId());
88 HttpEntity<String> entity = new HttpEntity<String>(null, headers);
89 ResponseEntity<CloudSite> actualCloudSite = restTemplate.exchange(builder.toUriString(),HttpMethod.GET, entity, CloudSite.class);
90 builder = UriComponentsBuilder.fromHttpUrl("http://localhost:"+ port + uri);
91 ResponseEntity<String> cloudSiteString = restTemplate.exchange(builder.toUriString(),HttpMethod.GET, entity, String.class);
92 System.out.println(cloudSiteString.getBody());
93 assertEquals(Response.Status.OK.getStatusCode(), actualCloudSite.getStatusCode().value());
94 assertThat(actualCloudSite.getBody(), sameBeanAs(cloudSite).ignoring("created").ignoring("updated")
95 .ignoring("identityService.created").ignoring("identityService.updated"));