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.
10 package eu
.etaxonomy
.cdm
.api
.service
;
12 import static org
.junit
.Assert
.assertEquals
;
15 import java
.util
.UUID
;
17 import junit
.framework
.Assert
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.junit
.Ignore
;
21 import org
.junit
.Test
;
22 import org
.unitils
.dbunit
.annotation
.DataSet
;
23 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
25 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
26 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
27 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
28 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
29 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
30 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
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
.test
.integration
.CdmIntegrationTest
;
42 public class CommonServiceImplTest
extends CdmIntegrationTest
{
43 private static final Logger logger
= Logger
.getLogger(CommonServiceImplTest
.class);
46 private ICommonService service
;
49 private ITaxonService taxonService
;
52 private IReferenceService referenceService
;
55 private IAgentService agentService
;
58 private IUserService userService
;
61 private IOccurrenceService occurrenceService
;
63 /****************** TESTS *****************************/
66 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#setDao(eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao)}.
69 public final void testSetDao() {
70 Assert
.assertNotNull(service
);
74 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#getTaxonByUuid(java.util.UUID)}.
79 public final void testGetReferencingObjects() {
80 ReferenceFactory refFactory
= ReferenceFactory
.newInstance();
81 BotanicalName name
= BotanicalName
.NewInstance(Rank
.SPECIES());
82 name
.setTitleCache("A name", true);
83 Reference ref1
= refFactory
.newArticle();
84 Taxon taxon
= Taxon
.NewInstance(name
, ref1
);
85 Person author
= Person
.NewInstance();
86 author
.setTitleCache("Author", true);
87 ref1
.addAnnotation(Annotation
.NewInstance("A1", Language
.DEFAULT()));
88 ref1
.setAuthorTeam(author
);
89 name
.setBasionymAuthorTeam(author
);
91 name
.setNomenclaturalReference(ref1
);
93 taxonService
.save(taxon
);
94 // UUID uuid = UUID.fromString("613980ac-9bd5-43b9-a374-d71e1794688f");
95 // Reference ref1 = referenceService.findByUuid(uuid);
98 Set
<CdmBase
> referencedObjects
= service
.getReferencingObjects(ref1
);
99 System
.out
.println("############## RESULT ###################");
100 for (CdmBase obj
: referencedObjects
){
101 System
.out
.println("Object: " + obj
.getClass().getSimpleName() + " - " + obj
);
103 assertEquals(3, referencedObjects
.size());
104 System
.out
.println("############## ENDE ###################");
108 // UUID uuidAuthor = UUID.fromString("4ce66544-a5a3-4601-ab0b-1f0a1338327b");
109 // AgentBase author = agentService.findByUuid(uuidAuthor);
111 referencedObjects
= service
.getReferencingObjects(author
);
112 System
.out
.println("############## RESULT ###################");
113 for (CdmBase obj
: referencedObjects
){
114 System
.out
.println("Object: " + obj
.getClass().getSimpleName() + " - " + obj
);
116 assertEquals(2, referencedObjects
.size());
117 System
.out
.println("############## ENDE ###################");
121 * Test method for getReferencingObject.
126 public final void testGetReferencingObjects2() {
127 // SpecimenDescription desc1 = SpecimenDescription.NewInstance();
128 // desc1.setTitleCache("desc1");
129 // SpecimenDescription desc2 = SpecimenDescription.NewInstance();
130 // desc2.setTitleCache("desc2");
132 // SpecimenOrObservationBase spec1 = Specimen.NewInstance();
134 // desc1.addDescribedSpecimenOrObservation(spec1);
135 // //Taxon taxon = Taxon.NewInstance(taxonNameBase, sec)
136 // spec1.addDescription(desc2);
138 // occurrenceService.save(spec1);
140 UUID uuidSpec
= UUID
.fromString("41539e9c-3764-4f14-9712-2d07d00c8e4c");
141 SpecimenOrObservationBase spec1
= occurrenceService
.find(uuidSpec
);
144 Set
<CdmBase
> referencedObjects
= service
.getReferencingObjects(spec1
);
145 System
.out
.println("############## RESULT ###################");
146 for (CdmBase obj
: referencedObjects
){
147 System
.out
.println("Object: " + obj
.getClass().getSimpleName() + " - " + obj
);
149 assertEquals(2, referencedObjects
.size());
150 System
.out
.println("############## ENDE ###################");
156 public final void printDataSet() {
157 printDataSet(System
.out
);
163 public final void testLoadCacheStrategyForReference(){
164 Reference ref
= referenceService
.load(UUID
.fromString("613980ac-9bd5-43b9-a374-d71e1794688f"));
165 ref
.setType(ReferenceType
.Article
);
166 referenceService
.update(ref
);
167 referenceService
.updateTitleCache();