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