package org.nthx.pat.tests;
import org.nthx.pat.IdentityMap;
import org.nthx.pat.Pat;
import org.nthx.pat.Persisteble;
public class IdentityMapTest
extends PatTestCase
{
public void setUp()
{
}
public void testCreatingEmptyRoot()
{
Pat.unload();
cleanPrevaylersRepo();
Bank bank = new Bank();
assertEquals(1, ((IdentityMap)bank).getMapForTestsOnly().size());
assertNotNull(((IdentityMap)bank).getObject(new Long(1)));
assertEquals(bank, ((IdentityMap)bank).getObject(new Long(1)));
assertEquals(bank, Pat.getInstance().getRootAsIdentityMap());
Pat.unload();
bank = new Bank();
assertEquals(1, ((IdentityMap)bank).getMapForTestsOnly().size());
assertNotNull(((IdentityMap)bank).getObject(new Long(1)));
assertEquals(bank, ((IdentityMap)bank).getObject(new Long(1)));
assertEquals(bank, Pat.getInstance().getRootAsIdentityMap());
}
public void testCreatingRootAndAddingSomeData_Snapshot()
{
Pat.unload();
cleanPrevaylersRepo();
TestRoot root = new TestRoot();
TestUser tomasz = root.newUser("Tomasz");
assertEquals(3, ((IdentityMap)root).getMapForTestsOnly().size());
assertNotNull(((IdentityMap)root).getObject(new Long(1)));
assertNotNull(((IdentityMap)root).getObject(new Long(2)));
assertNotNull(((IdentityMap)root).getObject(new Long(3)));
assertEquals(root, ((IdentityMap)root).getObject(new Long(2)));
assertEquals(root.getUsers(), ((IdentityMap)root).getObject(new Long(1)));
TestUsers usersFromIM = (TestUsers)(((IdentityMap)root).getObject(new Long(1)));
assertEquals(1, usersFromIM.size());
assertEquals(root.findUser("Tomasz"), ((IdentityMap)root).getObject(new Long(3)));
assertEquals(root, Pat.getInstance().getRootAsIdentityMap());
((Persisteble)root).takeSnapshot();
Pat.unload();
root = new TestRoot();
assertEquals("Should be 3 BOs", 3, ((IdentityMap)root).getMapForTestsOnly().size());
assertNotNull(((IdentityMap)root).getObject(new Long(1)));
assertNotNull(((IdentityMap)root).getObject(new Long(2)));
assertNotNull(((IdentityMap)root).getObject(new Long(3)));
assertEquals(root, ((IdentityMap)root).getObject(new Long(2)));
assertEquals(root.getUsers(), ((IdentityMap)root).getObject(new Long(1)));
usersFromIM = (TestUsers)(((IdentityMap)root).getObject(new Long(1)));
assertEquals(1, usersFromIM.size());
assertEquals(root.findUser("Tomasz"), ((IdentityMap)root).getObject(new Long(3)));
assertEquals(root, Pat.getInstance().getRootAsIdentityMap());
}
public void testCreatingRootAndAddingSomeData_WithoutSnapshot()
{
Pat.unload();
cleanPrevaylersRepo();
TestRoot root = new TestRoot();
TestUser tomasz = root.newUser("Tomasz");
assertEquals(3, ((IdentityMap)root).getMapForTestsOnly().size());
assertNotNull(((IdentityMap)root).getObject(new Long(1)));
assertNotNull(((IdentityMap)root).getObject(new Long(2)));
assertNotNull(((IdentityMap)root).getObject(new Long(3)));
assertEquals(root, ((IdentityMap)root).getObject(new Long(2)));
assertEquals("Differs 1st time",root.getUsers(), ((IdentityMap)root).getObject(new Long(1)));
TestUsers usersFromIM = (TestUsers)(((IdentityMap)root).getObject(new Long(1)));
assertEquals(1, usersFromIM.size());
assertEquals(root.findUser("Tomasz"), ((IdentityMap)root).getObject(new Long(3)));
assertEquals(root, Pat.getInstance().getRootAsIdentityMap());
Pat.unload();
root = new TestRoot();
assertEquals("Should be 3 BOs", 3, ((IdentityMap)root).getMapForTestsOnly().size());
assertNotNull(((IdentityMap)root).getObject(new Long(1)));
assertNotNull(((IdentityMap)root).getObject(new Long(2)));
assertNotNull(((IdentityMap)root).getObject(new Long(3)));
assertEquals(root, ((IdentityMap)root).getObject(new Long(2)));
logTest.debug("SSS: ----------");
logTest.debug("IM(1): " + ((IdentityMap)root).getObject(new Long(1)));
logTest.debug("IM(2): " + ((IdentityMap)root).getObject(new Long(2)));
logTest.debug("IM(3): " + ((IdentityMap)root).getObject(new Long(3)));
assertEquals("Differs 2nd time",root.getUsers(), ((IdentityMap)root).getObject(new Long(1)));
usersFromIM = (TestUsers)(((IdentityMap)root).getObject(new Long(1)));
assertEquals(1, usersFromIM.size());
assertEquals(root.findUser("Tomasz"), ((IdentityMap)root).getObject(new Long(3)));
assertEquals(root, Pat.getInstance().getRootAsIdentityMap());
}
public IdentityMapTest(String arg)
{
super(arg);
}
public static void main(String[] args)
{
junit.textui.TestRunner.run(IdentityMapTest.class);
}
}