2 * ============LICENSE_START=======================================================
3 * policy-yaml unit test
4 * ================================================================================
5 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.controlloop.compiler;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
27 import java.io.FileInputStream;
28 import java.io.InputStream;
29 import org.junit.Test;
30 import org.onap.policy.controlloop.guard.compiler.ControlLoopGuardCompiler;
32 public class ControlLoopGuardCompilerTest {
34 private static final String ACTOR_ERROR = "Unable to find property 'actor'";
37 public void testTest1() throws Exception {
38 this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml");
42 public void testTest2() throws Exception {
43 this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml");
47 public void testBad1() {
48 assertThatThrownBy(() -> this.test("src/test/resources/v2.0.0-guard/no_guard_policy.yaml"))
49 .hasMessage("Guard policies should not be null");
53 public void testBad2() {
54 assertThatThrownBy(() -> this.test("src/test/resources/v2.0.0-guard/duplicate_guard_policy.yaml"))
55 .hasMessageContaining(ACTOR_ERROR);
59 public void testBad3() {
60 assertThatThrownBy(() -> this.test("src/test/resources/v2.0.0-guard/no_guard_constraint.yaml"))
61 .hasMessageContaining(ACTOR_ERROR);
65 public void testBad4() {
66 assertThatThrownBy(() -> this.test("src/test/resources/v2.0.0-guard/duplicate_guard_constraint.yaml"))
67 .hasMessageContaining(ACTOR_ERROR);
71 * Does the actual test.
73 * @param testFile input test file
74 * @throws Exception exception thrown
76 public void test(String testFile) throws Exception {
77 try (InputStream is = new FileInputStream(new File(testFile))) {
78 ControlLoopGuardCompiler.compile(is, null);