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;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 public class ControlLoopProcessorTest {
43 private static final Logger logger = LoggerFactory.getLogger(ControlLoopProcessorTest.class);
47 try (InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"))) {
48 String result = IOUtils.toString(is, StandardCharsets.UTF_8);
49 this.testSuccess(result);
50 this.testFailure(result);
51 } catch (FileNotFoundException e) {
54 } catch (IOException e) {
57 } catch (ControlLoopException e) {
63 public void testSuccess(String yaml) throws ControlLoopException {
64 ControlLoopProcessor processor = new ControlLoopProcessor(yaml);
65 logger.debug("testSuccess: {}", processor.getControlLoop());
67 FinalResult result = processor.checkIsCurrentPolicyFinal();
69 logger.debug("{}", result);
72 Policy policy = processor.getCurrentPolicy();
73 assertNotNull(policy);
74 logger.debug("current policy is: {} {}", policy.getId(), policy.getName());
75 processor.nextPolicyForResult(PolicyResult.SUCCESS);
79 public void testFailure(String yaml) throws ControlLoopException {
80 ControlLoopProcessor processor = new ControlLoopProcessor(yaml);
81 logger.debug("testFailure: {}", processor.getControlLoop());
83 FinalResult result = processor.checkIsCurrentPolicyFinal();
85 logger.debug("{}", result);
88 Policy policy = processor.getCurrentPolicy();
89 assertNotNull(policy);
90 logger.debug("current policy is: {} {}", policy.getId(), policy.getName());
91 processor.nextPolicyForResult(PolicyResult.FAILURE);