2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.asdc.client.test.rest;
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.post;
25 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
27 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
28 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNotNull;
31 import static org.junit.Assert.assertNull;
34 import java.util.ArrayList;
35 import java.util.HashMap;
36 import java.util.HashSet;
37 import java.util.List;
40 import javax.transaction.Transactional;
41 import javax.ws.rs.core.Response;
43 import org.junit.Ignore;
44 import org.junit.Test;
45 import org.mockito.Spy;
46 import org.onap.so.asdc.BaseTest;
47 import org.onap.so.asdc.client.test.emulators.DistributionClientEmulator;
48 import org.onap.so.asdc.client.test.emulators.NotificationDataImpl;
49 import org.onap.so.db.catalog.beans.AllottedResource;
50 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
51 import org.onap.so.db.catalog.beans.CollectionResource;
52 import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
53 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
54 import org.onap.so.db.catalog.beans.ConfigurationResource;
55 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
56 import org.onap.so.db.catalog.beans.InstanceGroup;
57 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
58 import org.onap.so.db.catalog.beans.NetworkResource;
59 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
60 import org.onap.so.db.catalog.beans.Service;
61 import org.onap.so.db.catalog.beans.ServiceProxyResource;
62 import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
63 import org.onap.so.db.catalog.beans.ServiceRecipe;
64 import org.onap.so.db.catalog.beans.ToscaCsar;
65 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
66 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
67 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
68 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
69 import org.onap.so.db.catalog.data.repository.CollectionResourceInstanceGroupCustomizationRepository;
70 import org.onap.so.db.catalog.data.repository.CollectionResourceRepository;
71 import org.onap.so.db.catalog.data.repository.ConfigurationResourceRepository;
72 import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
73 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
74 import org.onap.so.db.catalog.data.repository.ServiceProxyResourceRepository;
75 import org.onap.so.db.catalog.data.repository.ServiceRepository;
76 import org.onap.so.db.catalog.data.repository.VnfcInstanceGroupCustomizationRepository;
77 import org.springframework.beans.factory.annotation.Autowired;
78 import org.springframework.boot.context.embedded.LocalServerPort;
79 import org.springframework.boot.test.web.client.TestRestTemplate;
80 import org.springframework.http.HttpEntity;
81 import org.springframework.http.HttpHeaders;
82 import org.springframework.http.HttpMethod;
83 import org.springframework.http.ResponseEntity;
85 import com.fasterxml.jackson.annotation.JsonInclude.Include;
86 import com.fasterxml.jackson.databind.DeserializationFeature;
87 import com.fasterxml.jackson.databind.MapperFeature;
88 import com.fasterxml.jackson.databind.ObjectMapper;
90 public class ASDCRestInterfaceTest extends BaseTest {
91 //ASDC Controller writes to this path
93 System.setProperty("mso.config.path", "src/test/resources/");
98 private AllottedResourceRepository allottedRepo;
101 private ServiceRepository serviceRepo;
104 private NetworkResourceRepository networkRepo;
107 private ASDCRestInterface asdcRestInterface;
109 private TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
111 private HttpHeaders headers = new HttpHeaders();
114 DistributionClientEmulator spyClient = new DistributionClientEmulator();
122 public void testAllottedResourceService() throws Exception {
124 stubFor(post(urlPathMatching("/aai/.*"))
125 .willReturn(aResponse()
127 .withHeader("Content-Type", "application/json")));
129 ObjectMapper mapper = new ObjectMapper();
130 NotificationDataImpl request = mapper.readValue(new File("src/test/resources/resource-examples/allottedresource/notif-portm.json"), NotificationDataImpl.class);
131 headers.add("resource-location", "src/test/resources/resource-examples/allottedresource/");
132 HttpEntity<NotificationDataImpl> entity = new HttpEntity<NotificationDataImpl>(request, headers);
134 ResponseEntity<String> response = restTemplate.exchange(createURLWithPort("test/treatNotification/v1"), HttpMethod.POST,
135 entity, String.class);
137 assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
139 AllottedResource expectedService = new AllottedResource();
140 expectedService.setDescription("rege1802pnf");
141 expectedService.setModelInvariantUUID("b8f83c3f-077c-4e2c-b489-c66382060436");
142 expectedService.setModelName("rege1802pnf");
143 expectedService.setModelUUID("5b18c75e-2d08-4bf2-ad58-4ea704ec648d");
144 expectedService.setModelVersion("1.0");
145 expectedService.setSubcategory("Contrail Route");
146 expectedService.setToscaNodeType("org.openecomp.resource.pnf.Rege1802pnf");
147 Set<AllottedResourceCustomization> arCustomizationSet = new HashSet<AllottedResourceCustomization>();
148 AllottedResourceCustomization arCustomization = new AllottedResourceCustomization();
149 arCustomization.setModelCustomizationUUID("f62bb612-c5d4-4406-865c-0abec30631ba");
150 arCustomization.setModelInstanceName("rege1802pnf 0");
151 arCustomizationSet.add(arCustomization);
153 arCustomization.setAllottedResource(expectedService);
156 expectedService.setAllotedResourceCustomization(arCustomizationSet);
158 AllottedResource actualResponse = allottedRepo.findResourceByModelUUID("5b18c75e-2d08-4bf2-ad58-4ea704ec648d");
161 if(actualResponse == null)
162 throw new Exception("No Allotted Resource Written to database");
165 assertThat(actualResponse, sameBeanAs(expectedService).ignoring("0x1.created").ignoring("0x1.allotedResourceCustomization.created"));
169 public void invokeASDCStatusDataNullTest() {
171 Response response = asdcRestInterface.invokeASDCStatusData(request);
172 assertNull(response);
180 protected String createURLWithPort(String uri) {
181 return "http://localhost:" + port + uri;