aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/GetConfigServiceTest.java
blob: a3c1b2b0585c1f034aae2405d44dbe6cd6d53e89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*-
 * ============LICENSE_START=======================================================
 * ONAP-PDP-REST
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */
package org.onap.policy.pdp.rest.api.test;

import static org.junit.Assert.assertEquals;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.onap.policy.api.ConfigRequestParameters;
import org.onap.policy.api.PolicyConfigStatus;
import org.onap.policy.pdp.rest.api.models.PolicyConfig;
import org.onap.policy.pdp.rest.api.services.GetConfigService;

public class GetConfigServiceTest {
	private static final String TEST = "test";
	
	@SuppressWarnings("unchecked")
	@Test
	public void filterMethodTest() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
		ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
		GetConfigService getConfigService= new GetConfigService(configRequestParameters, null);
		Method filter = GetConfigService.class.getDeclaredMethod("filterResults", Collection.class,ConfigRequestParameters.class);
		filter.setAccessible(true);
		List<PolicyConfig> policyConfigs = new LinkedList<>();
		
		List<PolicyConfig> filterResults = (List<PolicyConfig>) filter.invoke(getConfigService, policyConfigs,configRequestParameters);
		assertEquals(PolicyConfigStatus.CONFIG_NOT_FOUND, filterResults.get(0).getPolicyConfigStatus());
		// Check again with some values 
		configRequestParameters.setPolicyName(TEST);
		configRequestParameters.setOnapName(TEST);
		configRequestParameters.setConfigName(TEST);
		Map<String,String> configAttributes = new HashMap<>();
		configAttributes.put(TEST, TEST);
		configRequestParameters.setConfigAttributes(configAttributes);
		PolicyConfig pConfig = new PolicyConfig();
		pConfig.setPolicyName(TEST);
		Map<String,String> matching = new HashMap<>();
		matching.put("ONAPName", TEST);
		matching.put("ConfigName", TEST);
		matching.put("TEST", TEST);
		pConfig.setMatchingConditions(matching);
		policyConfigs.add(pConfig);
		filterResults = (List<PolicyConfig>) filter.invoke(getConfigService, policyConfigs,configRequestParameters);
		assertEquals(PolicyConfigStatus.CONFIG_NOT_FOUND, filterResults.get(0).getPolicyConfigStatus());
	}
}