Modified code to use java system variable to identify temp
directory.
Change-Id: Ib656dd2a2d57e43febb0daaa25cf90cb1b9330a7
Issue-ID: POLICY-920
Signed-off-by: Jim Hahn <jrh3@att.com>
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.Properties;
import java.io.IOException;
import java.util.Properties;
import org.junit.Test;
import org.onap.policy.xacml.std.pap.StdEngineFactory;
import org.junit.Test;
import org.onap.policy.xacml.std.pap.StdEngineFactory;
import com.att.research.xacml.api.pap.PAPException;
import com.att.research.xacml.std.pap.StdEngine;
import com.att.research.xacml.util.FactoryException;
import com.att.research.xacml.api.pap.PAPException;
import com.att.research.xacml.std.pap.StdEngine;
import com.att.research.xacml.util.FactoryException;
- public void testNegativeCase() throws FactoryException, PAPException {
+ public void testNegativeCase() throws Exception {
// Setup test data
Properties props = new Properties();
// Setup test data
Properties props = new Properties();
- props.setProperty(StdEngine.PROP_PAP_REPO, "/tmp");
+ String tmpdir = System.getProperty("java.io.tmpdir");
+ props.setProperty(StdEngine.PROP_PAP_REPO, tmpdir);
// Set the system property temporarily
String systemKey = StdEngine.PROP_PAP_REPO;
String oldProperty = System.getProperty(systemKey);
// Set the system property temporarily
String systemKey = StdEngine.PROP_PAP_REPO;
String oldProperty = System.getProperty(systemKey);
- System.setProperty(systemKey, "/tmp");
+ System.setProperty(systemKey, tmpdir);
// Test factory failure cases
try {
// Test factory failure cases
try {
* ============LICENSE_START=======================================================
* ONAP-XACML
* ================================================================================
* ============LICENSE_START=======================================================
* ONAP-XACML
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Path;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Path;
-import java.nio.file.Paths;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.xacml.util.XACMLPolicyWriter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.xacml.util.XACMLPolicyWriter;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
- public void testWrites() {
+ public void testWrites() throws Exception {
// Set up test data
PolicyType policyType = new PolicyType();
OutputStream os = new ByteArrayOutputStream();
// Set up test data
PolicyType policyType = new PolicyType();
OutputStream os = new ByteArrayOutputStream();
- Path filename = Paths.get("/tmp/foo");
+ File tmpfile = File.createTempFile("foo", null);
+ Path filename = tmpfile.toPath();
PolicySetType policySet = new PolicySetType();
PolicySetType policySet = new PolicySetType();
+
+ // delete tmp file before running the test
+ tmpfile.delete();
+
+ // ensure its deleted after writePolicyFile() re-creates it
+ tmpfile.deleteOnExit();
// Test write combinations
assertNotNull(XACMLPolicyWriter.writePolicyFile(filename, policySet));
// Test write combinations
assertNotNull(XACMLPolicyWriter.writePolicyFile(filename, policySet));