cleanup CdmEntitySessionAwareTest
authorAndreas Müller <a.mueller@bgbm.org>
Mon, 29 Jun 2020 00:29:34 +0000 (02:29 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Mon, 29 Jun 2020 00:29:34 +0000 (02:29 +0200)
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionAwareTest.java

index 135c0dd4ab2d5d5533194e58db349df2808bb8ca..cc6eea7a03341dae59fdbba280ed8cc14f25a273 100644 (file)
@@ -37,28 +37,26 @@ import eu.etaxonomy.cdm.model.agent.AgentBase;
 import eu.etaxonomy.cdm.model.agent.Person;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Credit;
-import eu.etaxonomy.cdm.model.term.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.Extension;
 import eu.etaxonomy.cdm.model.common.IdentifiableSource;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.LanguageString;
-import eu.etaxonomy.cdm.model.term.TermType;
-import eu.etaxonomy.cdm.model.term.TermVocabulary;
 import eu.etaxonomy.cdm.model.description.Feature;
 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.media.Rights;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.term.DefinedTermBase;
+import eu.etaxonomy.cdm.model.term.TermType;
+import eu.etaxonomy.cdm.model.term.TermVocabulary;
 import eu.etaxonomy.cdm.persistence.dto.MergeResult;
 import eu.etaxonomy.taxeditor.httpinvoker.RemotingSessionAwareTest;
 import eu.etaxonomy.taxeditor.httpinvoker.TestThread;
 
-
 /**
  * @author cmathew
  * @date 7 Oct 2014
- *
  */
 @DataSet
 public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
@@ -71,8 +69,6 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
     UUID taxon1Uuid = UUID.fromString("2b336df7-29e8-4f79-985f-66502739d22f");
     UUID personUuid = UUID.fromString("945d08f2-eb92-45b6-9252-6275ea6d338b");
 
-
-
     IPolytomousKeyService polytomousKeyService = getRemoteApplicationController().getPolytomousKeyService();
     IPolytomousKeyNodeService polytomousKeyNodeService = getRemoteApplicationController().getPolytomousKeyNodeService();
     ICommonService commonService = getRemoteApplicationController().getCommonService();
@@ -83,13 +79,10 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
 
     //Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
 
-
-
     @BeforeClass
     public static void initializePolytomousKeyTest() {
     }
 
-
     @Test
     @Ignore
     public void readAllPolytomousKeys() {
@@ -99,7 +92,6 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
         Assert.assertEquals(pKeysItr.next().getUuid(),UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66"));
     }
 
-
     @Test
     //@DataSet("PolytomousKeyTest.readPolytmousKeyData.xml")
     public void readPolytmousKeyData() {
@@ -137,14 +129,11 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
         // TO DO : Added tests for Annotations , Markers
     }
 
-
-
     @Test
     public void readPolytomousKeyDataFromNodes() {
         PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
         PolytomousKeyNode rootNode = pKey.getRoot();
 
-
         Assert.assertEquals(rootNode.getId(), 2750);
 
         Assert.assertEquals(rootNode.getChildAt(0).getId(), 2751);
@@ -174,7 +163,7 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
     }
 
     @Test
-@Ignore
+    @Ignore
     public void addGrandChildPolytomousKeyNode() {
 
         PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
@@ -204,10 +193,8 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
         PolytomousKeyNode grandChildNode = PolytomousKeyNode.NewInstance();
         rootChildNode.addChild(grandChildNode);
 
-
         polytomousKeyNodeService.merge(grandChildNode, true);
 
-
         Assert.assertFalse(pKey.getRoot().getChildAt(0).getChildAt(0).getId() == 0);
     }
 
@@ -246,7 +233,6 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
 
         pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
 
-
         pkeynode = pkey.getRoot();
         for(PolytomousKeyNode node : pkeynode.getChildren()) {
             Assert.assertNull(node.getQuestion());
@@ -270,7 +256,6 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
             Assert.assertEquals(newStatement, node.getStatement().getLabel(Language.ENGLISH()).getText());
         }
         //Assert.assertEquals(pkeynode.getFeature().getId(), feature.getId());
-
     }
 
 
@@ -279,14 +264,12 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
 
         PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
 
-
         PolytomousKeyNode pkeynode = pkey.getRoot();
 
         PolytomousKey subkey1 = CdmBase.deproxy(pkeynode.getChildAt(0).getSubkey(), PolytomousKey.class);
         String subkey1title = subkey1.getTitleCache();
         subkey1.setTitleCache(subkey1title + "test", true);
 
-
         PolytomousKey subkey2 = CdmBase.deproxy(pkeynode.getChildAt(1).getChildAt(0).getSubkey(), PolytomousKey.class);
         String subkey2title = subkey2.getTitleCache();
         subkey2.setTitleCache(subkey2title + "test", true);
@@ -301,7 +284,6 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
 
         PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
 
-
         PolytomousKeyNode pkeynode = pkey.getRoot();
 //because of the check for null values in getChildren it isn't a persistent list anymore
   //     PersistentCollection children = (PersistentCollection) pkeynode.getChildren();
@@ -322,8 +304,6 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
         polytomousKeyService.merge(pkey, true);
     }
 
-
-
     @Test
     public void savePolytomousKeyNodeDataWithSameLanguageInLabel() {
 
@@ -333,11 +313,9 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
         Map<Language, LanguageString> label1 = pkeynode.getQuestion().getLabel();
         label1.size();
 
-
         Map<Language, LanguageString> label2 = pkeynode.getChildAt(0).getStatement().getLabel();
         label2.size();
 
-
         polytomousKeyService.merge(pkey, true);
     }
 
@@ -345,20 +323,17 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
     public void deleteSubKeyInPolytomousSubKeyWithoutInitializing() {
         PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
 
-
         PolytomousKeyNode rootNode = pKey.getRoot();
 
         PolytomousKeyNode childNode = rootNode.getChildAt(0);
         PolytomousKey subKey = HibernateProxyHelper.deproxy( childNode.getSubkey(), PolytomousKey.class);;
 
-
         DeleteResult result = polytomousKeyService.delete(subKey.getUuid());
         //A used subKey can't be deleted
         if (result.isOk()){
             Assert.fail();
         }
 
-
         Set<Integer> ids = new HashSet<Integer>();
         ids.add(2753);
         ids.add(2754);
@@ -428,23 +403,23 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
 
     @Test
     public void saveNewTermVocabulary() {
-        TermVocabulary termVocabulary =
+        TermVocabulary<Feature> termVocabulary =
                 TermVocabulary.NewInstance(TermType.Feature,
                         null,
                         "Untitled",
                         null,
                         null);
         try {
-            List<TermVocabulary<DefinedTermBase>> vocabularies = vocabularyService.findByTermType(TermType.Feature, null);
+            List<TermVocabulary<? extends DefinedTermBase<?>>> vocabularies = (List)vocabularyService.findByTermType(TermType.Feature, null);
 
-            for(TermVocabulary vocab : vocabularies) {
+            for(TermVocabulary<?> vocab : vocabularies) {
                 vocab.getTermsOrderedByLabels(Language.ENGLISH());
             }
 
             termVocabulary = vocabularyService.merge(termVocabulary);
             vocabularies.add(termVocabulary);
             termVocabulary.setLabel("Test");
-            vocabularyService.merge(new ArrayList<TermVocabulary>(vocabularies));
+            vocabularyService.merge(new ArrayList<>(vocabularies));
         } finally {
             vocabularyService.delete(termVocabulary);
         }
@@ -454,7 +429,7 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
     public void saveNewTerm() {
         UUID vocNameFeatureUuid = UUID.fromString("fa7ca3eef-4092-49e1-beec-ed5096193e5e");
         UUID vocFeatureUuid = UUID.fromString("b187d555-f06f-4d65-9e53-da7c93f8eaa8");
-        DefinedTermBase newTerm = TermType.Feature.getEmptyDefinedTermBase();
+        Feature newTerm = (Feature)TermType.Feature.getEmptyDefinedTermBase();
         newTerm.setLabel("CreateTest");
 
         try {
@@ -475,20 +450,23 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
 //             }
 
             Assert.assertNotNull(newTerm);
-            TermVocabulary vocNameFeature = vocabularyService.find(vocNameFeatureUuid);
-            TermVocabulary vocFeature = vocabularyService.find(vocFeatureUuid);
+            @SuppressWarnings("unchecked")
+            TermVocabulary<Feature> vocNameFeature = vocabularyService.find(vocNameFeatureUuid);
+            @SuppressWarnings("unchecked")
+            TermVocabulary<Feature> vocFeature = vocabularyService.find(vocFeatureUuid);
 
-            List<TermVocabulary> vocs = new ArrayList<TermVocabulary>();
+            @SuppressWarnings("rawtypes")
+            List<TermVocabulary> vocs = new ArrayList<>();
 
             vocs.add(vocNameFeature);
             vocs.add(vocFeature);
 
             vocNameFeature.addTerm(newTerm);
 
-            List<MergeResult<TermVocabulary>> mergeResults = vocabularyService.merge(vocs, true);
+            List<MergeResult<TermVocabulary<Feature>>> mergeResults = (List)vocabularyService.merge(vocs, true);
 
-            for(MergeResult<TermVocabulary> result : mergeResults){
-               TermVocabulary voc = result.getMergedEntity();
+            for(MergeResult<TermVocabulary<Feature>> result : mergeResults){
+               TermVocabulary<Feature> voc = result.getMergedEntity();
                 if(voc.getUuid().equals(vocNameFeatureUuid)) {
                     vocNameFeature = voc;
                 }
@@ -496,8 +474,8 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
 
             Assert.assertTrue(vocNameFeature.getTerms().contains(newTerm));
 
-            for(Object obj : vocNameFeature.getTerms()) {
-                DefinedTermBase dtb = (DefinedTermBase)obj;
+            for(Feature obj : vocNameFeature.getTerms()) {
+                Feature dtb = obj;
                 if("CreateTest".equals(dtb.getLabel())) {
                     newTerm = dtb;
                     Assert.assertNotNull(dtb.getCreatedBy());
@@ -508,7 +486,7 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
                 }
             }
             newTerm.setLabel("UpdateTest");
-            newTerm = termService.merge(newTerm);
+            newTerm = (Feature)termService.merge(newTerm);
             Assert.assertNotNull(newTerm.getUpdatedBy());
             Assert.assertNotNull(newTerm.getUpdated());
 
@@ -521,7 +499,6 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
         }
     }
 
-
     @Test
     public void updatePerson() {
         // Test for #5138
@@ -530,7 +507,6 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
         CdmApplicationState.getCurrentAppConfig().getAgentService().merge(person, true);
     }
 
-
     @Test
     public void createPerson() {
         // Test for #5138