1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.cdm.api.service;
|
5
|
|
6
|
import static org.junit.Assert.assertEquals;
|
7
|
|
8
|
import java.util.Set;
|
9
|
import java.util.UUID;
|
10
|
|
11
|
import junit.framework.Assert;
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
import org.junit.Ignore;
|
15
|
import org.junit.Test;
|
16
|
import org.unitils.dbunit.annotation.DataSet;
|
17
|
import org.unitils.spring.annotation.SpringBeanByType;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
20
|
import eu.etaxonomy.cdm.model.agent.Person;
|
21
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
22
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
23
|
import eu.etaxonomy.cdm.model.common.Group;
|
24
|
import eu.etaxonomy.cdm.model.common.Language;
|
25
|
import eu.etaxonomy.cdm.model.common.User;
|
26
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
27
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
28
|
import eu.etaxonomy.cdm.model.name.Rank;
|
29
|
import eu.etaxonomy.cdm.model.occurrence.Specimen;
|
30
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
31
|
import eu.etaxonomy.cdm.model.reference.Article;
|
32
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
33
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
34
|
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
|
35
|
|
36
|
/**
|
37
|
* @author a.mueller
|
38
|
*
|
39
|
*/
|
40
|
public class CommonServiceImplTest extends CdmIntegrationTest {
|
41
|
private static final Logger logger = Logger.getLogger(CommonServiceImplTest.class);
|
42
|
|
43
|
@SpringBeanByType
|
44
|
private ICommonService service;
|
45
|
|
46
|
@SpringBeanByType
|
47
|
private ITaxonService taxonService;
|
48
|
|
49
|
@SpringBeanByType
|
50
|
private IReferenceService referenceService;
|
51
|
|
52
|
@SpringBeanByType
|
53
|
private IAgentService agentService;
|
54
|
|
55
|
@SpringBeanByType
|
56
|
private IUserService userService;
|
57
|
|
58
|
@SpringBeanByType
|
59
|
private IOccurrenceService occurrenceService;
|
60
|
|
61
|
/****************** TESTS *****************************/
|
62
|
|
63
|
/**
|
64
|
* Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#setDao(eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao)}.
|
65
|
*/
|
66
|
@Test
|
67
|
public final void testSetDao() {
|
68
|
Assert.assertNotNull(service);
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#getTaxonByUuid(java.util.UUID)}.
|
73
|
*/
|
74
|
@Test
|
75
|
@DataSet
|
76
|
@Ignore
|
77
|
public final void testGetReferencingObjects() {
|
78
|
BotanicalName name = BotanicalName.NewInstance(Rank.SPECIES());
|
79
|
name.setTitleCache("A name");
|
80
|
ReferenceBase ref1 = Article.NewInstance();
|
81
|
Taxon taxon = Taxon.NewInstance(name, ref1);
|
82
|
Person author = Person.NewInstance();
|
83
|
author.setTitleCache("Author");
|
84
|
ref1.addAnnotation(Annotation.NewInstance("A1", Language.DEFAULT()));
|
85
|
ref1.setAuthorTeam(author);
|
86
|
name.setBasionymAuthorTeam(author);
|
87
|
|
88
|
name.setNomenclaturalReference(ref1);
|
89
|
|
90
|
taxonService.save(taxon);
|
91
|
// UUID uuid = UUID.fromString("613980ac-9bd5-43b9-a374-d71e1794688f");
|
92
|
// ReferenceBase ref1 = referenceService.findByUuid(uuid);
|
93
|
|
94
|
|
95
|
Set<CdmBase> referencedObjects = service.getReferencingObjects(ref1);
|
96
|
System.out.println("############## RESULT ###################");
|
97
|
for (CdmBase obj: referencedObjects){
|
98
|
System.out.println("Object: " + obj.getClass().getSimpleName() + " - " + obj);
|
99
|
}
|
100
|
assertEquals(3, referencedObjects.size());
|
101
|
System.out.println("############## ENDE ###################");
|
102
|
|
103
|
|
104
|
|
105
|
// UUID uuidAuthor = UUID.fromString("4ce66544-a5a3-4601-ab0b-1f0a1338327b");
|
106
|
// AgentBase author = agentService.findByUuid(uuidAuthor);
|
107
|
|
108
|
referencedObjects = service.getReferencingObjects(author);
|
109
|
System.out.println("############## RESULT ###################");
|
110
|
for (CdmBase obj: referencedObjects){
|
111
|
System.out.println("Object: " + obj.getClass().getSimpleName() + " - " + obj);
|
112
|
}
|
113
|
assertEquals(2, referencedObjects.size());
|
114
|
System.out.println("############## ENDE ###################");
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* Test method for getReferencingObject.
|
119
|
* Test
|
120
|
*/
|
121
|
@Test
|
122
|
@DataSet
|
123
|
public final void testGetReferencingObjects2() {
|
124
|
// SpecimenDescription desc1 = SpecimenDescription.NewInstance();
|
125
|
// desc1.setTitleCache("desc1");
|
126
|
// SpecimenDescription desc2 = SpecimenDescription.NewInstance();
|
127
|
// desc2.setTitleCache("desc2");
|
128
|
//
|
129
|
// SpecimenOrObservationBase spec1 = Specimen.NewInstance();
|
130
|
//
|
131
|
// desc1.addDescribedSpecimenOrObservation(spec1);
|
132
|
// //Taxon taxon = Taxon.NewInstance(taxonNameBase, sec)
|
133
|
// spec1.addDescription(desc2);
|
134
|
//
|
135
|
// occurrenceService.save(spec1);
|
136
|
|
137
|
UUID uuidSpec = UUID.fromString("41539e9c-3764-4f14-9712-2d07d00c8e4c");
|
138
|
SpecimenOrObservationBase spec1 = occurrenceService.findByUuid(uuidSpec);
|
139
|
|
140
|
|
141
|
Set<CdmBase> referencedObjects = service.getReferencingObjects(spec1);
|
142
|
System.out.println("############## RESULT ###################");
|
143
|
for (CdmBase obj: referencedObjects){
|
144
|
System.out.println("Object: " + obj.getClass().getSimpleName() + " - " + obj);
|
145
|
}
|
146
|
assertEquals(2, referencedObjects.size());
|
147
|
System.out.println("############## ENDE ###################");
|
148
|
|
149
|
|
150
|
|
151
|
|
152
|
}
|
153
|
|
154
|
|
155
|
|
156
|
@Test
|
157
|
@Ignore
|
158
|
public final void testPrintDataSet() {
|
159
|
|
160
|
printDataSet(System.out);
|
161
|
}
|
162
|
|
163
|
}
|