6240b21839a2501c9884d431c300c741dc9e2507
[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 @Test
59 @DataSet("CdmDeleteListenerTest.xml")
60 public void testPrintDataset(){
61 BotanicalName botName1 = BotanicalName.NewInstance(Rank.SPECIES());
62 BotanicalName botName2 = BotanicalName.NewInstance(Rank.SPECIES());
63 //botName1.addRelationshipToName(botName2, NameRelationshipType.ORTHOGRAPHIC_VARIANT(), null);
64 botName1.addHybridChild(botName2, HybridRelationshipType.FEMALE_PARENT(), null);
65 taxonNameDao.saveOrUpdate(botName1);
66 //taxonNameDao.flush();
67 try {
68 File file = new File("testXXX.txt");
69 if (!file.exists()){
70 file.createNewFile();
71 }
72 //printDataSet(new FileOutputStream(file));
73 } catch (Exception e) {
74 e.printStackTrace();
75 }
76 }
77
78
79 /**
80 * Test method for {@link eu.etaxonomy.cdm.persistence.hibernate.CdmDeleteListener#onDelete(org.hibernate.event.DeleteEvent, java.util.Set)}.
81 */
82 @Test
83 @DataSet("CdmDeleteListenerTest.xml")
84 @ExpectedDataSet
85 public void testOnDelete() {
86 NonViralName name1 = (NonViralName)taxonNameDao.findByUuid(name1Uuid);
87 assertNotNull(name1);
88 Set<NameRelationship> relations = name1.getNameRelations();
89 Assert.assertEquals("There must be 1 name relationship", 1, relations.size());
90 name1.removeNameRelationship(relations.iterator().next());
91
92 Set<HybridRelationship> hybridRels = name1.getParentRelationships();
93 Assert.assertEquals("There must be 1 parent relationship", 1, hybridRels.size());
94
95 taxonNameDao.saveOrUpdate(name1);
96 }
97
98 @Test
99 @Ignore
100 public void testPrintDataset2(){
101 try {
102 File file = new File("testXXX.txt");
103 if (!file.exists()){
104 file.createNewFile();
105 }
106 printDataSet(new FileOutputStream(file));
107 } catch (Exception e) {
108 e.printStackTrace();
109 }
110 }
111 }