Sonar Fixes policy/models, removing model-yaml
[policy/models.git] / models-interactions / model-yaml / src / test / java / org / onap / policy / controlloop / compiler / ControlLoopGuardCompilerTest.java
1 /*-
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.controlloop.compiler;
23
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25
26 import java.io.File;
27 import java.io.FileInputStream;
28 import java.io.InputStream;
29 import org.junit.Test;
30 import org.onap.policy.controlloop.guard.compiler.ControlLoopGuardCompiler;
31
32 public class ControlLoopGuardCompilerTest {
33
34     private static final String ACTOR_ERROR = "Unable to find property 'actor'";
35
36     @Test
37     public void testTest1() throws Exception {
38         this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml");
39     }
40
41     @Test
42     public void testTest2() throws Exception {
43         this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml");
44     }
45
46     @Test
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");
50     }
51
52     @Test
53     public void testBad2() {
54         assertThatThrownBy(() -> this.test("src/test/resources/v2.0.0-guard/duplicate_guard_policy.yaml"))
55                         .hasMessageContaining(ACTOR_ERROR);
56     }
57
58     @Test
59     public void testBad3() {
60         assertThatThrownBy(() -> this.test("src/test/resources/v2.0.0-guard/no_guard_constraint.yaml"))
61                         .hasMessageContaining(ACTOR_ERROR);
62     }
63
64     @Test
65     public void testBad4() {
66         assertThatThrownBy(() -> this.test("src/test/resources/v2.0.0-guard/duplicate_guard_constraint.yaml"))
67                         .hasMessageContaining(ACTOR_ERROR);
68     }
69
70     /**
71      * Does the actual test.
72      *
73      * @param testFile input test file
74      * @throws Exception exception thrown
75      */
76     public void test(String testFile) throws Exception {
77         try (InputStream is = new FileInputStream(new File(testFile))) {
78             ControlLoopGuardCompiler.compile(is, null);
79         }
80     }
81
82 }