Merge from ECOMP's repository
[vid.git] / vid-app-common / src / test / java / org / onap / vid / mso / RequestDetailsTest.java
1 package org.onap.vid.mso;
2
3 import com.google.common.collect.ImmutableList;
4 import com.google.common.collect.ImmutableMap;
5 import org.onap.vid.exceptions.NotFoundException;
6 import org.onap.vid.mso.rest.RequestDetails;
7 import org.testng.annotations.DataProvider;
8 import org.testng.annotations.Test;
9
10 import java.util.Collections;
11 import java.util.List;
12 import java.util.Map;
13
14 import static org.testng.AssertJUnit.assertEquals;
15
16 public class RequestDetailsTest {
17
18     private static final ImmutableList<String> LCP_CLOUD_REGION_ID_PATH = ImmutableList.of("requestDetails", "cloudConfiguration", "lcpCloudRegionId");
19
20     @DataProvider
21     public static Object[][] extractValueByPathDataProvider() {
22
23         RequestDetails requestDetails1 = new RequestDetails();
24         Map cloudConfiguration = ImmutableMap.of("lcpCloudRegionId", "lcp1");
25         requestDetails1.setAdditionalProperty("requestDetails",
26                                                 ImmutableMap.of("cloudConfiguration", cloudConfiguration));
27
28
29         return new Object[][] {
30                 { requestDetails1, LCP_CLOUD_REGION_ID_PATH, String.class, "lcp1" },
31                 { requestDetails1, ImmutableList.of("requestDetails", "cloudConfiguration"), Map.class, cloudConfiguration },
32
33         };
34     }
35
36     @Test(dataProvider = "extractValueByPathDataProvider")
37     public void testExtractValueByPath(RequestDetails requestDetails, List<String> keys, Class clz, Object expectedValue) {
38         assertEquals(expectedValue, requestDetails.extractValueByPathUsingAdditionalProperties(keys, clz));
39     }
40
41     @DataProvider
42     public static Object[][] extractValueByPathDataProviderThrowException() {
43         RequestDetails requestDetails1 = new RequestDetails();
44         requestDetails1.setAdditionalProperty("requestDetails",
45                 ImmutableMap.of("cloudConfiguration", "notMap"));
46
47         RequestDetails requestDetails2 = new RequestDetails();
48         requestDetails2.setAdditionalProperty("requestDetails",
49                 ImmutableMap.of("cloudConfiguration", Collections.EMPTY_MAP));
50
51         return new Object[][] {
52                 { new RequestDetails(), LCP_CLOUD_REGION_ID_PATH, String.class},
53                 { requestDetails1, LCP_CLOUD_REGION_ID_PATH, String.class},
54                 { requestDetails1, ImmutableList.of("requestDetails", "abc"), String.class},
55                 { requestDetails2, LCP_CLOUD_REGION_ID_PATH, String.class},
56         };
57     }
58
59     @Test(dataProvider = "extractValueByPathDataProviderThrowException", expectedExceptions = NotFoundException.class)
60     public void testExtractValueByPathThrowException(RequestDetails requestDetails, List<String> keys, Class clz) {
61         requestDetails.extractValueByPathUsingAdditionalProperties(keys, clz);
62     }
63 }