2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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=========================================================
23 package org.onap.policy.xacml.test.std.pap;
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
28 import com.att.research.xacml.api.pap.PAPException;
29 import com.att.research.xacml.std.pap.StdEngine;
30 import com.att.research.xacml.util.FactoryException;
32 import java.io.IOException;
33 import java.util.Properties;
35 import org.junit.Test;
36 import org.onap.policy.xacml.std.pap.StdEngineFactory;
38 public class StdEngineFactoryTest {
40 public void testStdEngineFactory() throws FactoryException, PAPException, IOException {
41 StdEngineFactory stdFactory = new StdEngineFactory();
42 System.setProperty("xacml.pap.pdps", "src/test/resources/pdps");
43 assertTrue(stdFactory.newEngine() != null);
44 Properties properties = new Properties();
45 properties.setProperty("xacml.pap.pdps", "src/test/resources/pdps");
46 assertTrue(stdFactory.newEngine(properties) != null);
48 StdEngineFactory stdFactoryNew = new StdEngineFactory();
49 System.setProperty("xacml.pap.pdps", "src/test/resources/pdpstest");
50 assertTrue(stdFactoryNew.newEngine() != null);
54 public void testNegativeCase() throws Exception {
56 Properties props = new Properties();
57 String tmpdir = System.getProperty("java.io.tmpdir");
58 props.setProperty(StdEngine.PROP_PAP_REPO, tmpdir);
60 // Set the system property temporarily
61 String systemKey = StdEngine.PROP_PAP_REPO;
62 String oldProperty = System.getProperty(systemKey);
63 System.setProperty(systemKey, tmpdir);
65 // Test factory failure cases
67 StdEngineFactory factory = new StdEngineFactory();
69 factory.newEngine(props);
70 } catch (Exception ex) {
71 fail("Not expecting any exceptions: " + ex);
74 // Restore the original system property
75 if (oldProperty != null) {
76 System.setProperty(systemKey, oldProperty);
78 System.clearProperty(systemKey);