package com.github.jsonldjava.core;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;

import java.net.URL;
import java.util.Map;

import org.junit.Test;

import com.github.jsonldjava.utils.JsonUtils;

public class LongestPrefixTest {
    @Test
    public void toRdfWithNamespace() throws Exception {

        final URL contextUrl = getClass().getResource("/custom/contexttest-0003.jsonld");
        assertNotNull(contextUrl);
        final Object context = JsonUtils.fromURL(contextUrl);
        assertNotNull(context);

        final JsonLdOptions options = new JsonLdOptions();
        options.useNamespaces = true;
        final RDFDataset rdf = (RDFDataset) JsonLdProcessor.toRDF(context, options);
        System.out.println(rdf.getNamespaces());
        assertEquals("http://vocab.getty.edu/aat/", rdf.getNamespace("aat"));
        assertEquals("http://vocab.getty.edu/aat/rev/", rdf.getNamespace("aat_rev"));
    }

    @Test
    public void fromRdfWithNamespace() throws Exception {
        
        RDFDataset inputRdf = new RDFDataset();
        inputRdf.setNamespace("aat", "http://vocab.getty.edu/aat/");
        inputRdf.setNamespace("aat_rev", "http://vocab.getty.edu/aat/rev/");
        
        inputRdf.addTriple("http://vocab.getty.edu/aat/rev/5001065997", JsonLdConsts.RDF_TYPE, "http://vocab.getty.edu/aat/datatype");
        
        final JsonLdOptions options = new JsonLdOptions();
        options.useNamespaces = true;
        
        Object fromRDF = JsonLdProcessor.compact(new JsonLdApi(options).fromRDF(inputRdf),inputRdf.getContext(), options);
        
        final RDFDataset rdf = (RDFDataset) JsonLdProcessor.toRDF(fromRDF, options);
        System.out.println(rdf.getNamespaces());
        assertEquals("http://vocab.getty.edu/aat/", rdf.getNamespace("aat"));
        assertEquals("http://vocab.getty.edu/aat/rev/", rdf.getNamespace("aat_rev"));
        
        String toJSONLD = JsonUtils.toPrettyString(fromRDF);
        System.out.println(toJSONLD);
        
        assertFalse("Longest prefix was not used", toJSONLD.contains("aat:rev/"));
    }
}

@@ -169,29 +169,51 @@
 ll;%0A
-%0A
 import 
-java.net.URL;
+static org.junit.Assert.assertTrue;%0A
 %0Aimp
@@ -225,16 +225,15 @@
 ava.
-util.Map
+net.URL
 ;%0A%0Ai
@@ -1062,32 +1062,63 @@
 RdfWithNamespace
+LexicographicallyShortestChosen
 () throws Except
@@ -2150,42 +2150,1282 @@
 sert
-False(%22Longest prefix was not used
+True(%22The lexicographically shortest URI was not chosen%22, toJSONLD.contains(%22aat:rev/%22));%0A    %7D%0A%0A    @Test%0A    public void fromRdfWithNamespaceLexicographicallyShortestChosen2() throws Exception %7B%0A        %0A        RDFDataset inputRdf = new RDFDataset();%0A        inputRdf.setNamespace(%22aat%22, %22http://vocab.getty.edu/aat/%22);%0A        inputRdf.setNamespace(%22aatrev%22, %22http://vocab.getty.edu/aat/rev/%22);%0A        %0A        inputRdf.addTriple(%22http://vocab.getty.edu/aat/rev/5001065997%22, JsonLdConsts.RDF_TYPE, %22http://vocab.getty.edu/aat/datatype%22);%0A        %0A        final JsonLdOptions options = new JsonLdOptions();%0A        options.useNamespaces = true;%0A        %0A        Object fromRDF = JsonLdProcessor.compact(new JsonLdApi(options).fromRDF(inputRdf),inputRdf.getContext(), options);%0A        %0A        final RDFDataset rdf = (RDFDataset) JsonLdProcessor.toRDF(fromRDF, options);%0A        System.out.println(rdf.getNamespaces());%0A        assertEquals(%22http://vocab.getty.edu/aat/%22, rdf.getNamespace(%22aat%22));%0A        assertEquals(%22http://vocab.getty.edu/aat/rev/%22, rdf.getNamespace(%22aatrev%22));%0A        %0A        String toJSONLD = JsonUtils.toPrettyString(fromRDF);%0A        System.out.println(toJSONLD);%0A        %0A        assertFalse(%22The lexicographically shortest URI was not chosen
 %22, t

Add tests to verify the lexicographical comparison, rather than the prefix length comparison