41fd47057cb9dd1054e20fa8bdc8be1e14e1a634
[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 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
27
28 import java.util.HashMap;
29 import java.util.Map;
30 import org.junit.Test;
31 import org.onap.policy.models.decisions.concepts.DecisionRequest;
32 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
33
34 public class GuardPolicyRequestTest {
35
36     @Test
37     public void testAnomalies() throws ToscaPolicyConversionException {
38         DecisionRequest decisionRequest = new DecisionRequest();
39         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
40
41         Map<String, Object> resources = new HashMap<>();
42         decisionRequest.setResource(resources);
43         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
44
45         resources.put("notguard", "foo");
46         decisionRequest.setResource(resources);
47         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
48
49         resources.put("guard", null);
50         decisionRequest.setResource(resources);
51         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
52
53         Map<String, Object> guard = new HashMap<>();
54         resources.put("guard", guard);
55         decisionRequest.setResource(resources);
56         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
57
58         guard.put("crap", "notused");
59         resources.put("guard", guard);
60         decisionRequest.setResource(resources);
61         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
62
63         guard.put("actor", "notused");
64         resources.put("guard", guard);
65         decisionRequest.setResource(resources);
66         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
67
68         guard.put("recipe", "notused");
69         resources.put("guard", guard);
70         decisionRequest.setResource(resources);
71         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
72
73         guard.put("clname", "notused");
74         resources.put("guard", guard);
75         decisionRequest.setResource(resources);
76         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
77
78         guard.put("target", "notused");
79         resources.put("guard", guard);
80         decisionRequest.setResource(resources);
81         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
82
83         guard.put("vfCount", 1);
84         resources.put("guard", guard);
85         decisionRequest.setResource(resources);
86         assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
87
88         guard.put("vfCount", "I am not valid");
89         resources.put("guard", guard);
90         decisionRequest.setResource(resources);
91         assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() ->
92             GuardPolicyRequest.createInstance(decisionRequest));
93     }
94
95 }