2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (C) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.policy.xacml.test.std.pap;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26 import java.io.IOException;
27 import java.util.Properties;
28 import org.junit.Test;
29 import org.onap.policy.xacml.std.pap.StdEngineFactory;
30 import com.att.research.xacml.api.pap.PAPException;
31 import com.att.research.xacml.std.pap.StdEngine;
32 import com.att.research.xacml.util.FactoryException;
34 public class StdEngineFactoryTest {
36 public void testStdEngineFactory() throws FactoryException, PAPException, IOException {
37 StdEngineFactory stdFactory = new StdEngineFactory();
38 System.setProperty("xacml.pap.pdps", "src/test/resources/pdps");
39 assertTrue(stdFactory.newEngine() != null);
40 Properties properties = new Properties();
41 properties.setProperty("xacml.pap.pdps", "src/test/resources/pdps");
42 assertTrue(stdFactory.newEngine(properties) != null);
44 StdEngineFactory stdFactoryNew = new StdEngineFactory();
45 System.setProperty("xacml.pap.pdps", "src/test/resources/pdpstest");
46 assertTrue(stdFactoryNew.newEngine() != null);
50 public void testNegativeCase() throws Exception {
52 Properties props = new Properties();
53 String tmpdir = System.getProperty("java.io.tmpdir");
54 props.setProperty(StdEngine.PROP_PAP_REPO, tmpdir);
56 // Set the system property temporarily
57 String systemKey = StdEngine.PROP_PAP_REPO;
58 String oldProperty = System.getProperty(systemKey);
59 System.setProperty(systemKey, tmpdir);
61 // Test factory failure cases
63 StdEngineFactory factory = new StdEngineFactory();
65 factory.newEngine(props);
66 } catch (Exception ex) {
67 fail("Not expecting any exceptions: " + ex);
70 // Restore the original system property
71 if (oldProperty != null) {
72 System.setProperty(systemKey, oldProperty);
74 System.clearProperty(systemKey);