2353b5eb0ea51955784029812d1170a194649829
[cdmlib.git] / cdmlib-services / src / test / java / eu / etaxonomy / cdm / api / application / FirstDataInserterTest.java
1 /**
2 * Copyright (C) 2012 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.api.application;
10
11 import static org.junit.Assert.assertEquals;
12
13 import java.io.FileNotFoundException;
14 import java.util.List;
15 import java.util.Set;
16 import java.util.UUID;
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.taxon.Taxon;
33 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
34 import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
35
36 /**
37 * test for the {@link FirstDataInserter}
38 *
39 * @author a.kohlbecker
40 * @since Oct 12, 2012
41 */
42 @DataSet
43 public class FirstDataInserterTest extends CdmTransactionalIntegrationTest {
44
45 private final String[] tableNames = new String[]{"USERACCOUNT", "USERACCOUNT_GRANTEDAUTHORITYIMPL", "GRANTEDAUTHORITYIMPL", "CDMMETADATA"};
46
47 @SuppressWarnings("unused")
48 private static final Logger logger = Logger.getLogger(TaxonServiceImplTest.class);
49
50 @SpringBeanByType
51 private ITaxonService taxonService;
52
53 @SpringBeanByType
54 private INameService nameService;
55
56 @SpringBeanByType
57 private IReferenceService referenceService;
58
59 @SpringBeanByType
60 private IClassificationService classificationService;
61
62 @SpringBeanByType
63 private IDescriptionService descriptionService;
64
65 @Test
66 @DataSet(value="FirstDataInserterTest.testBlankDB.xml")
67 @ExpectedDataSet(value="FirstDataInserterTest.testBlankDB-result.xml")
68 public void testBlankDB(){
69
70 commitAndStartNewTransaction(null);
71 // printDataSet(System.err, tableNames);
72 }
73
74 @Test
75 @DataSet(value="FirstDataInserterTest.testBlankDB.xml")
76 public void testInsertData(){
77 commitAndStartNewTransaction(null);
78
79 Taxon newTaxon = TaxonGenerator.getTestTaxon();
80 UUID taxonUUID = taxonService.save(newTaxon).getUuid();
81 nameService.save(newTaxon.getName().getBasionyms());
82 List<TaxonNode> childNodes = newTaxon.getTaxonNodes().iterator().next().getChildNodes();
83 classificationService.saveTaxonNodeAll(childNodes);
84 taxonService.saveOrUpdate(childNodes.stream().filter(tn->!tn.getTaxon().getAllMisappliedNames().isEmpty()).findFirst().get().getTaxon().getAllMisappliedNames().iterator().next());
85
86 TaxonDescription description = TaxonGenerator.getTestDescription(1);
87 newTaxon.addDescription(description);
88 Set<TaxonDescription> descriptions = newTaxon.getDescriptions();
89 descriptionService.save(description);
90
91 newTaxon = null;
92 newTaxon = (Taxon)taxonService.find(taxonUUID);
93 descriptions = newTaxon.getDescriptions();
94 assertEquals(2, descriptions.size());
95 }
96
97
98 @Override
99 public void createTestDataSet() throws FileNotFoundException {}
100
101 }