minor
[cdmlib.git] / cdmlib-persistence / src / test / java / eu / etaxonomy / cdm / persistence / hibernate / CdmDeleteListenerTest.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.cdm.persistence.hibernate;
12
13 import static org.junit.Assert.assertNotNull;
14
15 import java.io.File;
16 import java.io.FileOutputStream;
17 import java.util.Set;
18 import java.util.UUID;
19
20 import org.apache.log4j.Logger;
21 import org.junit.Assert;
22 import org.junit.Ignore;
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.BotanicalName;
29 import eu.etaxonomy.cdm.model.name.HybridRelationship;
30 import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
31 import eu.etaxonomy.cdm.model.name.NameRelationship;
32 import eu.etaxonomy.cdm.model.name.NonViralName;
33 import eu.etaxonomy.cdm.model.name.Rank;
34 import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao;
35 import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
36
37 /**
38 * @author a.mueller
39 * @created 17.09.2009
40 * @version 1.0
41 */
42 public class CdmDeleteListenerTest extends CdmIntegrationTest {
43 @SuppressWarnings("unused")
44 private static final Logger logger = Logger.getLogger(CdmDeleteListenerTest.class);
45
46 @SpringBeanByType
47 private ITaxonNameDao taxonNameDao;
48
49 private UUID name1Uuid = UUID.fromString("a49a3963-c4ea-4047-8588-2f8f15352730");
50
51 @Ignore
52 @Test
53 @DataSet("CdmDeleteListenerTest.xml")
54 public void testTaxonNameDao() throws Exception {
55 assertNotNull("taxonNameDao should exist",taxonNameDao);
56 }
57
58 /**
59 * Test method for {@link eu.etaxonomy.cdm.persistence.hibernate.CdmDeleteListener#onDelete(org.hibernate.event.DeleteEvent, java.util.Set)}.
60 */
61 @Test
62 @DataSet("CdmDeleteListenerTest.xml")
63 @ExpectedDataSet
64 public void testOnDelete() {
65 NonViralName name1 = (NonViralName)taxonNameDao.findByUuid(name1Uuid);
66 assertNotNull(name1);
67 Set<NameRelationship> relations = name1.getNameRelations();
68 Assert.assertEquals("There must be 1 name relationship", 1, relations.size());
69 name1.removeNameRelationship(relations.iterator().next());
70
71 Set<HybridRelationship> hybridRels = name1.getParentRelationships();
72 Assert.assertEquals("There must be 1 parent relationship", 1, hybridRels.size());
73
74 taxonNameDao.saveOrUpdate(name1);
75 }
76 }