2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 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.vid.mso;
23 import com.google.common.collect.ImmutableList;
24 import com.google.common.collect.ImmutableMap;
25 import org.onap.vid.exceptions.NotFoundException;
26 import org.onap.vid.mso.rest.RequestDetails;
27 import org.testng.annotations.DataProvider;
28 import org.testng.annotations.Test;
30 import java.util.Collections;
31 import java.util.List;
34 import static org.testng.AssertJUnit.assertEquals;
36 public class RequestDetailsTest {
38 private static final ImmutableList<String> LCP_CLOUD_REGION_ID_PATH = ImmutableList.of("requestDetails", "cloudConfiguration", "lcpCloudRegionId");
41 public static Object[][] extractValueByPathDataProvider() {
43 RequestDetails requestDetails1 = new RequestDetails();
44 Map cloudConfiguration = ImmutableMap.of("lcpCloudRegionId", "lcp1");
45 requestDetails1.setAdditionalProperty("requestDetails",
46 ImmutableMap.of("cloudConfiguration", cloudConfiguration));
49 return new Object[][] {
50 { requestDetails1, LCP_CLOUD_REGION_ID_PATH, String.class, "lcp1" },
51 { requestDetails1, ImmutableList.of("requestDetails", "cloudConfiguration"), Map.class, cloudConfiguration },
56 @Test(dataProvider = "extractValueByPathDataProvider")
57 public void testExtractValueByPath(RequestDetails requestDetails, List<String> keys, Class clz, Object expectedValue) {
58 assertEquals(expectedValue, requestDetails.extractValueByPathUsingAdditionalProperties(keys, clz));
62 public static Object[][] extractValueByPathDataProviderThrowException() {
63 RequestDetails requestDetails1 = new RequestDetails();
64 requestDetails1.setAdditionalProperty("requestDetails",
65 ImmutableMap.of("cloudConfiguration", "notMap"));
67 RequestDetails requestDetails2 = new RequestDetails();
68 requestDetails2.setAdditionalProperty("requestDetails",
69 ImmutableMap.of("cloudConfiguration", Collections.EMPTY_MAP));
71 return new Object[][] {
72 { new RequestDetails(), LCP_CLOUD_REGION_ID_PATH, String.class},
73 { requestDetails1, LCP_CLOUD_REGION_ID_PATH, String.class},
74 { requestDetails1, ImmutableList.of("requestDetails", "abc"), String.class},
75 { requestDetails2, LCP_CLOUD_REGION_ID_PATH, String.class},
79 @Test(dataProvider = "extractValueByPathDataProviderThrowException", expectedExceptions = NotFoundException.class)
80 public void testExtractValueByPathThrowException(RequestDetails requestDetails, List<String> keys, Class clz) {
81 requestDetails.extractValueByPathUsingAdditionalProperties(keys, clz);