fix tests
authorKatja Luther <k.luther@bgbm.org>
Mon, 1 Feb 2016 08:23:05 +0000 (09:23 +0100)
committerKatja Luther <k.luther@bgbm.org>
Mon, 1 Feb 2016 08:23:05 +0000 (09:23 +0100)
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionManagerTest.java

index 4c8d58f41609524db7621fb8a760b57eead73314..a38e68cde517cafef358514fcfdea0d6e59e354e 100644 (file)
@@ -1,5 +1,6 @@
 package eu.etaxonomy.taxeditor.session;
 
 package eu.etaxonomy.taxeditor.session;
 
+import java.util.Iterator;
 import java.util.List;
 import java.util.UUID;
 
 import java.util.List;
 import java.util.UUID;
 
@@ -9,13 +10,17 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.unitils.dbunit.annotation.DataSet;
 
 import org.junit.Test;
 import org.unitils.dbunit.annotation.DataSet;
 
+import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
 import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
 import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.LanguageString;
 import eu.etaxonomy.cdm.model.description.KeyStatement;
 import eu.etaxonomy.cdm.model.description.PolytomousKey;
 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.LanguageString;
 import eu.etaxonomy.cdm.model.description.KeyStatement;
 import eu.etaxonomy.cdm.model.description.PolytomousKey;
 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
+import eu.etaxonomy.cdm.persistence.dao.description.IPolytomousKeyNodeDao;
+import eu.etaxonomy.cdm.persistence.dto.MergeResult;
 import eu.etaxonomy.taxeditor.httpinvoker.RemotingSessionAwareTest;
 
 //FIXME:Remoting fix data issue : User#30
 import eu.etaxonomy.taxeditor.httpinvoker.RemotingSessionAwareTest;
 
 //FIXME:Remoting fix data issue : User#30
@@ -28,6 +33,7 @@ public class CdmEntitySessionManagerTest extends RemotingSessionAwareTest {
 
 
        IPolytomousKeyService polytomousKeyService = getRemoteApplicationController().getPolytomousKeyService();
 
 
        IPolytomousKeyService polytomousKeyService = getRemoteApplicationController().getPolytomousKeyService();
+       IPolytomousKeyNodeService polytomousKeyNodeService = getRemoteApplicationController().getPolytomousKeyNodeService();
 
        private final UUID polytomousKeyUuid = UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66");
        private final Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
 
        private final UUID polytomousKeyUuid = UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66");
        private final Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
@@ -62,14 +68,15 @@ public class CdmEntitySessionManagerTest extends RemotingSessionAwareTest {
                String upStatement = "Updated Statement";
                pKey.setTitleCache(upTitleCache, true);
 
                String upStatement = "Updated Statement";
                pKey.setTitleCache(upTitleCache, true);
 
-               pKey.getRoot().getChildAt(0).getStatement().getLabel(english).setText(upStatement);
-               polytomousKeyService.merge(pKey);
+               PolytomousKeyNode node = pKey.getRoot().getChildAt(0);
+               node.getStatement().getLabel(english).setText(upStatement);
+               polytomousKeyService.merge(pKey, true);
 
                pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
 
 
                Assert.assertEquals(pKey.getTitleCache(), upTitleCache);
 
                pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
 
 
                Assert.assertEquals(pKey.getTitleCache(), upTitleCache);
-               PolytomousKeyNode node = pKey.getRoot().getChildAt(0);
+               node = pKey.getRoot().getChildAt(0);
                KeyStatement statement = node.getStatement();
                LanguageString label = statement.getLabel(english);
                Assert.assertEquals(label.getText(), upStatement);
                KeyStatement statement = node.getStatement();
                LanguageString label = statement.getLabel(english);
                Assert.assertEquals(label.getText(), upStatement);
@@ -92,14 +99,27 @@ public class CdmEntitySessionManagerTest extends RemotingSessionAwareTest {
                String upStatement = "Updated Statement";
                pKeys.get(0).setTitleCache(upTitleCache, true);
                polytomousKeyService.merge(pKeys.get(0));
                String upStatement = "Updated Statement";
                pKeys.get(0).setTitleCache(upTitleCache, true);
                polytomousKeyService.merge(pKeys.get(0));
-               pKeys.get(1).getRoot().getChildAt(0).getStatement().getLabel(english).setText(upStatement);
-               polytomousKeyService.merge(pKeys.get(1));
-
-
+               PolytomousKey key = pKeys.get(1);
+               PolytomousKeyNode root = key.getRoot();
+               root = HibernateProxyHelper.deproxy(root, PolytomousKeyNode.class);
+               PolytomousKeyNode node = root.getChildAt(0);
+               List<PolytomousKeyNode> nodes = root.getChildren();
+               node.getStatement().getLabel(english).setText(upStatement);
+               
+               MergeResult<PolytomousKey> result = polytomousKeyService.merge(key, true);
+               key = result.getMergedEntity();
                pKeys = polytomousKeyService.list(PolytomousKey.class, null, null, null, null);
 
                Assert.assertEquals(pKeys.get(0).getTitleCache(), upTitleCache);
                pKeys = polytomousKeyService.list(PolytomousKey.class, null, null, null, null);
 
                Assert.assertEquals(pKeys.get(0).getTitleCache(), upTitleCache);
-               PolytomousKeyNode node = pKeys.get(1).getRoot().getChildAt(0);
+               key = pKeys.get(1);
+               root = key.getRoot();
+               nodes = root.getChildren();
+               Iterator<PolytomousKeyNode> it = nodes.iterator();
+               if (it.hasNext()){
+                       node = it.next();
+               } else {
+                       Assert.fail();
+               }
                Assert.assertEquals(node.getStatement().getLabel(english).getText(), upStatement);
 
        }
                Assert.assertEquals(node.getStatement().getLabel(english).getText(), upStatement);
 
        }