package org.exist.xquery.functions.util;

import org.exist.security.xacml.AccessContext;
import org.exist.xquery.FunctionSignature;
import org.exist.xquery.XPathException;
import org.exist.xquery.XQueryContext;
import org.exist.xquery.value.BinaryValue;
import org.exist.xquery.value.StringValue;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

/**
 *
 * @author aretter
 */
public class BinaryToStringTest {

    @Test
    public void roundtrip() throws XPathException {
        final String value = "hello world";
        final String encoding = "UTF-8";

        TestableBinaryToString testable = new TestableBinaryToString(new MockXQueryContext(), null);

        final BinaryValue binary = testable.stringToBinary(value, encoding);
        StringValue result = testable.binaryToString(binary, encoding);

        assertEquals(value, result.getStringValue());
    }

    public class TestableBinaryToString extends BinaryToString {
        public TestableBinaryToString(XQueryContext context, FunctionSignature signature) {
            super(context, signature);
        }

        @Override
        public StringValue binaryToString(BinaryValue binary, String encoding) throws XPathException {
            return super.binaryToString(binary, encoding);
        }

        @Override
        public BinaryValue stringToBinary(String str, String encoding) throws XPathException {
            return super.stringToBinary(str, encoding);
        }
    }

    public class MockXQueryContext extends XQueryContext {
        public MockXQueryContext() {
            super(AccessContext.TEST);
        }
    }
}

@@ -1610,20 +1610,290 @@
 ;%0A        %7D%0A
+        %0A        public String getCacheClass() %7B%0A        %09return %22org.exist.util.io.FileFilterInputStreamCache%22;%0A%09        //return %22org.exist.util.io.MemoryMappedFileFilterInputStreamCache%22;%0A%09        //return %22org.exist.util.io.MemoryFilterInputStreamCache%22;%0A        %7D%0A%0A
     %7D%0A%7D%0A

update test