Project

General

Profile

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

    
11
import static org.junit.Assert.assertNotNull;
12

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

    
17
import org.apache.log4j.Logger;
18
import org.hibernate.LockMode;
19
import org.hibernate.LockOptions;
20
import org.junit.Assert;
21
import org.junit.Before;
22
import org.junit.Test;
23
import org.unitils.dbunit.annotation.DataSet;
24
import org.unitils.dbunit.annotation.ExpectedDataSet;
25
import org.unitils.spring.annotation.SpringBeanByType;
26

    
27
import eu.etaxonomy.cdm.model.name.HybridRelationship;
28
import eu.etaxonomy.cdm.model.name.NameRelationship;
29
import eu.etaxonomy.cdm.model.name.TaxonName;
30
import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao;
31
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
32

    
33
/**
34
 * @author a.mueller
35
 * @since 17.09.2009
36
 */
37
public class CdmDeleteListenerTest extends CdmTransactionalIntegrationTest {
38

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

    
42
	@SpringBeanByType
43
	private ITaxonNameDao taxonNameDao;
44

    
45
	private UUID uuid;
46

    
47
	@Before
48
	public void setUp() throws Exception {
49
		uuid = UUID.fromString("44415fc0-1703-11df-8a39-0800200c9a66");
50
	}
51

    
52
	@Test
53
	@DataSet("CdmDeleteListenerTest.xml")
54
	@ExpectedDataSet
55
	public void testOnDelete() throws Exception {
56
		TaxonName name = taxonNameDao.findByUuid(uuid);
57
		/**
58
		 * Ended up with some horrible hibernate errors otherwise
59
		 */
60
		taxonNameDao.refresh(name, new LockOptions(LockMode.READ), null);
61
		assertNotNull(name);
62
//		int nRels = taxonDao.countAllRelationships();  //TODO needs fixing on test side or dao method side as it jumps into auditing
63
//		Assert.assertEquals("There should be 2 relationships", 2, nRels);
64
		Set<NameRelationship> relations = name.getNameRelations();
65
		Assert.assertEquals("There must be 1 name relationship", 1, relations.size());
66
		name.removeNameRelationship(relations.iterator().next());
67

    
68
		Set<HybridRelationship> hybridRels = name.getHybridParentRelations();
69
		Assert.assertEquals("There must be 1 parent relationship", 1, hybridRels.size());
70

    
71
		taxonNameDao.saveOrUpdate(name);
72

    
73
		setComplete();
74
		endTransaction();
75
		startNewTransaction();
76

    
77
//		nRels = taxonDao.countAllRelationships();
78
//		Assert.assertEquals("There should be 1 relationship now", 1, nRels);
79
	}
80

    
81
    @Override
82
    public void createTestDataSet() throws FileNotFoundException {}
83
}
(2-2/6)