Project

General

Profile

Download (3.99 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 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.service;
10

    
11
import static org.junit.Assert.assertEquals;
12

    
13
import java.io.FileNotFoundException;
14
import java.lang.reflect.Field;
15
import java.util.UUID;
16

    
17
import org.apache.log4j.Logger;
18
import org.junit.Test;
19
import org.unitils.dbunit.annotation.DataSet;
20
import org.unitils.spring.annotation.SpringBeanByType;
21

    
22
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
23
import eu.etaxonomy.cdm.model.reference.Reference;
24
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
25
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
26

    
27
/**
28
 * @author a.mueller
29
 * @since 13.02.2019
30
 */
31
public class ReferenceServiceImplTest extends CdmTransactionalIntegrationTest {
32

    
33
    @SuppressWarnings("unused")
34
    private static final Logger logger = Logger.getLogger(ReferenceServiceImplTest.class);
35

    
36
    private static final UUID REFERENCE1_UUID = UUID.fromString("4857d1f5-77d1-4583-87c4-f0d08fcfefcc");
37
    private static final UUID REFERENCE2_UUID = UUID.fromString("fcdfb0cc-9ef6-48e3-ad56-492614491c73");
38
    private static final UUID REFERENCE3_UUID = UUID.fromString("2821f503-5dd1-49b1-8a1c-8ed623e89e10");
39
    private static final UUID REFERENCE4_UUID = UUID.fromString("f2d2614c-f652-437b-8b4f-f5f7242df5af");
40

    
41
    @SpringBeanByType
42
    private IReferenceService service;
43

    
44
/* ******************** TESTS ********************************************/
45

    
46
    @Test  //7874 //8030
47
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="ReferenceServiceImplTest.testUpdateCaches.xml")
48
    public void testUpdateCaches() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
49

    
50
        Field titleCacheField = IdentifiableEntity.class.getDeclaredField("titleCache");
51
        titleCacheField.setAccessible(true);
52
        Field abbrevCacheField = Reference.class.getDeclaredField("abbrevTitleCache");
53
        abbrevCacheField.setAccessible(true);
54

    
55
        Reference ref1 = service.load(REFERENCE1_UUID);
56
        Reference ref2 = service.load(REFERENCE2_UUID);
57
        Reference ref3 = service.load(REFERENCE3_UUID);
58
        Reference ref4 = service.load(REFERENCE4_UUID);
59

    
60
        assertEquals("TitleCache should be the persisted one", "--needs update--", titleCacheField.get(ref1));
61
        assertEquals("AbbrevCache should be the persisted one", "-still wrong-", abbrevCacheField.get(ref1));
62

    
63
        assertEquals("TitleCache should be the persisted one", "Reference2", titleCacheField.get(ref2));
64
        assertEquals("AbbrevCache should be the persisted one", "-needs update-", abbrevCacheField.get(ref2));
65

    
66
        assertEquals("TitleCache should be the persisted one", "-wrong-", titleCacheField.get(ref3));
67
        assertEquals("AbbrevCache should be the persisted one", "Protec. ref.", abbrevCacheField.get(ref3));
68

    
69
        assertEquals("TitleCache should be the persisted one", "Inref", titleCacheField.get(ref4));
70

    
71
        service.updateCaches();
72

    
73
        assertEquals("Expecting titleCache to be updated", "Species plantarum", titleCacheField.get(ref1));
74
        assertEquals("Expecting nameCache to be updated", "Sp. Pl.", abbrevCacheField.get(ref1));
75

    
76
        assertEquals("Expecting titleCache to be updated", "Reference2", titleCacheField.get(ref2));
77
        assertEquals("Expecting nameCache to not be updated", "ref. 2", abbrevCacheField.get(ref2));
78

    
79
        assertEquals("Expecting titleCache to be updated", "Reference three", titleCacheField.get(ref3));
80
        assertEquals("Expecting nameCache to be updated", "Protec. ref.", abbrevCacheField.get(ref3));
81

    
82
        assertEquals("Expecting error message for self-referencing in-refererence", "-- invalid inreference (self-referencing) --", titleCacheField.get(ref4));
83
    }
84

    
85
    @Override
86
    public void createTestDataSet() throws FileNotFoundException {}
87
}
(21-21/38)