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 static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsExcluding;
24 import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
25 import static org.hamcrest.MatcherAssert.assertThat;
26 import static org.testng.AssertJUnit.assertEquals;
28 import com.google.common.collect.ImmutableList;
29 import com.google.common.collect.ImmutableMap;
30 import java.util.Collections;
31 import java.util.List;
33 import org.assertj.core.api.AssertionsForClassTypes;
34 import org.onap.vid.exceptions.NotFoundException;
35 import org.onap.vid.testUtils.TestUtils;
36 import org.testng.annotations.BeforeClass;
37 import org.testng.annotations.BeforeMethod;
38 import org.testng.annotations.DataProvider;
39 import org.testng.annotations.Test;
42 public class RequestDetailsTest {
44 private RequestDetails requestDetails;
46 private String propertyName = "testProperty";
47 private String additionalProperty = "testAdditionalProperty";
49 private static final ImmutableList<String> LCP_CLOUD_REGION_ID_PATH =
50 ImmutableList.of("requestDetails", "cloudConfiguration", "lcpCloudRegionId");
53 public static void registerValueGenerator() {
54 TestUtils.registerCloudConfigurationValueGenerator();
59 requestDetails = new RequestDetails();
63 public void shouldHaveProperSettersAndGetters() {
64 assertThat(RequestDetails.class, hasValidGettersAndSettersExcluding("additionalProperties"));
68 public void shouldHaveProperGetterAndSetterForAdditionalProperties() {
70 requestDetails.setAdditionalProperty(propertyName,additionalProperty);
73 AssertionsForClassTypes.assertThat( requestDetails.getAdditionalProperties().get(propertyName) ).isEqualTo(additionalProperty);
77 public void shouldProperlyConvertRelatedInstanceObjectToString() {
79 requestDetails.setAdditionalProperty(propertyName,additionalProperty);
82 String response = requestDetails.toString();
85 AssertionsForClassTypes.assertThat(response).contains(
86 "additionalProperties={"+propertyName+"="+additionalProperty+"}]"
91 public void shouldProperlyCheckIfObjectsAreEqual() {
92 assertThat(RequestDetails.class, hasValidBeanEqualsExcluding("additionalProperties"));
96 public static Object[][] extractValueByPathDataProvider() {
98 RequestDetails requestDetails1 = new RequestDetails();
99 Map cloudConfiguration = ImmutableMap.of("lcpCloudRegionId", "lcp1");
100 requestDetails1.setAdditionalProperty("requestDetails",
101 ImmutableMap.of("cloudConfiguration", cloudConfiguration));
104 return new Object[][] {
105 { requestDetails1, LCP_CLOUD_REGION_ID_PATH, String.class, "lcp1" },
106 { requestDetails1, ImmutableList.of("requestDetails", "cloudConfiguration"), Map.class, cloudConfiguration },
111 @Test(dataProvider = "extractValueByPathDataProvider")
112 public void testExtractValueByPath(RequestDetails requestDetails, List<String> keys, Class clz, Object expectedValue) {
113 assertEquals(expectedValue, requestDetails.extractValueByPathUsingAdditionalProperties(keys, clz));
117 public static Object[][] extractValueByPathDataProviderThrowException() {
118 RequestDetails requestDetails1 = new RequestDetails();
119 requestDetails1.setAdditionalProperty("requestDetails",
120 ImmutableMap.of("cloudConfiguration", "notMap"));
122 RequestDetails requestDetails2 = new RequestDetails();
123 requestDetails2.setAdditionalProperty("requestDetails",
124 ImmutableMap.of("cloudConfiguration", Collections.EMPTY_MAP));
126 return new Object[][] {
127 { new RequestDetails(), LCP_CLOUD_REGION_ID_PATH, String.class},
128 { requestDetails1, LCP_CLOUD_REGION_ID_PATH, String.class},
129 { requestDetails1, ImmutableList.of("requestDetails", "abc"), String.class},
130 { requestDetails2, LCP_CLOUD_REGION_ID_PATH, String.class},
134 @Test(dataProvider = "extractValueByPathDataProviderThrowException", expectedExceptions = NotFoundException.class)
135 public void testExtractValueByPathThrowException(RequestDetails requestDetails, List<String> keys, Class clz) {
136 requestDetails.extractValueByPathUsingAdditionalProperties(keys, clz);