package uk.me.graphe.server;

import junit.framework.Assert;
import junit.framework.TestCase;
import uk.me.graphe.server.database.Database;
import uk.me.graphe.server.database.DatabaseFactory;
import uk.me.graphe.shared.Edge;
import uk.me.graphe.shared.Vertex;
import uk.me.graphe.shared.graphmanagers.GraphManager2d;
import uk.me.graphe.shared.graphmanagers.OTGraphManager2d;
import uk.me.graphe.shared.graphmanagers.OTGraphManagerFactory;
import uk.me.graphe.shared.messages.operations.AddEdgeOperation;
import uk.me.graphe.shared.messages.operations.AddNodeOperation;

public class DatabaseTest extends TestCase {

    private Database db = DatabaseFactory.newInstance();
    private OTGraphManager2d mManager;
    private int graphId = 0;

    @Override
    protected void setUp() throws Exception {
        // TODO Auto-generated method stub
        super.setUp();
        mManager = OTGraphManagerFactory.newInstance(17);
    }

    @Override
    protected void tearDown() throws Exception {
        // TODO Auto-generated method stub
        super.tearDown();
        mManager = null;
    }

    public void testStore() {
        Vertex v1 = new Vertex("v1");
        Vertex v2 = new Vertex("v2");
        mManager.applyOperation(new AddNodeOperation(v1, 1, 1));
        mManager.applyOperation(new AddNodeOperation(v2, 1, 4));
        mManager.applyOperation(new AddEdgeOperation(new Edge(v1, v2)));
        graphId = db.store(mManager);
        GraphManager2d m = db.retrieve(graphId);
        Assert.assertNotNull(m.getEdgeDrawables());        
        Assert.assertEquals(mManager.getEdgeDrawables().size(), m.getEdgeDrawables().size());
        Assert.assertNotNull(m.getVertexDrawables());
        Assert.assertEquals(mManager.getVertexDrawables().size(), m.getVertexDrawables().size());
    }

    public void testRetrieve() {
        // OTGraphManager2d retrieve = db.retrieve(graphId);

    }
}

@@ -178,32 +178,96 @@
 atabaseFactory;%0A
+import uk.me.graphe.server.org.json.wrapper.JSONWrapperFactory;%0A
 import uk.me.gra
@@ -283,16 +283,16 @@
 d.Edge;%0A
-
 import u
@@ -490,32 +490,87 @@
 ManagerFactory;%0A
+import uk.me.graphe.shared.jsonwrapper.JSONImplHolder;%0A
 import uk.me.gra
@@ -978,24 +978,85 @@
 er.setUp();%0A
+        JSONImplHolder.initialise(new JSONWrapperFactory());%0A
         mMan
@@ -1719,24 +1719,16 @@
 bles());
-        
 %0A       
@@ -1810,24 +1810,25 @@
 ().size());%0A
+%0A
         Asse

fix a bug in database test where the json factory wasn't being initialised