Monitoring policy creation foundation
[policy/xacml-pdp.git] / applications / guard / src / test / java / org / onap / policy / xacml / pdp / application / guard / GuardPdpApplicationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
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
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.assertThatCode;
27
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;
32
33 import org.junit.Before;
34 import org.junit.ClassRule;
35 import org.junit.Test;
36 import org.junit.rules.TemporaryFolder;
37
38 public class GuardPdpApplicationTest {
39
40     @ClassRule
41     public static final TemporaryFolder policyFolder = new TemporaryFolder();
42
43     /**
44      * This is a simple annotation class to simulate
45      * requests coming in.
46      */
47     @XACMLRequest(ReturnPolicyIdList = true)
48     public class MyXacmlRequest {
49
50         @XACMLSubject(includeInResults = true)
51         String onapName = "Drools";
52
53         @XACMLResource(includeInResults = true)
54         String resource = "onap.policies.Guard";
55
56         @XACMLAction()
57         String action = "guard";
58     }
59
60     @Before
61     public void setUp() throws Exception {
62
63     }
64
65     @Test
66     public void testBasics() {
67         assertThatCode(() -> {
68             GuardPdpApplication guard = new GuardPdpApplication();
69             //
70             // Set the path
71             //
72             guard.initialize(policyFolder.getRoot().toPath());
73             //
74             // Application name
75             //
76             assertThat(guard.applicationName()).isNotEmpty();
77             //
78             // Decisions
79             //
80             assertThat(guard.actionDecisionsSupported().size()).isEqualTo(1);
81             assertThat(guard.actionDecisionsSupported()).contains("guard");
82             //
83             // Supported policy types
84             //
85             assertThat(guard.supportedPolicyTypes()).isNotEmpty();
86             assertThat(guard.supportedPolicyTypes().size()).isEqualTo(2);
87             assertThat(guard.canSupportPolicyType("onap.policies.controlloop.guard.FrequencyLimiter", "1.0.0"))
88                 .isTrue();
89             assertThat(guard.canSupportPolicyType("onap.policies.controlloop.guard.FrequencyLimiter", "1.0.1"))
90                 .isFalse();
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();
95     }
96 }