32 itkFactorylessNewMacro(Self);
39 RuleIDType GetRuleID()
const override 47 return "TestRule_type1";
51 std::string GetDisplayName()
const override {
return "TestDisplayName"; }
52 std::string GetSourceRoleName()
const override {
return "source role"; }
53 std::string GetDestinationRoleName()
const override {
return "destination role"; }
57 bool IsAbstract()
const override {
return m_AbstractMode; }
59 using Superclass::GetRootKeyPath;
60 using Superclass::Connect;
63 TestRule() : m_AbstractMode(false)
67 ~TestRule()
override =
default;
72 bool IsSupportedRuleID(
const RuleIDType& ruleID)
const override 76 return ruleID.find(this->GetRuleID()) == 0;
80 return Superclass::IsSupportedRuleID(ruleID);
84 InstanceIDVectorType GetInstanceID_datalayer(
const IPropertyProvider *source,
85 const IPropertyProvider *destination)
const override 87 InstanceIDVectorType result;
89 auto destProp = destination->GetConstProperty(
"name");
91 if (destProp.IsNotNull())
95 auto regEx = std::regex(destRegExStr);
96 std::smatch instance_matches;
98 auto keys = source->GetPropertyKeys();
100 for (
const auto &key : keys)
102 if (std::regex_search(key, instance_matches, regEx))
104 auto sourceProp = source->GetConstProperty(key);
105 if (sourceProp->GetValueAsString() == destProp->GetValueAsString())
107 if (instance_matches.size()>1)
109 result.push_back(instance_matches[1]);
118 bool HasImplicitDataRelation(
const IPropertyProvider *source,
119 const IPropertyProvider *destination)
const override 121 auto destProp = destination->GetConstProperty(
"name");
122 auto sourceProp = source->GetConstProperty(
"referencedName");
124 return destProp.IsNotNull() && sourceProp.IsNotNull() &&
125 destProp->GetValueAsString() == sourceProp->GetValueAsString();
128 void Connect_datalayer(IPropertyOwner *source,
129 const IPropertyProvider *destination,
130 const InstanceIDType &instanceID)
const override 132 auto destProp = destination->GetConstProperty(
"name");
140 void Disconnect_datalayer(IPropertyOwner *source,
const InstanceIDType & )
const override 142 source->RemoveProperty(
"referencedName");
149 CPPUNIT_TEST_SUITE(mitkPropertyRelationRuleBaseTestSuite);
159 MITK_TEST(GetDestinationCandidateIndicator);
169 CPPUNIT_TEST_SUITE_END();
197 if (!instance.empty())
199 keyPath.AddElement(instance);
205 for (
const auto &key : keys)
207 if (key.find(prefix) == 0)
217 void setUp()
override 219 rule = mitk::TestRule::New();
221 abstractRule = mitk::TestRule::New();
222 abstractRule->m_AbstractMode =
true;
225 unRelated->SetName(
"unRelated");
227 unRelated->SetData(unRelated_1_data);
230 dest_1->SetName(
"dest_1");
232 dest_1->SetData(dest_1_data);
235 dest_2->SetName(
"dest_2");
237 dest_2->SetData(dest_2_data);
243 std::string name =
"MITK.Relations.1.relationUID";
245 name =
"MITK.Relations.1.destinationUID";
247 name =
"MITK.Relations.1.ruleID";
250 source_data_1 = source_implicit_1->Clone();
251 name =
"MITK.Relations.1.relationUID";
253 name =
"MITK.Relations.1.dataHandle";
255 name =
"MITK.Relations.1.ruleID";
257 name =
"MITK.Relations.2.relationUID";
259 name =
"MITK.Relations.2.destinationUID";
261 name =
"MITK.Relations.2.ruleID";
264 source_1 = source_data_1->Clone();
265 name =
"MITK.Relations.1.relationUID";
267 name =
"MITK.Relations.1.destinationUID";
269 name =
"MITK.Relations.1.ruleID";
271 name =
"MITK.Relations.2.relationUID";
273 name =
"MITK.Relations.2.destinationUID";
275 name =
"MITK.Relations.2.ruleID";
278 source_multi = source_1->Clone();
279 name =
"MITK.Relations.1.relationUID";
281 name =
"MITK.Relations.1.destinationUID";
283 name =
"MITK.Relations.1.ruleID";
285 name =
"MITK.Relations.4.relationUID";
287 name =
"MITK.Relations.4.destinationUID";
289 name =
"MITK.Relations.4.ruleID";
291 name =
"MITK.Relations.2.relationUID";
293 name =
"MITK.Relations.2.destinationUID";
295 name =
"MITK.Relations.2.ruleID";
299 name =
"MITK.Relations.1.relationUID";
301 name =
"MITK.Relations.1.destinationUID";
303 name =
"MITK.Relations.1.ruleID";
307 name =
"MITK.Relations.1.relationUID";
309 name =
"MITK.Relations.1.destinationUID";
311 name =
"MITK.Relations.1.ruleID";
315 void tearDown()
override {}
317 void GetRootKeyPath()
324 void IsSourceCandidate()
327 CPPUNIT_ASSERT(!rule->IsSourceCandidate(
nullptr));
330 void IsDestinationCandidate()
333 CPPUNIT_ASSERT(!rule->IsDestinationCandidate(
nullptr));
338 CPPUNIT_ASSERT_THROW_MESSAGE(
339 "Violated precondition (nullptr) does not throw.", rule->IsSource(
nullptr), itk::ExceptionObject);
341 CPPUNIT_ASSERT(!rule->IsSource(unRelated));
342 CPPUNIT_ASSERT(!rule->IsSource(source_implicit_1));
343 CPPUNIT_ASSERT(rule->IsSource(source_data_1));
344 CPPUNIT_ASSERT(rule->IsSource(source_idOnly_1));
345 CPPUNIT_ASSERT(rule->IsSource(source_1));
346 CPPUNIT_ASSERT(rule->IsSource(source_multi));
348 CPPUNIT_ASSERT(!rule->IsSource(source_otherRule));
349 CPPUNIT_ASSERT(!rule->IsSource(source_otherTypeRule));
351 CPPUNIT_ASSERT(!abstractRule->IsSource(unRelated));
352 CPPUNIT_ASSERT(!abstractRule->IsSource(source_implicit_1));
353 CPPUNIT_ASSERT(abstractRule->IsSource(source_data_1));
354 CPPUNIT_ASSERT(abstractRule->IsSource(source_idOnly_1));
355 CPPUNIT_ASSERT(abstractRule->IsSource(source_1));
356 CPPUNIT_ASSERT(abstractRule->IsSource(source_multi));
358 CPPUNIT_ASSERT(!abstractRule->IsSource(source_otherRule));
359 CPPUNIT_ASSERT(abstractRule->IsSource(source_otherTypeRule));
364 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (source is nullptr) does not throw.",
365 rule->HasRelation(
nullptr, dest_1),
366 itk::ExceptionObject);
368 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (destination is nullptr) does not throw.",
369 rule->HasRelation(source_1,
nullptr),
370 itk::ExceptionObject);
377 CPPUNIT_ASSERT(rule->HasRelation(source_implicit_1, dest_1) ==
379 CPPUNIT_ASSERT(rule->HasRelation(source_data_1, dest_1) ==
381 CPPUNIT_ASSERT(rule->HasRelation(source_idOnly_1, dest_1) ==
384 CPPUNIT_ASSERT(rule->HasRelation(source_multi, dest_1) ==
388 CPPUNIT_ASSERT(rule->HasRelation(source_multi, dest_2) ==
395 CPPUNIT_ASSERT(abstractRule->HasRelation(source_otherTypeRule, dest_1) ==
398 CPPUNIT_ASSERT(abstractRule->HasRelation(source_implicit_1, dest_1) ==
400 CPPUNIT_ASSERT(abstractRule->HasRelation(source_data_1, dest_1) ==
402 CPPUNIT_ASSERT(abstractRule->HasRelation(source_idOnly_1, dest_1) ==
405 CPPUNIT_ASSERT(abstractRule->HasRelation(source_multi, dest_1) ==
409 CPPUNIT_ASSERT(abstractRule->HasRelation(source_multi, dest_2) ==
413 void GetExistingRelations()
415 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (source is nullptr) does not throw.",
416 rule->GetExistingRelations(
nullptr),
417 itk::ExceptionObject);
419 CPPUNIT_ASSERT(rule->GetExistingRelations(unRelated).empty());
420 CPPUNIT_ASSERT(rule->GetExistingRelations(source_otherRule).empty());
421 CPPUNIT_ASSERT(rule->GetExistingRelations(source_otherTypeRule).empty());
422 CPPUNIT_ASSERT(rule->GetExistingRelations(source_implicit_1).empty());
424 auto uids = rule->GetExistingRelations(source_idOnly_1);
425 CPPUNIT_ASSERT(uids.size() == 1);
426 CPPUNIT_ASSERT(uids.front() ==
"uid1");
428 uids = rule->GetExistingRelations(source_data_1);
429 CPPUNIT_ASSERT(uids.size() == 1);
430 CPPUNIT_ASSERT(uids.front() ==
"uid2");
432 uids = rule->GetExistingRelations(source_1);
433 CPPUNIT_ASSERT(uids.size() == 1);
434 CPPUNIT_ASSERT(uids.front() ==
"uid3");
436 uids = rule->GetExistingRelations(source_multi);
437 CPPUNIT_ASSERT(uids.size() == 3);
438 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid4") != uids.end());
439 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid5") != uids.end());
440 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid6") != uids.end());
443 CPPUNIT_ASSERT(abstractRule->GetExistingRelations(unRelated).empty());
444 CPPUNIT_ASSERT(abstractRule->GetExistingRelations(source_otherRule).empty());
445 CPPUNIT_ASSERT(abstractRule->GetExistingRelations(source_implicit_1).empty());
447 uids = abstractRule->GetExistingRelations(source_idOnly_1);
448 CPPUNIT_ASSERT(uids.size() == 1);
449 CPPUNIT_ASSERT(uids.front() ==
"uid1");
451 uids = abstractRule->GetExistingRelations(source_data_1);
452 CPPUNIT_ASSERT(uids.size() == 2);
453 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid2") != uids.end());
454 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid10") != uids.end());
456 uids = abstractRule->GetExistingRelations(source_1);
457 CPPUNIT_ASSERT(uids.size() == 2);
458 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid3") != uids.end());
459 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid8") != uids.end());
461 uids = abstractRule->GetExistingRelations(source_multi);
462 CPPUNIT_ASSERT(uids.size() == 3);
463 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid4") != uids.end());
464 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid5") != uids.end());
465 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid6") != uids.end());
467 uids = abstractRule->GetExistingRelations(source_otherTypeRule);
468 CPPUNIT_ASSERT(uids.size() == 1);
469 CPPUNIT_ASSERT(uids.front() ==
"uid9");
473 void GetRelationUIDs()
475 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (source is nullptr) does not throw.",
476 rule->GetRelationUIDs(
nullptr, dest_1),
477 itk::ExceptionObject);
479 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (destination is nullptr) does not throw.",
480 rule->GetRelationUIDs(source_1,
nullptr),
481 itk::ExceptionObject);
483 CPPUNIT_ASSERT(rule->GetRelationUIDs(source_1, unRelated).empty());
484 CPPUNIT_ASSERT(rule->GetRelationUIDs(source_1, dest_2).empty());
485 CPPUNIT_ASSERT(rule->GetRelationUIDs(unRelated, dest_1).empty());
486 CPPUNIT_ASSERT(rule->GetRelationUIDs(source_otherRule, dest_1).empty());
487 CPPUNIT_ASSERT(rule->GetRelationUIDs(source_otherTypeRule, dest_1).empty());
489 CPPUNIT_ASSERT(rule->GetRelationUIDs(source_idOnly_1, dest_1).front() ==
"uid1");
490 CPPUNIT_ASSERT(rule->GetRelationUIDs(source_data_1, dest_1).front() ==
"uid2");
491 auto uids = rule->GetRelationUIDs(source_1, dest_1);
492 CPPUNIT_ASSERT(uids.size() == 1);
493 CPPUNIT_ASSERT(uids.front() ==
"uid3");
494 CPPUNIT_ASSERT(rule->GetRelationUIDs(source_multi, dest_1).front() ==
"uid4");
495 CPPUNIT_ASSERT(rule->GetRelationUIDs(source_multi, dest_2).front() ==
"uid5");
497 CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(source_1, unRelated).empty());
498 CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(unRelated, dest_1).empty());
499 CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(source_otherRule, dest_1).empty());
500 CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(source_otherTypeRule, dest_1).front() ==
"uid9");
502 CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(source_idOnly_1, dest_1).front() ==
"uid1");
503 uids = abstractRule->GetRelationUIDs(source_data_1, dest_1);
504 CPPUNIT_ASSERT(uids.size() == 2);
505 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid2") != uids.end());
506 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid10") != uids.end());
507 uids = abstractRule->GetRelationUIDs(source_1, dest_1);
508 CPPUNIT_ASSERT(uids.size() == 1);
509 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid3") != uids.end());
510 uids = abstractRule->GetRelationUIDs(source_1, dest_2);
511 CPPUNIT_ASSERT(uids.size() == 1);
512 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid8") != uids.end());
513 CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(source_1, dest_1).front() ==
"uid3");
514 CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(source_multi, dest_1).front() ==
"uid4");
515 CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(source_multi, dest_2).front() ==
"uid5");
519 void GetSourceCandidateIndicator()
521 auto predicate = rule->GetSourceCandidateIndicator();
524 CPPUNIT_ASSERT(!predicate->CheckNode(
nullptr));
527 void GetDestinationCandidateIndicator()
529 auto predicate = rule->GetDestinationCandidateIndicator();
532 CPPUNIT_ASSERT(!predicate->CheckNode(
nullptr));
535 void GetConnectedSourcesDetector()
537 auto predicate = rule->GetConnectedSourcesDetector();
539 CPPUNIT_ASSERT(!predicate->CheckNode(
nullptr));
540 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated));
541 CPPUNIT_ASSERT(!predicate->CheckNode(source_implicit_1));
542 CPPUNIT_ASSERT(predicate->CheckNode(source_data_1));
543 CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1));
544 CPPUNIT_ASSERT(predicate->CheckNode(source_1));
545 CPPUNIT_ASSERT(predicate->CheckNode(source_multi));
547 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule));
548 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherTypeRule));
551 auto predicate2 = abstractRule->GetConnectedSourcesDetector();
553 CPPUNIT_ASSERT(!predicate2->CheckNode(
nullptr));
554 CPPUNIT_ASSERT(!predicate2->CheckNode(unRelated));
555 CPPUNIT_ASSERT(!predicate2->CheckNode(source_implicit_1));
556 CPPUNIT_ASSERT(predicate2->CheckNode(source_data_1));
557 CPPUNIT_ASSERT(predicate2->CheckNode(source_idOnly_1));
558 CPPUNIT_ASSERT(predicate2->CheckNode(source_1));
559 CPPUNIT_ASSERT(predicate2->CheckNode(source_multi));
561 CPPUNIT_ASSERT(!predicate2->CheckNode(source_otherRule));
562 CPPUNIT_ASSERT(predicate2->CheckNode(source_otherTypeRule));
565 void GetSourcesDetector()
567 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (destination is nullptr) does not throw.",
568 rule->GetSourcesDetector(
nullptr),
569 itk::ExceptionObject);
571 auto predicate = rule->GetSourcesDetector(dest_1);
573 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated));
574 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule));
575 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherTypeRule));
577 CPPUNIT_ASSERT(predicate->CheckNode(source_implicit_1));
578 CPPUNIT_ASSERT(predicate->CheckNode(source_data_1));
579 CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1));
580 CPPUNIT_ASSERT(predicate->CheckNode(source_1));
581 CPPUNIT_ASSERT(predicate->CheckNode(source_multi));
585 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated));
586 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule));
587 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherTypeRule));
589 CPPUNIT_ASSERT(!predicate->CheckNode(source_implicit_1));
590 CPPUNIT_ASSERT(predicate->CheckNode(source_data_1));
591 CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1));
592 CPPUNIT_ASSERT(predicate->CheckNode(source_1));
593 CPPUNIT_ASSERT(predicate->CheckNode(source_multi));
597 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated));
598 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule));
599 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherTypeRule));
601 CPPUNIT_ASSERT(!predicate->CheckNode(source_implicit_1));
602 CPPUNIT_ASSERT(!predicate->CheckNode(source_data_1));
603 CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1));
604 CPPUNIT_ASSERT(predicate->CheckNode(source_1));
605 CPPUNIT_ASSERT(predicate->CheckNode(source_multi));
609 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated));
610 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule));
611 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherTypeRule));
613 CPPUNIT_ASSERT(!predicate->CheckNode(source_implicit_1));
614 CPPUNIT_ASSERT(!predicate->CheckNode(source_data_1));
615 CPPUNIT_ASSERT(!predicate->CheckNode(source_idOnly_1));
616 CPPUNIT_ASSERT(!predicate->CheckNode(source_1));
617 CPPUNIT_ASSERT(predicate->CheckNode(source_multi));
621 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated));
622 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule));
623 CPPUNIT_ASSERT(predicate->CheckNode(source_otherTypeRule));
625 CPPUNIT_ASSERT(!predicate->CheckNode(source_implicit_1));
626 CPPUNIT_ASSERT(predicate->CheckNode(source_data_1));
627 CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1));
628 CPPUNIT_ASSERT(predicate->CheckNode(source_1));
629 CPPUNIT_ASSERT(predicate->CheckNode(source_multi));
631 predicate = abstractRule->GetSourcesDetector(dest_1);
633 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated));
634 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule));
635 CPPUNIT_ASSERT(predicate->CheckNode(source_otherTypeRule));
637 CPPUNIT_ASSERT(predicate->CheckNode(source_implicit_1));
638 CPPUNIT_ASSERT(predicate->CheckNode(source_data_1));
639 CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1));
640 CPPUNIT_ASSERT(predicate->CheckNode(source_1));
641 CPPUNIT_ASSERT(predicate->CheckNode(source_multi));
644 void GetDestinationsDetector()
646 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (source is nullptr) does not throw.",
647 rule->GetDestinationsDetector(
nullptr),
648 itk::ExceptionObject);
650 auto predicate = rule->GetDestinationsDetector(source_otherRule);
651 CPPUNIT_ASSERT(!predicate->CheckNode(dest_1));
653 predicate = rule->GetDestinationsDetector(source_otherTypeRule);
654 CPPUNIT_ASSERT(!predicate->CheckNode(dest_1));
656 predicate = rule->GetDestinationsDetector(source_implicit_1);
657 CPPUNIT_ASSERT(predicate->CheckNode(dest_1));
660 CPPUNIT_ASSERT(!predicate->CheckNode(dest_1));
662 predicate = rule->GetDestinationsDetector(source_data_1);
663 CPPUNIT_ASSERT(predicate->CheckNode(dest_1));
666 CPPUNIT_ASSERT(predicate->CheckNode(dest_1));
669 CPPUNIT_ASSERT(!predicate->CheckNode(dest_1));
671 predicate = rule->GetDestinationsDetector(source_idOnly_1);
672 CPPUNIT_ASSERT(predicate->CheckNode(dest_1));
675 CPPUNIT_ASSERT(predicate->CheckNode(dest_1));
678 CPPUNIT_ASSERT(predicate->CheckNode(dest_1));
680 predicate = rule->GetDestinationsDetector(source_1);
681 CPPUNIT_ASSERT(predicate->CheckNode(dest_1));
682 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated));
683 CPPUNIT_ASSERT(!predicate->CheckNode(dest_2));
686 CPPUNIT_ASSERT(predicate->CheckNode(dest_1));
687 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated));
688 CPPUNIT_ASSERT(!predicate->CheckNode(dest_2));
691 CPPUNIT_ASSERT(predicate->CheckNode(dest_1));
692 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated));
693 CPPUNIT_ASSERT(!predicate->CheckNode(dest_2));
695 predicate = rule->GetDestinationsDetector(source_multi);
696 CPPUNIT_ASSERT(predicate->CheckNode(dest_1));
697 CPPUNIT_ASSERT(predicate->CheckNode(dest_2));
700 CPPUNIT_ASSERT(predicate->CheckNode(dest_1));
701 CPPUNIT_ASSERT(predicate->CheckNode(dest_2));
704 CPPUNIT_ASSERT(predicate->CheckNode(dest_1));
705 CPPUNIT_ASSERT(predicate->CheckNode(dest_2));
707 predicate = abstractRule->GetDestinationsDetector(source_otherTypeRule);
708 CPPUNIT_ASSERT(predicate->CheckNode(dest_1));
709 predicate = abstractRule->GetDestinationsDetector(source_otherTypeRule);
710 CPPUNIT_ASSERT(predicate->CheckNode(dest_1));
714 void GetDestinationDetector()
716 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (source is nullptr) does not throw.",
717 rule->GetDestinationDetector(
nullptr,
"uid1"),
718 itk::ExceptionObject);
720 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (relation uid is invalid) does not throw.",
721 rule->GetDestinationDetector(source_1,
"invalid uid"),
722 itk::ExceptionObject);
724 auto predicate = rule->GetDestinationDetector(source_1,
"uid3");
725 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated));
726 CPPUNIT_ASSERT(predicate->CheckNode(dest_1));
727 CPPUNIT_ASSERT(!predicate->CheckNode(dest_2));
729 predicate = rule->GetDestinationDetector(source_multi,
"uid5");
730 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated));
731 CPPUNIT_ASSERT(!predicate->CheckNode(dest_1));
732 CPPUNIT_ASSERT(predicate->CheckNode(dest_2));
737 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (source is nullptr) does not throw.",
738 rule->Connect(
nullptr, dest_1),
739 itk::ExceptionObject);
741 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (destination is nullptr) does not throw.",
742 rule->Connect(source_1,
nullptr),
743 itk::ExceptionObject);
746 CPPUNIT_ASSERT(rule->HasRelation(source_implicit_1, dest_1) ==
748 rule->Connect(source_implicit_1, dest_1);
749 CPPUNIT_ASSERT(rule->HasRelation(source_implicit_1, dest_1) ==
753 CPPUNIT_ASSERT(rule->HasRelation(source_data_1, dest_1) ==
755 rule->Connect(source_data_1, dest_1);
756 CPPUNIT_ASSERT(rule->HasRelation(source_data_1, dest_1) ==
758 std::string name =
"MITK.Relations.1.destinationUID";
759 auto prop = source_data_1->GetProperty(name.c_str());
760 CPPUNIT_ASSERT_MESSAGE(
761 "Destination uid was not stored with the correct key. Already existing session should be used.", prop);
762 CPPUNIT_ASSERT_MESSAGE(
"Incorrect destination uid was stored.", prop->GetValueAsString() == dest_1_data->GetUID());
765 rule->Connect(source_idOnly_1, dest_1);
766 CPPUNIT_ASSERT(rule->HasRelation(source_idOnly_1, dest_1) ==
768 CPPUNIT_ASSERT_MESSAGE(
"Additional relation was defined instead of updating exting one.",
769 rule->GetExistingRelations(source_1).size() == 1);
770 name =
"MITK.Relations.1.dataHandle";
771 prop = source_idOnly_1->GetProperty(name.c_str());
772 CPPUNIT_ASSERT_MESSAGE(
773 "Data layer information was not stored with the correct key. Already existing session should be used.", prop);
774 CPPUNIT_ASSERT_MESSAGE(
"Incorrect data layer information not stored.",
775 prop->GetValueAsString() == dest_1->GetName());
776 prop = source_idOnly_1->GetProperty(
"referencedName");
777 CPPUNIT_ASSERT_MESSAGE(
778 "Data layer information was not stored with the correct key. Already existing session should be used.", prop);
779 CPPUNIT_ASSERT_MESSAGE(
"Incorrect data layer information was stored.",
780 prop->GetValueAsString() == dest_1->GetName());
783 rule->Connect(source_1, dest_1);
785 CPPUNIT_ASSERT_MESSAGE(
"Additional relation was defined instead of updating exting one.",
786 rule->GetExistingRelations(source_1).size() == 1);
789 auto newConnectUID = rule->Connect(source_multi, unRelated);
790 CPPUNIT_ASSERT(rule->HasRelation(source_multi, unRelated) ==
792 name =
"MITK.Relations.5.dataHandle";
793 prop = source_multi->GetProperty(name.c_str());
794 CPPUNIT_ASSERT_MESSAGE(
795 "Data layer information was not stored with the correct key. Already existing session should be used.", prop);
796 CPPUNIT_ASSERT_MESSAGE(
"Incorrect data layer information was stored.",
797 prop->GetValueAsString() == unRelated->GetName());
798 prop = source_multi->GetProperty(
"referencedName");
799 CPPUNIT_ASSERT_MESSAGE(
800 "Data layer information was not stored with the correct key. Already existing session should be used.", prop);
801 CPPUNIT_ASSERT_MESSAGE(
"Incorrect data layer information was stored.",
802 prop->GetValueAsString() == unRelated->GetName());
803 name =
"MITK.Relations.5.destinationUID";
804 prop = source_multi->GetProperty(name.c_str());
805 CPPUNIT_ASSERT_MESSAGE(
806 "Destination uid was not stored with the correct key. Already existing session should be used.", prop);
807 CPPUNIT_ASSERT_MESSAGE(
"Incorrect destination uid was stored.", prop->GetValueAsString() == unRelated_1_data->GetUID());
809 auto storedRelationUIDs = rule->GetRelationUIDs(source_multi, unRelated);
810 CPPUNIT_ASSERT_MESSAGE(
811 "Relation uid was not stored for given source and destination.", storedRelationUIDs.size() == 1);
812 CPPUNIT_ASSERT_MESSAGE(
"Incorrect Relation uid was stored.", storedRelationUIDs[0] == newConnectUID);
817 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (source is nullptr) does not throw.",
818 rule->Disconnect(
nullptr, dest_1),
819 itk::ExceptionObject);
821 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (destination is nullptr) does not throw.",
822 rule->Disconnect(source_1,
nullptr),
823 itk::ExceptionObject);
825 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (destination is nullptr) does not throw.",
826 rule->Disconnect(
nullptr,
"uid"),
827 itk::ExceptionObject);
830 rule->Disconnect(source_1, unRelated);
832 CPPUNIT_ASSERT_MESSAGE(
"Data property was not removed.", !source_1->GetProperty(
"referencedName"));
834 rule->Disconnect(source_1, dest_2);
836 CPPUNIT_ASSERT(this->hasRelationProperties(source_1));
839 rule->Disconnect(source_1, dest_1);
841 CPPUNIT_ASSERT(!this->hasRelationProperties(source_1,
"1"));
842 CPPUNIT_ASSERT_MESSAGE(
"Data of other rule type was removed.",this->hasRelationProperties(source_1,
"2"));
844 CPPUNIT_ASSERT(rule->HasRelation(source_multi, dest_1) ==
846 rule->Disconnect(source_multi, dest_1);
848 CPPUNIT_ASSERT(!this->hasRelationProperties(source_multi,
"1"));
849 CPPUNIT_ASSERT(this->hasRelationProperties(source_multi,
"2"));
850 CPPUNIT_ASSERT(this->hasRelationProperties(source_multi,
"4"));
852 rule->Disconnect(source_multi,
"uid6");
853 CPPUNIT_ASSERT(!this->hasRelationProperties(source_multi,
"1"));
854 CPPUNIT_ASSERT(!this->hasRelationProperties(source_multi,
"2"));
855 CPPUNIT_ASSERT(this->hasRelationProperties(source_multi,
"4"));
857 rule->Disconnect(source_multi,
"unkownRelationUID");
858 CPPUNIT_ASSERT(!this->hasRelationProperties(source_multi,
"1"));
859 CPPUNIT_ASSERT(!this->hasRelationProperties(source_multi,
"2"));
860 CPPUNIT_ASSERT(this->hasRelationProperties(source_multi,
"4"));
862 rule->Disconnect(source_otherTypeRule, dest_1);
863 CPPUNIT_ASSERT_MESSAGE(
"Data of other rule type was removed.", this->hasRelationProperties(source_otherTypeRule,
"1"));
866 void Connect_abstract()
868 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (abstract does not connect) does not throw.",
869 abstractRule->Connect(
nullptr, dest_1),
870 itk::ExceptionObject);
872 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (abstract does not connect) does not throw.",
873 abstractRule->Connect(source_1,
nullptr),
874 itk::ExceptionObject);
877 void Disconnect_abstract()
881 abstractRule->Disconnect(source_1, dest_2);
883 CPPUNIT_ASSERT(!this->hasRelationProperties(source_1,
"2"));
886 abstractRule->Disconnect(source_1, dest_1);
888 CPPUNIT_ASSERT(!this->hasRelationProperties(source_1,
"1"));
890 CPPUNIT_ASSERT(abstractRule->HasRelation(source_multi, dest_1) ==
892 abstractRule->Disconnect(source_multi, dest_1);
894 CPPUNIT_ASSERT(!this->hasRelationProperties(source_multi,
"1"));
895 CPPUNIT_ASSERT(this->hasRelationProperties(source_multi,
"2"));
896 CPPUNIT_ASSERT(this->hasRelationProperties(source_multi,
"4"));
898 abstractRule->Disconnect(source_multi,
"uid6");
899 CPPUNIT_ASSERT(!this->hasRelationProperties(source_multi,
"1"));
900 CPPUNIT_ASSERT(!this->hasRelationProperties(source_multi,
"2"));
901 CPPUNIT_ASSERT(this->hasRelationProperties(source_multi,
"4"));
903 abstractRule->Disconnect(source_multi,
"unkownRelationUID");
904 CPPUNIT_ASSERT(!this->hasRelationProperties(source_multi,
"1"));
905 CPPUNIT_ASSERT(!this->hasRelationProperties(source_multi,
"2"));
906 CPPUNIT_ASSERT(this->hasRelationProperties(source_multi,
"4"));
908 abstractRule->Disconnect(source_otherTypeRule, dest_1);
909 CPPUNIT_ASSERT_MESSAGE(
"Data of other rule type was removed.", !this->hasRelationProperties(source_otherTypeRule,
"1"));
MITKCORE_EXPORT std::string PropertyKeyPathToPropertyName(const PropertyKeyPath &tagPath)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
std::string InstanceIDType
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
DataCollection - Class to facilitate loading/accessing structured data.
PropertyKeyPath & AddElement(const ElementNameType &name)
static PropertyKeyPath GetRootKeyPath()
virtual std::vector< std::string > GetPropertyKeys(const std::string &contextName="", bool includeDefaultContext=false) const =0
Query keys of existing properties.
Identifiable::UIDType RelationUIDType
#define mitkClassMacro(className, SuperClassName)
Test fixture for parameterized tests.
std::vector< RelationUIDType > RelationUIDVectorType
std::vector< InstanceIDType > InstanceIDVectorType
Class that can be used to specify nested or wild carded property keys. E.g. for the use in context of...
MITKCORE_EXPORT std::string PropertyKeyPathToPropertyRegEx(const PropertyKeyPath &tagPath)