Project

General

Profile

Download (7.4 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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 java.io.FileNotFoundException;
13
import java.net.URI;
14

    
15
import org.apache.log4j.Logger;
16
import org.junit.Assert;
17
import org.junit.Test;
18
import org.unitils.dbunit.annotation.DataSet;
19
import org.unitils.dbunit.annotation.DataSets;
20
import org.unitils.spring.annotation.SpringBeanByType;
21

    
22
import eu.etaxonomy.cdm.model.agent.Contact;
23
import eu.etaxonomy.cdm.model.agent.Person;
24
import eu.etaxonomy.cdm.model.agent.Team;
25
import eu.etaxonomy.cdm.model.common.Annotation;
26
import eu.etaxonomy.cdm.model.location.Point;
27
import eu.etaxonomy.cdm.model.name.Rank;
28
import eu.etaxonomy.cdm.model.name.TaxonName;
29
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
30
import eu.etaxonomy.cdm.strategy.merge.MergeException;
31
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
32
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
33

    
34
/**
35
 * @author a.mueller
36
 * @since 2015-04-01
37
 */
38
public class AgentServiceImplTest extends CdmTransactionalIntegrationTest{
39

    
40
    @SuppressWarnings("unused")
41
	private static final Logger logger = Logger.getLogger(AgentServiceImplTest.class);
42

    
43
    @SpringBeanByType
44
    private IAgentService service;
45

    
46
    @SpringBeanByType
47
    private INameService nameSerivce;
48

    
49

    
50
    @Test
51
    @DataSets({
52
        @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
53
        @DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
54
    })
55
    public void testConvertPerson2Team(){
56
    	String fullAuthor = "Original author";
57
    	String nomTitle = "Abrev. aut.";
58
    	Person person = Person.NewTitledInstance(fullAuthor);
59
    	person.setNomenclaturalTitle(nomTitle);
60
    	Annotation annotation = Annotation.NewDefaultLanguageInstance("Meine annotation");
61
    	person.setContact(getContact());
62
    	TaxonName name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
63
    	name.setCombinationAuthorship(person);
64
    	person.addAnnotation(annotation);
65

    
66
    	service.save(person);
67
    	nameSerivce.save(name);
68

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

    
84
    }
85

    
86
    private Contact getContact(){
87
    	URI uri = URI.create("a");
88
    	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));
89
    	return contact;
90
    }
91

    
92

    
93
    @Test
94
    @DataSets({
95
        @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
96
        @DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
97
    })
98
    public void testConvertTeam2Person(){
99
    	String fullAuthor = "Original author";
100
    	String nomTitle = "Abrev. aut.";
101
    	Team team = Team.NewTitledInstance(fullAuthor, nomTitle);
102
    	Annotation annotation = Annotation.NewDefaultLanguageInstance("Meine annotation");
103
    	team.addAnnotation(annotation);
104
    	team.setContact(getContact());
105
    	TaxonName name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
106
    	name.setCombinationAuthorship(team);
107

    
108
    	service.save(team);
109
    	nameSerivce.save(name);
110

    
111
    	UpdateResult result = null;
112
    	Person person = null;
113
		try {
114
			result = service.convertTeam2Person(team);
115
			person = (Person)result.getCdmEntity();
116
		} catch (IllegalArgumentException e) {
117
			Assert.fail("No IllegalArgumentException should be thrown");
118
		} catch (MergeException e) {
119
			Assert.fail("No Merge exception should be thrown");
120
		}
121
    	Assert.assertNotNull(person);
122
    	Assert.assertEquals("Title cache must be equal", fullAuthor, person.getTitleCache());
123
    	Assert.assertEquals("Nom. title must be equal", nomTitle, person.getNomenclaturalTitle());
124
    	Assert.assertEquals("Annotations should be moved", 1, person.getAnnotations().size());
125
    	Assert.assertNotNull("Contact must be copied too", person.getContact());
126
    	Assert.assertEquals("person must be combination author now", person, name.getCombinationAuthorship());
127
    }
128

    
129

    
130
    @Test
131
    @DataSets({
132
        @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
133
        @DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
134
    })
135
    public void testConvertTeam2PersonWithMember(){
136
    	String fullAuthor = "Original author";
137
    	String nomTitle = "Abrev. aut.";
138
    	Team team = Team.NewTitledInstance(fullAuthor, nomTitle);
139
    	Annotation annotation = Annotation.NewDefaultLanguageInstance("Meine annotation");
140
    	team.addAnnotation(annotation);
141
    	Annotation annotation2 = Annotation.NewDefaultLanguageInstance("Meine annotation2");
142
    	team.addAnnotation(annotation2);
143
    	team.setContact(getContact());
144
    	TaxonName name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
145
    	name.setCombinationAuthorship(team);
146
    	Person member = Person.NewTitledInstance("Member person");
147
    	member.setNomenclaturalTitle("Memb. pers.");
148
    	Annotation annotation3 = Annotation.NewDefaultLanguageInstance("Meine annotation3");
149
    	member.addAnnotation(annotation3);
150
    	team.addTeamMember(member);
151

    
152
    	service.save(team);
153

    
154
    	nameSerivce.save(name);
155

    
156
    	Person person = null;
157
    	UpdateResult result = null;
158
		try {
159
		    result = service.convertTeam2Person(team);
160
		    person = (Person) result.getCdmEntity();
161
		} catch (IllegalArgumentException e) {
162
			Assert.fail("No IllegalArgumentException should be thrown");
163
		} catch (MergeException e) {
164
			Assert.fail("No Merge exception should be thrown");
165
		}
166
    	Assert.assertNotNull(person);
167
    	Assert.assertEquals("Convert result and 'member' must be equal'", member, person);
168
    	Assert.assertEquals("Title cache must be equal", "Member person", person.getTitleCache());
169
    	Assert.assertEquals("Nom. title must be equal", "Memb. pers.", person.getNomenclaturalTitle());
170
    	//FIXME should annotations be taken only from member ??
171
//    	Assert.assertEquals("Annotations should be moved", 1, person.getAnnotations().size());
172
    	String annotationText = person.getAnnotations().iterator().next().getText();
173
//    	Assert.assertEquals("The only annotation should be annotation 3", annotation3.getText(), annotationText);
174
    	//FIXME currently merge mode is still MERGE for user defined fields
175
//    	Assert.assertNull("Contact must not be copied", person.getContact());
176
    	Assert.assertEquals("person must be combination author now", person, name.getCombinationAuthorship());
177
    }
178

    
179
    @Override
180
    public void createTestDataSet() throws FileNotFoundException {}
181
}
(2-2/35)