@@ -0,0 +1,2971 @@
+package lux.functions;%0A%0Aimport java.io.IOException;%0A%0Aimport lux.api.QueryContext;%0Aimport lux.api.ResultSet;%0Aimport lux.saxon.Saxon;%0Aimport lux.saxon.Saxon.Dialect;%0Aimport lux.xpath.QName;%0A%0Aimport net.sf.saxon.s9api.XdmAtomicValue;%0A%0Aimport org.apache.commons.io.IOUtils;%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test;%0A%0Aimport static org.junit.Assert.*;%0A%0Apublic class TransformTest %7B%0A    %0A    @Test%0A    public void testBasicQuery () %7B%0A        // just make sure everything is wired up properly to run XQuery%0A        assertXQuery (%222%22, %221 + 1%22);%0A        assertXQuery (%22ABC%22, %22concat('A','B','C')%22);%0A    %7D%0A    %0A    @Test%0A    public void testTransform1 () throws Exception %7B%0A        // test a query that calls lux:transform%0A        assertXQueryFile (%222%22, %22transform-1.xqy%22);%0A    %7D%0A    %0A    @Test%0A    public void testTransformError () throws Exception %7B%0A        // test a query that doesn't compile%0A        assertXQueryFile (null, %22transform-error.xqy%22, %22The supplied file does not appear to be a stylesheet%22);%0A    %7D%0A    %0A    @Test%0A    public void testTransformContext () throws Exception %7B%0A        // test a stylesheet that expects an external variable - attempt%0A        // to bind one, but it is not seen by the stylesheet%0A        String query = IOUtils.toString(TransformTest.class.getResourceAsStream(%22transform-context.xqy%22));%0A        QueryContext context = new QueryContext(saxon);%0A        context.bindVariable(new QName(%22external-var%22), new XdmAtomicValue(10));%0A        ResultSet%3C?%3E results = saxon.compile(query).evaluate(context);%0A        assertNull (%22got an unexpected error%22, results.getErrors());%0A        assertEquals (%22undefined%22, results.iterator().next().toString());%0A    %7D%0A    %0A    private static Saxon saxon;%0A    %0A    @BeforeClass%0A    public static void setup () %7B%0A        saxon = new Saxon(Dialect.XQUERY_1);%0A    %7D%0A%0A    private void assertXQueryFile (String result, String queryFile) throws IOException %7B%0A        assertXQueryFile (result, queryFile, null);%0A    %7D%0A    %0A    private void assertXQueryFile (String result, String queryFile, String firstError) throws IOException %7B%0A        String query = IOUtils.toString(TransformTest.class.getResourceAsStream(queryFile));%0A        assertXQuery (result, query, firstError);%0A    %7D%0A%0A    private void assertXQuery (String result, String query) %7B%0A        assertXQuery (result, query, null);%0A    %7D%0A    %0A    private void assertXQuery (String result, String query, String firstError) %7B%0A        ResultSet%3C?%3E results = saxon.compile(query).evaluate(new QueryContext(saxon));%0A        if (result == null) %7B%0A            assertEquals (0, results.size());%0A            if (firstError != null) %7B%0A                assertEquals (firstError, results.getErrors().iterator().next().getMessage());%0A            %7D else %7B%0A                assertNull (results.getErrors());%0A            %7D%0A            return;%0A        %7D%0A        assertEquals (1, results.size());%0A        assertEquals (result, results.iterator().next().toString());%0A    %7D%0A%7D%0A

test lux:transform