Project

General

Profile

Revision bfa30d38

IDbfa30d386a174253ec596a813640d48d2933f834
Parent 5d2a77b2
Child e11d18c9

Added by Andreas Müller about 1 month ago

ref #8030 add tests for nameService (not yet finished) and fixing updateCache handling in TaxonName

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IdentifiableEntity.java
281 281
                    logger.warn("newCache should never be null");
282 282
                }
283 283
                if (oldTitleCache == null){
284
                    logger.info("oldTitleCache should never be null");
284
                    logger.info("oldTitleCache was illegaly null and has been fixed");
285 285
                }
286 286
                return true;
287 287
            }
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/TaxonName.java
3592 3592
        //updates the authorship cache if necessary and via the listener updates all higher caches
3593 3593
        if (protectedAuthorshipCache == false){
3594 3594
            String oldCache = this.authorshipCache;
3595
            String newCache = this.getAuthorshipCache();
3595
            String newCache = cacheStrategy.getAuthorshipCache(this);
3596 3596
            if (!CdmUtils.nullSafeEqual(oldCache, newCache)){
3597
                this.setAuthorshipCache(this.getAuthorshipCache(), false);
3597
                this.setAuthorshipCache(null, false);
3598
                this.getAuthorshipCache();
3598 3599
                return true;
3599 3600
            }
3600 3601
        }
......
3608 3609
        //updates the name cache if necessary and via the listener updates all higher caches
3609 3610
        if (protectedNameCache == false){
3610 3611
            String oldCache = this.nameCache;
3611
            String newCache = this.getNameCache();
3612
            String newCache = cacheStrategy.getNameCache(this);
3612 3613
            if (!CdmUtils.nullSafeEqual(oldCache, newCache)){
3613
                this.setNameCache(this.getNameCache(), false);
3614
                this.setNameCache(null, false);
3615
                this.getNameCache();
3614 3616
                return true;
3615 3617
            }
3616 3618
        }
......
3624 3626
    private boolean updateFullTitleCache() {
3625 3627
        if (protectedFullTitleCache == false){
3626 3628
            String oldCache = this.fullTitleCache;
3627
            String newCache = this.getFullTitleCache();
3629
            String newCache = cacheStrategy.getFullTitleCache(this);
3628 3630
            if (!CdmUtils.nullSafeEqual(oldCache, newCache)){
3629
                this.setFullTitleCache(this.getFullTitleCache(), false);
3631
                this.setFullTitleCache(null, false);
3632
                this.getFullTitleCache();
3630 3633
                return true;
3631 3634
            }
3632 3635
        }
......
3642 3645
     * modifying only some of the attributes.<BR><BR>
3643 3646
     * Usages of this name in a taxon concept are <b>not</b> cloned.<BR>
3644 3647
     * <b>The name gets a newly created homotypical group</b><BR>
3645
     * (CAUTION: this behaviour needs to be discussed and may change in future).<BR><BR>
3648
     * (CAUTION: this behavior needs to be discussed and may change in future).<BR><BR>
3646 3649
     * {@link TaxonNameDescription Name descriptions} are cloned and not reused.<BR>
3647 3650
     * {@link TypeDesignationBase Type designations} are cloned and not reused.<BR>
3648 3651
     *
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/Reference.java
1181 1181
                    logger.warn("New abbrevCache should never be null");
1182 1182
                }
1183 1183
                if (oldAbbrevTitleCache == null){
1184
                    logger.info("Old abbrevTitleCache should never be null");
1184
                    logger.info("oldAbbrevTitleCache was illegaly null and has been fixed");
1185 1185
                }
1186 1186
                result = true;
1187 1187
            }
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/AgentServiceImplTest.java
190 190
    }
191 191

  
192 192

  
193
    @Test  //7874
193
    @Test  //7874 //8030
194 194
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="AgentServiceImplTest.testUpdateTitleCache.xml")
195 195
    public final void testUpdateNomTitle() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
196 196

  
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/NameServiceImplTest.java
12 12
import static org.junit.Assert.assertTrue;
13 13

  
14 14
import java.io.FileNotFoundException;
15
import java.lang.reflect.Field;
15 16
import java.util.Arrays;
16 17
import java.util.List;
17 18
import java.util.Set;
......
36 37
import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
37 38
import eu.etaxonomy.cdm.api.service.pager.Pager;
38 39
import eu.etaxonomy.cdm.model.common.CdmBase;
40
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
39 41
import eu.etaxonomy.cdm.model.common.Language;
40 42
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
41 43
import eu.etaxonomy.cdm.model.description.Feature;
......
71 73
 *
72 74
 */
73 75
public class NameServiceImplTest extends CdmTransactionalIntegrationTest {
76

  
74 77
    private static final Logger logger = Logger.getLogger(NameServiceImplTest.class);
75 78

  
79
    private static final UUID NAME1_UUID = UUID.fromString("6dbd41d1-fe13-4d9c-bb58-31f051c2c384");
80
    private static final UUID NAME2_UUID = UUID.fromString("f9e9c13f-5fa5-48d3-88cf-712c921a099e");
81
    private static final UUID NAME3_UUID = UUID.fromString("e1e66264-f16a-4df9-80fd-6ab5028a3c28");
82

  
76 83
    @SpringBeanByType
77 84
    private INameService nameService;
78 85

  
......
1054 1061

  
1055 1062
    }
1056 1063

  
1064
    @Test  //7874 //8030
1065
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="NameServiceImplTest.testUpdateCaches.xml")
1066
    public void testUpdateCaches() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
1067

  
1068
        Field titleCacheField = IdentifiableEntity.class.getDeclaredField("titleCache");
1069
        titleCacheField.setAccessible(true);
1070
        Field nameCacheField = TaxonName.class.getDeclaredField("nameCache");
1071
        nameCacheField.setAccessible(true);
1072
        Field authorCacheField = TaxonName.class.getDeclaredField("authorshipCache");
1073
        authorCacheField.setAccessible(true);
1074
        Field fullTitleCacheField = TaxonName.class.getDeclaredField("fullTitleCache");
1075
        fullTitleCacheField.setAccessible(true);
1076

  
1077
        TaxonName name1 = nameService.load(NAME1_UUID);
1078
        TaxonName name2 = nameService.load(NAME2_UUID);
1079
        TaxonName name3 = nameService.load(NAME3_UUID);
1080

  
1081
        assertEquals("TitleCache should be the persisted one", "Name1", titleCacheField.get(name1));
1082
        assertEquals("NameCache should be the persisted one", "", nameCacheField.get(name1));
1083
        assertEquals("AuthorCache should be the persisted one", "", authorCacheField.get(name1));
1084
        assertEquals("FullTitleCache should be the persisted one", "", fullTitleCacheField.get(name1));
1085

  
1086
        assertEquals("TitleCache should be the persisted one", "Name2", titleCacheField.get(name2));
1087
        assertEquals("NameCache should be the persisted one", "Protected name", nameCacheField.get(name2));
1088
        assertEquals("AuthorCache should be the persisted one", null, authorCacheField.get(name2));
1089
        assertEquals("FullTitleCache should be the persisted one", "", fullTitleCacheField.get(name2));
1090

  
1091
        nameService.updateTitleCache();
1092

  
1093
        assertEquals("Expecting titleCache to be updated", "First name Turl.", titleCacheField.get(name1));
1094
        assertEquals("Expecting nameCache to be updated", "First name", nameCacheField.get(name1));
1095
        assertEquals("Expecting authorshipCache to be updated", "Turl.", authorCacheField.get(name1));
1096
        assertEquals("Expecting fullTitleCache to be updated", "First name Turl.", fullTitleCacheField.get(name1));
1097

  
1098
        assertEquals("Expecting titleCache to be updated", "Protected name", titleCacheField.get(name2));
1099
        assertEquals("Expecting nameCache to not be updated", "Protected name", nameCacheField.get(name2));
1100
        assertEquals("Expecting authorshipCache to be updated", "", authorCacheField.get(name2));
1101
        assertEquals("Expecting fullTitleCache to be updated", "Protected name", fullTitleCacheField.get(name2));
1102

  
1103
    }
1104

  
1057 1105
    private Rank getSpeciesRank() {
1058 1106
        return (Rank)termService.find(Rank.uuidSpecies);
1059 1107
    }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)