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