Project

General

Profile

Download (5.37 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.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
	private static final Logger logger = Logger.getLogger(CommonServiceImplTest.class);
44
	
45
	@SpringBeanByType
46
	private ICommonService service;
47
	
48
	@SpringBeanByType
49
	private ITaxonService taxonService;
50
	
51
	@SpringBeanByType
52
	private IReferenceService referenceService;
53
	
54
	@SpringBeanByType
55
	private IAgentService agentService;
56
	
57
	@SpringBeanByType
58
	private IUserService userService;
59
	
60
	@SpringBeanByType
61
	private IOccurrenceService occurrenceService;
62
	
63
/****************** TESTS *****************************/
64
	
65
	/**
66
	 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#setDao(eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao)}.
67
	 */
68
	@Test
69
	public final void testSetDao() {
70
		Assert.assertNotNull(service);
71
	}
72

    
73
	/**
74
	 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#getTaxonByUuid(java.util.UUID)}.
75
	 */
76
	@Test
77
	@DataSet
78
	@Ignore
79
	public final void testGetReferencingObjects() {
80
		ReferenceFactory refFactory = ReferenceFactory.newInstance();
81
		BotanicalName name = BotanicalName.NewInstance(Rank.SPECIES());
82
		name.setTitleCache("A name", true);
83
		Reference ref1 = refFactory.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
	}
156

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