Updates to support fixed guard policy types
[policy/xacml-pdp.git] / applications / guard / src / test / java / org / onap / policy / xacml / pdp / application / guard / GuardPolicyRequestTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 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  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.xacml.pdp.application.guard;
24
25 import static org.assertj.core.api.Assertions.assertThat;
26
27 import java.util.HashMap;
28 import java.util.Map;
29 import org.junit.Test;
30 import org.onap.policy.models.decisions.concepts.DecisionRequest;
31
32 public class GuardPolicyRequestTest {
33
34     @Test
35     public void testAnomalies() {
36         DecisionRequest decisionRequest = new DecisionRequest();
37         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
38
39         Map<String, Object> resources = new HashMap<>();
40         decisionRequest.setResource(resources);
41         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
42
43         resources.put("notguard", "foo");
44         decisionRequest.setResource(resources);
45         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
46
47         resources.put("guard", null);
48         decisionRequest.setResource(resources);
49         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
50
51         Map<String, Object> guard = new HashMap<>();
52         resources.put("guard", guard);
53         decisionRequest.setResource(resources);
54         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
55
56         guard.put("crap", "notused");
57         resources.put("guard", guard);
58         decisionRequest.setResource(resources);
59         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
60
61         guard.put("actor", "notused");
62         resources.put("guard", guard);
63         decisionRequest.setResource(resources);
64         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
65
66         guard.put("recipe", "notused");
67         resources.put("guard", guard);
68         decisionRequest.setResource(resources);
69         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
70
71         guard.put("clname", "notused");
72         resources.put("guard", guard);
73         decisionRequest.setResource(resources);
74         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
75
76         guard.put("target", "notused");
77         resources.put("guard", guard);
78         decisionRequest.setResource(resources);
79         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
80
81         guard.put("vfCount", 1);
82         resources.put("guard", guard);
83         decisionRequest.setResource(resources);
84         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
85     }
86
87 }