From: Cherian Mathew Date: Wed, 24 Jun 2015 07:40:31 +0000 (+0200) Subject: Merge branch 'develop' of wp5.e-taxonomy.eu:/var/git/taxeditor into remoting-4.0 X-Git-Tag: remoting-3.9.0~135 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/19a8bfe7b1bc7f737a85baeb4255edb32c79e7fa Merge branch 'develop' of wp5.e-taxonomy.eu:/var/git/taxeditor into remoting-4.0 Conflicts: eu.etaxonomy.taxeditor.cdmlib/.classpath eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF eu.etaxonomy.taxeditor.cdmlib/build.properties --- 19a8bfe7b1bc7f737a85baeb4255edb32c79e7fa diff --cc eu.etaxonomy.taxeditor.cdmlib/.classpath index 48de1b135,cd1058349..b0f53bf55 --- a/eu.etaxonomy.taxeditor.cdmlib/.classpath +++ b/eu.etaxonomy.taxeditor.cdmlib/.classpath @@@ -1,10 -1,18 +1,18 @@@ + + + + + + + + - - - + + + diff --cc eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/lazyloading/AbstractLazyInitializerTest.java index 35abb014a,000000000..81afe0628 mode 100644,000000..100644 --- a/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/lazyloading/AbstractLazyInitializerTest.java +++ b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/lazyloading/AbstractLazyInitializerTest.java @@@ -1,215 -1,0 +1,215 @@@ +/** + * Copyright (C) 2014 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.lazyloading; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +import org.apache.log4j.Logger; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.unitils.dbunit.annotation.DataSet; + +import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController; +import eu.etaxonomy.cdm.api.service.IClassificationService; +import eu.etaxonomy.cdm.api.service.ITaxonService; +import eu.etaxonomy.cdm.model.agent.Person; +import eu.etaxonomy.cdm.model.agent.Team; +import eu.etaxonomy.cdm.model.common.CdmBase; +import eu.etaxonomy.cdm.model.name.BotanicalName; +import eu.etaxonomy.cdm.model.name.NonViralName; +import eu.etaxonomy.cdm.model.name.TaxonNameBase; +import eu.etaxonomy.cdm.model.taxon.Classification; +import eu.etaxonomy.cdm.model.taxon.SynonymRelationship; +import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; +import eu.etaxonomy.taxeditor.httpinvoker.BaseRemotingTest; + + + + +/** + * Class to test the {@link CdmApplicationRemoteController} + * + */ +// FIXME:Remoting need to create a proper dataset for this test +// Could be combined with RemotePersistentCollectionTest +@Ignore +@DataSet +public class AbstractLazyInitializerTest extends BaseRemotingTest { + private static final Logger logger = Logger.getLogger(AbstractLazyInitializerTest.class); + + private static IClassificationService classificationService; + private static ITaxonService taxonService; + + private static List taxonNodes; + + private final UUID taxonUuid1 = UUID.fromString("8217ef77-2ab1-4318-bd67-ccd0cdef07c4"); + private final UUID taxonUuid2 = UUID.fromString("ef96fafa-7750-4141-b31b-1ad1daab3e76"); + + + @BeforeClass + public static void initializeRemoteLazyLoading() { + + taxonService = getRemoteApplicationController().getTaxonService(); + classificationService= getRemoteApplicationController().getClassificationService(); + List classifications = classificationService.listClassifications(1,0,null,null); + Assert.assertFalse(classifications.isEmpty()); + + Classification classification = classifications.get(0); + Assert.assertNotNull(classification); + taxonNodes = classificationService.getAllNodes(); + Assert.assertFalse(taxonNodes.isEmpty()); + + } + + + + @Test + public void testCDMEntityGet() { + //ITaxonService taxonService = getRemoteApplicationController().getTaxonService(); + Iterator taxonNodeItr = taxonNodes.iterator(); + int maxcount = 30; + int count = 0; + while(taxonNodeItr.hasNext() && count <= maxcount) { + TaxonNode taxonNode = taxonNodeItr.next(); + Assert.assertNotNull(taxonNode); + + Taxon taxon = taxonNode.getTaxon(); + Assert.assertNotNull(taxon); + + String taxonTitle = taxon.getTitleCache(); + logger.info("Taxon : " + taxonTitle); + + TaxonNameBase name = taxon.getName(); + Assert.assertNotNull(name); + + String nameTitle = name.getTitleCache(); + logger.info("Taxon Name : " + nameTitle); + + count++; + } + } + + @Test + public void taxonReadTest() { + Taxon taxon = (Taxon)taxonService.find(taxonUuid1); + + } + + + @Test + public void testCDMEntitySave() { + Taxon taxon = (Taxon)taxonService.find(taxonUuid1); + String oldTitleCache = taxon.getTitleCache(); + + System.out.println("Taxon title : " + oldTitleCache); + + taxon.setTitleCache(oldTitleCache + ":updated", true); + taxonService.merge(taxon); + + Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1); + System.out.println("New Taxon Title : " + taxonNew.getTitleCache()); + + Assert.assertTrue("Title caches should not be equal",oldTitleCache.equals(taxonNew.getTitleCache())); + + + taxonNew.setTitleCache(oldTitleCache, true); + taxonService.merge(taxonNew); + + Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1); + System.out.println("Old Taxon Title : " + taxonOld.getTitleCache()); + + Assert.assertEquals("Title caches should be equal",oldTitleCache,taxonOld.getTitleCache()); + + } + + + @Test + public void testCDMEntitySaveLazyNew() { + Team combAuthor = Team.NewInstance(); + combAuthor.addTeamMember(Person.NewTitledInstance("test member")); + BotanicalName name = BotanicalName.NewInstance(null, "Test1", null, null, null, null, null, null, null); - name.setCombinationAuthorTeam(combAuthor); ++ name.setCombinationAuthorship(combAuthor); + Taxon tax1 = Taxon.NewInstance(name, null); + UUID taxonUuid1 = taxonService.save(tax1); + + Taxon taxon = (Taxon)taxonService.find(taxonUuid1); + + NonViralName nvn = CdmBase.deproxy(taxon.getName(),NonViralName.class); + String oldTitleCache = nvn.getTitleCache(); + logger.info("Taxon Name Title : " + oldTitleCache); + nvn.setTitleCache(oldTitleCache + ":updated",false); + taxonService.update(taxon); + + Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1); + NonViralName nvnNew = CdmBase.deproxy(taxon.getName(),NonViralName.class); + logger.info("New Taxon Name Title : " + nvnNew.getTitleCache()); + + Assert.assertTrue("Title caches should not be equal",oldTitleCache.equals(nvnNew.getTitleCache())); + + nvnNew.setTitleCache(oldTitleCache, true); + taxonService.update(taxon); + + Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1); + NonViralName nvnOld = CdmBase.deproxy(taxon.getName(),NonViralName.class); + logger.info("Old Taxon Name Title : " + nvnNew.getTitleCache()); + + Assert.assertEquals("Title caches should be equal",oldTitleCache,nvnOld.getTitleCache()); + } + + @Ignore + @Test + public void testCDMEntitySaveCollection() { + Taxon taxon = (Taxon)taxonService.find(taxonUuid1); + + Set synRelations = taxon.getSynonymRelations(); + Set relToTitles = new HashSet(); + Iterator srItr = synRelations.iterator(); + while(srItr.hasNext()) { + SynonymRelationship sr = srItr.next(); + System.out.println("Synonym Title Cache : " + sr.getSynonym().getTitleCache()); + relToTitles.add(sr.getSynonym().getTitleCache()); + sr.getSynonym().setTitleCache(sr.getSynonym().getTitleCache() + ":updated"); + + } + taxonService.merge(taxon); + + Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1); + Set synRelationsNew = taxonNew.getSynonymRelations(); + + Iterator srItrNew = synRelationsNew.iterator(); + Iterator relToTitlesItr = relToTitles.iterator(); + while(srItrNew.hasNext() && relToTitlesItr.hasNext()) { + SynonymRelationship srNew = srItrNew.next(); + String relToTitle = relToTitlesItr.next(); + System.out.println("New Synonym Title Cache: " + srNew.getSynonym().getTitleCache()); + Assert.assertTrue("Synonym Title caches should not be equal", srNew.getSynonym().getTitleCache().equals(relToTitle)); + srNew.getSynonym().setTitleCache(relToTitle); + } + + Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1); + + Set synRelationsOld = taxonNew.getSynonymRelations(); + Iterator srItrOld = synRelationsOld.iterator(); + relToTitlesItr = relToTitles.iterator(); + while(srItrOld.hasNext() && relToTitlesItr.hasNext()) { + SynonymRelationship srOld = srItrOld.next(); + String relToTitle = relToTitlesItr.next(); + System.out.println("New Synonym Title Cache: " + srOld.getSynonym().getTitleCache()); + Assert.assertEquals("Synonym Title caches should be equal", srOld.getSynonym().getTitleCache(), relToTitle); + + } + } +} diff --cc eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/lazyloading/RemoteLazyLoadingTest.java index 706c4a37c,000000000..b0e1c9bcc mode 100644,000000..100644 --- a/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/lazyloading/RemoteLazyLoadingTest.java +++ b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/lazyloading/RemoteLazyLoadingTest.java @@@ -1,276 -1,0 +1,276 @@@ +/** + * Copyright (C) 2014 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.lazyloading; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +import org.apache.log4j.Logger; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import eu.etaxonomy.cdm.api.service.IClassificationService; +import eu.etaxonomy.cdm.api.service.ITaxonService; +import eu.etaxonomy.cdm.model.agent.Person; +import eu.etaxonomy.cdm.model.agent.Team; +import eu.etaxonomy.cdm.model.common.CdmBase; +import eu.etaxonomy.cdm.model.name.BotanicalName; +import eu.etaxonomy.cdm.model.name.NonViralName; +import eu.etaxonomy.cdm.model.name.TaxonNameBase; +import eu.etaxonomy.cdm.model.taxon.SynonymRelationship; +import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; +import eu.etaxonomy.taxeditor.httpinvoker.BaseRemotingTest; + + + +/** + * Test class which tests remoting for persistent cdm entities. + * + * FIXME:Remoting saving tests are ignored until the merge development is underway + * @author c.mathew + * + */ +//FIXME:Remoting need to create a proper dataset for this test +//Could be combined with AbstractLazyInitializerTest +@Ignore +public class RemoteLazyLoadingTest extends BaseRemotingTest { + + private static final Logger logger = Logger.getLogger(RemoteLazyLoadingTest.class); + + private static IClassificationService classificationService; + private static ITaxonService taxonService; + + private static List taxonNodes; + + private final UUID taxonUuid1 = UUID.fromString("8217ef77-2ab1-4318-bd67-ccd0cdef07c4"); + private final UUID taxonUuid2 = UUID.fromString("ef96fafa-7750-4141-b31b-1ad1daab3e76"); + + + @BeforeClass + public static void initializeRemoteLazyLoading() { + taxonService = getRemoteApplicationController().getTaxonService(); + + classificationService= getRemoteApplicationController().getClassificationService(); + //List classifications = classificationService.listClassifications(1,0,null,null); +// Assert.assertFalse(classifications.isEmpty()); +// +// Classification classification = classifications.get(0); +// Assert.assertNotNull(classification); + taxonNodes = classificationService.getAllNodes(); + Assert.assertFalse(taxonNodes.isEmpty()); + + } + + + + @Test + public void testCDMEntityGet() { + Iterator taxonNodeItr = taxonNodes.iterator(); + int maxcount = 30; + int count = 0; + while(taxonNodeItr.hasNext() && count <= maxcount) { + TaxonNode taxonNode = taxonNodeItr.next(); + Assert.assertNotNull(taxonNode); + + Taxon taxon = taxonNode.getTaxon(); + Assert.assertNotNull(taxon); + + String taxonTitle = taxon.getTitleCache(); + logger.info("Taxon : " + taxonTitle); + + TaxonNameBase name = taxon.getName(); + Assert.assertNotNull(name); + + String nameTitle = name.getTitleCache(); + logger.info("Taxon Name : " + nameTitle); + + count++; + } + + + } + + @Test + public void test() { + + } + + @Test + public void testCDMEntitySaveEager() { + Taxon taxon = (Taxon)taxonService.find(taxonUuid1); + String oldTitleCache = taxon.getTitleCache(); + + System.out.println("Taxon title : " + oldTitleCache); + + taxon.setTitleCache(oldTitleCache + ":updated"); + taxonService.merge(taxon); + + Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1); + System.out.println("New Taxon Title : " + taxonNew.getTitleCache()); + + Assert.assertTrue("Title caches should not be equal",oldTitleCache.equals(taxonNew.getTitleCache())); + + taxonNew.setTitleCache(oldTitleCache); + taxonService.merge(taxonNew); + + Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1); + System.out.println("Old Taxon Title : " + taxonOld.getTitleCache()); + + Assert.assertEquals("Title caches should be equal",oldTitleCache,taxonOld.getTitleCache()); + + } + + + @Test + public void testCDMEntityUpdate() { + + Team combAuthor = Team.NewInstance(); + combAuthor.addTeamMember(Person.NewTitledInstance("test member")); + BotanicalName name = BotanicalName.NewInstance(null, "Test1", null, null, null, null, null, null, null); - name.setCombinationAuthorTeam(combAuthor); ++ name.setCombinationAuthorship(combAuthor); + Taxon taxon = Taxon.NewInstance(name, null); + UUID taxonUuid = taxonService.save(taxon); + + // Taxon taxon = (Taxon)taxonService.find(taxonUuid1); + // NonViralName nvn = CdmBase.deproxy(taxon.getName(),NonViralName.class); + // String oldTitleCache = nvn.getTitleCache(); + // System.out.println("Taxon Name Title : " + oldTitleCache); + // nvn.setTitleCache(oldTitleCache + ":updated", true); + // + // taxon.setTitleCache(oldTitleCache + ":updated",true); + // try { + // taxonService.update(taxon); + // } catch (LazyInitializationException lie) { + // lie.printStackTrace(); + // } + + List TAXON_INIT_STRATEGY = Arrays.asList(new String[] { + "name" + }); + Taxon taxonNew = (Taxon)taxonService.findTaxonByUuid(taxonUuid,TAXON_INIT_STRATEGY); + NonViralName nvn = CdmBase.deproxy(taxonNew.getName(),NonViralName.class); - Team team = CdmBase.deproxy(nvn.getCombinationAuthorTeam(),Team.class); ++ Team team = CdmBase.deproxy(nvn.getCombinationAuthorship(),Team.class); + String oldTitleCache = nvn.getTitleCache(); + System.out.println("Taxon Name Title : " + oldTitleCache); + nvn.setTitleCache(oldTitleCache + ":updated", true); + taxonService.update(taxonNew); + + } + + + @Test + public void testCDMEntitySaveLazy() { + Taxon taxon = (Taxon)taxonService.find(taxonUuid1); + + NonViralName nvn = CdmBase.deproxy(taxon.getName(),NonViralName.class); + String oldTitleCache = nvn.getTitleCache(); + System.out.println("Taxon Name Title : " + oldTitleCache); + nvn.setTitleCache(oldTitleCache + ":updated", true); + taxonService.update(taxon); + + // Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1); + // NonViralName nvnNew = CdmBase.deproxy(taxon.getName(),NonViralName.class); + // System.out.println("New Taxon Name Title : " + nvnNew.getTitleCache()); + // + // Assert.assertNotEquals("Title caches should not be equal",oldTitleCache,nvnNew.getTitleCache()); + // + // nvnNew.setTitleCache(oldTitleCache, true); + // taxonService.update(taxon); + // + // Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1); + // NonViralName nvnOld = CdmBase.deproxy(taxon.getName(),NonViralName.class); + // System.out.println("Old Taxon Name Title : " + nvnNew.getTitleCache()); + // + // Assert.assertEquals("Title caches should be equal",oldTitleCache,nvnOld.getTitleCache()); + } + + @Test + public void testCDMEntitySaveLazyNew() { + Team combAuthor = Team.NewInstance(); + combAuthor.addTeamMember(Person.NewTitledInstance("test member")); + BotanicalName name = BotanicalName.NewInstance(null, "Test1", null, null, null, null, null, null, null); - name.setCombinationAuthorTeam(combAuthor); ++ name.setCombinationAuthorship(combAuthor); + Taxon tax1 = Taxon.NewInstance(name, null); + UUID taxonUuid1 = taxonService.save(tax1); + + Taxon taxon = (Taxon)taxonService.find(taxonUuid1); + + NonViralName nvn = CdmBase.deproxy(taxon.getName(),NonViralName.class); + String oldTitleCache = nvn.getTitleCache(); + logger.info("Taxon Name Title : " + oldTitleCache); + nvn.setTitleCache(oldTitleCache + ":updated",false); + taxonService.update(taxon); + + Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1); + NonViralName nvnNew = CdmBase.deproxy(taxon.getName(),NonViralName.class); + logger.info("New Taxon Name Title : " + nvnNew.getTitleCache()); + + Assert.assertTrue("Title caches should not be equal",oldTitleCache.equals(nvnNew.getTitleCache())); + + nvnNew.setTitleCache(oldTitleCache, true); + taxonService.update(taxon); + + Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1); + NonViralName nvnOld = CdmBase.deproxy(taxon.getName(),NonViralName.class); + logger.info("Old Taxon Name Title : " + nvnNew.getTitleCache()); + + Assert.assertEquals("Title caches should be equal",oldTitleCache,nvnOld.getTitleCache()); + } + @Ignore + @Test + public void testCDMEntitySaveCollection() { + Taxon taxon = (Taxon)taxonService.find(taxonUuid1); + + Set synRelations = taxon.getSynonymRelations(); + Set relToTitles = new HashSet(); + Iterator srItr = synRelations.iterator(); + while(srItr.hasNext()) { + SynonymRelationship sr = srItr.next(); + System.out.println("Synonym Title Cache : " + sr.getSynonym().getTitleCache()); + relToTitles.add(sr.getSynonym().getTitleCache()); + sr.getSynonym().setTitleCache(sr.getSynonym().getTitleCache() + ":updated"); + + } + taxonService.merge(taxon); + + Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1); + Set synRelationsNew = taxonNew.getSynonymRelations(); + + Iterator srItrNew = synRelationsNew.iterator(); + Iterator relToTitlesItr = relToTitles.iterator(); + while(srItrNew.hasNext() && relToTitlesItr.hasNext()) { + SynonymRelationship srNew = srItrNew.next(); + String relToTitle = relToTitlesItr.next(); + System.out.println("New Synonym Title Cache: " + srNew.getSynonym().getTitleCache()); + Assert.assertTrue("Synonym Title caches should not be equal", srNew.getSynonym().getTitleCache().equals(relToTitle)); + srNew.getSynonym().setTitleCache(relToTitle); + } + + Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1); + + Set synRelationsOld = taxonNew.getSynonymRelations(); + Iterator srItrOld = synRelationsOld.iterator(); + relToTitlesItr = relToTitles.iterator(); + while(srItrOld.hasNext() && relToTitlesItr.hasNext()) { + SynonymRelationship srOld = srItrOld.next(); + String relToTitle = relToTitlesItr.next(); + System.out.println("New Synonym Title Cache: " + srOld.getSynonym().getTitleCache()); + Assert.assertEquals("Synonym Title caches should be equal", srOld.getSynonym().getTitleCache(), relToTitle); + + } + } +}