2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.controlloop.processor;
23 import static org.junit.Assert.*;
26 import java.io.FileInputStream;
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.nio.charset.StandardCharsets;
32 import org.apache.commons.io.IOUtils;
33 import org.junit.Test;
35 import org.onap.policy.controlloop.ControlLoopException;
36 import org.onap.policy.controlloop.policy.FinalResult;
37 import org.onap.policy.controlloop.policy.Policy;
38 import org.onap.policy.controlloop.policy.PolicyResult;
40 public class ControlLoopProcessorTest {
44 try (InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"))) {
45 String result = IOUtils.toString(is, StandardCharsets.UTF_8);
46 this.testSuccess(result);
47 this.testFailure(result);
48 } catch (FileNotFoundException e) {
51 } catch (IOException e) {
54 } catch (ControlLoopException e) {
60 public void testSuccess(String yaml) throws ControlLoopException {
61 ControlLoopProcessor processor = new ControlLoopProcessor(yaml);
62 System.out.println("testSuccess: " + processor.getControlLoop().toString());
64 FinalResult result = processor.checkIsCurrentPolicyFinal();
66 System.out.println(result);
69 Policy policy = processor.getCurrentPolicy();
70 assertNotNull(policy);
71 System.out.println("current policy is: " + policy.id + " " + policy.name);
72 processor.nextPolicyForResult(PolicyResult.SUCCESS);
76 public void testFailure(String yaml) throws ControlLoopException {
77 ControlLoopProcessor processor = new ControlLoopProcessor(yaml);
78 System.out.println("testFailure: " + processor.getControlLoop().toString());
80 FinalResult result = processor.checkIsCurrentPolicyFinal();
82 System.out.println(result);
85 Policy policy = processor.getCurrentPolicy();
86 assertNotNull(policy);
87 System.out.println("current policy is: " + policy.id + " " + policy.name);
88 processor.nextPolicyForResult(PolicyResult.FAILURE);