Revision bfa30d38
Added by Andreas Müller about 5 years ago
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
ref #8030 add tests for nameService (not yet finished) and fixing updateCache handling in TaxonName