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
;
14 import java
.io
.FileNotFoundException
;
16 import java
.util
.UUID
;
18 import org
.junit
.Assert
;
20 import org
.apache
.log4j
.Logger
;
21 import org
.junit
.Ignore
;
22 import org
.junit
.Test
;
23 import org
.unitils
.dbunit
.annotation
.DataSet
;
24 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
26 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
27 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
28 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
29 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
30 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
31 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
32 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
33 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
34 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
35 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
37 import eu
.etaxonomy
.cdm
.test
.integration
.CdmIntegrationTest
;
43 public class CommonServiceImplTest
extends CdmIntegrationTest
{
44 @SuppressWarnings("unused")
45 private static final Logger logger
= Logger
.getLogger(CommonServiceImplTest
.class);
48 private ICommonService service
;
51 private ITaxonService taxonService
;
54 private IReferenceService referenceService
;
57 // private IAgentService agentService;
60 // private IUserService userService;
63 private IOccurrenceService occurrenceService
;
65 /****************** TESTS *****************************/
68 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#setDao(eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao)}.
71 public final void testSetDao() {
72 Assert
.assertNotNull(service
);
76 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#getTaxonByUuid(java.util.UUID)}.
81 public final void testGetReferencingObjects() {
82 BotanicalName name
= BotanicalName
.NewInstance(Rank
.SPECIES());
83 name
.setTitleCache("A name", true);
84 Reference
<?
> ref1
= ReferenceFactory
.newArticle();
85 Taxon taxon
= Taxon
.NewInstance(name
, ref1
);
86 Person author
= Person
.NewInstance();
87 author
.setTitleCache("Author", true);
88 ref1
.addAnnotation(Annotation
.NewInstance("A1", Language
.DEFAULT()));
89 ref1
.setAuthorship(author
);
90 name
.setBasionymAuthorTeam(author
);
92 name
.setNomenclaturalReference(ref1
);
94 taxonService
.save(taxon
);
95 // UUID uuid = UUID.fromString("613980ac-9bd5-43b9-a374-d71e1794688f");
96 // Reference ref1 = referenceService.findByUuid(uuid);
99 Set
<CdmBase
> referencedObjects
= service
.getReferencingObjects(ref1
);
100 System
.out
.println("############## RESULT ###################");
101 for (CdmBase obj
: referencedObjects
){
102 System
.out
.println("Object: " + obj
.getClass().getSimpleName() + " - " + obj
);
104 assertEquals(3, referencedObjects
.size());
105 System
.out
.println("############## ENDE ###################");
109 // UUID uuidAuthor = UUID.fromString("4ce66544-a5a3-4601-ab0b-1f0a1338327b");
110 // AgentBase author = agentService.findByUuid(uuidAuthor);
112 referencedObjects
= service
.getReferencingObjects(author
);
113 System
.out
.println("############## RESULT ###################");
114 for (CdmBase obj
: referencedObjects
){
115 System
.out
.println("Object: " + obj
.getClass().getSimpleName() + " - " + obj
);
117 assertEquals(2, referencedObjects
.size());
118 System
.out
.println("############## ENDE ###################");
122 * Test method for getReferencingObject.
127 public final void testGetReferencingObjects2() {
128 // SpecimenDescription desc1 = SpecimenDescription.NewInstance();
129 // desc1.setTitleCache("desc1");
130 // SpecimenDescription desc2 = SpecimenDescription.NewInstance();
131 // desc2.setTitleCache("desc2");
133 // SpecimenOrObservationBase spec1 = Specimen.NewInstance();
135 // desc1.addDescribedSpecimenOrObservation(spec1);
136 // //Taxon taxon = Taxon.NewInstance(taxonNameBase, sec)
137 // spec1.addDescription(desc2);
139 // occurrenceService.save(spec1);
141 UUID uuidSpec
= UUID
.fromString("41539e9c-3764-4f14-9712-2d07d00c8e4c");
142 SpecimenOrObservationBase
<?
> spec1
= occurrenceService
.find(uuidSpec
);
145 Set
<CdmBase
> referencedObjects
= service
.getReferencingObjects(spec1
);
146 System
.out
.println("############## RESULT ###################");
147 for (CdmBase obj
: referencedObjects
){
148 System
.out
.println("Object: " + obj
.getClass().getSimpleName() + " - " + obj
);
150 assertEquals(2, referencedObjects
.size());
151 System
.out
.println("############## ENDE ###################");
158 public final void testLoadCacheStrategyForReference(){
159 Reference
<?
> ref
= referenceService
.load(UUID
.fromString("613980ac-9bd5-43b9-a374-d71e1794688f"));
160 ref
.setType(ReferenceType
.Article
);
161 referenceService
.update(ref
);
162 referenceService
.updateTitleCache();
166 * @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
169 protected void createTestDataSet() throws FileNotFoundException
{
170 // TODO Auto-generated method stub