Project

General

Profile

Download (3.06 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2014 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.taxeditor.lazyloading;
11

    
12
import java.util.UUID;
13

    
14
import org.apache.log4j.Level;
15
import org.apache.log4j.Logger;
16
import org.hibernate.collection.spi.PersistentCollection;
17
import org.junit.Assert;
18
import org.junit.BeforeClass;
19
import org.junit.Test;
20

    
21
import eu.etaxonomy.cdm.api.service.ICommonService;
22
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
23
import eu.etaxonomy.cdm.api.service.ITaxonService;
24
import eu.etaxonomy.cdm.model.common.CdmBase;
25
import eu.etaxonomy.cdm.model.common.Language;
26
import eu.etaxonomy.cdm.model.description.PolytomousKey;
27
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
28
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
29
import eu.etaxonomy.taxeditor.httpinvoker.BaseRemotingTest;
30
import eu.etaxonomy.taxeditor.httpinvoker.CDMServer;
31

    
32
/**
33
 * @author cmathew
34
 * @date 16 Oct 2014
35
 *
36
 */
37
public class CdmEntityCacherTest extends BaseRemotingTest {
38

    
39
    private static final Logger logger = Logger.getLogger(CdmEntityCacherTest.class);
40

    
41
    UUID polytomousKeyUuid = UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66");
42
    UUID taxon1Uuid = UUID.fromString("2b336df7-29e8-4f79-985f-66502739d22f");
43

    
44

    
45
    IPolytomousKeyService polytomousKeyService = getRemoteApplicationController().getPolytomousKeyService();
46
    ICommonService commonService = getRemoteApplicationController().getCommonService();
47
    ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
48

    
49
    Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
50

    
51
    @BeforeClass
52
    public static void initializePolytomousKeyTest() {
53
        logger.setLevel(Level.INFO);
54
        CDMServer.getInstance().setKeepServerRunning(true);
55

    
56
        initializeController("default", "127.0.0.1", 8080, "", NomenclaturalCode.ICNAFP);
57
    }
58

    
59
    @Test
60
    public void testSimpleCache() {
61

    
62

    
63
    }
64

    
65
    @Test
66
    public void testCachingCdmEntities() {
67
        PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
68
        PolytomousKeyNode pkeynode = pkey.getRoot();
69

    
70
        PersistentCollection children = (PersistentCollection) pkeynode.getChildren();
71
        PolytomousKeyNode childNode0 = (PolytomousKeyNode)commonService.get(children, 0);
72
        PolytomousKey subkey1 = CdmBase.deproxy(childNode0.getSubkey(),PolytomousKey.class);
73
        String subkey1title = subkey1.getTitleCache();
74
        subkey1.setTitleCache(subkey1title + "test", true);
75

    
76
        PolytomousKeyNode childNode1 = (PolytomousKeyNode)commonService.get(children, 1);
77
        PolytomousKey subkey2 = CdmBase.deproxy(childNode1.getSubkey(),PolytomousKey.class);
78
        String subkey2title = subkey2.getTitleCache();
79
        subkey2.setTitleCache(subkey2title + "test", true);
80

    
81
        Assert.assertNotSame(subkey1, subkey2);
82

    
83
        polytomousKeyService.merge(pkey);
84

    
85

    
86
    }
87

    
88

    
89
}
(2-2/5)