Springboot 2.0 upgrade
[so.git] / adapters / mso-catalog-db-adapter / src / test / java / org / onap / so / adapters / catalogdb / catalogrest / CloudConfigTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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.so.adapters.catalogdb.catalogrest;
22
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.db.catalog.beans.AuthenticationType;
31 import org.onap.so.db.catalog.beans.CloudIdentity;
32 import org.onap.so.db.catalog.beans.CloudSite;
33 import org.onap.so.db.catalog.beans.ServerType;
34 import org.springframework.boot.web.server.LocalServerPort;
35 import org.springframework.boot.test.context.SpringBootTest;
36 import org.springframework.boot.test.web.client.TestRestTemplate;
37 import org.springframework.http.HttpEntity;
38 import org.springframework.http.HttpHeaders;
39 import org.springframework.http.HttpMethod;
40 import org.springframework.http.ResponseEntity;
41 import org.springframework.test.context.ActiveProfiles;
42 import org.springframework.test.context.junit4.SpringRunner;
43 import org.springframework.web.util.UriComponentsBuilder;
44 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
45 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
46
47 @RunWith(SpringRunner.class)
48 @SpringBootTest(classes = CatalogDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
49 @ActiveProfiles("test")
50 public class CloudConfigTest {
51
52     protected TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
53
54     protected HttpHeaders headers = new HttpHeaders();
55
56     @LocalServerPort
57     private int port;
58
59     @Test
60     @Transactional
61     public void createCloudSiteRest_TEST() {
62         headers.set("Accept", MediaType.APPLICATION_JSON);
63         headers.set("Content-Type",MediaType.APPLICATION_JSON);
64
65         CloudSite cloudSite = new CloudSite();
66         cloudSite.setId("MTN6");
67         cloudSite.setClli("TESTCLLI");
68         cloudSite.setRegionId("regionId");
69         cloudSite.setCloudVersion("VERSION");
70         cloudSite.setPlatform("PLATFORM");
71
72         CloudIdentity cloudIdentity = new CloudIdentity();
73         cloudIdentity.setId("RANDOMID");
74         cloudIdentity.setIdentityUrl("URL");
75         cloudIdentity.setMsoId("MSO_ID");
76         cloudIdentity.setMsoPass("MSO_PASS");
77         cloudIdentity.setAdminTenant("ADMIN_TENANT");
78         cloudIdentity.setMemberRole("ROLE");
79         cloudIdentity.setIdentityServerType(ServerType.KEYSTONE);
80         cloudIdentity.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
81         cloudSite.setIdentityService(cloudIdentity);
82         String uri = "/cloudSite";
83         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:"+ port + uri);
84         HttpEntity<CloudSite> request = new HttpEntity<CloudSite>(cloudSite, headers);  
85         ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(),
86                 HttpMethod.POST, request, String.class);
87         assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusCode().value());
88
89         builder = UriComponentsBuilder.fromHttpUrl("http://localhost:"+ port + uri +"/" + cloudSite.getId());
90         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
91         ResponseEntity<CloudSite> actualCloudSite = restTemplate.exchange(builder.toUriString(),HttpMethod.GET, entity, CloudSite.class);
92
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"));
96
97     }
98
99 }