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.test;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.fail;
27 import java.nio.file.Files;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
31 import org.junit.Test;
32 import org.onap.policy.api.NotificationScheme;
33 import org.onap.policy.api.PolicyEngine;
34 import org.onap.policy.api.PolicyEngineException;
35 import org.onap.policy.common.logging.flexlogger.FlexLogger;
36 import org.onap.policy.common.logging.flexlogger.Logger;
38 public class PolicyEngineTest {
40 private static final Logger logger = FlexLogger.getLogger(PolicyEngineTest.class);
41 private PolicyEngine policyEngine = null;
42 private String filePath = null;
45 public void testPolicyEngineForFail() {
48 policyEngine = new PolicyEngine(filePath);
49 } catch (PolicyEngineException e) {
50 logger.warn(e.getMessage());
52 assertNull(policyEngine);
53 // Test even for this case.
56 policyEngine = new PolicyEngine(filePath);
57 } catch (PolicyEngineException e) {
58 logger.warn(e.getMessage());
60 assertNull(policyEngine);
64 public void testPolicyEngineforPropertyFileError() {
65 filePath = "Test/config_error.property";
66 isFileAvailable(filePath);
68 policyEngine = new PolicyEngine(filePath);
69 } catch (PolicyEngineException e) {
70 logger.warn(e.getMessage());
72 assertNull(policyEngine);
76 public void testPolicyEngineforPDPURLError() {
77 String filePath = "Test/config_fail.properties";
78 isFileAvailable(filePath);
80 policyEngine = new PolicyEngine(filePath);
81 } catch (PolicyEngineException e) {
82 logger.warn(e.getMessage());
84 assertNull(policyEngine);
88 public void testPolicyEngineForPass() {
89 String filePath = "Test/config_pass.properties";
90 isFileAvailable(filePath);
92 policyEngine = new PolicyEngine(filePath);
93 } catch (PolicyEngineException e) {
94 logger.warn(e.getMessage());
96 assertNotNull(policyEngine);
100 public void testPolicyEngineForUEBPass() {
101 String filePath = "Test/config_UEB_pass.properties";
102 isFileAvailable(filePath);
104 policyEngine = new PolicyEngine(filePath);
105 } catch (PolicyEngineException e) {
106 logger.warn(e.getMessage());
108 assertNotNull(policyEngine);
113 public void testPolicyEngineForUEBBadType() {
114 String filePath = "Test/config_UEB_bad_type.properties";
115 isFileAvailable(filePath);
117 policyEngine = new PolicyEngine(filePath);
118 } catch (PolicyEngineException e) {
119 logger.warn(e.getMessage());
121 assertNotNull(policyEngine);
125 public void testPolicyEngineForUEBBadServerType() {
126 String filePath = "Test/config_UEB_badservers.properties";
127 isFileAvailable(filePath);
129 policyEngine = new PolicyEngine(filePath);
130 } catch (PolicyEngineException e) {
131 logger.warn(e.getMessage());
133 assertNotNull(policyEngine);
137 public void testPolicyEngineNotficationAutoUEB() {
138 String filePath = "Test/config_UEB_pass.properties";
139 isFileAvailable(filePath);
141 policyEngine = new PolicyEngine(filePath);
142 policyEngine.setScheme(NotificationScheme.AUTO_ALL_NOTIFICATIONS);
143 } catch (PolicyEngineException e) {
144 logger.warn(e.getMessage());
146 assertNotNull(policyEngine);
150 public void testPolicyEngineNotficationAuto() {
151 String filePath = "Test/config_pass.properties";
152 isFileAvailable(filePath);
154 policyEngine = new PolicyEngine(filePath);
155 policyEngine.setScheme(NotificationScheme.AUTO_ALL_NOTIFICATIONS);
156 //policyEngine.getNotification();
157 } catch (PolicyEngineException e) {
158 logger.warn(e.getMessage());
160 assertNotNull(policyEngine);
163 public void isFileAvailable(String filePath) {
164 Path file = Paths.get(filePath);
165 if (Files.notExists(file)) {
166 logger.error("File Doesn't Exist "+ file.toString());
167 fail("File: " +filePath + " Not found");