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 org.junit.Test;
29 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
31 public class CoordinationGuardTranslatorTest {
34 public void testUnsupportedMethods() {
35 CoordinationGuardTranslator translator = new CoordinationGuardTranslator();
37 assertThatExceptionOfType(ToscaPolicyConversionException.class)
38 .isThrownBy(() -> translator.convertRequest(null))
39 .withMessageContaining("this convertRequest shouldn't be used");
41 assertThat(translator.convertResponse(null)).isNull();
45 public void testLoadingDirectives() {
46 assertThat(CoordinationGuardTranslator.loadCoordinationDirectiveFromFile(null)).isNull();
48 assertThat(CoordinationGuardTranslator.loadCoordinationDirectiveFromFile("nonexistent.yaml")).isNull();
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");
59 public void testGeneratingXacml() {
60 CoordinationDirective directive = CoordinationGuardTranslator
61 .loadCoordinationDirectiveFromFile("src/test/resources/test-directive.yaml");
63 assertThatExceptionOfType(ToscaPolicyConversionException.class)
64 .isThrownBy(() -> CoordinationGuardTranslator
65 .generateXacmlFromCoordinationDirective(directive, "idontexist.yaml"))
66 .withMessageContaining("Unable to find prototype ");