// Path: src/main/java/es/tid/fiware/iot/ac/util/Util.java
// public class Util {
// 
//     public static String read(Class clazz, String f) {
//         return new Scanner(clazz.getResourceAsStream(f)).useDelimiter("\\Z").next();
//     }
// 
// }
// 
// Path: src/main/java/es/tid/fiware/iot/ac/util/Xml.java
// public class Xml {
// 
//     // DocumentBuilder is not thread safe: <http://stackoverflow.com/a/3442674/1035380>
// 
//     private static DocumentBuilder db() {
//         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//         factory.setIgnoringComments(true);
//         factory.setNamespaceAware(true);
//         try {
//             return factory.newDocumentBuilder();
//         } catch (ParserConfigurationException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public static String toString(Document doc) throws TransformerConfigurationException, TransformerException {
//         TransformerFactory tf = TransformerFactory.newInstance();
//         Transformer transformer = tf.newTransformer();
//         transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
//         StringWriter writer = new StringWriter();
//         transformer.transform(new DOMSource(doc), new StreamResult(writer));
//         return writer.getBuffer().toString().replaceAll("\n|\r", "");
//     }
//     
//     public static Document toXml(String str) throws IOException, SAXException {
//         return db().parse(new InputSource(new StringReader(str)));
//     }
// 
//     public static Document newDocument() {
//         return db().newDocument();
//     }
// }


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.AssertJUnit.assertEquals;
import es.tid.fiware.iot.ac.util.Util;
import es.tid.fiware.iot.ac.util.Xml;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.wso2.balana.PDP;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
                  "policy01_request01.xml", "Permit" },

                { "One Policy, two Subjects and Permit",
                  Arrays.asList("policy01.xml"),
                  "policy01_request03.xml", "Permit" },

                { "Policy with resource target",
                  Arrays.asList("policy03.xml"),
                  "policy01_request01.xml", "Permit" },

                { "Policy with several actions permitted",
                  Arrays.asList("policy05.xml"),
                  "policy01_request01.xml", "Permit" },

                { "Policy with any action permitted",
                  Arrays.asList("policy06.xml"),
                  "policy01_request01.xml", "Permit" },

                 { "One PolicySet, one Subject and Permit",
                  Arrays.asList("policyset01.xml"),
                  "policyset01_request01.xml", "Permit" },
        };
    }

    @Test(dataProvider = "policies")
    public void testPolicyEval(String testName, List<String> policies,
            String request, String decision) throws Exception {

        PDP pdp = createPDP(policies);

// Path: src/main/java/es/tid/fiware/iot/ac/util/Util.java
// public class Util {
// 
//     public static String read(Class clazz, String f) {
//         return new Scanner(clazz.getResourceAsStream(f)).useDelimiter("\\Z").next();
//     }
// 
// }
// 
// Path: src/main/java/es/tid/fiware/iot/ac/util/Xml.java
// public class Xml {
// 
//     // DocumentBuilder is not thread safe: <http://stackoverflow.com/a/3442674/1035380>
// 
//     private static DocumentBuilder db() {
//         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//         factory.setIgnoringComments(true);
//         factory.setNamespaceAware(true);
//         try {
//             return factory.newDocumentBuilder();
//         } catch (ParserConfigurationException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public static String toString(Document doc) throws TransformerConfigurationException, TransformerException {
//         TransformerFactory tf = TransformerFactory.newInstance();
//         Transformer transformer = tf.newTransformer();
//         transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
//         StringWriter writer = new StringWriter();
//         transformer.transform(new DOMSource(doc), new StreamResult(writer));
//         return writer.getBuffer().toString().replaceAll("\n|\r", "");
//     }
//     
//     public static Document toXml(String str) throws IOException, SAXException {
//         return db().parse(new InputSource(new StringReader(str)));
//     }
// 
//     public static Document newDocument() {
//         return db().newDocument();
//     }
// }


// Path: src/test/java/es/tid/fiware/iot/ac/xacml/TestSamplesXACML.java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.AssertJUnit.assertEquals;
import es.tid.fiware.iot.ac.util.Util;
import es.tid.fiware.iot.ac.util.Xml;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.wso2.balana.PDP;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;

                  "policy01_request01.xml", "Permit" },

                { "One Policy, two Subjects and Permit",
                  Arrays.asList("policy01.xml"),
                  "policy01_request03.xml", "Permit" },

                { "Policy with resource target",
                  Arrays.asList("policy03.xml"),
                  "policy01_request01.xml", "Permit" },

                { "Policy with several actions permitted",
                  Arrays.asList("policy05.xml"),
                  "policy01_request01.xml", "Permit" },

                { "Policy with any action permitted",
                  Arrays.asList("policy06.xml"),
                  "policy01_request01.xml", "Permit" },

                 { "One PolicySet, one Subject and Permit",
                  Arrays.asList("policyset01.xml"),
                  "policyset01_request01.xml", "Permit" },
        };
    }

    @Test(dataProvider = "policies")
    public void testPolicyEval(String testName, List<String> policies,
            String request, String decision) throws Exception {

        PDP pdp = createPDP(policies);

        String xacmlRes = pdp.evaluate(Util.read(this.getClass(), request));