fixed problem with deletion of nodes.
[cdmlib.git] / cdmlib-services / src / test / java / eu / etaxonomy / cdm / api / application / FirstDataInserterTest.java
1 // $Id$
2 /**
3 * Copyright (C) 2012 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 package eu.etaxonomy.cdm.api.application;
11
12 import static org.junit.Assert.*;
13
14 import java.util.Set;
15 import java.util.UUID;
16
17
18 import org.apache.log4j.Logger;
19 import org.junit.Test;
20 import org.unitils.dbunit.annotation.DataSet;
21 import org.unitils.dbunit.annotation.ExpectedDataSet;
22 import org.unitils.spring.annotation.SpringBeanByType;
23
24 import eu.etaxonomy.cdm.api.service.IClassificationService;
25 import eu.etaxonomy.cdm.api.service.IDescriptionService;
26 import eu.etaxonomy.cdm.api.service.INameService;
27 import eu.etaxonomy.cdm.api.service.IReferenceService;
28 import eu.etaxonomy.cdm.api.service.ITaxonService;
29 import eu.etaxonomy.cdm.api.service.TaxonServiceImplTest;
30 import eu.etaxonomy.cdm.datagenerator.TaxonGenerator;
31 import eu.etaxonomy.cdm.model.description.TaxonDescription;
32 import eu.etaxonomy.cdm.model.name.BotanicalName;
33 import eu.etaxonomy.cdm.model.name.Rank;
34 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
35 import eu.etaxonomy.cdm.model.reference.IBook;
36 import eu.etaxonomy.cdm.model.reference.Reference;
37 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
38 import eu.etaxonomy.cdm.model.taxon.Taxon;
39 import eu.etaxonomy.cdm.strategy.cache.reference.IReferenceBaseCacheStrategy;
40 import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
41
42 /**
43 * test for the {@link FirstDataInserter}
44 *
45 * @author a.kohlbecker
46 * @date Oct 12, 2012
47 *
48 */
49 @DataSet
50 public class FirstDataInserterTest extends CdmTransactionalIntegrationTest {
51
52 private final String[] tableNames = new String[]{"USERACCOUNT", "USERACCOUNT_GRANTEDAUTHORITYIMPL", "GRANTEDAUTHORITYIMPL", "CDMMETADATA"};
53
54 @SuppressWarnings("unused")
55 private static final Logger logger = Logger.getLogger(TaxonServiceImplTest.class);
56
57 @SpringBeanByType
58 private ITaxonService taxonService;
59
60 @SpringBeanByType
61 private INameService nameService;
62
63 @SpringBeanByType
64 private IReferenceService referenceService;
65
66 @SpringBeanByType
67 private IClassificationService classificationService;
68
69 @SpringBeanByType
70 private IDescriptionService descriptionService;
71
72 @Test
73 @DataSet(value="FirstDataInserterTest.testBlankDB.xml")
74 @ExpectedDataSet(value="FirstDataInserterTest.testBlankDB-result.xml")
75 public void testBlankDB(){
76
77 commitAndStartNewTransaction(null);
78 // printDataSet(System.err, tableNames);
79 }
80
81 @Test
82 @DataSet(value="FirstDataInserterTest.testBlankDB.xml")
83 public void testInsertData(){
84 commitAndStartNewTransaction(null);
85 TaxonGenerator.getTestTaxon();
86 Taxon newTaxon = TaxonGenerator.getTestTaxon();
87 UUID taxonUUID = taxonService.save(newTaxon);
88
89
90 TaxonDescription description = TaxonGenerator.getTestDescription(1);
91 newTaxon.addDescription(description);
92 Set<TaxonDescription> descriptions = newTaxon.getDescriptions();
93 descriptionService.save(description);
94 newTaxon = null;
95 newTaxon = (Taxon)taxonService.find(taxonUUID);
96 descriptions = newTaxon.getDescriptions();
97 assertEquals(2, descriptions.size());
98
99
100
101
102
103 }
104
105 }