Project

General

Profile

« Previous | Next » 

Revision 2b9b03a1

Added by Andreas Kohlbecker over 6 years ago

fix #7154 CdmEntityCache can update cached entities and using this in ToOneRelatedEntityReloader and in
SpecimenTypeDesignationWorkingsetEditorPresenter to update the ui with modified collections

View differences:

src/test/java/eu/etaxonomy/cdm/cache/EntityCacheTest.java
9 9
package eu.etaxonomy.cdm.cache;
10 10

  
11 11

  
12
import org.joda.time.DateTime;
12 13
import org.junit.Assert;
13 14
import org.junit.Test;
14 15

  
......
22 23
public class EntityCacheTest {
23 24

  
24 25
    @Test
25
    public void EntityKeyTest() {
26
    public void entityKeyTest() {
26 27

  
27 28
        Collection collection1 = Collection.NewInstance();
28 29
        Collection collection2 = Collection.NewInstance();
......
43 44
        Assert.assertNotNull(cache.find(collection1));
44 45
    }
45 46

  
47
    @Test
48
    public void testFindOrUpdate() {
49

  
50
        Collection collection = Collection.NewInstance();
51
        collection.setId(10);
52
        collection.setCode("A");
53

  
54
        CdmEntityCache cache = new CdmEntityCache(collection);
55

  
56
        Assert.assertEquals(collection, cache.find(Collection.class, 10));
57
        Assert.assertEquals("A", cache.find(Collection.class, 10).getCode());
58

  
59
        Collection copyCollection = collection.clone();
60
        copyCollection.setId(collection.getId()); // clone does not copy the id!
61
        copyCollection.setUuid(collection.getUuid());
62
        copyCollection.setCode("B");
63
        copyCollection.setUpdated(new DateTime(2017, 12, 1, 0, 0));
64
        Assert.assertEquals("B", cache.findAndUpdate(copyCollection).getCode());
65

  
66
        copyCollection = collection.clone();
67
        copyCollection.setId(10); // clone does not copy the id!
68
        copyCollection.setUuid(collection.getUuid());
69
        copyCollection.setCode("C");
70
        copyCollection.setUpdated(new DateTime(2018, 1, 1, 0, 0));
71
        Assert.assertEquals("C", cache.findAndUpdate(copyCollection).getCode());
72

  
73
    }
74

  
46 75
}

Also available in: Unified diff