Project

General

Profile

Download (3.43 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
package eu.etaxonomy.cdm.persistence.hibernate.replace;
10

    
11
import java.io.FileNotFoundException;
12
import java.util.UUID;
13

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

    
23
import eu.etaxonomy.cdm.model.agent.Institution;
24
import eu.etaxonomy.cdm.model.agent.Person;
25
import eu.etaxonomy.cdm.model.name.TaxonName;
26
import eu.etaxonomy.cdm.persistence.dao.agent.IAgentDao;
27
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
28
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
29

    
30
/**
31
 * @author ben.clark
32
 * @since 22.12.2009
33
 */
34
public class ReferringObjectMetadataFactoryTest extends CdmTransactionalIntegrationTest {
35

    
36
    @SuppressWarnings("unused")
37
	private static Logger logger = Logger.getLogger(ReferringObjectMetadataFactoryTest.class);
38

    
39
	@SpringBeanByType
40
	private ReferringObjectMetadataFactory referringObjectMetadataFactory;
41

    
42
	@SpringBeanByType
43
	private IAgentDao agentDao;
44

    
45
	private UUID institution1;
46

    
47
	private UUID institution2;
48

    
49
    private UUID person1;
50

    
51
	private UUID person2;
52

    
53
	private UUID person3;
54

    
55
	@Before
56
	public void setUp() throws Exception {
57
		institution1 = UUID.fromString("18679846-7343-4e5f-b14e-5eb56b967989");
58
		institution2 = UUID.fromString("28f6aaa5-e03e-4831-9ce2-71eaf56cdebe");
59
		person1 = UUID.fromString("ed6ac546-8c6c-48c4-9b91-40b1157c05c6");
60
		person2 = UUID.fromString("e4ec436a-3e8c-4166-a834-3bb84c2b5ad6");
61
		person3 = UUID.fromString("c62cd389-d787-47f4-99c3-b80eb12a1ef2");
62
	}
63

    
64
	@Test
65
	public void testReferringObjectMetadataFactory() throws Exception {
66
		referringObjectMetadataFactory.get(Person.class);
67
	}
68

    
69
	@Test
70
	@DataSet
71
	public void testReplaceUnmapped() throws Exception {
72
		Institution x = (Institution)agentDao.findByUuid(institution1);
73
		Institution y = (Institution)agentDao.findByUuid(institution2);
74

    
75
		Assert.assertNotNull(x);
76
		Assert.assertNotNull(y);
77

    
78
		agentDao.replace(x,y);
79
	}
80

    
81
	@Test
82
	@DataSets({
83
	        @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
84
	        @DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml"),
85
	        @DataSet(value="ReferringObjectMetadataFactoryTest.xml")
86
	    })
87
	@ExpectedDataSet
88
	public void testReplaceToOneProperty() throws Exception {
89
		Person x = (Person)agentDao.findByUuid(person1);
90
		Person y = (Person)agentDao.findByUuid(person2);
91

    
92
		Assert.assertNotNull(x);
93
		Assert.assertNotNull(y);
94

    
95
		agentDao.replace(x,y);
96
		this.setComplete();
97
		this.endTransaction();
98
	}
99

    
100
	@Test
101
	@DataSet
102
	//@ExpectedDataSet
103
	public void testReplaceToManyProperty() throws Exception {
104
		Person x = (Person)agentDao.findByUuid(person3);
105
		Person y = (Person)agentDao.findByUuid(person2);
106

    
107
		Assert.assertNotNull(x);
108
		Assert.assertNotNull(y);
109

    
110
		agentDao.replace(x,y);
111
	}
112

    
113
	@Test
114
	public void testIgnoreBidirectionalRelationship() {
115
		referringObjectMetadataFactory.get(TaxonName.class);
116
	}
117

    
118
    @Override
119
    public void createTestDataSet() throws FileNotFoundException {}
120
}
    (1-1/1)