2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.assertThatCode;
28 import com.att.research.xacml.std.annotations.XACMLAction;
29 import com.att.research.xacml.std.annotations.XACMLRequest;
30 import com.att.research.xacml.std.annotations.XACMLResource;
31 import com.att.research.xacml.std.annotations.XACMLSubject;
33 import org.junit.Before;
34 import org.junit.ClassRule;
35 import org.junit.Test;
36 import org.junit.rules.TemporaryFolder;
38 public class GuardPdpApplicationTest {
41 public static final TemporaryFolder policyFolder = new TemporaryFolder();
44 * This is a simple annotation class to simulate
47 @XACMLRequest(ReturnPolicyIdList = true)
48 public class MyXacmlRequest {
50 @XACMLSubject(includeInResults = true)
51 String onapName = "Drools";
53 @XACMLResource(includeInResults = true)
54 String resource = "onap.policies.Guard";
57 String action = "guard";
61 public void setUp() throws Exception {
66 public void testBasics() {
67 assertThatCode(() -> {
68 GuardPdpApplication guard = new GuardPdpApplication();
72 guard.initialize(policyFolder.getRoot().toPath());
76 assertThat(guard.applicationName()).isNotEmpty();
80 assertThat(guard.actionDecisionsSupported().size()).isEqualTo(1);
81 assertThat(guard.actionDecisionsSupported()).contains("guard");
83 // Supported policy types
85 assertThat(guard.supportedPolicyTypes()).isNotEmpty();
86 assertThat(guard.supportedPolicyTypes().size()).isEqualTo(2);
87 assertThat(guard.canSupportPolicyType("onap.policies.controlloop.guard.FrequencyLimiter", "1.0.0"))
89 assertThat(guard.canSupportPolicyType("onap.policies.controlloop.guard.FrequencyLimiter", "1.0.1"))
91 assertThat(guard.canSupportPolicyType("onap.policies.controlloop.guard.MinMax", "1.0.0")).isTrue();
92 assertThat(guard.canSupportPolicyType("onap.policies.controlloop.guard.MinMax", "1.0.1")).isFalse();
93 assertThat(guard.canSupportPolicyType("onap.foo", "1.0.1")).isFalse();
94 }).doesNotThrowAnyException();