2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (C) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.policy.pdp.rest.api.test;
24 import static org.junit.Assert.assertEquals;
25 import java.lang.reflect.InvocationTargetException;
26 import java.lang.reflect.Method;
27 import java.util.Collection;
28 import java.util.HashMap;
29 import java.util.LinkedList;
30 import java.util.List;
32 import org.junit.Test;
33 import org.onap.policy.api.ConfigRequestParameters;
34 import org.onap.policy.api.PolicyConfigStatus;
35 import org.onap.policy.pdp.rest.api.models.PolicyConfig;
36 import org.onap.policy.pdp.rest.api.services.GetConfigService;
38 public class GetConfigServiceTest {
39 private static final String TEST = "test";
41 @SuppressWarnings("unchecked")
43 public void filterMethodTest() throws NoSuchMethodException, SecurityException, IllegalAccessException,
44 IllegalArgumentException, InvocationTargetException {
45 ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
46 GetConfigService getConfigService = new GetConfigService(configRequestParameters, null);
47 Method filter = GetConfigService.class.getDeclaredMethod("filterResults", Collection.class,
48 ConfigRequestParameters.class);
49 filter.setAccessible(true);
50 List<PolicyConfig> policyConfigs = new LinkedList<>();
52 List<PolicyConfig> filterResults =
53 (List<PolicyConfig>) filter.invoke(getConfigService, policyConfigs, configRequestParameters);
54 assertEquals(PolicyConfigStatus.CONFIG_NOT_FOUND, filterResults.get(0).getPolicyConfigStatus());
55 // Check again with some values
56 configRequestParameters.setPolicyName(TEST);
57 configRequestParameters.setOnapName(TEST);
58 configRequestParameters.setConfigName(TEST);
59 Map<String, String> configAttributes = new HashMap<>();
60 configAttributes.put(TEST, TEST);
61 configRequestParameters.setConfigAttributes(configAttributes);
62 PolicyConfig pConfig = new PolicyConfig();
63 pConfig.setPolicyName(TEST);
64 Map<String, String> matching = new HashMap<>();
65 matching.put("ONAPName", TEST);
66 matching.put("ConfigName", TEST);
67 matching.put("TEST", TEST);
68 pConfig.setMatchingConditions(matching);
69 policyConfigs.add(pConfig);
70 filterResults = (List<PolicyConfig>) filter.invoke(getConfigService, policyConfigs, configRequestParameters);
71 assertEquals(PolicyConfigStatus.CONFIG_NOT_FOUND, filterResults.get(0).getPolicyConfigStatus());