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 static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
27 import java.util.List;
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;
70 @RunWith(SpringRunner.class)
71 @SpringBootTest(classes = CatalogDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
72 @ActiveProfiles("test")
73 public class CloudConfigTest {
75 protected TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
77 protected HttpHeaders headers = new HttpHeaders();
84 public void createCloudSiteRest_TEST() {
85 headers.set("Accept", MediaType.APPLICATION_JSON);
86 headers.set("Content-Type",MediaType.APPLICATION_JSON);
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");
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());
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);
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"));