Project

General

Profile

Revision a55e93b5

IDa55e93b53618a3c284000541dcb924ad9f26c2eb
Parent 2114bbc7
Child d1eb3fc7

Added by Andreas Kohlbecker over 2 years ago

ref #7874 test for nomenclaturalTitle cache updater and fixing problem in IdentifiableServiceBase
which prevented from running the updater when titleCache was protected

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IdentifiableServiceBase.java
33 33
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
34 34
import eu.etaxonomy.cdm.model.agent.Person;
35 35
import eu.etaxonomy.cdm.model.agent.Team;
36
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
36 37
import eu.etaxonomy.cdm.model.common.CdmBase;
37 38
import eu.etaxonomy.cdm.model.common.DefinedTerm;
38 39
import eu.etaxonomy.cdm.model.common.ISourceable;
......
293 294
			List<T> entitiesToUpdate = new ArrayList<>();
294 295
			for (T entity : list){
295 296
				HibernateProxyHelper.deproxy(entity, clazz);
296
				if (entity.isProtectedTitleCache() == false){
297
				if (entity.isProtectedTitleCache() == false || TeamOrPersonBase.class.isAssignableFrom(entity.getClass())){
298
				    // always execute for TeamOrPersonBase to allow updating the nomenclaturalTitle
297 299
					updateTitleCacheForSingleEntity(cacheStrategy, entitiesToUpdate, entity);
298 300
				}
299 301
				worked++;
......
411 413
			}
412 414
		} else if (entity instanceof Team){
413 415
            Team team = (Team) entity;
414
            if(!team.isProtectedTitleCache()){
416
            if(!team.isProtectedNomenclaturalTitleCache()){
415 417
                team.setProtectedNomenclaturalTitleCache(true);
416 418
                oldNomenclaturalTitle = team.getNomenclaturalTitle();
417 419
                team.setProtectedNomenclaturalTitleCache(false);
418 420
            }
419 421
        } else if (entity instanceof Person){
420
            // Person has no flag so for for protecting the nomenclaturalTitle
422
            // Person has no flag for protecting the nomenclaturalTitle
421 423
            Person person = (Person) entity;
422 424
            oldNomenclaturalTitle = person.getNomenclaturalTitle();
423 425
        }
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/AgentServiceImplTest.java
9 9

  
10 10
package eu.etaxonomy.cdm.api.service;
11 11

  
12
import static org.junit.Assert.assertEquals;
13
import static org.junit.Assert.assertFalse;
14
import static org.junit.Assert.assertNull;
15
import static org.junit.Assert.assertTrue;
16

  
12 17
import java.io.FileNotFoundException;
18
import java.lang.reflect.Field;
13 19
import java.net.URI;
20
import java.util.UUID;
14 21

  
15 22
import org.apache.log4j.Logger;
16 23
import org.junit.Assert;
......
22 29
import eu.etaxonomy.cdm.model.agent.Contact;
23 30
import eu.etaxonomy.cdm.model.agent.Person;
24 31
import eu.etaxonomy.cdm.model.agent.Team;
32
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
25 33
import eu.etaxonomy.cdm.model.common.Annotation;
26 34
import eu.etaxonomy.cdm.model.location.Point;
27 35
import eu.etaxonomy.cdm.model.name.Rank;
......
176 184
    	Assert.assertEquals("person must be combination author now", person, name.getCombinationAuthorship());
177 185
    }
178 186

  
187

  
188
    @Test
189
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="AgentServiceImplTest.testUpdateTitleCache.xml")
190
    public final void testUpdateNomTitle() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
191

  
192
        Field nomenclaturalTitleField = TeamOrPersonBase.class.getDeclaredField("nomenclaturalTitle");
193
        nomenclaturalTitleField.setAccessible(true);
194

  
195
        Person turland = (Person) service.load(UUID.fromString("a598ab3f-b33b-4b4b-b237-d616fcb6b5b1"));
196
        Person monro = (Person) service.load(UUID.fromString("e7206bc5-61ab-468e-a9f5-dec118b46b7f"));
197

  
198
        Team turland_monro_protected = (Team) service.load(UUID.fromString("5bff55de-f7cc-44d9-baac-908f52ad0cb8"));
199
        Team turland_monro = (Team) service.load(UUID.fromString("30ca93d6-b543-4bb9-b6ff-e9ededa65af7"));
200
        Team turland_monro_null = (Team) service.load(UUID.fromString("a4ca0d37-d78b-4bcc-875e-d4ea5a031089"));
201

  
202
        // Person has no flag for protecting the nomenclaturalTitle
203
        assertNull(nomenclaturalTitleField.get(turland));
204
        assertEquals("A.M. Monro", nomenclaturalTitleField.get(monro).toString());
205

  
206
        // Team has a flag for protectedNomenclaturalTitle flag
207
        assertEquals("Turland, Monro", nomenclaturalTitleField.get(turland_monro_protected));
208
        assertTrue(turland_monro_protected.isProtectedNomenclaturalTitleCache());
209
        assertEquals("--to be updated--", nomenclaturalTitleField.get(turland_monro).toString());
210
        assertFalse(turland_monro.isProtectedNomenclaturalTitleCache());
211
        assertNull(nomenclaturalTitleField.get(turland_monro_null));
212
        assertFalse(turland_monro_null.isProtectedNomenclaturalTitleCache());
213

  
214
        service.updateTitleCache();
215

  
216
        turland_monro_protected = (Team) service.load(UUID.fromString("5bff55de-f7cc-44d9-baac-908f52ad0cb8"));
217
        turland_monro = (Team) service.load(UUID.fromString("30ca93d6-b543-4bb9-b6ff-e9ededa65af7"));
218

  
219
        assertEquals("Expecting nomenclaturalTitle to be set since it was NULL", "Turland, N.J.", nomenclaturalTitleField.get(turland));
220
        assertEquals("Expecting nomenclaturalTitle to be unchanged", "A.M. Monro", nomenclaturalTitleField.get(monro).toString());
221

  
222
        assertEquals("Turland, Monro", nomenclaturalTitleField.get(turland_monro_protected));
223
        assertEquals("Turland, N.J. & A.M. Monro", nomenclaturalTitleField.get(turland_monro).toString());
224
        assertEquals("Expecting nomenclaturalTitle to be set since it was NULL", "Turland, N.J. & A.M. Monro", nomenclaturalTitleField.get(turland_monro_null).toString());
225

  
226
    }
227

  
228

  
179 229
    @Override
180 230
    public void createTestDataSet() throws FileNotFoundException {}
181 231
}
cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/AgentServiceImplTest.testUpdateTitleCache.xml
1
<?xml version='1.0' encoding='UTF-8'?>
2
<dataset>
3
  <AGENTBASE DTYPE="Person" ID="1" CREATED="2009-03-12 11:24:58.0" UUID="a598ab3f-b33b-4b4b-b237-d616fcb6b5b1" TITLECACHE="Turland, N.J." PROTECTEDTITLECACHE="true"                                      FAMILYNAME="Turland" INITIALS="N.J." LIFESPAN_END="00000000" PROTECTEDCOLLECTORTITLECACHE="FALSE" LIFESPAN_START="00000000"/>
4
  <AGENTBASE DTYPE="Person" ID="2" CREATED="2009-03-12 11:24:58.0" UUID="e7206bc5-61ab-468e-a9f5-dec118b46b7f" TITLECACHE="Monro, A.M."   PROTECTEDTITLECACHE="true" NOMENCLATURALTITLE="A.M. Monro" FAMILYNAME="Monro"   INITIALS="A.M." LIFESPAN_END="00000000" PROTECTEDCOLLECTORTITLECACHE="FALSE" LIFESPAN_START="00000000"/>
5
  <AGENTBASE DTYPE="Team" ID="3" CREATED="2009-03-12 11:24:58.0" UUID="5bff55de-f7cc-44d9-baac-908f52ad0cb8" TITLECACHE="Turland, N.J., A.M. Monro"  PROTECTEDTITLECACHE="true" NOMENCLATURALTITLE="Turland, Monro" PROTECTEDNOMENCLATURALTITLECACHE="true" LIFESPAN_END="00000000" LIFESPAN_START="00000000" PROTECTEDCOLLECTORTITLECACHE="FALSE" HASMOREMEMBERS="FALSE"/>
6
  <AGENTBASE DTYPE="Team" ID="4" CREATED="2009-03-12 11:24:58.0" UUID="30ca93d6-b543-4bb9-b6ff-e9ededa65af7" TITLECACHE="Turland, N.J., Monro, A.M." PROTECTEDTITLECACHE="true" NOMENCLATURALTITLE="--to be updated--"         PROTECTEDNOMENCLATURALTITLECACHE="false" LIFESPAN_END="00000000" LIFESPAN_START="00000000" PROTECTEDCOLLECTORTITLECACHE="FALSE" HASMOREMEMBERS="FALSE"/>
7
  <AGENTBASE DTYPE="Team" ID="5" CREATED="2009-03-12 11:24:58.0" UUID="a4ca0d37-d78b-4bcc-875e-d4ea5a031089" TITLECACHE="Turland, N.J., Monro, A.M." PROTECTEDTITLECACHE="true"                                                PROTECTEDNOMENCLATURALTITLECACHE="false" LIFESPAN_END="00000000" LIFESPAN_START="00000000" PROTECTEDCOLLECTORTITLECACHE="FALSE" HASMOREMEMBERS="FALSE"/>
8
  <AGENTBASE_AGENTBASE TEAM_ID="3" TEAMMEMBERS_ID="1" SORTINDEX="0"/>
9
  <AGENTBASE_AGENTBASE TEAM_ID="3" TEAMMEMBERS_ID="2" SORTINDEX="1"/>
10
  <AGENTBASE_AGENTBASE TEAM_ID="4" TEAMMEMBERS_ID="1" SORTINDEX="0"/>
11
  <AGENTBASE_AGENTBASE TEAM_ID="4" TEAMMEMBERS_ID="2" SORTINDEX="1"/>
12
  <AGENTBASE_AGENTBASE TEAM_ID="5" TEAMMEMBERS_ID="1" SORTINDEX="0"/>
13
  <AGENTBASE_AGENTBASE TEAM_ID="5" TEAMMEMBERS_ID="2" SORTINDEX="1"/>
14
</dataset>

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)