Project

General

Profile

Download (5.36 KB) Statistics
| Branch: | Tag: | Revision:
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.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.IArticle;
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
	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
		
82
		BotanicalName name = BotanicalName.NewInstance(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.setAuthorTeam(author);
90
		name.setBasionymAuthorTeam(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
	}
157

    
158
	
159
	
160
	@Test
161
	@Ignore
162
	public final void testPrintDataSet() {
163
		
164
		printDataSet(System.out);
165
	}
166
	
167
	
168
	@Test
169
	public final void testLoadCacheStrategyForReference(){
170
		Reference ref = referenceService.load(UUID.fromString("613980ac-9bd5-43b9-a374-d71e1794688f"));
171
		ref.setType(ReferenceType.Article);
172
		referenceService.update(ref);
173
		referenceService.updateTitleCache();
174
		
175
	}
176
}
(2-2/15)