/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.caboto;

import com.hp.hpl.jena.vocabulary.DCTerms;
import com.hp.hpl.jena.vocabulary.DC;
import com.hp.hpl.jena.vocabulary.RDF;
import org.caboto.vocabulary.Annotea;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Resource;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author pldms
 */
public class CabotoJsonSupportTest {
    private Resource resource;
    private Resource body;

    public CabotoJsonSupportTest() {
    }

    @Before
    public void setUp() throws Exception {
        Model model = ModelFactory.createDefaultModel();
        resource = model.createResource();
        body = model.createResource();
        resource.addProperty(RDF.type,
                model.createResource("http://example.com/TheType"));
        resource.addProperty(Annotea.annotates,
                model.createResource("http://example.com/annotated"));
        resource.addProperty(Annotea.body, body);
        /*body.addProperty(DC.subject, "subj1");
        body.addProperty(DC.subject, "subj2");
        body.addProperty(DCTerms.subject,
                model.createResource("http://example.com/subject/1"));
        body.addProperty(DCTerms.subject,
                model.createResource("http://example.com/subject/2"));*/
        
    }

    /**
     * Test of generateJsonObject method, of class CabotoJsonSupport.
     */
    @Test
    public void testGenerateJsonObject_Literal() throws Exception {
        body.addProperty(DC.subject, "subj1");
        
        CabotoJsonSupport instance = new CabotoJsonSupport();
        String expResult = 
                "{\"body\":{\"subject\":[\"subj1\"]},\"annotates\":\"http:\\/\\/example.com\\/annotated\",\"type\":\"TheType\"}";
        JSONObject result = instance.generateJsonObject(resource);
        
        assertEquals(expResult, result.toString());
        
        body.addProperty(DC.subject, "subj2");
        
        expResult = 
                "{\"body\":{\"subject\":[\"subj2\",\"subj1\"]},\"annotates\":\"http:\\/\\/example.com\\/annotated\",\"type\":\"TheType\"}";
        
        result = instance.generateJsonObject(resource);
        
        assertEquals(expResult, result.toString());
    }
    
    /**
     * Test of generateJsonObject method, of class CabotoJsonSupport.
     */
    @Test
    public void testGenerateJsonObject_Resource() throws Exception {
        body.addProperty(DCTerms.provenance, body.getModel().createResource("http://example.com/doc/1"));
        
        CabotoJsonSupport instance = new CabotoJsonSupport();
        String expResult = 
                "{\"body\":{\"provenance\":[\"http:\\/\\/example.com\\/doc\\/1\"]},\"annotates\":\"http:\\/\\/example.com\\/annotated\",\"type\":\"TheType\"}";
        JSONObject result = instance.generateJsonObject(resource);
        
        assertEquals(expResult, result.toString());
        
        body.addProperty(DCTerms.provenance, body.getModel().createResource("http://example.com/doc/2"));
        
        expResult = 
                "{\"body\":{\"provenance\":[\"http:\\/\\/example.com\\/doc\\/2\",\"http:\\/\\/example.com\\/doc\\/1\"]},\"annotates\":\"http:\\/\\/example.com\\/annotated\",\"type\":\"TheType\"}";
        
        result = instance.generateJsonObject(resource);
        
        assertEquals(expResult, result.toString());
    }
}
@@ -3,103 +3,1644 @@
 %0A * 
-To change this template, choose Tools %7C Templates%0A * and open 
+Copyright (c) 2011, University of Bristol%0A * All rights reserved.%0A *%0A * Redistribution and use in source and binary forms, with or without%0A * modification, are permitted provided that the following conditions are met:%0A *%0A * 1) Redistributions of source code must retain the above copyright notice,%0A *    this list of conditions and the following disclaimer.%0A *%0A * 2) Redistributions in binary form must reproduce the above copyright notice,%0A *    this list of conditions and the following disclaimer in the documentation%0A *    and/or other materials provided with the distribution.%0A *%0A * 3) Nei
 the
+r
  t
-emplate in the editor.
+he names of the University of Bristol and the%0A *    University of Manchester nor the names of their%0A *    contributors may be used to endorse or promote products derived from this%0A *    software without specific prior written permission.%0A *%0A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS %22AS IS%22%0A * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE%0A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE%0A * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE%0A * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR%0A * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF%0A * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS%0A * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN%0A * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)%0A * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE%0A * POSSIBILITY OF SUCH DAMAGE.%0A *
 %0A */%0A
-%0A
 pack
@@ -1948,53 +1948,8 @@
 ce;%0A
-import org.codehaus.jettison.json.JSONArray;%0A
 impo
@@ -2011,97 +2011,14 @@
 nit.
-After;%0Aimport org.junit.AfterClass;%0Aimport org.junit.Before;%0Aimport org.junit.BeforeClass
+Before
 ;%0Aim

Remove unused imports