-// $Id$
/**
* Copyright (C) 2014 EDIT
* European Distributed Institute of Taxonomy
import org.apache.log4j.Logger;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.unitils.dbunit.annotation.DataSet;
import eu.etaxonomy.cdm.model.description.KeyStatement;
import eu.etaxonomy.cdm.model.description.PolytomousKey;
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
-import eu.etaxonomy.taxeditor.httpinvoker.BaseRemotingTest;
+import eu.etaxonomy.taxeditor.httpinvoker.RemotingSessionAwareTest;
import eu.etaxonomy.taxeditor.remoting.cache.CdmTransientEntityCacher;
-import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
-import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
-import eu.etaxonomy.taxeditor.session.MockSessionOwner;
/**
* @author cmathew
*
*/
@DataSet
-public class CdmClientCachingTest extends BaseRemotingTest {
+public class CdmClientCachingTest extends RemotingSessionAwareTest {
private static final Logger logger = Logger.getLogger(CdmClientCachingTest.class);
private final ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
- private CdmTransientEntityCacher cacher;
- private ICdmEntitySession cdmEntitySession;
-
private static final List<String> PKEY_DEPTH1_INIT_STRATEGY = Arrays.asList(new String[] {
});
private static final List<String> PKEY_DEPTH3_INIT_STRATEGY = Arrays.asList(new String[] {
"root.statement"});
- private ICdmEntitySessionEnabled sessionOwner;
@BeforeClass
public static void initializePolytomousKeyTest() {
}
- @Before
- public void initializeSession() {
- sessionOwner = new MockSessionOwner();
- cdmEntitySession = cdmEntitySessionManager.newSession(sessionOwner, true);
- cacher = getCacher(sessionOwner);
- }
// in a recursive call
PolytomousKey pkey1 = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH1_INIT_STRATEGY),PolytomousKey.class);
-
// checking to make sure the root object is in the session cache
- Assert.assertSame(pkey1.getRoot(), cacher.getFromCache(pkey1.getRoot()));
+ Assert.assertSame(CdmBase.deproxy(pkey1.getRoot(),PolytomousKeyNode.class), cacher.getFromCache(pkey1.getRoot()));
}
PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH2_INIT_STRATEGY),PolytomousKey.class);
CdmTransientEntityCacher cacher = getCacher(sessionOwner);
// checking to make sure the root object is in the session cache
- Assert.assertSame(pkey.getRoot(), cacher.getFromCache(pkey.getRoot()));
- Assert.assertSame(pkey.getRoot().getStatement(), cacher.getFromCache(pkey.getRoot().getStatement()));
- Assert.assertSame(pkey.getRoot().getQuestion(), cacher.getFromCache(pkey.getRoot().getQuestion()));
+ Assert.assertSame(CdmBase.deproxy(pkey.getRoot(),PolytomousKeyNode.class), cacher.getFromCache(pkey.getRoot()));
+ Assert.assertSame(CdmBase.deproxy(pkey.getRoot().getStatement(),KeyStatement.class), cacher.getFromCache(pkey.getRoot().getStatement()));
+ Assert.assertSame(CdmBase.deproxy(pkey.getRoot().getQuestion(),KeyStatement.class), cacher.getFromCache(pkey.getRoot().getQuestion()));
}
// |- root : polytomous key node
// in a recursive call
PolytomousKey pkey1 = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH1_INIT_STRATEGY),PolytomousKey.class);
+ KeyStatement ks1 = CdmBase.deproxy(pkey1.getRoot().getStatement(), KeyStatement.class);
CdmTransientEntityCacher cacher = getCacher(sessionOwner);
// |- root : polytomous key node
// |- question : KeyStatement
// |- statement : KeyStatement
- PolytomousKey pkey2 = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH2_INIT_STRATEGY),PolytomousKey.class);
+ PolytomousKey pkey2 = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH3_INIT_STRATEGY),PolytomousKey.class);
+ KeyStatement ks2 = CdmBase.deproxy(pkey2.getRoot().getStatement(), KeyStatement.class);
- Assert.assertSame(pkey2.getRoot().getStatement(), cacher.getFromCache(pkey2.getRoot().getStatement()));
- Assert.assertSame(pkey1.getRoot().getStatement(), pkey2.getRoot().getStatement());
- Assert.assertSame(cacher.getFromCache(pkey1.getRoot().getStatement()), cacher.getFromCache(pkey2.getRoot().getStatement()));
+ Assert.assertSame(ks2, cacher.getFromCache(ks2));
+ Assert.assertSame(cacher.getFromCache(KeyStatement.class, ks1.getId()), cacher.getFromCache(ks2));
}
// |- question : KeyStatement
// |- statement : KeyStatement
PolytomousKey pkey1 = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH2_INIT_STRATEGY),PolytomousKey.class);
-
+ KeyStatement ks1 = pkey1.getRoot().getStatement();
+ Assert.assertSame(ks1, pkey1.getRoot().getStatement());
CdmTransientEntityCacher cacher = getCacher(sessionOwner);
// this call will load into the session cache the graph and update the objects in the sub-graph for a
// |- root : polytomous key node
PolytomousKey pkey2 = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH1_INIT_STRATEGY),PolytomousKey.class);
-
- Assert.assertSame(pkey2.getRoot().getStatement(), cacher.getFromCache(pkey2.getRoot().getStatement()));
Assert.assertSame(pkey1.getRoot().getStatement(), pkey2.getRoot().getStatement());
- Assert.assertSame(cacher.getFromCache(pkey1.getRoot().getStatement()), cacher.getFromCache(pkey2.getRoot().getStatement()));
+ pkey2.getRoot().getStatement().getCreatedBy();
+ Assert.assertSame(cacher.getFromCache(ks1), cacher.getFromCache(pkey2.getRoot().getStatement()));
}
/**
// |- statement : KeyStatement
PolytomousKey pkey1 = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH2_INIT_STRATEGY),PolytomousKey.class);
+
CdmTransientEntityCacher cacher = getCacher(sessionOwner);
// checking that the root is not null and
// that it exists in the cache and
// that both the original object and the
// cached object are the same
- Assert.assertNotNull(pkey1.getRoot().getStatement());
+ Assert.assertNotNull(CdmBase.deproxy(pkey1.getRoot().getStatement(), KeyStatement.class));
Assert.assertNotNull(cacher.getFromCache(pkey1.getRoot().getStatement()));
// this call will load into the session cache the graph and update the objects in the sub-graph for a
// |- root : polytomous key node
PolytomousKey pkey2 = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
+ KeyStatement ks2 = CdmBase.deproxy(pkey2.getRoot().getStatement(), KeyStatement.class);
+ Assert.assertSame(ks2, cacher.getFromCache(pkey2.getRoot().getStatement()));
-
- Assert.assertSame(pkey2.getRoot().getStatement(), cacher.getFromCache(pkey2.getRoot().getStatement()));
Assert.assertSame(pkey1.getRoot().getStatement(), pkey2.getRoot().getStatement());
Assert.assertSame(cacher.getFromCache(pkey1.getRoot().getStatement()), cacher.getFromCache(pkey2.getRoot().getStatement()));
}
PolytomousKey pkey2 = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH2_INIT_STRATEGY),PolytomousKey.class);
- Assert.assertSame(pkey2.getRoot().getStatement(), cacher.getFromCache(pkey2.getRoot().getStatement(), KeyStatement.class));
- Assert.assertSame(st, pkey2.getRoot().getStatement());
+ Assert.assertSame(CdmBase.deproxy(pkey2.getRoot().getStatement(), KeyStatement.class), cacher.getFromCache(pkey2.getRoot().getStatement(), KeyStatement.class));
+ Assert.assertSame(st, CdmBase.deproxy(pkey2.getRoot().getStatement(), KeyStatement.class));
Assert.assertSame(cacher.getFromCache(st), cacher.getFromCache(pkey2.getRoot().getStatement(), KeyStatement.class));
}