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.rest;
23 import com.google.common.collect.ImmutableList;
24 import com.google.common.collect.ImmutableMap;
25 import org.assertj.core.api.AssertionsForClassTypes;
26 import org.onap.vid.exceptions.NotFoundException;
27 import org.testng.annotations.BeforeMethod;
28 import org.testng.annotations.DataProvider;
29 import org.testng.annotations.Test;
31 import java.util.Collections;
32 import java.util.List;
35 import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsExcluding;
36 import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
37 import static org.hamcrest.MatcherAssert.assertThat;
38 import static org.testng.AssertJUnit.assertEquals;
41 public class RequestDetailsTest {
43 private RequestDetails requestDetails;
45 private String propertyName = "testProperty";
46 private String additionalProperty = "testAdditionalProperty";
48 private static final ImmutableList<String> LCP_CLOUD_REGION_ID_PATH =
49 ImmutableList.of("requestDetails", "cloudConfiguration", "lcpCloudRegionId");
54 requestDetails = new RequestDetails();
58 public void shouldHaveProperSettersAndGetters() {
59 assertThat(RequestDetails.class, hasValidGettersAndSettersExcluding("additionalProperties"));
63 public void shouldHaveProperGetterAndSetterForAdditionalProperties() {
65 requestDetails.setAdditionalProperty(propertyName,additionalProperty);
68 AssertionsForClassTypes.assertThat( requestDetails.getAdditionalProperties().get(propertyName) ).isEqualTo(additionalProperty);
72 public void shouldProperlyConvertRelatedInstanceObjectToString() {
74 requestDetails.setAdditionalProperty(propertyName,additionalProperty);
77 String response = requestDetails.toString();
80 AssertionsForClassTypes.assertThat(response).contains(
81 "additionalProperties={"+propertyName+"="+additionalProperty+"}]"
86 public void shouldProperlyCheckIfObjectsAreEqual() {
87 assertThat(RequestDetails.class, hasValidBeanEqualsExcluding("additionalProperties"));
91 public static Object[][] extractValueByPathDataProvider() {
93 RequestDetails requestDetails1 = new RequestDetails();
94 Map cloudConfiguration = ImmutableMap.of("lcpCloudRegionId", "lcp1");
95 requestDetails1.setAdditionalProperty("requestDetails",
96 ImmutableMap.of("cloudConfiguration", cloudConfiguration));
99 return new Object[][] {
100 { requestDetails1, LCP_CLOUD_REGION_ID_PATH, String.class, "lcp1" },
101 { requestDetails1, ImmutableList.of("requestDetails", "cloudConfiguration"), Map.class, cloudConfiguration },
106 @Test(dataProvider = "extractValueByPathDataProvider")
107 public void testExtractValueByPath(RequestDetails requestDetails, List<String> keys, Class clz, Object expectedValue) {
108 assertEquals(expectedValue, requestDetails.extractValueByPathUsingAdditionalProperties(keys, clz));
112 public static Object[][] extractValueByPathDataProviderThrowException() {
113 RequestDetails requestDetails1 = new RequestDetails();
114 requestDetails1.setAdditionalProperty("requestDetails",
115 ImmutableMap.of("cloudConfiguration", "notMap"));
117 RequestDetails requestDetails2 = new RequestDetails();
118 requestDetails2.setAdditionalProperty("requestDetails",
119 ImmutableMap.of("cloudConfiguration", Collections.EMPTY_MAP));
121 return new Object[][] {
122 { new RequestDetails(), LCP_CLOUD_REGION_ID_PATH, String.class},
123 { requestDetails1, LCP_CLOUD_REGION_ID_PATH, String.class},
124 { requestDetails1, ImmutableList.of("requestDetails", "abc"), String.class},
125 { requestDetails2, LCP_CLOUD_REGION_ID_PATH, String.class},
129 @Test(dataProvider = "extractValueByPathDataProviderThrowException", expectedExceptions = NotFoundException.class)
130 public void testExtractValueByPathThrowException(RequestDetails requestDetails, List<String> keys, Class clz) {
131 requestDetails.extractValueByPathUsingAdditionalProperties(keys, clz);