1
|
/**
|
2
|
* Copyright (C) 2017 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.utility;
|
10
|
|
11
|
import static org.junit.Assert.assertEquals;
|
12
|
|
13
|
import java.io.FileNotFoundException;
|
14
|
|
15
|
import org.junit.Test;
|
16
|
import org.unitils.dbunit.annotation.DataSet;
|
17
|
import org.unitils.spring.annotation.SpringBeanByType;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
20
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
21
|
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
|
22
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
23
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
24
|
|
25
|
/**
|
26
|
*
|
27
|
* @author a.kohlbecker
|
28
|
* @since Jun 23, 2017
|
29
|
*
|
30
|
*/
|
31
|
@DataSet // the dataset cleans up the DerivedUnits created in the tests
|
32
|
public class DerivedUnitConverterIntegrationTest extends CdmTransactionalIntegrationTest {
|
33
|
|
34
|
@SpringBeanByType
|
35
|
private IOccurrenceService service;
|
36
|
|
37
|
@Test
|
38
|
public void toMediaSpecimen_issue7114() throws DerivedUnitConversionException {
|
39
|
|
40
|
// NOTE:
|
41
|
// normally we would run this test as CdmIntegrationTest, but due to bug #7138
|
42
|
// this is not possible, so we use CdmTransactionalIntegrationTest as super class
|
43
|
// and stop the transaction at the beginning of the test
|
44
|
commit();
|
45
|
|
46
|
assertEquals(0, service.list(null, null, null, null, null).size());
|
47
|
|
48
|
DerivedUnit du = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
49
|
du.setTitleCache("test derived unit", true);
|
50
|
du = (DerivedUnit) service.save(du); // intermediate save is essential for this test
|
51
|
DerivedUnitConverter<MediaSpecimen> duc = DerivedUnitConverterFactory.createDerivedUnitConverter(du, MediaSpecimen.class);
|
52
|
MediaSpecimen target = duc.convertTo(MediaSpecimen.class, SpecimenOrObservationType.StillImage);
|
53
|
service.save(target);
|
54
|
|
55
|
assertEquals(1, service.list(null, null, null, null, null).size());
|
56
|
assertEquals(1, service.list(MediaSpecimen.class, null, null, null, null).size());
|
57
|
}
|
58
|
|
59
|
@Test
|
60
|
public void toDerivedUnit_issue7114() throws DerivedUnitConversionException {
|
61
|
|
62
|
// NOTE:
|
63
|
// normally we would run this test as CdmIntegrationTest, but due to bug #7138
|
64
|
// this is not possible, so we use CdmTransactionalIntegrationTest as super class
|
65
|
// and stop the transaction at the beginning of the test
|
66
|
commit();
|
67
|
|
68
|
assertEquals(0, service.list(null, null, null, null, null).size());
|
69
|
|
70
|
MediaSpecimen du = MediaSpecimen.NewInstance(SpecimenOrObservationType.StillImage);
|
71
|
du.setTitleCache("test media specimen", true);
|
72
|
DerivedUnitConverter<DerivedUnit> duc = DerivedUnitConverterFactory.createDerivedUnitConverter(du, DerivedUnit.class);
|
73
|
du = (MediaSpecimen) service.save(du); // intermediate save is essential for this test
|
74
|
DerivedUnit target = duc.convertTo(DerivedUnit.class, SpecimenOrObservationType.PreservedSpecimen);
|
75
|
service.save(target);
|
76
|
|
77
|
assertEquals(1, service.list(null, null, null, null, null).size());
|
78
|
assertEquals(1, service.list(DerivedUnit.class, null, null, null, null).size());
|
79
|
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* {@inheritDoc}
|
84
|
*/
|
85
|
@Override
|
86
|
public void createTestDataSet() throws FileNotFoundException {
|
87
|
// using empty database
|
88
|
|
89
|
}
|
90
|
|
91
|
}
|