deleted project from trunk to work on branch
[taxeditor.git] / eu.etaxonomy.taxeditor.remoting / src / test / java / eu / etaxonomy / taxeditor / lazyloading / RemotePersistentCollectionTest.java
diff --git a/eu.etaxonomy.taxeditor.remoting/src/test/java/eu/etaxonomy/taxeditor/lazyloading/RemotePersistentCollectionTest.java b/eu.etaxonomy.taxeditor.remoting/src/test/java/eu/etaxonomy/taxeditor/lazyloading/RemotePersistentCollectionTest.java
deleted file mode 100644 (file)
index c486213..0000000
+++ /dev/null
@@ -1,226 +0,0 @@
-/**
-* 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.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.hibernate.collection.internal.AbstractPersistentCollection;
-import org.hibernate.collection.spi.PersistentCollection;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import eu.etaxonomy.cdm.api.service.IClassificationService;
-import eu.etaxonomy.cdm.api.service.ICommonService;
-import eu.etaxonomy.cdm.model.common.Language;
-import eu.etaxonomy.cdm.model.common.LanguageString;
-import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
-import eu.etaxonomy.cdm.model.description.TaxonDescription;
-import eu.etaxonomy.cdm.model.description.TextData;
-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.taxeditor.httpinvoker.BaseRemotingTest;
-
-/**
- * Test class which tests remoting for persistent collections.
- *
- * @author c.mathew
- * @created 13.03.2014
- */
-public class RemotePersistentCollectionTest extends BaseRemotingTest {
-       private static final Logger logger = Logger.getLogger(RemotePersistentCollectionTest.class);
-
-       private static IClassificationService classificationService;
-       private static ICommonService commonService;
-
-       @BeforeClass
-       public static void initializeServices() {
-               Logger.getRootLogger().setLevel(Level.INFO);
-               classificationService = getRemoteApplicationController().getClassificationService();
-               commonService = getRemoteApplicationController().getCommonService();
-       }
-
-       /**
-        * Test method which checks remoting for persistent lists.
-        *
-        */
-       @Test
-       public void persistentListTest() {
-
-               List<TaxonNode> taxonNodes = classificationService.getAllNodes();
-               int size = taxonNodes.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));
-
-                       // 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();
-
-                       // this size call will initialise the list remotely and only return the
-                       // size of the list
-                       int remoteChildCount = commonService.size((PersistentCollection)childNodes);
-                       Assert.assertEquals(childCount, remoteChildCount);
-
-                       String firstNodeTaxonTitle = taxonNode.getTaxon().getTitleCache();
-                       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)commonService.get((PersistentCollection)childNodes,0);
-
-                               // 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(commonService.contains((PersistentCollection)childNodes, localTaxonNode));
-                               Assert.assertTrue(commonService.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(commonService.contains((PersistentCollection)taxa, localTaxon));
-//                             }
-//                     }
-//             }
-//     }
-
-       @Test
-       public void persistentMapTest() {
-               List<TaxonNode> taxonNodes = classificationService.getAllNodes();
-               // calling iterator will initialise the collection
-               Iterator<TaxonNode> taxonNodesItr = taxonNodes.iterator();
-               while(taxonNodesItr.hasNext()) {
-                       TaxonNode taxonNode = taxonNodesItr.next();
-                       Taxon taxon = taxonNode.getTaxon();
-
-                       if(taxon != null) {
-                               Set<TaxonDescription> descriptions = taxon.getDescriptions();
-                               Iterator<TaxonDescription> descriptionsItr = descriptions.iterator();
-                               while(descriptionsItr.hasNext()) {
-                                       TaxonDescription desc = descriptionsItr.next();
-                                       if(desc != null) {
-                                               for (DescriptionElementBase element : desc.getElements()){
-                                                       if (element.isInstanceOf(TextData.class)){
-                                                               // usually a call to 'get' collections should not initialise the collection,
-                                                               // but the 'getMultilanguageText' call internally calls readSize on the collection
-                                                               // which triggers the initialisation
-                                                               Map<Language, LanguageString> multilanguagetextMap = ((TextData)element).getMultilanguageText();
-                                                               boolean init = AbstractPersistentCollection.isInitialized(multilanguagetextMap);
-                                                               Assert.assertTrue(init);
-
-                                                               if(!multilanguagetextMap.isEmpty()) {
-                                                                       // found a map whcih we can test!
-                                                                       logger.info("Found Non-empty multilanguagetextMap");
-                                                                       boolean empty = commonService.isEmpty((PersistentCollection)multilanguagetextMap);
-                                                                       Assert.assertFalse(empty);
-                                                                       // test retrieval of key set, which should already by initialised
-                                                                       Set<Language> langKeySet = multilanguagetextMap.keySet();
-                                                                       Iterator<Language> langKeySetItr = langKeySet.iterator();
-                                                                       while(langKeySetItr.hasNext()) {
-                                                                               Language key = langKeySetItr.next();
-                                                                               // testing 'containsKey' on locally initialised collection
-                                                                               boolean localContainsKey = multilanguagetextMap.containsKey(key);
-                                                                               Assert.assertTrue(localContainsKey);
-                                                                               // testing 'containsKey' on remotely initialised collection
-                                                                               boolean remoteContainsKey =
-                                                                                               commonService.containsKey((PersistentCollection)multilanguagetextMap, key);
-                                                                               Assert.assertTrue(remoteContainsKey);
-
-                                                                               LanguageString value = multilanguagetextMap.get(key);
-                                                                               // testing 'containsValue' on locally initialised collection
-                                                                               boolean localContainsValue = multilanguagetextMap.containsValue(value);
-                                                                               Assert.assertTrue(localContainsValue);
-                                                                               // testing 'containsValue' on remotely initialised collection
-                                                                               boolean remoteContainsValue =
-                                                                                               commonService.containsValue((PersistentCollection)multilanguagetextMap, value);
-                                                                               Assert.assertTrue(remoteContainsValue);
-
-                                                                       }
-                                                                       return;
-                                                               }
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-               }
-       }
-}