a279144ebaf978da63d3b52319285aa25bd810bc
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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.apihandlerinfra;
22
23
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.core.JsonParseException;
40 import com.fasterxml.jackson.databind.DeserializationFeature;
41 import com.fasterxml.jackson.databind.JsonMappingException;
42 import com.fasterxml.jackson.databind.ObjectMapper;
43
44 public class AAIDeserializeTest extends BaseTest {
45
46     private final ObjectMapper mapper = new ObjectMapper();
47
48     @Autowired
49     private MsoRequest msoReq;
50
51     @Value("${wiremock.server.port}")
52     private String wiremockPort;
53
54     @Before
55     public void beforeClass() {
56         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
57     }
58
59     public String inputStream(String JsonInput) throws IOException {
60         JsonInput = "src/test/resources/MsoRequestTest" + JsonInput;
61         return new String(Files.readAllBytes(Paths.get(JsonInput)));
62     }
63
64     @Test
65     public void doNotFailOnUnknownPropertiesTest() throws JsonParseException, JsonMappingException, IOException {
66         wireMockServer.stubFor(get(("/aai/" + AAIVersion.LATEST
67                 + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner/mdt1/tenants/tenant/88a6ca3ee0394ade9403f075db23167e"))
68                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
69                                 .withBodyFile("aai/UnknownProperty.json")
70                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
71         ServiceInstancesRequest sir = mapper.readValue(inputStream("/AAI.json"), ServiceInstancesRequest.class);
72         String tenantId = "88a6ca3ee0394ade9403f075db23167e";
73         String tenantNameFromAAI = "testTenantName";
74         String cloudOwner = "cloudOwner";
75         sir.getRequestDetails().getCloudConfiguration().setCloudOwner(cloudOwner);
76         Tenant tenant = new Tenant();
77         tenant.setTenantId(tenantId);
78         tenant.setTenantName(tenantNameFromAAI);
79         String tenantName = msoReq.getTenantNameFromAAI(sir);
80         assertEquals(tenantNameFromAAI, tenantName);
81     }
82
83 }
84