added test class for persistent collections and also a base class for configuringsett...
authorCherian Mathew <c.mathew@bgbm.org>
Thu, 13 Mar 2014 09:00:53 +0000 (09:00 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Thu, 13 Mar 2014 09:00:53 +0000 (09:00 +0000)
.gitattributes
eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemoteApplicationConfigurationTest.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemotePersistentCollectionTest.java [new file with mode: 0644]

index 6efb72c677a01752f41f34cdab0458feb6168be9..15ef3f6c063abc9aa38fe582316d4a7e024b3202 100644 (file)
@@ -328,7 +328,9 @@ eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/localApplicati
 eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remotingApplicationContext.xml -text
 eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remoting_persistence_security.xml -text
 eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remoting_services_security.xml -text
+eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemoteApplicationConfigurationTest.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemoteLazyLoadingTest.java -text
+eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemotePersistentCollectionTest.java -text
 eu.etaxonomy.taxeditor.editor/.classpath -text
 eu.etaxonomy.taxeditor.editor/.project -text
 eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF -text
diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemoteApplicationConfigurationTest.java b/eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemoteApplicationConfigurationTest.java
new file mode 100644 (file)
index 0000000..493706b
--- /dev/null
@@ -0,0 +1,61 @@
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy 
+* http://www.e-taxonomy.eu
+* 
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.remoting;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.hibernate.collection.internal.AbstractPersistentCollection;
+import org.hibernate.proxy.AbstractLazyInitializer;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.unitils.UnitilsJUnit4;
+
+import eu.etaxonomy.cdm.api.application.CdmApplicationController;
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
+import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
+import eu.etaxonomy.cdm.database.DataSourceNotFoundException;
+import eu.etaxonomy.cdm.database.ICdmDataSource;
+
+/**
+ * Base class for remoting tests, responsible mainly for setting up the 
+ * remote configuration.
+ * 
+ * @author c.mathew
+ * @created 13.032014
+ */
+
+public class RemoteApplicationConfigurationTest extends UnitilsJUnit4 {
+
+       protected static ICdmApplicationConfiguration applicationController;
+       /**
+        * @throws DataSourceNotFoundException 
+        */
+       @BeforeClass
+       public static void initializeContext() throws DataSourceNotFoundException {
+               
+               Resource DEFAULT_APPLICATION_CONTEXT = new ClassPathResource(
+                               "/eu/etaxonomy/cdm/remotingApplicationContext.xml");
+               //FIXME:Remoting Currently the 'local-cyprus' param does not really do anything.
+               //               This will just connect to a local runjettyrun cdmserver
+               //               instance
+               ICdmDataSource datasource = CdmPersistentDataSource.NewInstance("local-cyprus");
+               applicationController = 
+                               CdmApplicationController.NewInstance(DEFAULT_APPLICATION_CONTEXT, 
+                                               datasource, 
+                                               null,
+                                               false, 
+                                               null);
+               AbstractLazyInitializer.setConfiguration(applicationController);
+               AbstractPersistentCollection.setConfiguration(applicationController);
+
+       }
+
+}
diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemotePersistentCollectionTest.java b/eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemotePersistentCollectionTest.java
new file mode 100644 (file)
index 0000000..9241946
--- /dev/null
@@ -0,0 +1,84 @@
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy 
+* http://www.e-taxonomy.eu
+* 
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.remoting;
+
+
+
+import java.util.List;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+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.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+
+/**
+ * Test class which tests remoting for persistent collections.
+ * 
+ * @author c.mathew
+ * @created 13.032014
+ */
+public class RemotePersistentCollectionTest extends RemoteApplicationConfigurationTest {
+       private static final Logger logger = Logger.getLogger(RemotePersistentCollectionTest.class);
+       
+       
+       private static IClassificationService classificationService;
+
+       @BeforeClass
+       public static void initializeServices() {
+               Logger.getRootLogger().setLevel(Level.DEBUG);
+               classificationService= applicationController.getClassificationService();
+       }
+       
+       @Test
+       public void persistentListTest() {
+               
+               List<TaxonNode> taxonNodes = classificationService.getAllNodes();
+               logger.debug("classificationService.getAllNodes() size : " + taxonNodes.size());
+               
+               int size = taxonNodes.size();
+               logger.info("classification children size : " + size);
+               TaxonNode taxonNode = null;
+               if(size > 0) {
+                       taxonNode = taxonNodes.get(0);
+                       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 ?
+                       int childCount = childNodes.size();
+                       logger.info("first node child count : " + childCount);
+                       
+                       String firstNodeTaxonTitle = taxonNode.getTaxon().getTitleCache();
+                       Assert.assertNotNull(firstNodeTaxonTitle);
+                       logger.info("first node taxon : " + firstNodeTaxonTitle);
+                       
+                       if(childCount > 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());               
+               }
+               
+               Assert.assertNotNull(taxonNode);
+               Assert.assertTrue(taxonNodes.contains(taxonNode));
+               
+       }
+}