2 * ============LICENSE_START=======================================================
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
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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.xacml.pdp.application.guard;
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
28 import java.util.HashMap;
30 import org.junit.Test;
31 import org.onap.policy.models.decisions.concepts.DecisionRequest;
32 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
34 public class GuardPolicyRequestTest {
37 public void testAnomalies() throws ToscaPolicyConversionException {
38 DecisionRequest decisionRequest = new DecisionRequest();
39 assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
41 Map<String, Object> resources = new HashMap<>();
42 decisionRequest.setResource(resources);
43 assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
45 resources.put("notguard", "foo");
46 decisionRequest.setResource(resources);
47 assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
49 resources.put("guard", null);
50 decisionRequest.setResource(resources);
51 assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
53 Map<String, Object> guard = new HashMap<>();
54 resources.put("guard", guard);
55 decisionRequest.setResource(resources);
56 assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
58 guard.put("crap", "notused");
59 resources.put("guard", guard);
60 decisionRequest.setResource(resources);
61 assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
63 guard.put("actor", "notused");
64 resources.put("guard", guard);
65 decisionRequest.setResource(resources);
66 assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
68 guard.put("recipe", "notused");
69 resources.put("guard", guard);
70 decisionRequest.setResource(resources);
71 assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
73 guard.put("clname", "notused");
74 resources.put("guard", guard);
75 decisionRequest.setResource(resources);
76 assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
78 guard.put("target", "notused");
79 resources.put("guard", guard);
80 decisionRequest.setResource(resources);
81 assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
83 guard.put("vfCount", 1);
84 resources.put("guard", guard);
85 decisionRequest.setResource(resources);
86 assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
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));