diff options
Diffstat (limited to 'applications/guard/src/test')
3 files changed, 73 insertions, 4 deletions
diff --git a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslatorTest.java b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslatorTest.java new file mode 100644 index 00000000..d0541e2a --- /dev/null +++ b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslatorTest.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.xacml.pdp.application.guard; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import org.junit.Test; +import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException; + +public class CoordinationGuardTranslatorTest { + + @Test + public void testUnsupportedMethods() { + CoordinationGuardTranslator translator = new CoordinationGuardTranslator(); + + assertThatExceptionOfType(ToscaPolicyConversionException.class) + .isThrownBy(() -> translator.convertRequest(null)) + .withMessageContaining("this convertRequest shouldn't be used"); + + assertThat(translator.convertResponse(null)).isNull(); + } + + @Test + public void testLoadingDirectives() { + assertThat(CoordinationGuardTranslator.loadCoordinationDirectiveFromFile(null)).isNull(); + + assertThat(CoordinationGuardTranslator.loadCoordinationDirectiveFromFile("nonexistent.yaml")).isNull(); + + CoordinationDirective directive = CoordinationGuardTranslator + .loadCoordinationDirectiveFromFile("src/test/resources/test-directive.yaml"); + assertThat(directive).isNotNull(); + assertThat(directive.getCoordinationFunction()).isEqualTo("whatisthisvaluesupposedtobe"); + assertThat(directive.getControlLoop()).hasSize(2); + assertThat(directive.getControlLoop()).contains("cl1", "cl2"); + } + + @Test + public void testGeneratingXacml() { + CoordinationDirective directive = CoordinationGuardTranslator + .loadCoordinationDirectiveFromFile("src/test/resources/test-directive.yaml"); + + assertThatExceptionOfType(ToscaPolicyConversionException.class) + .isThrownBy(() -> CoordinationGuardTranslator + .generateXacmlFromCoordinationDirective(directive, "idontexist.yaml")) + .withMessageContaining("Unable to find prototype "); + } + +} diff --git a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslatorTest.java b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslatorTest.java index 07e60c61..efe698eb 100644 --- a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslatorTest.java +++ b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslatorTest.java @@ -136,11 +136,11 @@ public class GuardTranslatorTest { assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() -> translator.convertPolicy(policy) ).withMessageContaining("Missing blacklist"); - } else if ("blacklist-noalgorithm".equals(policy.getName())) { + } else if ("filter-noalgorithm".equals(policy.getName())) { assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() -> translator.convertPolicy(policy) - ).withMessageContaining("Missing precedence"); - } else if ("blacklist-badalgorithm".equals(policy.getName())) { + ).withMessageContaining("Missing algorithm"); + } else if ("filter-badalgorithm".equals(policy.getName())) { assertThatExceptionOfType(ToscaPolicyConversionException.class) .isThrownBy(() -> translator.convertPolicy(policy)) .withMessageContaining( diff --git a/applications/guard/src/test/resources/test-directive.yaml b/applications/guard/src/test/resources/test-directive.yaml index 44dfa74b..1f477766 100644 --- a/applications/guard/src/test/resources/test-directive.yaml +++ b/applications/guard/src/test/resources/test-directive.yaml @@ -1,4 +1,4 @@ controlLoop: - cl1 - cl2 -directive: whatisthisvaluesupposedtobe +coordinationFunction: whatisthisvaluesupposedtobe |