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.apihandlerinfra;
24 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
25 import static com.github.tomakehurst.wiremock.client.WireMock.get;
26 import static org.junit.Assert.assertEquals;
27 import java.io.IOException;
28 import java.nio.file.Files;
29 import java.nio.file.Paths;
30 import javax.ws.rs.core.MediaType;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.aai.domain.yang.Tenant;
34 import org.onap.aaiclient.client.aai.AAIVersion;
35 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.beans.factory.annotation.Value;
38 import org.springframework.http.HttpHeaders;
39 import com.fasterxml.jackson.databind.DeserializationFeature;
40 import com.fasterxml.jackson.databind.JsonMappingException;
41 import com.fasterxml.jackson.databind.ObjectMapper;
43 public class AAIDeserializeTest extends BaseTest {
45 private final ObjectMapper mapper = new ObjectMapper();
48 private MsoRequest msoReq;
50 @Value("${wiremock.server.port}")
51 private String wiremockPort;
54 public void beforeClass() {
55 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
58 public String inputStream(String JsonInput) throws IOException {
59 JsonInput = "src/test/resources/MsoRequestTest" + JsonInput;
60 return new String(Files.readAllBytes(Paths.get(JsonInput)));
64 public void doNotFailOnUnknownPropertiesTest() throws JsonMappingException, IOException {
65 wireMockServer.stubFor(get(("/aai/" + AAIVersion.LATEST
66 + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner/mdt1/tenants/tenant/88a6ca3ee0394ade9403f075db23167e"))
67 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
68 .withBodyFile("aai/UnknownProperty.json")
69 .withStatus(org.apache.http.HttpStatus.SC_OK)));
70 ServiceInstancesRequest sir = mapper.readValue(inputStream("/AAI.json"), ServiceInstancesRequest.class);
71 String tenantId = "88a6ca3ee0394ade9403f075db23167e";
72 String tenantNameFromAAI = "testTenantName";
73 String cloudOwner = "cloudOwner";
74 sir.getRequestDetails().getCloudConfiguration().setCloudOwner(cloudOwner);
75 Tenant tenant = new Tenant();
76 tenant.setTenantId(tenantId);
77 tenant.setTenantName(tenantNameFromAAI);
78 String tenantName = msoReq.getTenantNameFromAAI(sir);
79 assertEquals(tenantNameFromAAI, tenantName);