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
|
|
10
|
package eu.etaxonomy.cdm.api.service;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
|
14
|
import java.util.Set;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.junit.Assert;
|
18
|
|
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;
|
24
|
|
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;
|
37
|
|
38
|
/**
|
39
|
* @author a.mueller
|
40
|
*
|
41
|
*/
|
42
|
public class CommonServiceImplTest extends CdmIntegrationTest {
|
43
|
@SuppressWarnings("unused")
|
44
|
private static final Logger logger = Logger.getLogger(CommonServiceImplTest.class);
|
45
|
|
46
|
@SpringBeanByType
|
47
|
private ICommonService service;
|
48
|
|
49
|
@SpringBeanByType
|
50
|
private ITaxonService taxonService;
|
51
|
|
52
|
@SpringBeanByType
|
53
|
private IReferenceService referenceService;
|
54
|
//
|
55
|
// @SpringBeanByType
|
56
|
// private IAgentService agentService;
|
57
|
//
|
58
|
// @SpringBeanByType
|
59
|
// private IUserService userService;
|
60
|
|
61
|
@SpringBeanByType
|
62
|
private IOccurrenceService occurrenceService;
|
63
|
|
64
|
/****************** TESTS *****************************/
|
65
|
|
66
|
/**
|
67
|
* Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#setDao(eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao)}.
|
68
|
*/
|
69
|
@Test
|
70
|
public final void testSetDao() {
|
71
|
Assert.assertNotNull(service);
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#getTaxonByUuid(java.util.UUID)}.
|
76
|
*/
|
77
|
@Test
|
78
|
@DataSet
|
79
|
@Ignore
|
80
|
public final void testGetReferencingObjects() {
|
81
|
BotanicalName name = BotanicalName.NewInstance(Rank.SPECIES());
|
82
|
name.setTitleCache("A name", true);
|
83
|
Reference<?> ref1 = ReferenceFactory.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);
|
90
|
|
91
|
name.setNomenclaturalReference(ref1);
|
92
|
|
93
|
taxonService.save(taxon);
|
94
|
// UUID uuid = UUID.fromString("613980ac-9bd5-43b9-a374-d71e1794688f");
|
95
|
// Reference ref1 = referenceService.findByUuid(uuid);
|
96
|
|
97
|
|
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);
|
102
|
}
|
103
|
assertEquals(3, referencedObjects.size());
|
104
|
System.out.println("############## ENDE ###################");
|
105
|
|
106
|
|
107
|
|
108
|
// UUID uuidAuthor = UUID.fromString("4ce66544-a5a3-4601-ab0b-1f0a1338327b");
|
109
|
// AgentBase author = agentService.findByUuid(uuidAuthor);
|
110
|
|
111
|
referencedObjects = service.getReferencingObjects(author);
|
112
|
System.out.println("############## RESULT ###################");
|
113
|
for (CdmBase obj: referencedObjects){
|
114
|
System.out.println("Object: " + obj.getClass().getSimpleName() + " - " + obj);
|
115
|
}
|
116
|
assertEquals(2, referencedObjects.size());
|
117
|
System.out.println("############## ENDE ###################");
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* Test method for getReferencingObject.
|
122
|
* Test
|
123
|
*/
|
124
|
@Test
|
125
|
@DataSet
|
126
|
public final void testGetReferencingObjects2() {
|
127
|
// SpecimenDescription desc1 = SpecimenDescription.NewInstance();
|
128
|
// desc1.setTitleCache("desc1");
|
129
|
// SpecimenDescription desc2 = SpecimenDescription.NewInstance();
|
130
|
// desc2.setTitleCache("desc2");
|
131
|
//
|
132
|
// SpecimenOrObservationBase spec1 = Specimen.NewInstance();
|
133
|
//
|
134
|
// desc1.addDescribedSpecimenOrObservation(spec1);
|
135
|
// //Taxon taxon = Taxon.NewInstance(taxonNameBase, sec)
|
136
|
// spec1.addDescription(desc2);
|
137
|
//
|
138
|
// occurrenceService.save(spec1);
|
139
|
|
140
|
UUID uuidSpec = UUID.fromString("41539e9c-3764-4f14-9712-2d07d00c8e4c");
|
141
|
SpecimenOrObservationBase<?> spec1 = occurrenceService.find(uuidSpec);
|
142
|
|
143
|
|
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);
|
148
|
}
|
149
|
assertEquals(2, referencedObjects.size());
|
150
|
System.out.println("############## ENDE ###################");
|
151
|
|
152
|
}
|
153
|
|
154
|
|
155
|
@Test
|
156
|
@DataSet
|
157
|
public final void testLoadCacheStrategyForReference(){
|
158
|
Reference<?> ref = referenceService.load(UUID.fromString("613980ac-9bd5-43b9-a374-d71e1794688f"));
|
159
|
ref.setType(ReferenceType.Article);
|
160
|
referenceService.update(ref);
|
161
|
referenceService.updateTitleCache();
|
162
|
}
|
163
|
}
|