1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.api.service;
|
10
|
|
11
|
import static org.junit.Assert.assertEquals;
|
12
|
|
13
|
import java.io.FileNotFoundException;
|
14
|
import java.util.Set;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.junit.Assert;
|
19
|
import org.junit.Ignore;
|
20
|
import org.junit.Test;
|
21
|
import org.unitils.dbunit.annotation.DataSet;
|
22
|
import org.unitils.spring.annotation.SpringBeanByType;
|
23
|
|
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.test.integration.CdmIntegrationTest;
|
37
|
|
38
|
/**
|
39
|
* @author a.mueller
|
40
|
*/
|
41
|
public class CommonServiceImplTest extends CdmIntegrationTest {
|
42
|
@SuppressWarnings("unused")
|
43
|
private static final Logger logger = Logger.getLogger(CommonServiceImplTest.class);
|
44
|
|
45
|
@SpringBeanByType
|
46
|
private ICommonService service;
|
47
|
|
48
|
@SpringBeanByType
|
49
|
private ITaxonService taxonService;
|
50
|
|
51
|
@SpringBeanByType
|
52
|
private IReferenceService referenceService;
|
53
|
|
54
|
@SpringBeanByType
|
55
|
private IOccurrenceService occurrenceService;
|
56
|
|
57
|
/****************** TESTS *****************************/
|
58
|
|
59
|
@Test
|
60
|
public final void testSetDao() {
|
61
|
Assert.assertNotNull(service);
|
62
|
}
|
63
|
|
64
|
@Test
|
65
|
@DataSet
|
66
|
@Ignore
|
67
|
public final void testGetReferencingObjects() {
|
68
|
IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
69
|
name.setTitleCache("A name", true);
|
70
|
Reference ref1 = ReferenceFactory.newArticle();
|
71
|
Taxon taxon = Taxon.NewInstance(name, ref1);
|
72
|
Person author = Person.NewInstance();
|
73
|
author.setTitleCache("Author", true);
|
74
|
ref1.addAnnotation(Annotation.NewInstance("A1", Language.DEFAULT()));
|
75
|
ref1.setAuthorship(author);
|
76
|
name.setBasionymAuthorship(author);
|
77
|
|
78
|
name.setNomenclaturalReference(ref1);
|
79
|
|
80
|
taxonService.save(taxon);
|
81
|
// UUID uuid = UUID.fromString("613980ac-9bd5-43b9-a374-d71e1794688f");
|
82
|
// Reference ref1 = referenceService.findByUuid(uuid);
|
83
|
|
84
|
Set<CdmBase> referencedObjects = service.getReferencingObjects(ref1);
|
85
|
System.out.println("############## RESULT ###################");
|
86
|
for (CdmBase obj: referencedObjects){
|
87
|
System.out.println("Object: " + obj.getClass().getSimpleName() + " - " + obj);
|
88
|
}
|
89
|
assertEquals(3, referencedObjects.size());
|
90
|
System.out.println("############## ENDE ###################");
|
91
|
|
92
|
// UUID uuidAuthor = UUID.fromString("4ce66544-a5a3-4601-ab0b-1f0a1338327b");
|
93
|
// AgentBase author = agentService.findByUuid(uuidAuthor);
|
94
|
|
95
|
referencedObjects = service.getReferencingObjects(author);
|
96
|
System.out.println("############## RESULT ###################");
|
97
|
for (CdmBase obj: referencedObjects){
|
98
|
System.out.println("Object: " + obj.getClass().getSimpleName() + " - " + obj);
|
99
|
}
|
100
|
assertEquals(2, referencedObjects.size());
|
101
|
System.out.println("############## ENDE ###################");
|
102
|
}
|
103
|
|
104
|
@Test
|
105
|
@DataSet
|
106
|
public final void testGetReferencingObjects2() {
|
107
|
// SpecimenDescription desc1 = SpecimenDescription.NewInstance();
|
108
|
// desc1.setTitleCache("desc1");
|
109
|
// SpecimenDescription desc2 = SpecimenDescription.NewInstance();
|
110
|
// desc2.setTitleCache("desc2");
|
111
|
//
|
112
|
// SpecimenOrObservationBase spec1 = Specimen.NewInstance();
|
113
|
//
|
114
|
// desc1.addDescribedSpecimenOrObservation(spec1);
|
115
|
// //Taxon taxon = Taxon.NewInstance(taxonName, sec)
|
116
|
// spec1.addDescription(desc2);
|
117
|
//
|
118
|
// occurrenceService.save(spec1);
|
119
|
|
120
|
UUID uuidSpec = UUID.fromString("41539e9c-3764-4f14-9712-2d07d00c8e4c");
|
121
|
SpecimenOrObservationBase<?> spec1 = occurrenceService.find(uuidSpec);
|
122
|
|
123
|
|
124
|
Set<CdmBase> referencedObjects = service.getReferencingObjects(spec1);
|
125
|
System.out.println("############## RESULT ###################");
|
126
|
for (CdmBase obj: referencedObjects){
|
127
|
System.out.println("Object: " + obj.getClass().getSimpleName() + " - " + obj);
|
128
|
}
|
129
|
assertEquals(2, referencedObjects.size());
|
130
|
System.out.println("############## ENDE ###################");
|
131
|
}
|
132
|
|
133
|
@Test
|
134
|
@DataSet
|
135
|
public final void testLoadCacheStrategyForReference(){
|
136
|
Reference ref = referenceService.load(UUID.fromString("613980ac-9bd5-43b9-a374-d71e1794688f"));
|
137
|
ref.setType(ReferenceType.Article);
|
138
|
referenceService.update(ref);
|
139
|
referenceService.updateCaches();
|
140
|
}
|
141
|
|
142
|
@Override
|
143
|
public void createTestDataSet() throws FileNotFoundException {}
|
144
|
}
|