2 * ============LICENSE_START=======================================================
3 * policy-yaml unit test
4 * ================================================================================
5 * Copyright (C) 2017-2018 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.junit.Assert.fail;
27 import java.io.FileInputStream;
28 import java.io.FileNotFoundException;
29 import java.io.IOException;
30 import java.io.InputStream;
32 import org.junit.Test;
34 import org.onap.policy.controlloop.guard.compiler.ControlLoopGuardCompiler;
36 public class ControlLoopGuardCompilerTest {
39 public void testTest1() {
41 this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml");
42 } catch (Exception e) {
48 public void testTest2() {
50 this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml");
51 } catch (Exception e) {
57 public void testBad1() {
59 this.test("src/test/resources/v2.0.0-guard/no_guard_policy.yaml");
60 } catch (Exception e) {
66 public void testBad2() {
68 this.test("src/test/resources/v2.0.0-guard/duplicate_guard_policy.yaml");
69 } catch (Exception e) {
75 public void testBad3() {
77 this.test("src/test/resources/v2.0.0-guard/no_guard_constraint.yaml");
78 } catch (Exception e) {
84 public void testBad4() {
86 this.test("src/test/resources/v2.0.0-guard/duplicate_guard_constraint.yaml");
87 } catch (Exception e) {
93 * Does the actual test.
95 * @param testFile input test file
96 * @throws Exception exception thrown
98 public void test(String testFile) throws Exception {
99 try (InputStream is = new FileInputStream(new File(testFile))) {
100 ControlLoopGuardCompiler.compile(is, null);
101 } catch (FileNotFoundException e) {
102 fail(e.getMessage());
103 } catch (IOException e) {
104 fail(e.getMessage());
105 } catch (Exception e) {