Set all cross references of policy/xacml-pdp
[policy/xacml-pdp.git] / applications / guard / src / test / java / org / onap / policy / xacml / pdp / application / guard / CoordinationGuardTranslatorTest.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 org.junit.Test;
29 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
30
31 public class CoordinationGuardTranslatorTest {
32
33     @Test
34     public void testUnsupportedMethods() {
35         CoordinationGuardTranslator translator = new CoordinationGuardTranslator();
36
37         assertThatExceptionOfType(ToscaPolicyConversionException.class)
38                 .isThrownBy(() -> translator.convertRequest(null))
39                 .withMessageContaining("this convertRequest shouldn't be used");
40
41         assertThat(translator.convertResponse(null)).isNull();
42     }
43
44     @Test
45     public void testLoadingDirectives() {
46         assertThat(CoordinationGuardTranslator.loadCoordinationDirectiveFromFile(null)).isNull();
47
48         assertThat(CoordinationGuardTranslator.loadCoordinationDirectiveFromFile("nonexistent.yaml")).isNull();
49
50         CoordinationDirective directive = CoordinationGuardTranslator
51                 .loadCoordinationDirectiveFromFile("src/test/resources/test-directive.yaml");
52         assertThat(directive).isNotNull();
53         assertThat(directive.getCoordinationFunction()).isEqualTo("whatisthisvaluesupposedtobe");
54         assertThat(directive.getControlLoop()).hasSize(2);
55         assertThat(directive.getControlLoop()).contains("cl1", "cl2");
56     }
57
58     @Test
59     public void testGeneratingXacml() {
60         CoordinationDirective directive = CoordinationGuardTranslator
61                 .loadCoordinationDirectiveFromFile("src/test/resources/test-directive.yaml");
62
63         assertThatExceptionOfType(ToscaPolicyConversionException.class)
64                 .isThrownBy(() -> CoordinationGuardTranslator
65                         .generateXacmlFromCoordinationDirective(directive, "idontexist.yaml"))
66                 .withMessageContaining("Unable to find prototype ");
67     }
68
69 }