2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017, 2019 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.utils.test;
23 import static org.junit.Assert.assertFalse;
25 import java.util.Properties;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.policy.utils.AAFPolicyClient;
30 import org.onap.policy.utils.AAFPolicyClientImpl;
31 import org.onap.policy.utils.AAFPolicyException;
33 public class AAFClientTest {
34 AAFPolicyClient afClient;
41 * @throws AAFPolicyException AAFPolicyException
44 public void setUp() throws AAFPolicyException {
45 Properties props = new Properties();
46 props.setProperty("ENVIRONMENT", "TEST");
47 props.setProperty("aafClient.impl.className", AAFPolicyClientImpl.class.getName());
48 afClient = AAFPolicyClient.getInstance(props);
52 public void invalidClientTest() throws AAFPolicyException {
53 assertFalse(afClient.checkPerm(null, null, null, null, null));
54 assertFalse(afClient.checkPerm(user, null, null, null, null));
55 assertFalse(afClient.checkAuth(user, pass));
56 assertFalse(afClient.checkAuth(null, pass));
57 assertFalse(afClient.checkAuth(user, null));
58 assertFalse(afClient.checkPerm(user, pass, "policy-engine.config", "*", "*"));
59 Properties props = new Properties();
60 props.setProperty("aafClient.impl.className", AAFPolicyClientImpl.class.getName());
61 afClient = AAFPolicyClient.getInstance(props);
62 assertFalse(afClient.checkAuth(user, pass));
63 props.setProperty("ENVIRONMENT", "PROD");
64 props.setProperty("aafClient.impl.className", AAFPolicyClientImpl.class.getName());
65 afClient.updateProperties(props);
66 assertFalse(afClient.checkAuth("test", pass));
67 props.setProperty("aaf_url", "test");
68 afClient.updateProperties(props);
69 assertFalse(afClient.checkAuth("test", pass));
70 props = new Properties();
71 props.setProperty("ENVIRONMENT", "123");
72 afClient.updateProperties(props);
73 assertFalse(afClient.checkAuth("test", pass));
74 assertFalse(afClient.checkAuthPerm("test", pass, "decision", "*", "read"));
77 @Test(expected = AAFPolicyException.class)
78 public void invalidAafInstance() throws AAFPolicyException {
79 Properties props = new Properties();
80 props.setProperty("aafClient.impl.className", "errorClass");
81 afClient = AAFPolicyClient.getInstance(props);
84 @Test(expected = AAFPolicyException.class)
85 public void testPropNullException() throws AAFPolicyException {
86 afClient.updateProperties(null);
89 @Test(expected = AAFPolicyException.class)
90 public void testPropEmptyException() throws AAFPolicyException {
91 afClient.updateProperties(new Properties());
94 @Test(expected = AAFPolicyException.class)
95 public void testAafException() throws AAFPolicyException {
96 new AAFPolicyException();
97 new AAFPolicyException("error", new Exception());
98 throw new AAFPolicyException("error", new Exception(), false, false);