Merge "resolved sonar issue in QueryServiceMacroHolder"
[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 static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26 import java.net.URI;
27 import java.util.List;
28
29 import javax.transaction.Transactional;
30 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.Response;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.onap.so.adapters.catalogdb.CatalogDBApplication;
36 import org.onap.so.db.catalog.beans.AuthenticationType;
37 import org.onap.so.db.catalog.beans.BuildingBlockDetail;
38 import org.onap.so.db.catalog.beans.CloudIdentity;
39 import org.onap.so.db.catalog.beans.CloudSite;
40 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
41 import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
42 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
43 import org.onap.so.db.catalog.beans.InstanceGroup;
44 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
45 import org.onap.so.db.catalog.beans.ServerType;
46 import org.onap.so.db.catalog.client.CatalogDbClient;
47 import org.onap.so.logger.MsoLogger;
48 import org.onap.so.logging.jaxrs.filter.jersey.SpringClientFilter;
49 import org.springframework.beans.factory.annotation.Autowired;
50 import org.springframework.beans.factory.annotation.Value;
51 import org.springframework.boot.context.embedded.LocalServerPort;
52 import org.springframework.boot.test.context.SpringBootTest;
53 import org.springframework.boot.test.web.client.TestRestTemplate;
54 import org.springframework.http.HttpEntity;
55 import org.springframework.http.HttpHeaders;
56 import org.springframework.http.HttpMethod;
57 import org.springframework.http.ResponseEntity;
58 import org.springframework.http.client.BufferingClientHttpRequestFactory;
59 import org.springframework.http.client.ClientHttpRequestFactory;
60 import org.springframework.http.client.SimpleClientHttpRequestFactory;
61 import org.springframework.test.context.ActiveProfiles;
62 import org.springframework.test.context.junit4.SpringRunner;
63 import org.springframework.web.util.UriComponentsBuilder;
64 import uk.co.blackpepper.bowman.Client;
65 import uk.co.blackpepper.bowman.ClientFactory;
66 import uk.co.blackpepper.bowman.Configuration;
67 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
68 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
69
70 @RunWith(SpringRunner.class)
71 @SpringBootTest(classes = CatalogDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
72 @ActiveProfiles("test")
73 public class CloudConfigTest {
74
75     protected TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
76
77     protected HttpHeaders headers = new HttpHeaders();
78
79     @LocalServerPort
80     private int port;
81
82     @Test
83     @Transactional
84     public void createCloudSiteRest_TEST() {
85         headers.set("Accept", MediaType.APPLICATION_JSON);
86         headers.set("Content-Type",MediaType.APPLICATION_JSON);
87
88         CloudSite cloudSite = new CloudSite();
89         cloudSite.setId("MTN6");
90         cloudSite.setClli("TESTCLLI");
91         cloudSite.setRegionId("regionId");
92         cloudSite.setCloudVersion("VERSION");
93         cloudSite.setPlatform("PLATFORM");
94
95         CloudIdentity cloudIdentity = new CloudIdentity();
96         cloudIdentity.setId("RANDOMID");
97         cloudIdentity.setIdentityUrl("URL");
98         cloudIdentity.setMsoId("MSO_ID");
99         cloudIdentity.setMsoPass("MSO_PASS");
100         cloudIdentity.setAdminTenant("ADMIN_TENANT");
101         cloudIdentity.setMemberRole("ROLE");
102         cloudIdentity.setIdentityServerType(ServerType.KEYSTONE);
103         cloudIdentity.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
104         cloudSite.setIdentityService(cloudIdentity);
105         String uri = "/cloudSite";
106         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:"+ port + uri);
107         HttpEntity<CloudSite> request = new HttpEntity<CloudSite>(cloudSite, headers);  
108         ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(),
109                 HttpMethod.POST, request, String.class);
110         assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusCode().value());
111
112         builder = UriComponentsBuilder.fromHttpUrl("http://localhost:"+ port + uri +"/" + cloudSite.getId());
113         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
114         ResponseEntity<CloudSite> actualCloudSite = restTemplate.exchange(builder.toUriString(),HttpMethod.GET, entity, CloudSite.class);
115
116         assertEquals(Response.Status.OK.getStatusCode(), actualCloudSite.getStatusCode().value());
117         assertThat(actualCloudSite.getBody(), sameBeanAs(cloudSite).ignoring("created").ignoring("updated")
118                 .ignoring("identityService.created").ignoring("identityService.updated"));
119
120     }
121
122 }