2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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=========================================================
20 package org.onap.policy.pdp.rest.api.test;
22 import static org.junit.Assert.assertEquals;
24 import java.lang.reflect.InvocationTargetException;
25 import java.lang.reflect.Method;
26 import java.util.Collection;
27 import java.util.HashMap;
28 import java.util.LinkedList;
29 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 getConfigTest {
39 private static final String TEST = "test";
41 @SuppressWarnings("unchecked")
43 public void filterMethodTest() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
44 ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
45 GetConfigService getConfigService= new GetConfigService(configRequestParameters, null);
46 Method filter = GetConfigService.class.getDeclaredMethod("filterResults", Collection.class,ConfigRequestParameters.class);
47 filter.setAccessible(true);
48 List<PolicyConfig> policyConfigs = new LinkedList<>();
50 List<PolicyConfig> filterResults = (List<PolicyConfig>) filter.invoke(getConfigService, policyConfigs,configRequestParameters);
51 assertEquals(PolicyConfigStatus.CONFIG_NOT_FOUND, filterResults.get(0).getPolicyConfigStatus());
52 // Check again with some values
53 configRequestParameters.setPolicyName(TEST);
54 configRequestParameters.setOnapName(TEST);
55 configRequestParameters.setConfigName(TEST);
56 Map<String,String> configAttributes = new HashMap<>();
57 configAttributes.put(TEST, TEST);
58 configRequestParameters.setConfigAttributes(configAttributes);
59 PolicyConfig pConfig = new PolicyConfig();
60 pConfig.setPolicyName(TEST);
61 Map<String,String> matching = new HashMap<>();
62 matching.put("ONAPName", TEST);
63 matching.put("ConfigName", TEST);
64 matching.put("TEST", TEST);
65 pConfig.setMatchingConditions(matching);
66 policyConfigs.add(pConfig);
67 filterResults = (List<PolicyConfig>) filter.invoke(getConfigService, policyConfigs,configRequestParameters);
68 assertEquals(PolicyConfigStatus.CONFIG_NOT_FOUND, filterResults.get(0).getPolicyConfigStatus());