Add exclusions parameter
[policy/xacml-pdp.git] / main / src / test / java / org / onap / policy / pdpx / main / rest / TestGuardOverrideApplication.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2021 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.pdpx.main.rest;
24
25 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
26 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslator;
27 import org.onap.policy.xacml.pdp.application.guard.GuardPdpApplication;
28 import org.onap.policy.xacml.pdp.application.guard.GuardTranslator;
29
30 public class TestGuardOverrideApplication extends GuardPdpApplication {
31     public static final String MY_EXTRAGUARD_POLICY_TYPE = "onap.policies.controlloop.guard.common.myGuard";
32
33     private static class MyTranslator extends GuardTranslator {
34
35     }
36
37     private final GuardTranslator myTranslator = new MyTranslator();
38
39     /**
40      * Constructor calls the super to add all the default policy types,
41      * and then adds the extra supported guard policy type.
42      */
43     public TestGuardOverrideApplication() {
44         super();
45         this.supportedPolicyTypes.add(new ToscaConceptIdentifier(
46                 MY_EXTRAGUARD_POLICY_TYPE,
47                 STRING_VERSION100));
48
49     }
50
51     @Override
52     protected ToscaPolicyTranslator getTranslator(String type) {
53         if (MY_EXTRAGUARD_POLICY_TYPE.equals(type)) {
54             return myTranslator;
55         }
56         return super.getTranslator(type);
57     }
58
59     @Override
60     public boolean canSupportPolicyType(ToscaConceptIdentifier policyTypeId) {
61         boolean canSuper = super.canSupportPolicyType(policyTypeId);
62         if (canSuper) {
63             return canSuper;
64         }
65         if (MY_EXTRAGUARD_POLICY_TYPE.equals(policyTypeId.getName())) {
66             return true;
67         }
68         return false;
69     }
70 }