Project

General

Profile

Download (6.46 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.cdm.api.service;
12

    
13
import java.io.FileNotFoundException;
14
import java.net.URI;
15

    
16
import org.apache.log4j.Logger;
17
import org.junit.Assert;
18
import org.junit.Test;
19
import org.unitils.spring.annotation.SpringBeanByType;
20

    
21
import eu.etaxonomy.cdm.model.agent.Contact;
22
import eu.etaxonomy.cdm.model.agent.Person;
23
import eu.etaxonomy.cdm.model.agent.Team;
24
import eu.etaxonomy.cdm.model.common.Annotation;
25
import eu.etaxonomy.cdm.model.location.Point;
26
import eu.etaxonomy.cdm.model.name.BotanicalName;
27
import eu.etaxonomy.cdm.model.name.Rank;
28
import eu.etaxonomy.cdm.strategy.merge.MergeException;
29
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
30

    
31
/**
32
 * @author a.mueller
33
 * @created 2015-04-01
34
 */
35
public class AgentServiceImplTest extends CdmTransactionalIntegrationTest{
36

    
37
    @SuppressWarnings("unused")
38
	private static final Logger logger = Logger.getLogger(AgentServiceImplTest.class);
39

    
40
    @SpringBeanByType
41
    private IAgentService service;
42

    
43
    @SpringBeanByType
44
    private INameService nameSerivce;
45

    
46

    
47
    @Test
48
    public void testConvertPerson2Team(){
49
    	String fullAuthor = "Original author";
50
    	String nomTitle = "Abrev. aut.";
51
    	Person person = Person.NewTitledInstance(fullAuthor);
52
    	person.setNomenclaturalTitle(nomTitle);
53
    	Annotation annotation = Annotation.NewDefaultLanguageInstance("Meine annotation");
54
    	person.setContact(getContact());
55
    	BotanicalName name = BotanicalName.NewInstance(Rank.SPECIES());
56
    	name.setCombinationAuthorship(person);
57
    	person.addAnnotation(annotation);
58

    
59
    	service.save(person);
60
    	nameSerivce.save(name);
61

    
62
    	Team team = null;
63
    	UpdateResult result = null;
64
		try {
65
		    result = service.convertPerson2Team(person);
66
		    team = (Team) result.getCdmEntity();
67
		} catch (MergeException e) {
68
			Assert.fail("No Merge exception should be thrown");
69
		}
70
    	Assert.assertNotNull(team);
71
    	//Assert.assertEquals("Title cache must be equal", fullAuthor, team.getTitleCache());
72
    	//Assert.assertEquals("Nom. title must be equal", nomTitle, team.getNomenclaturalTitle());
73
    	Assert.assertEquals("Annotations should be moved", 1, team.getAnnotations().size());
74
       	Assert.assertNotNull("Contact must be copied too", team.getContact());
75
    	Assert.assertEquals("Team must be combination author now", team, name.getCombinationAuthorship());
76

    
77
    }
78

    
79
    private Contact getContact(){
80
    	URI uri = URI.create("a");
81
    	Contact contact = Contact.NewInstance("My street", "12345", null, null, null, "region", "a@bc.de", "030-445566", "030-12345", uri, Point.NewInstance(2d, 5d, null, null));
82
    	return contact;
83
    }
84

    
85

    
86
    @Test
87
    public void testConvertTeam2Person(){
88
    	String fullAuthor = "Original author";
89
    	String nomTitle = "Abrev. aut.";
90
    	Team team = Team.NewTitledInstance(fullAuthor, nomTitle);
91
    	Annotation annotation = Annotation.NewDefaultLanguageInstance("Meine annotation");
92
    	team.addAnnotation(annotation);
93
    	team.setContact(getContact());
94
    	BotanicalName name = BotanicalName.NewInstance(Rank.SPECIES());
95
    	name.setCombinationAuthorship(team);
96

    
97
    	service.save(team);
98
    	nameSerivce.save(name);
99

    
100
    	UpdateResult result = null;
101
    	Person person = null;
102
		try {
103
			result = service.convertTeam2Person(team);
104
			person = (Person)result.getCdmEntity();
105
		} catch (IllegalArgumentException e) {
106
			Assert.fail("No IllegalArgumentException should be thrown");
107
		} catch (MergeException e) {
108
			Assert.fail("No Merge exception should be thrown");
109
		}
110
    	Assert.assertNotNull(person);
111
    	Assert.assertEquals("Title cache must be equal", fullAuthor, person.getTitleCache());
112
    	Assert.assertEquals("Nom. title must be equal", nomTitle, person.getNomenclaturalTitle());
113
    	Assert.assertEquals("Annotations should be moved", 1, person.getAnnotations().size());
114
    	Assert.assertNotNull("Contact must be copied too", person.getContact());
115
    	Assert.assertEquals("person must be combination author now", person, name.getCombinationAuthorship());
116
    }
117

    
118

    
119
    @Test
120
    public void testConvertTeam2PersonWithMember(){
121
    	String fullAuthor = "Original author";
122
    	String nomTitle = "Abrev. aut.";
123
    	Team team = Team.NewTitledInstance(fullAuthor, nomTitle);
124
    	Annotation annotation = Annotation.NewDefaultLanguageInstance("Meine annotation");
125
    	team.addAnnotation(annotation);
126
    	Annotation annotation2 = Annotation.NewDefaultLanguageInstance("Meine annotation2");
127
    	team.addAnnotation(annotation2);
128
    	team.setContact(getContact());
129
    	BotanicalName name = BotanicalName.NewInstance(Rank.SPECIES());
130
    	name.setCombinationAuthorship(team);
131
    	Person member = Person.NewTitledInstance("Member person");
132
    	member.setNomenclaturalTitle("Memb. pers.");
133
    	Annotation annotation3 = Annotation.NewDefaultLanguageInstance("Meine annotation3");
134
    	member.addAnnotation(annotation3);
135
    	team.addTeamMember(member);
136

    
137
    	service.save(team);
138

    
139
    	nameSerivce.save(name);
140

    
141
    	Person person = null;
142
    	UpdateResult result = null;
143
		try {
144
		    result = service.convertTeam2Person(team);
145
		    person = (Person) result.getCdmEntity();
146
		} catch (IllegalArgumentException e) {
147
			Assert.fail("No IllegalArgumentException should be thrown");
148
		} catch (MergeException e) {
149
			Assert.fail("No Merge exception should be thrown");
150
		}
151
    	Assert.assertNotNull(person);
152
    	Assert.assertEquals("Convert result and 'member' must be equal'", member, person);
153
    	Assert.assertEquals("Title cache must be equal", "Member person", person.getTitleCache());
154
    	Assert.assertEquals("Nom. title must be equal", "Memb. pers.", person.getNomenclaturalTitle());
155
    	//FIXME should annotations be taken only from member ??
156
//    	Assert.assertEquals("Annotations should be moved", 1, person.getAnnotations().size());
157
    	String annotationText = person.getAnnotations().iterator().next().getText();
158
//    	Assert.assertEquals("The only annotation should be annotation 3", annotation3.getText(), annotationText);
159
    	//FIXME currently merge mode is still MERGE for user defined fields
160
//    	Assert.assertNull("Contact must not be copied", person.getContact());
161
    	Assert.assertEquals("person must be combination author now", person, name.getCombinationAuthorship());
162
    }
163

    
164
    @Override
165
    public void createTestDataSet() throws FileNotFoundException {}
166
}
(2-2/31)