Fix for Penetration test _ Session and cookie management
[vid.git] / vid-app-common / src / test / java / org / onap / vid / mso / RequestDetailsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
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.vid.mso;
22
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;
29
30 import java.util.Collections;
31 import java.util.List;
32 import java.util.Map;
33
34 import static org.testng.AssertJUnit.assertEquals;
35
36 public class RequestDetailsTest {
37
38     private static final ImmutableList<String> LCP_CLOUD_REGION_ID_PATH = ImmutableList.of("requestDetails", "cloudConfiguration", "lcpCloudRegionId");
39
40     @DataProvider
41     public static Object[][] extractValueByPathDataProvider() {
42
43         RequestDetails requestDetails1 = new RequestDetails();
44         Map cloudConfiguration = ImmutableMap.of("lcpCloudRegionId", "lcp1");
45         requestDetails1.setAdditionalProperty("requestDetails",
46                                                 ImmutableMap.of("cloudConfiguration", cloudConfiguration));
47
48
49         return new Object[][] {
50                 { requestDetails1, LCP_CLOUD_REGION_ID_PATH, String.class, "lcp1" },
51                 { requestDetails1, ImmutableList.of("requestDetails", "cloudConfiguration"), Map.class, cloudConfiguration },
52
53         };
54     }
55
56     @Test(dataProvider = "extractValueByPathDataProvider")
57     public void testExtractValueByPath(RequestDetails requestDetails, List<String> keys, Class clz, Object expectedValue) {
58         assertEquals(expectedValue, requestDetails.extractValueByPathUsingAdditionalProperties(keys, clz));
59     }
60
61     @DataProvider
62     public static Object[][] extractValueByPathDataProviderThrowException() {
63         RequestDetails requestDetails1 = new RequestDetails();
64         requestDetails1.setAdditionalProperty("requestDetails",
65                 ImmutableMap.of("cloudConfiguration", "notMap"));
66
67         RequestDetails requestDetails2 = new RequestDetails();
68         requestDetails2.setAdditionalProperty("requestDetails",
69                 ImmutableMap.of("cloudConfiguration", Collections.EMPTY_MAP));
70
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},
76         };
77     }
78
79     @Test(dataProvider = "extractValueByPathDataProviderThrowException", expectedExceptions = NotFoundException.class)
80     public void testExtractValueByPathThrowException(RequestDetails requestDetails, List<String> keys, Class clz) {
81         requestDetails.extractValueByPathUsingAdditionalProperties(keys, clz);
82     }
83 }