Project

General

Profile

Download (3 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;
11

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

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

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

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

    
34
/**
35
 * @author a.mueller
36
 * @created 17.09.2009
37
 */
38
public class CdmDeleteListenerTest extends CdmTransactionalIntegrationTest {
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
	/**
48
	 * @throws java.lang.Exception
49
	 */
50
	@Before
51
	public void setUp() throws Exception {
52
		uuid = UUID.fromString("44415fc0-1703-11df-8a39-0800200c9a66");
53
	}
54

    
55
	/**
56
	 * Test method for {@link eu.etaxonomy.cdm.persistence.hibernate.CdmDeleteListener#onDelete(org.hibernate.event.DeleteEvent, java.util.Set)}.
57
	 */
58
	@Test
59
	@DataSet("CdmDeleteListenerTest.xml")
60
	@ExpectedDataSet
61
	public void testOnDelete() throws Exception {
62
		NonViralName<?> name = (NonViralName<?>)taxonNameDao.findByUuid(uuid);
63
		/**
64
		 * Ended up with some horrible hibernate errors otherwise
65
		 */
66
		taxonNameDao.refresh(name, new LockOptions(LockMode.READ), null);
67
		assertNotNull(name);
68
//		int nRels = taxonDao.countAllRelationships();  //TODO needs fixing on test side or dao method side as it jumps into auditing
69
//		Assert.assertEquals("There should be 2 relationships", 2, nRels);
70
		Set<NameRelationship> relations = name.getNameRelations();
71
		Assert.assertEquals("There must be 1 name relationship", 1, relations.size());
72
		name.removeNameRelationship(relations.iterator().next());
73

    
74
		Set<HybridRelationship> hybridRels = name.getHybridParentRelations();
75
		Assert.assertEquals("There must be 1 parent relationship", 1, hybridRels.size());
76

    
77
		taxonNameDao.saveOrUpdate(name);
78

    
79
		setComplete();
80
		endTransaction();
81
		startNewTransaction();
82

    
83
//		nRels = taxonDao.countAllRelationships();
84
//		Assert.assertEquals("There should be 1 relationship now", 1, nRels);
85

    
86
	}
87

    
88
    /* (non-Javadoc)
89
     * @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
90
     */
91
    @Override
92
    public void createTestDataSet() throws FileNotFoundException {
93
        // TODO Auto-generated method stub
94

    
95
    }
96
}
(2-2/5)