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.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;
38 public void setUp() throws AAFPolicyException{
39 Properties props = new Properties();
40 props.setProperty("ENVIRONMENT", "TEST");
41 props.setProperty("aafClient.impl.className", AAFPolicyClientImpl.class.getName());
42 afClient = AAFPolicyClient.getInstance(props);
46 public void invalidClientTest() throws AAFPolicyException{
47 assertFalse(afClient.checkAuth("test", pass));
48 assertFalse(afClient.checkPerm("test", pass, "policy-engine.config", "*", "*"));
49 Properties props = new Properties();
50 props.setProperty("aafClient.impl.className", AAFPolicyClientImpl.class.getName());
51 afClient = AAFPolicyClient.getInstance(props);
52 assertFalse(afClient.checkAuth("test", pass));
53 props.setProperty("ENVIRONMENT", "PROD");
54 props.setProperty("aafClient.impl.className", AAFPolicyClientImpl.class.getName());
55 afClient.updateProperties(props);
56 assertFalse(afClient.checkAuth("test", pass));
57 props.setProperty("aaf_url", "test");
58 afClient.updateProperties(props);
59 assertFalse(afClient.checkAuth("test", pass));
60 props = new Properties();
61 props.setProperty("ENVIRONMENT", "123");
62 afClient.updateProperties(props);
63 assertFalse(afClient.checkAuth("test", pass));
64 assertFalse(afClient.checkAuthPerm("test", pass, "decision", "*", "read"));
67 @Test(expected = AAFPolicyException.class)
68 public void invalidAAFInstance() throws AAFPolicyException{
69 Properties props = new Properties();
70 props.setProperty("aafClient.impl.className", "errorClass");
71 afClient = AAFPolicyClient.getInstance(props);
74 @Test(expected = AAFPolicyException.class)
75 public void testPropNullException() throws AAFPolicyException {
76 afClient.updateProperties(null);
79 @Test(expected = AAFPolicyException.class)
80 public void testPropEmptyException() throws AAFPolicyException {
81 afClient.updateProperties(new Properties());
84 @Test(expected = AAFPolicyException.class)
85 public void testAAFException() throws AAFPolicyException{
86 new AAFPolicyException();
87 new AAFPolicyException("error", new Exception());
88 throw new AAFPolicyException("error", new Exception(), false, false);