Project

General

Profile

Download (3.63 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.persistence.hibernate.replace;
11

    
12

    
13
import java.io.FileNotFoundException;
14
import java.util.UUID;
15

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

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

    
32
/**
33
 * @author ben.clark
34
 * @created 22.12.2009
35
 */
36
public class ReferringObjectMetadataFactoryTest extends CdmTransactionalIntegrationTest {
37
	@SuppressWarnings("unused")
38
	private static Logger logger = Logger.getLogger(ReferringObjectMetadataFactoryTest.class);
39

    
40
	@SpringBeanByType
41
	private ReferringObjectMetadataFactory referringObjectMetadataFactory;
42

    
43
	@SpringBeanByType
44
	private IAgentDao agentDao;
45

    
46
	private UUID institution1;
47

    
48
	private UUID institution2;
49

    
50
    private UUID person1;
51

    
52
	private UUID person2;
53

    
54
	private UUID person3;
55

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

    
68
	/**
69
	 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#CdmEntityDaoBase(java.lang.Class)}.
70
	 * @throws Exception
71
	 */
72
	@Test
73
	public void testReferringObjectMetadataFactory() throws Exception {
74
		referringObjectMetadataFactory.get(Person.class);
75
	}
76

    
77
	@Test
78
	@DataSet
79
	public void testReplaceUnmapped() throws Exception {
80
		Institution x = (Institution)agentDao.findByUuid(institution1);
81
		Institution y = (Institution)agentDao.findByUuid(institution2);
82

    
83
		Assert.assertNotNull(x);
84
		Assert.assertNotNull(y);
85

    
86
		agentDao.replace(x,y);
87
	}
88

    
89
	@Test
90
	 @DataSets({
91
	        @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
92
	        @DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml"),
93
	        @DataSet(value="ReferringObjectMetadataFactoryTest.xml")
94
	    })
95
	@ExpectedDataSet
96
	public void testReplaceToOneProperty() throws Exception {
97
		Person x = (Person)agentDao.findByUuid(person1);
98
		Person y = (Person)agentDao.findByUuid(person2);
99

    
100
		Assert.assertNotNull(x);
101
		Assert.assertNotNull(y);
102

    
103
		agentDao.replace(x,y);
104
		this.setComplete();
105
		this.endTransaction();
106

    
107
	}
108

    
109
	@Test
110
	@DataSet
111
	//@ExpectedDataSet
112
	public void testReplaceToManyProperty() throws Exception {
113
		Person x = (Person)agentDao.findByUuid(person3);
114
		Person y = (Person)agentDao.findByUuid(person2);
115

    
116
		Assert.assertNotNull(x);
117
		Assert.assertNotNull(y);
118

    
119
		agentDao.replace(x,y);
120
	}
121

    
122
	@Test
123
	public void testIgnoreBidirectionalRelationship() {
124
		referringObjectMetadataFactory.get(TaxonName.class);
125
	}
126

    
127
    @Override
128
    public void createTestDataSet() throws FileNotFoundException {}
129
}
130

    
131

    
    (1-1/1)