Revision fd280052
Added by Andreas Müller almost 4 years ago
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionAwareTest.java | ||
---|---|---|
37 | 37 |
import eu.etaxonomy.cdm.model.agent.Person; |
38 | 38 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
39 | 39 |
import eu.etaxonomy.cdm.model.common.Credit; |
40 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
|
41 | 40 |
import eu.etaxonomy.cdm.model.common.Extension; |
42 | 41 |
import eu.etaxonomy.cdm.model.common.IdentifiableSource; |
43 | 42 |
import eu.etaxonomy.cdm.model.common.Language; |
44 | 43 |
import eu.etaxonomy.cdm.model.common.LanguageString; |
45 |
import eu.etaxonomy.cdm.model.term.TermType; |
|
46 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
|
47 | 44 |
import eu.etaxonomy.cdm.model.description.Feature; |
48 | 45 |
import eu.etaxonomy.cdm.model.description.KeyStatement; |
49 | 46 |
import eu.etaxonomy.cdm.model.description.PolytomousKey; |
50 | 47 |
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode; |
51 | 48 |
import eu.etaxonomy.cdm.model.media.Rights; |
52 | 49 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
50 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
|
51 |
import eu.etaxonomy.cdm.model.term.TermType; |
|
52 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
|
53 | 53 |
import eu.etaxonomy.cdm.persistence.dto.MergeResult; |
54 | 54 |
import eu.etaxonomy.taxeditor.httpinvoker.RemotingSessionAwareTest; |
55 | 55 |
import eu.etaxonomy.taxeditor.httpinvoker.TestThread; |
56 | 56 |
|
57 |
|
|
58 | 57 |
/** |
59 | 58 |
* @author cmathew |
60 | 59 |
* @date 7 Oct 2014 |
61 |
* |
|
62 | 60 |
*/ |
63 | 61 |
@DataSet |
64 | 62 |
public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest { |
... | ... | |
71 | 69 |
UUID taxon1Uuid = UUID.fromString("2b336df7-29e8-4f79-985f-66502739d22f"); |
72 | 70 |
UUID personUuid = UUID.fromString("945d08f2-eb92-45b6-9252-6275ea6d338b"); |
73 | 71 |
|
74 |
|
|
75 |
|
|
76 | 72 |
IPolytomousKeyService polytomousKeyService = getRemoteApplicationController().getPolytomousKeyService(); |
77 | 73 |
IPolytomousKeyNodeService polytomousKeyNodeService = getRemoteApplicationController().getPolytomousKeyNodeService(); |
78 | 74 |
ICommonService commonService = getRemoteApplicationController().getCommonService(); |
... | ... | |
83 | 79 |
|
84 | 80 |
//Language english = Language.getLanguageFromUuid(Language.uuidEnglish); |
85 | 81 |
|
86 |
|
|
87 |
|
|
88 | 82 |
@BeforeClass |
89 | 83 |
public static void initializePolytomousKeyTest() { |
90 | 84 |
} |
91 | 85 |
|
92 |
|
|
93 | 86 |
@Test |
94 | 87 |
@Ignore |
95 | 88 |
public void readAllPolytomousKeys() { |
... | ... | |
99 | 92 |
Assert.assertEquals(pKeysItr.next().getUuid(),UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66")); |
100 | 93 |
} |
101 | 94 |
|
102 |
|
|
103 | 95 |
@Test |
104 | 96 |
//@DataSet("PolytomousKeyTest.readPolytmousKeyData.xml") |
105 | 97 |
public void readPolytmousKeyData() { |
... | ... | |
137 | 129 |
// TO DO : Added tests for Annotations , Markers |
138 | 130 |
} |
139 | 131 |
|
140 |
|
|
141 |
|
|
142 | 132 |
@Test |
143 | 133 |
public void readPolytomousKeyDataFromNodes() { |
144 | 134 |
PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class); |
145 | 135 |
PolytomousKeyNode rootNode = pKey.getRoot(); |
146 | 136 |
|
147 |
|
|
148 | 137 |
Assert.assertEquals(rootNode.getId(), 2750); |
149 | 138 |
|
150 | 139 |
Assert.assertEquals(rootNode.getChildAt(0).getId(), 2751); |
... | ... | |
174 | 163 |
} |
175 | 164 |
|
176 | 165 |
@Test |
177 |
@Ignore |
|
166 |
@Ignore
|
|
178 | 167 |
public void addGrandChildPolytomousKeyNode() { |
179 | 168 |
|
180 | 169 |
PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class); |
... | ... | |
204 | 193 |
PolytomousKeyNode grandChildNode = PolytomousKeyNode.NewInstance(); |
205 | 194 |
rootChildNode.addChild(grandChildNode); |
206 | 195 |
|
207 |
|
|
208 | 196 |
polytomousKeyNodeService.merge(grandChildNode, true); |
209 | 197 |
|
210 |
|
|
211 | 198 |
Assert.assertFalse(pKey.getRoot().getChildAt(0).getChildAt(0).getId() == 0); |
212 | 199 |
} |
213 | 200 |
|
... | ... | |
246 | 233 |
|
247 | 234 |
pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class); |
248 | 235 |
|
249 |
|
|
250 | 236 |
pkeynode = pkey.getRoot(); |
251 | 237 |
for(PolytomousKeyNode node : pkeynode.getChildren()) { |
252 | 238 |
Assert.assertNull(node.getQuestion()); |
... | ... | |
270 | 256 |
Assert.assertEquals(newStatement, node.getStatement().getLabel(Language.ENGLISH()).getText()); |
271 | 257 |
} |
272 | 258 |
//Assert.assertEquals(pkeynode.getFeature().getId(), feature.getId()); |
273 |
|
|
274 | 259 |
} |
275 | 260 |
|
276 | 261 |
|
... | ... | |
279 | 264 |
|
280 | 265 |
PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class); |
281 | 266 |
|
282 |
|
|
283 | 267 |
PolytomousKeyNode pkeynode = pkey.getRoot(); |
284 | 268 |
|
285 | 269 |
PolytomousKey subkey1 = CdmBase.deproxy(pkeynode.getChildAt(0).getSubkey(), PolytomousKey.class); |
286 | 270 |
String subkey1title = subkey1.getTitleCache(); |
287 | 271 |
subkey1.setTitleCache(subkey1title + "test", true); |
288 | 272 |
|
289 |
|
|
290 | 273 |
PolytomousKey subkey2 = CdmBase.deproxy(pkeynode.getChildAt(1).getChildAt(0).getSubkey(), PolytomousKey.class); |
291 | 274 |
String subkey2title = subkey2.getTitleCache(); |
292 | 275 |
subkey2.setTitleCache(subkey2title + "test", true); |
... | ... | |
301 | 284 |
|
302 | 285 |
PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class); |
303 | 286 |
|
304 |
|
|
305 | 287 |
PolytomousKeyNode pkeynode = pkey.getRoot(); |
306 | 288 |
//because of the check for null values in getChildren it isn't a persistent list anymore |
307 | 289 |
// PersistentCollection children = (PersistentCollection) pkeynode.getChildren(); |
... | ... | |
322 | 304 |
polytomousKeyService.merge(pkey, true); |
323 | 305 |
} |
324 | 306 |
|
325 |
|
|
326 |
|
|
327 | 307 |
@Test |
328 | 308 |
public void savePolytomousKeyNodeDataWithSameLanguageInLabel() { |
329 | 309 |
|
... | ... | |
333 | 313 |
Map<Language, LanguageString> label1 = pkeynode.getQuestion().getLabel(); |
334 | 314 |
label1.size(); |
335 | 315 |
|
336 |
|
|
337 | 316 |
Map<Language, LanguageString> label2 = pkeynode.getChildAt(0).getStatement().getLabel(); |
338 | 317 |
label2.size(); |
339 | 318 |
|
340 |
|
|
341 | 319 |
polytomousKeyService.merge(pkey, true); |
342 | 320 |
} |
343 | 321 |
|
... | ... | |
345 | 323 |
public void deleteSubKeyInPolytomousSubKeyWithoutInitializing() { |
346 | 324 |
PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class); |
347 | 325 |
|
348 |
|
|
349 | 326 |
PolytomousKeyNode rootNode = pKey.getRoot(); |
350 | 327 |
|
351 | 328 |
PolytomousKeyNode childNode = rootNode.getChildAt(0); |
352 | 329 |
PolytomousKey subKey = HibernateProxyHelper.deproxy( childNode.getSubkey(), PolytomousKey.class);; |
353 | 330 |
|
354 |
|
|
355 | 331 |
DeleteResult result = polytomousKeyService.delete(subKey.getUuid()); |
356 | 332 |
//A used subKey can't be deleted |
357 | 333 |
if (result.isOk()){ |
358 | 334 |
Assert.fail(); |
359 | 335 |
} |
360 | 336 |
|
361 |
|
|
362 | 337 |
Set<Integer> ids = new HashSet<Integer>(); |
363 | 338 |
ids.add(2753); |
364 | 339 |
ids.add(2754); |
... | ... | |
428 | 403 |
|
429 | 404 |
@Test |
430 | 405 |
public void saveNewTermVocabulary() { |
431 |
TermVocabulary termVocabulary = |
|
406 |
TermVocabulary<Feature> termVocabulary =
|
|
432 | 407 |
TermVocabulary.NewInstance(TermType.Feature, |
433 | 408 |
null, |
434 | 409 |
"Untitled", |
435 | 410 |
null, |
436 | 411 |
null); |
437 | 412 |
try { |
438 |
List<TermVocabulary<DefinedTermBase>> vocabularies = vocabularyService.findByTermType(TermType.Feature, null);
|
|
413 |
List<TermVocabulary<? extends DefinedTermBase<?>>> vocabularies = (List)vocabularyService.findByTermType(TermType.Feature, null);
|
|
439 | 414 |
|
440 |
for(TermVocabulary vocab : vocabularies) { |
|
415 |
for(TermVocabulary<?> vocab : vocabularies) {
|
|
441 | 416 |
vocab.getTermsOrderedByLabels(Language.ENGLISH()); |
442 | 417 |
} |
443 | 418 |
|
444 | 419 |
termVocabulary = vocabularyService.merge(termVocabulary); |
445 | 420 |
vocabularies.add(termVocabulary); |
446 | 421 |
termVocabulary.setLabel("Test"); |
447 |
vocabularyService.merge(new ArrayList<TermVocabulary>(vocabularies));
|
|
422 |
vocabularyService.merge(new ArrayList<>(vocabularies)); |
|
448 | 423 |
} finally { |
449 | 424 |
vocabularyService.delete(termVocabulary); |
450 | 425 |
} |
... | ... | |
454 | 429 |
public void saveNewTerm() { |
455 | 430 |
UUID vocNameFeatureUuid = UUID.fromString("fa7ca3eef-4092-49e1-beec-ed5096193e5e"); |
456 | 431 |
UUID vocFeatureUuid = UUID.fromString("b187d555-f06f-4d65-9e53-da7c93f8eaa8"); |
457 |
DefinedTermBase newTerm = TermType.Feature.getEmptyDefinedTermBase();
|
|
432 |
Feature newTerm = (Feature)TermType.Feature.getEmptyDefinedTermBase();
|
|
458 | 433 |
newTerm.setLabel("CreateTest"); |
459 | 434 |
|
460 | 435 |
try { |
... | ... | |
475 | 450 |
// } |
476 | 451 |
|
477 | 452 |
Assert.assertNotNull(newTerm); |
478 |
TermVocabulary vocNameFeature = vocabularyService.find(vocNameFeatureUuid); |
|
479 |
TermVocabulary vocFeature = vocabularyService.find(vocFeatureUuid); |
|
453 |
@SuppressWarnings("unchecked") |
|
454 |
TermVocabulary<Feature> vocNameFeature = vocabularyService.find(vocNameFeatureUuid); |
|
455 |
@SuppressWarnings("unchecked") |
|
456 |
TermVocabulary<Feature> vocFeature = vocabularyService.find(vocFeatureUuid); |
|
480 | 457 |
|
481 |
List<TermVocabulary> vocs = new ArrayList<TermVocabulary>(); |
|
458 |
@SuppressWarnings("rawtypes") |
|
459 |
List<TermVocabulary> vocs = new ArrayList<>(); |
|
482 | 460 |
|
483 | 461 |
vocs.add(vocNameFeature); |
484 | 462 |
vocs.add(vocFeature); |
485 | 463 |
|
486 | 464 |
vocNameFeature.addTerm(newTerm); |
487 | 465 |
|
488 |
List<MergeResult<TermVocabulary>> mergeResults = vocabularyService.merge(vocs, true);
|
|
466 |
List<MergeResult<TermVocabulary<Feature>>> mergeResults = (List)vocabularyService.merge(vocs, true);
|
|
489 | 467 |
|
490 |
for(MergeResult<TermVocabulary> result : mergeResults){ |
|
491 |
TermVocabulary voc = result.getMergedEntity(); |
|
468 |
for(MergeResult<TermVocabulary<Feature>> result : mergeResults){
|
|
469 |
TermVocabulary<Feature> voc = result.getMergedEntity();
|
|
492 | 470 |
if(voc.getUuid().equals(vocNameFeatureUuid)) { |
493 | 471 |
vocNameFeature = voc; |
494 | 472 |
} |
... | ... | |
496 | 474 |
|
497 | 475 |
Assert.assertTrue(vocNameFeature.getTerms().contains(newTerm)); |
498 | 476 |
|
499 |
for(Object obj : vocNameFeature.getTerms()) {
|
|
500 |
DefinedTermBase dtb = (DefinedTermBase)obj;
|
|
477 |
for(Feature obj : vocNameFeature.getTerms()) {
|
|
478 |
Feature dtb = obj;
|
|
501 | 479 |
if("CreateTest".equals(dtb.getLabel())) { |
502 | 480 |
newTerm = dtb; |
503 | 481 |
Assert.assertNotNull(dtb.getCreatedBy()); |
... | ... | |
508 | 486 |
} |
509 | 487 |
} |
510 | 488 |
newTerm.setLabel("UpdateTest"); |
511 |
newTerm = termService.merge(newTerm); |
|
489 |
newTerm = (Feature)termService.merge(newTerm);
|
|
512 | 490 |
Assert.assertNotNull(newTerm.getUpdatedBy()); |
513 | 491 |
Assert.assertNotNull(newTerm.getUpdated()); |
514 | 492 |
|
... | ... | |
521 | 499 |
} |
522 | 500 |
} |
523 | 501 |
|
524 |
|
|
525 | 502 |
@Test |
526 | 503 |
public void updatePerson() { |
527 | 504 |
// Test for #5138 |
... | ... | |
530 | 507 |
CdmApplicationState.getCurrentAppConfig().getAgentService().merge(person, true); |
531 | 508 |
} |
532 | 509 |
|
533 |
|
|
534 | 510 |
@Test |
535 | 511 |
public void createPerson() { |
536 | 512 |
// Test for #5138 |
Also available in: Unified diff
cleanup CdmEntitySessionAwareTest