/**
-* Copyright (C) 2007 EDIT
+* Copyright (C) 2014 EDIT
* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
*
*/
package eu.etaxonomy.taxeditor.remoting;
-
-
import java.util.List;
+import java.util.Set;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
+import org.hibernate.collection.spi.PersistentCollection;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.unitils.UnitilsJUnit4;
import eu.etaxonomy.cdm.api.service.IClassificationService;
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;
import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.strategy.match.MatchException;
/**
* Test class which tests remoting for persistent collections.
*
* @author c.mathew
- * @created 13.032014
+ * @created 13.03.2014
*/
public class RemotePersistentCollectionTest extends RemoteApplicationConfigurationTest {
private static final Logger logger = Logger.getLogger(RemotePersistentCollectionTest.class);
@BeforeClass
public static void initializeServices() {
- Logger.getRootLogger().setLevel(Level.DEBUG);
+ Logger.getRootLogger().setLevel(Level.INFO);
classificationService= applicationController.getClassificationService();
}
+
+ /**
+ * Test class which checks remoting for persistent lists.
+ *
+ */
@Test
public void persistentListTest() {
- List<TaxonNode> taxonNodes = classificationService.getAllNodes();
- logger.debug("classificationService.getAllNodes() size : " + taxonNodes.size());
-
+ List<TaxonNode> taxonNodes = classificationService.getAllNodes();
int size = taxonNodes.size();
- logger.info("classification children size : " + size);
+ logger.debug("classificationService.getAllNodes() size : " + size);
TaxonNode taxonNode = null;
if(size > 0) {
+ Assert.assertFalse(taxonNodes.isEmpty());
+
taxonNode = taxonNodes.get(0);
+ Assert.assertNotNull(taxonNode);
Assert.assertTrue(taxonNodes.contains(taxonNode));
-
- List childNodes = taxonNode.getChildNodes();
- //FIXME:Remoting Are we expecting here to first remote initialise the child node list
- // and then get its size or are we expecting to retrieve the size remotely ?
+
+ // get the list of child nodes, which will give a
+ // proxy list which is not yet initialised
+ List<TaxonNode> childNodes = taxonNode.getChildNodes();
+ // this size call will first initialise the list locally by internally
+ // calling the ICommonService.initializeCollection method and then
+ // call size on the initialised list
int childCount = childNodes.size();
- logger.info("first node child count : " + childCount);
+
+ // this size call will initialise the list remotely and only return the
+ // size of the list
+ int remoteChildCount = applicationController.getCommonService().size((PersistentCollection)childNodes);
+ Assert.assertEquals(childCount, remoteChildCount);
String firstNodeTaxonTitle = taxonNode.getTaxon().getTitleCache();
- Assert.assertNotNull(firstNodeTaxonTitle);
- logger.info("first node taxon : " + firstNodeTaxonTitle);
+ Assert.assertNotNull(firstNodeTaxonTitle);
if(childCount > 0) {
+ Assert.assertFalse(childNodes.isEmpty());
+ // this get call will use the already initialised list to get the
+ // 0th element
+ TaxonNode localTaxonNode = childNodes.get(0);
+
+ // this get call will initialise the list remotely and only return the
+ // 0th element from the list
+ TaxonNode remoteTaxonNode = (TaxonNode)applicationController.getCommonService().get((PersistentCollection)childNodes,0);
- Assert.assertTrue(taxonNode.getChildNodes().contains(taxonNode.getChildNodes().get(0)));
- //FIXME:Remoting Are we expecting here to first remote initialise the child node list
- // and then get the 0th element or are we expecting to remote initialise
- // the 0th element of the child node list ?
- Assert.assertNotNull(taxonNode.getChildNodes().get(0).getTaxon());
- Assert.assertNotNull(taxonNode.getChildNodes().get(0).getTaxon());
- logger.info("first child node : " + taxonNode.getChildNodes().get(0).getTaxon());
- }
- Assert.assertFalse(taxonNodes.isEmpty());
+ // the locally and remotely retrieved taxon node should exist in the
+ // (local and remote) child nodes list, should be not-null and should be equal to each other
+ Assert.assertTrue(taxonNode.getChildNodes().contains(localTaxonNode));
+ Assert.assertTrue(taxonNode.getChildNodes().contains(remoteTaxonNode));
+ Assert.assertTrue(applicationController.getCommonService().contains((PersistentCollection)childNodes, localTaxonNode));
+ Assert.assertTrue(applicationController.getCommonService().contains((PersistentCollection)childNodes, remoteTaxonNode));
+ Assert.assertNotNull(remoteTaxonNode);
+ Assert.assertNotNull(localTaxonNode);
+ Assert.assertEquals(remoteTaxonNode,localTaxonNode);
+ }
+ }
+ }
+
+ @Test
+ public void persistentSetTest() {
+ List<Classification> classifications = classificationService.listClassifications(1,0,null,null);
+ int size = classifications.size();
+ if(size > 0) {
+ Assert.assertFalse(classifications.isEmpty());
+
+ Classification classification = classifications.get(0);
+ Assert.assertNotNull(classification);
+ Assert.assertTrue(classifications.contains(classification));
+
+ TaxonNode rootTaxonNode = classification.getRootNode();
+ // get the list of child nodes, which will give a
+ // proxy list which is not yet initialised
+ List<TaxonNode> childNodes = rootTaxonNode.getChildNodes();
+
+ // this size call will initialise the list locally by internally
+ // calling the ICommonService.initializeCollection method
+ int childCount = childNodes.size();
+
+ if(childCount > 0) {
+ Assert.assertFalse(childNodes.isEmpty());
+
+ // this get call will use the already initialised list to get the
+ // 0th element
+ Taxon localTaxon = childNodes.get(0).getTaxon();
+ Assert.assertNotNull(localTaxon);
+
+ TaxonNameBase taxonName = localTaxon.getName();
+ Assert.assertNotNull(taxonName);
+
+ // get the list of taxa, which will give a
+ // proxy set which is not yet initialised
+ Set<Taxon> taxa = taxonName.getTaxonBases();
+
+ // this size call will initialise the list locally by internally
+ // calling the ICommonService.initializeCollection method
+ int taxaCount = taxa.size();
+ Assert.assertNotEquals(taxaCount,-1);
+
+ if(taxaCount > 0) {
+ Assert.assertFalse(taxa.isEmpty());
+ // the locally retrieved taxon should exist in the
+ // (local and remote) taxon list and should be not-null
+ Assert.assertTrue(taxa.contains(localTaxon));
+ Assert.assertNotNull(localTaxon);
+ Assert.assertTrue(applicationController.getCommonService().contains((PersistentCollection)taxa, localTaxon));
+ }
+ }
}
-
- Assert.assertNotNull(taxonNode);
- Assert.assertTrue(taxonNodes.contains(taxonNode));
+ }
+
+ @Test
+ public void persistentMapTest() {
}
}