Project

General

Profile

Revision 41bd1e57

ID41bd1e5795e97230229fd5fccccb82304febe1e5
Parent 08f2d5e5
Child fefcbafa

Added by Andreas Kohlbecker almost 2 years ago

ref #7114 implementing test to reproduce the issue

View differences:

cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/utility/DerivedUnitConverterIntegrationTest.java
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.spring.annotation.SpringBeanByType;
17

  
18
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
19
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
20
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
21
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
22
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
23

  
24
/**
25
 *
26
 * @author a.kohlbecker
27
 * @since Jun 23, 2017
28
 *
29
 */
30
public class DerivedUnitConverterIntegrationTest extends CdmTransactionalIntegrationTest {
31

  
32
    @SpringBeanByType
33
    private IOccurrenceService service;
34

  
35
    @Test
36
    public void toMediaSpecimen_issue7114() throws DerivedUnitConversionException {
37

  
38
        assertEquals(0, service.list(null, null, null, null, null).size());
39

  
40
        DerivedUnit du = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
41
        du.setTitleCache("test derived unit", true);
42
        du = (DerivedUnit) service.save(du); // intermediate save is essential for this test
43
        DerivedUnitConverter<MediaSpecimen> duc = new DerivedUnitConverter<MediaSpecimen>(du);
44
        MediaSpecimen target = duc.convertTo(MediaSpecimen.class, SpecimenOrObservationType.StillImage);
45
        service.save(target);
46

  
47
        assertEquals(1, service.list(null, null, null, null, null).size());
48
        assertEquals(1, service.list(MediaSpecimen.class, null, null, null, null).size());
49
    }
50

  
51
    @Test
52
    public void toDerivedUnit_issue7114() throws DerivedUnitConversionException {
53

  
54
        assertEquals(0, service.list(null, null, null, null, null).size());
55

  
56
        MediaSpecimen du = MediaSpecimen.NewInstance(SpecimenOrObservationType.StillImage);
57
        du.setTitleCache("test media specimen", true);
58
        DerivedUnitConverter<DerivedUnit> duc = new DerivedUnitConverter<DerivedUnit>(du);
59
        du = (MediaSpecimen) service.save(du); // intermediate save is essential for this test
60
        DerivedUnit target = duc.convertTo(DerivedUnit.class, SpecimenOrObservationType.PreservedSpecimen);
61
        service.save(target);
62

  
63
        assertEquals(1, service.list(null, null, null, null, null).size());
64
        assertEquals(1, service.list(DerivedUnit.class, null, null, null, null).size());
65

  
66
    }
67

  
68
    /**
69
     * {@inheritDoc}
70
     */
71
    @Override
72
    public void createTestDataSet() throws FileNotFoundException {
73
       // using empty database
74

  
75
    }
76

  
77
}
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/utility/DerivedUnitConverterTest.java
34 34
        assertEquals("test derived unit", target.getTitleCache());
35 35
    }
36 36

  
37
    @Test
37 38
    public void toDerivedUnit() throws DerivedUnitConversionException {
39

  
38 40
        MediaSpecimen du = MediaSpecimen.NewInstance(SpecimenOrObservationType.StillImage);
39 41
        du.setTitleCache("test media specimen", true);
40 42
        DerivedUnitConverter<DerivedUnit> duc = new DerivedUnitConverter<DerivedUnit>(du);

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)