2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.api
.service
;
11 import static org
.junit
.Assert
.assertEquals
;
13 import java
.io
.FileNotFoundException
;
15 import java
.util
.UUID
;
17 import org
.apache
.logging
.log4j
.LogManager
;
18 import org
.apache
.logging
.log4j
.Logger
;
19 import org
.junit
.Assert
;
20 import org
.junit
.Test
;
21 import org
.unitils
.dbunit
.annotation
.DataSet
;
22 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
24 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
25 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
26 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
28 import eu
.etaxonomy
.cdm
.model
.name
.IBotanicalName
;
29 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
30 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
31 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
32 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
33 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
34 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
36 import eu
.etaxonomy
.cdm
.persistence
.dto
.ReferencingObjectDto
;
37 import eu
.etaxonomy
.cdm
.test
.integration
.CdmIntegrationTest
;
42 public class CommonServiceImplTest
extends CdmIntegrationTest
{
44 private static final Logger logger
= LogManager
.getLogger();
47 private ICommonService service
;
50 private ITaxonService taxonService
;
53 private IReferenceService referenceService
;
56 private IOccurrenceService occurrenceService
;
58 /****************** TESTS *****************************/
61 public final void testSetDao() {
62 Assert
.assertNotNull(service
);
67 public final void testGetReferencingObjectsDto() {
69 IBotanicalName name
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
70 name
.setTitleCache("A name", true);
71 Reference ref1
= ReferenceFactory
.newArticle();
72 Taxon taxon
= Taxon
.NewInstance(name
, ref1
);
73 taxon
.addImportSource("id1", null, ref1
, null);
74 Person author
= Person
.NewInstance();
75 author
.setTitleCache("Author", true);
76 ref1
.addAnnotation(Annotation
.NewInstance("A1", Language
.DEFAULT()));
77 ref1
.setAuthorship(author
);
78 name
.setBasionymAuthorship(author
);
80 name
.setNomenclaturalReference(ref1
);
82 taxonService
.save(taxon
);
84 Set
<ReferencingObjectDto
> referencedObjects
= service
.getReferencingObjectDtos(ref1
);
85 String debug
= "############## RESULT ###################\n";
86 for (ReferencingObjectDto obj
: referencedObjects
){
87 debug
+= "Object: " + obj
.getClass().getSimpleName() + " - " + obj
+ "\n";
89 assertEquals(3, referencedObjects
.size()); //AM: was expected=3 first, as annotations are not reported I reduced to 2 (this is not related to not having a commit before, I tested it)
90 //should not throw an exception
91 referencedObjects
= service
.initializeReferencingObjectDtos(referencedObjects
, true, true, true, null);
92 debug
+= "############## END ###################\n";
94 referencedObjects
= service
.getReferencingObjectDtos(author
);
95 debug
+= "############## RESULT ###################\n";
96 for (ReferencingObjectDto obj
: referencedObjects
){
97 debug
+= "Object: " + obj
.getClass().getSimpleName() + " - " + obj
+ "\n";
99 assertEquals(2, referencedObjects
.size());
100 referencedObjects
= service
.initializeReferencingObjectDtos(referencedObjects
, true, true, true, null);
101 debug
+= "############## END ###################\n";
107 public final void testGetReferencingObjects() {
109 IBotanicalName name
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
110 name
.setTitleCache("A name", true);
111 Reference ref1
= ReferenceFactory
.newArticle();
112 Taxon taxon
= Taxon
.NewInstance(name
, ref1
);
113 Person author
= Person
.NewInstance();
114 author
.setTitleCache("Author", true);
115 ref1
.addAnnotation(Annotation
.NewInstance("A1", Language
.DEFAULT()));
116 ref1
.setAuthorship(author
);
117 name
.setBasionymAuthorship(author
);
119 name
.setNomenclaturalReference(ref1
);
121 taxonService
.save(taxon
);
123 Set
<CdmBase
> referencedObjects
= service
.getReferencingObjects(ref1
);
124 System
.out
.println("############## RESULT ###################\n");
125 for (CdmBase obj
: referencedObjects
){
126 System
.out
.println("Object: " + obj
.getClass().getSimpleName() + " - " + obj
+ "\n");
128 assertEquals(2, referencedObjects
.size()); //AM: was expected=3 first, as annotations are not reported I reduced to 2 (this is not related to not having a commit before, I tested it)
129 System
.out
.println("############## END ###################\n");
131 referencedObjects
= service
.getReferencingObjects(author
);
132 System
.out
.println("############## RESULT ###################\n");
133 for (CdmBase obj
: referencedObjects
){
134 System
.out
.println("Object: " + obj
.getClass().getSimpleName() + " - " + obj
+ "\n");
136 assertEquals(2, referencedObjects
.size());
137 System
.out
.println("############## END ###################\n");
142 public final void testGetReferencingObjects2() {
143 // SpecimenDescription desc1 = SpecimenDescription.NewInstance();
144 // desc1.setTitleCache("desc1");
145 // SpecimenDescription desc2 = SpecimenDescription.NewInstance();
146 // desc2.setTitleCache("desc2");
148 // SpecimenOrObservationBase spec1 = Specimen.NewInstance();
150 // desc1.addDescribedSpecimenOrObservation(spec1);
151 // //Taxon taxon = Taxon.NewInstance(taxonName, sec)
152 // spec1.addDescription(desc2);
154 // occurrenceService.save(spec1);
156 UUID uuidSpec
= UUID
.fromString("41539e9c-3764-4f14-9712-2d07d00c8e4c");
157 SpecimenOrObservationBase
<?
> spec1
= occurrenceService
.find(uuidSpec
);
159 Set
<CdmBase
> referencedObjects
= service
.getReferencingObjects(spec1
);
160 // System.out.println("############## RESULT ###################");
161 // for (CdmBase obj: referencedObjects){
162 // System.out.println("Object: " + obj.getClass().getSimpleName() + " - " + obj);
164 assertEquals(2, referencedObjects
.size());
165 System
.out
.println("############## ENDE ###################");
170 public final void testLoadCacheStrategyForReference(){
171 Reference ref
= referenceService
.load(UUID
.fromString("613980ac-9bd5-43b9-a374-d71e1794688f"));
172 ref
.setType(ReferenceType
.Article
);
173 referenceService
.update(ref
);
174 referenceService
.updateCaches();
178 public void createTestDataSet() throws FileNotFoundException
{}