From a30444758678f0d4b1b6cff0c47c90b687a6cda7 Mon Sep 17 00:00:00 2001 From: Cherian Mathew Date: Thu, 13 Mar 2014 09:00:53 +0000 Subject: [PATCH] added test class for persistent collections and also a base class for configuringsetting up remote configuration. --- .gitattributes | 2 + .../RemoteApplicationConfigurationTest.java | 61 ++++++++++++++ .../RemotePersistentCollectionTest.java | 84 +++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemoteApplicationConfigurationTest.java create mode 100644 eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemotePersistentCollectionTest.java diff --git a/.gitattributes b/.gitattributes index 6efb72c67..15ef3f6c0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 index 000000000..493706b11 --- /dev/null +++ b/eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemoteApplicationConfigurationTest.java @@ -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 index 000000000..92419469b --- /dev/null +++ b/eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemotePersistentCollectionTest.java @@ -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 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)); + + } +} -- 2.34.1