f2f06d7f3d6b11093a3c098b202c0afccc5212c0
[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.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;
47
48 public class CloudConfigTest extends CatalogDbAdapterBaseTest {
49
50     protected TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
51
52     protected HttpHeaders headers = new HttpHeaders();
53
54     @LocalServerPort
55     private int port;
56
57     @Test
58     @Transactional
59     public void createCloudSiteRest_TEST() {
60         headers.set("Accept", MediaType.APPLICATION_JSON);
61         headers.set("Content-Type",MediaType.APPLICATION_JSON);
62
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");
69
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());
86
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"));
96
97     }
98
99
100
101 }