/**
 * Copyright (C) 2013 Halloran Parry. All rights reserved.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as 
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.hellblazer.CoRE.access.resource;

import javax.ws.rs.core.Response;

import org.junit.Assert;
import org.junit.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.hellblazer.CoRE.ExistentialRuleform;
import com.hellblazer.CoRE.Ruleform;
import com.hellblazer.CoRE.network.Relationship;
import com.hellblazer.CoRE.product.Product;
import com.hellblazer.CoRE.resource.Resource;
import com.hellblazer.CoRE.resource.ResourceRelationshipProductAuthorization;
import com.hellblazer.CoRE.test.DatabaseTest;

/**
 * @author hparry
 * 
 */
public class CollectionResourceTest extends DatabaseTest {

    CollectionResource resource;
    Resource           core;

    @Test
    public void testCollectionResource() {
        resource = new CollectionResource(emf);
        em.getTransaction().begin();

        Resource core = new Resource("CoRE");
        core.setUpdatedBy(core);
        core = em.merge(core);
        Assert.assertTrue(core != null);
        Resource user = new Resource("User", null, core);
        user = em.merge(user);
        Product channel = new Product("MyChannel", null, core);
        channel = em.merge(channel);
        Relationship owns = new Relationship("owns", null, core);
        owns = em.merge(owns);
        Relationship ownedBy = new Relationship("ownedBy", null, core);
        ownedBy = em.merge(ownedBy); 
        owns.setInverse(ownedBy);
        ownedBy.setInverse(owns); 

        Ruleform[] rules = new Ruleform[4];
        rules[0] = user;
        rules[1] = channel;
        rules[2] = owns;
        rules[3] = ownedBy; 

        em.getTransaction().commit();

    }
    
    
    @Test
    public void testInsertSingleRuleform() throws JsonProcessingException {
    	resource = new CollectionResource(emf);
    	Resource core = new Resource("hparry", "test resource");
    	core.setUpdatedBy(core);
    	
    	Response res = resource.post(core);
    	Assert.assertTrue(res.getStatus() == 200);
    	
    }
    
    @Test
    public void testInsertSimpleGraph() throws JsonProcessingException {
    	resource = new CollectionResource(emf);
    	Resource core = new Resource("insertSimpleGraph", "test resource");
    	core.setUpdatedBy(core);
    	
    	Product prod = new Product("myProd", null, core);
    	Response res = resource.post(prod);
    	Assert.assertTrue(res.getStatus() == 200);
    }

}

@@ -814,32 +814,39 @@
 sponse;%0A%0Aimport 
+static 
 org.junit.Assert
@@ -845,16 +845,18 @@
 t.Assert
+.*
 ;%0Aimport
@@ -936,56 +936,8 @@
 on;%0A
-import com.hellblazer.CoRE.ExistentialRuleform;%0A
 impo
@@ -1112,86 +1112,8 @@
 ce;%0A
-import com.hellblazer.CoRE.resource.ResourceRelationshipProductAuthorization;%0A
 impo
@@ -1565,23 +1565,16 @@
         
-Assert.
 assertTr
@@ -2532,39 +2532,32 @@
 ost(core);%0A    %09
-Assert.
 assertTrue(res.g
@@ -2931,23 +2931,22 @@
 );%0A    %09
-Assert.
+%0A    %09
 assertTr
@@ -2969,21 +2969,84 @@
 () == 200);%0A
+    %09%0A    %09em.refresh(prod);%0A    %09assertNotNull(prod.getId());%0A
     %7D%0A%0A%7D%0A

clean up imports