Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkSourceImageRelationRuleTest.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 #include "mitkDataNode.h"
16 #include "mitkPointSet.h"
17 #include "mitkStringProperty.h"
18 
19 #include "mitkTestFixture.h"
20 #include "mitkTestingMacros.h"
21 #include "mitkPropertyNameHelper.h"
23 #include "mitkPropertyNameHelper.h"
24 
25 #include <regex>
26 
27 class mitkSourceImageRelationRuleTestSuite : public mitk::TestFixture
28 {
29  CPPUNIT_TEST_SUITE(mitkSourceImageRelationRuleTestSuite);
30 
31  MITK_TEST(IsSourceCandidate);
32  MITK_TEST(IsDestinationCandidate);
33  MITK_TEST(IsSource);
34  MITK_TEST(HasRelation);
35  MITK_TEST(GetExistingRelations);
36  MITK_TEST(GetRelationUIDs);
37  MITK_TEST(GetSourceCandidateIndicator);
38  MITK_TEST(GetDestinationCandidateIndicator);
39  MITK_TEST(GetConnectedSourcesDetector);
40  MITK_TEST(GetSourcesDetector);
41  MITK_TEST(GetDestinationsDetector);
42  MITK_TEST(GetDestinationDetector);
43  MITK_TEST(Connect);
44  MITK_TEST(Disconnect);
45  MITK_TEST(Connect_abstract);
46  MITK_TEST(Disconnect_abstract);
47 
48  CPPUNIT_TEST_SUITE_END();
49 
50 private:
53 
54  mitk::Image::Pointer unRelated;
55  mitk::DataNode::Pointer unRelated_Node;
56 
57  mitk::Image::Pointer source_implicit_1;
58  mitk::DataNode::Pointer source_implicit_1_Node;
59  mitk::Image::Pointer source_data_1;
60  mitk::DataNode::Pointer source_data_1_Node;
61  mitk::Image::Pointer source_idOnly_1;
62  mitk::DataNode::Pointer source_idOnly_1_Node;
63  mitk::Image::Pointer source_1;
64  mitk::DataNode::Pointer source_1_Node;
65 
66  mitk::Image::Pointer source_otherRule;
67  mitk::DataNode::Pointer source_otherRule_Node;
68 
69  mitk::Image::Pointer source_otherPurpose;
70  mitk::DataNode::Pointer source_otherPurpose_Node; //relevant for abstract rule checks. Abstract rule should see it concrete rule not.
71 
72  mitk::DataNode::Pointer dest_1_Node;
73  mitk::Image::Pointer dest_1;
74  mitk::DataNode::Pointer dest_2_Node;
75  mitk::Image::Pointer dest_2;
76 
77  bool hasRelationProperties(mitk::IPropertyProvider *provider, std::string instance = "") const
78  {
80  if (!instance.empty())
81  {
82  keyPath.AddElement(instance);
83  }
84 
85  auto prefix = mitk::PropertyKeyPathToPropertyName(keyPath);
86  auto keys = provider->GetPropertyKeys();
87 
88  for (const auto &key : keys)
89  {
90  if (key.find(prefix) == 0)
91  {
92  return true;
93  }
94  }
95 
96  return false;
97  }
98 
99  std::vector<std::string> GetReferenceSequenceIndices(const mitk::IPropertyProvider * source,
100  const mitk::IPropertyProvider * destination) const
101  {
102  std::vector<std::string> result;
103 
104  auto destInstanceUIDProp = destination->GetConstProperty(mitk::GeneratePropertyNameForDICOMTag(0x0008, 0x0018));
105 
106  if (destInstanceUIDProp.IsNull())
107  {
108  return result;
109  }
110 
111  mitk::PropertyKeyPath referencedInstanceUIDs;
112  referencedInstanceUIDs.AddElement("DICOM").AddElement("0008").AddAnySelection("2112").AddElement("0008").AddElement("1155");
113 
114  auto sourceRegExStr = PropertyKeyPathToPropertyRegEx(referencedInstanceUIDs);;
115  auto regEx = std::regex(sourceRegExStr);
116 
117  std::vector<std::string> keys;
118  //workaround until T24729 is done. Please remove if T24728 is done
119  keys = source->GetPropertyKeys();
120  //end workaround for T24729
121 
122  for (const auto &key : keys)
123  {
124  if (std::regex_match(key, regEx))
125  {
126  auto refUIDProp = source->GetConstProperty(key);
127  if (*refUIDProp == *destInstanceUIDProp)
128  {
130  result.push_back(std::to_string(finding.GetNode(2).selection));
131  }
132  }
133  }
134 
135  return result;
136  };
137 
138  void SetDICOMReferenceInfo(mitk::IPropertyOwner* owner, const std::string& instanceUID, const std::string& classUID, const std::string& purpose, unsigned int sequElement)
139  {
140  mitk::PropertyKeyPath refInstanceUIDPath;
141  refInstanceUIDPath.AddElement("DICOM").AddElement("0008").AddSelection("2112", sequElement).AddElement("0008").AddElement("1155");
143 
144  mitk::PropertyKeyPath refClassUIDPath;
145  refClassUIDPath.AddElement("DICOM").AddElement("0008").AddSelection("2112", sequElement).AddElement("0008").AddElement("1150");
147 
148  mitk::PropertyKeyPath purposePath;
149  purposePath.AddElement("DICOM").AddElement("0008").AddSelection("2112", sequElement).AddElement("0040").AddSelection("a170", 0).AddElement("0008").AddElement("0104");
151  }
152 
153  bool IsCorrectDICOMReference(const mitk::IPropertyOwner* owner, const std::string& instanceUID, const std::string& classUID, const std::string& purpose, unsigned int sequElement) const
154  {
155  mitk::PropertyKeyPath refInstanceUIDPath;
156  refInstanceUIDPath.AddElement("DICOM").AddElement("0008").AddSelection("2112", sequElement).AddElement("0008").AddElement("1155");
157  auto prop = owner->GetConstProperty(PropertyKeyPathToPropertyName(refInstanceUIDPath));
158  if (prop->GetValueAsString() != instanceUID)
159  {
160  return false;
161  }
162 
163  mitk::PropertyKeyPath refClassUIDPath;
164  refClassUIDPath.AddElement("DICOM").AddElement("0008").AddSelection("2112", sequElement).AddElement("0008").AddElement("1150");
165  prop = owner->GetConstProperty(PropertyKeyPathToPropertyName(refClassUIDPath));
166  if (prop->GetValueAsString() != classUID)
167  {
168  return false;
169  }
170 
171  mitk::PropertyKeyPath purposePath;
172  purposePath.AddElement("DICOM").AddElement("0008").AddSelection("2112", sequElement).AddElement("0040").AddSelection("a170", 0).AddElement("0008").AddElement("0104");
173  prop = owner->GetConstProperty(PropertyKeyPathToPropertyName(purposePath));
174  if (prop->GetValueAsString() != purpose)
175  {
176  return false;
177  }
178 
179  return true;
180  }
181 
182 
183 public:
184  void setUp() override
185  {
186  auto instanceUIDPropName = mitk::GeneratePropertyNameForDICOMTag(0x0008, 0x0018);
187  auto classUIDPropName = mitk::GeneratePropertyNameForDICOMTag(0x0008, 0x0016);
188 
189  rule = mitk::SourceImageRelationRule::New("Test");
190 
191  abstractRule = mitk::SourceImageRelationRule::New();
192 
193  unRelated = mitk::Image::New();
194  unRelated->SetProperty(instanceUIDPropName, mitk::TemporoSpatialStringProperty::New("unRelated"));
195  unRelated->SetProperty(classUIDPropName, mitk::TemporoSpatialStringProperty::New("image"));
196  unRelated_Node = mitk::DataNode::New();
197  unRelated_Node->SetData(unRelated);
198 
199  dest_1_Node = mitk::DataNode::New();
200  dest_1_Node->SetName("dest_1");
201  dest_1 = mitk::Image::New();
202  dest_1->SetProperty(instanceUIDPropName, mitk::TemporoSpatialStringProperty::New("dest_1"));
203  dest_1->SetProperty(classUIDPropName, mitk::TemporoSpatialStringProperty::New("image"));
204  dest_1_Node->SetData(dest_1);
205 
206 
207 
208  dest_2_Node = mitk::DataNode::New();
209  dest_2_Node->SetName("dest_2");
210  dest_2 = mitk::Image::New();
211  dest_2->SetProperty(instanceUIDPropName, mitk::TemporoSpatialStringProperty::New("dest_2"));
212  dest_2->SetProperty(classUIDPropName, mitk::TemporoSpatialStringProperty::New("image"));
213  dest_2_Node->SetData(dest_2);
214 
215  source_implicit_1 = mitk::Image::New();
216  SetDICOMReferenceInfo(source_implicit_1, "dest_1", "image", "Test", 0);
217  source_implicit_1_Node = mitk::DataNode::New();
218  source_implicit_1_Node->SetData(source_implicit_1);
219 
220  source_idOnly_1 = mitk::Image::New();
221  std::string name = "MITK.Relations.1.relationUID";
222  source_idOnly_1->SetProperty(name.c_str(), mitk::StringProperty::New("uid1"));
223  name = "MITK.Relations.1.destinationUID";
224  source_idOnly_1->SetProperty(name.c_str(), mitk::StringProperty::New(dest_1->GetUID()));
225  name = "MITK.Relations.1.ruleID";
226  source_idOnly_1->SetProperty(name.c_str(), mitk::StringProperty::New(rule->GetRuleID()));
227  source_idOnly_1_Node = mitk::DataNode::New();
228  source_idOnly_1_Node->SetData(source_idOnly_1);
229 
230  source_data_1 = mitk::Image::New();
231  SetDICOMReferenceInfo(source_data_1, "dest_1", "image", "Test", 0);
232  SetDICOMReferenceInfo(source_data_1, "dest_2", "image", "otherpurpose", 1);
233  name = "MITK.Relations.1.relationUID";
234  source_data_1->SetProperty(name.c_str(), mitk::StringProperty::New("uid2"));
235  name = "MITK.Relations.1.ruleID";
236  source_data_1->SetProperty(name.c_str(), mitk::StringProperty::New(rule->GetRuleID()));
237  name = "MITK.Relations.1.SourceImageSequenceItem";
238  source_data_1->SetProperty(name.c_str(), mitk::StringProperty::New("0"));
239  name = "MITK.Relations.2.relationUID";
240  source_data_1->SetProperty(name.c_str(), mitk::StringProperty::New("uid10"));
241  name = "MITK.Relations.2.SourceImageSequenceItem";
242  source_data_1->SetProperty(name.c_str(), mitk::StringProperty::New("1"));
243  name = "MITK.Relations.2.ruleID";
244  source_data_1->SetProperty(name.c_str(), mitk::StringProperty::New("SourceImageRelation otherpurpose"));
245  source_data_1_Node = mitk::DataNode::New();
246  source_data_1_Node->SetData(source_data_1);
247 
248  source_1 = mitk::Image::New();
249  SetDICOMReferenceInfo(source_1, "dest_1", "image", "Test", 0);
250  SetDICOMReferenceInfo(source_1, "dest_2", "image", "otherpurpose", 1);
251  name = "MITK.Relations.1.relationUID";
252  source_1->SetProperty(name.c_str(), mitk::StringProperty::New("uid3"));
253  name = "MITK.Relations.1.destinationUID";
254  source_1->SetProperty(name.c_str(), mitk::StringProperty::New(dest_1->GetUID()));
255  name = "MITK.Relations.1.ruleID";
256  source_1->SetProperty(name.c_str(), mitk::StringProperty::New(rule->GetRuleID()));
257  name = "MITK.Relations.1.SourceImageSequenceItem";
258  source_1->SetProperty(name.c_str(), mitk::StringProperty::New("0"));
259  name = "MITK.Relations.2.relationUID";
260  source_1->SetProperty(name.c_str(), mitk::StringProperty::New("uid8"));
261  name = "MITK.Relations.2.destinationUID";
262  source_1->SetProperty(name.c_str(), mitk::StringProperty::New(dest_2->GetUID()));
263  name = "MITK.Relations.2.ruleID";
264  source_1->SetProperty(name.c_str(), mitk::StringProperty::New("SourceImageRelation otherpurpose"));
265  name = "MITK.Relations.2.SourceImageSequenceItem";
266  source_1->SetProperty(name.c_str(), mitk::StringProperty::New("1"));
267  source_1_Node = mitk::DataNode::New();
268  source_1_Node->SetData(source_1);
269 
270  source_otherRule = mitk::Image::New();
271  name = "MITK.Relations.1.relationUID";
272  source_otherRule->SetProperty(name.c_str(), mitk::StringProperty::New("uid7"));
273  name = "MITK.Relations.1.destinationUID";
274  source_otherRule->SetProperty(name.c_str(), mitk::StringProperty::New(dest_1->GetUID()));
275  name = "MITK.Relations.1.ruleID";
276  source_otherRule->SetProperty(name.c_str(), mitk::StringProperty::New("otherRuleID"));
277  source_otherRule_Node = mitk::DataNode::New();
278  source_otherRule_Node->SetData(source_otherRule);
279 
280  source_otherPurpose = mitk::Image::New();
281  name = "MITK.Relations.1.relationUID";
282  source_otherPurpose->SetProperty(name.c_str(), mitk::StringProperty::New("uid9"));
283  name = "MITK.Relations.1.destinationUID";
284  source_otherPurpose->SetProperty(name.c_str(), mitk::StringProperty::New(dest_1->GetUID()));
285  name = "MITK.Relations.1.ruleID";
286  source_otherPurpose->SetProperty(name.c_str(), mitk::StringProperty::New("SourceImageRelation otherpurpose"));
287  source_otherPurpose_Node = mitk::DataNode::New();
288  source_otherPurpose_Node->SetData(source_otherPurpose);
289  }
290 
291  void tearDown() override {}
292 
293  void IsSourceCandidate()
294  {
295  CPPUNIT_ASSERT(rule->IsSourceCandidate(mitk::DataNode::New()));
296  CPPUNIT_ASSERT(!rule->IsSourceCandidate(nullptr));
297  }
298 
299  void IsDestinationCandidate()
300  {
301  CPPUNIT_ASSERT(rule->IsDestinationCandidate(this->dest_1_Node));
302  CPPUNIT_ASSERT(rule->IsDestinationCandidate(this->dest_1));
303  CPPUNIT_ASSERT(!rule->IsDestinationCandidate(mitk::DataNode::New()));
304  CPPUNIT_ASSERT(!rule->IsDestinationCandidate(nullptr));
305  }
306 
307  void IsSource()
308  {
309  CPPUNIT_ASSERT_THROW_MESSAGE(
310  "Violated precondition (nullptr) does not throw.", rule->IsSource(nullptr), itk::ExceptionObject);
311 
312  CPPUNIT_ASSERT(!rule->IsSource(unRelated));
313  CPPUNIT_ASSERT(!rule->IsSource(source_implicit_1));
314  CPPUNIT_ASSERT(rule->IsSource(source_data_1));
315  CPPUNIT_ASSERT(rule->IsSource(source_idOnly_1));
316  CPPUNIT_ASSERT(rule->IsSource(source_1));
317 
318  CPPUNIT_ASSERT(!rule->IsSource(source_otherRule));
319  CPPUNIT_ASSERT(!rule->IsSource(source_otherPurpose));
320 
321  CPPUNIT_ASSERT(!rule->IsSource(source_implicit_1_Node));
322  CPPUNIT_ASSERT(rule->IsSource(source_data_1_Node));
323  CPPUNIT_ASSERT(rule->IsSource(source_idOnly_1_Node));
324  CPPUNIT_ASSERT(rule->IsSource(source_1_Node));
325 
326  CPPUNIT_ASSERT(!rule->IsSource(source_otherRule_Node));
327  CPPUNIT_ASSERT(!rule->IsSource(source_otherPurpose_Node));
328 
329 
330  CPPUNIT_ASSERT(!abstractRule->IsSource(unRelated));
331  CPPUNIT_ASSERT(!abstractRule->IsSource(source_implicit_1));
332  CPPUNIT_ASSERT(abstractRule->IsSource(source_data_1));
333  CPPUNIT_ASSERT(abstractRule->IsSource(source_idOnly_1));
334  CPPUNIT_ASSERT(abstractRule->IsSource(source_1));
335 
336  CPPUNIT_ASSERT(!abstractRule->IsSource(source_otherRule));
337  CPPUNIT_ASSERT(abstractRule->IsSource(source_otherPurpose));
338 
339  CPPUNIT_ASSERT(!abstractRule->IsSource(unRelated_Node));
340  CPPUNIT_ASSERT(!abstractRule->IsSource(source_implicit_1_Node));
341  CPPUNIT_ASSERT(abstractRule->IsSource(source_data_1_Node));
342  CPPUNIT_ASSERT(abstractRule->IsSource(source_idOnly_1_Node));
343  CPPUNIT_ASSERT(abstractRule->IsSource(source_1_Node));
344 
345  CPPUNIT_ASSERT(!abstractRule->IsSource(source_otherRule_Node));
346  CPPUNIT_ASSERT(abstractRule->IsSource(source_otherPurpose_Node));
347  }
348 
349  void HasRelation()
350  {
351  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (source is nullptr) does not throw.",
352  rule->HasRelation(nullptr, dest_1),
353  itk::ExceptionObject);
354 
355  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (destination is nullptr) does not throw.",
356  rule->HasRelation(source_1, nullptr),
357  itk::ExceptionObject);
358 
359  CPPUNIT_ASSERT(rule->HasRelation(source_1, unRelated) == mitk::PropertyRelationRuleBase::RelationType::None);
360  CPPUNIT_ASSERT(rule->HasRelation(unRelated, dest_1) == mitk::PropertyRelationRuleBase::RelationType::None);
361  CPPUNIT_ASSERT(rule->HasRelation(source_otherRule, dest_1) == mitk::PropertyRelationRuleBase::RelationType::None);
362  CPPUNIT_ASSERT(rule->HasRelation(source_otherPurpose, dest_1) == mitk::PropertyRelationRuleBase::RelationType::None);
363 
364  CPPUNIT_ASSERT(rule->HasRelation(source_implicit_1, dest_1) ==
366  CPPUNIT_ASSERT(rule->HasRelation(source_data_1, dest_1) ==
368  CPPUNIT_ASSERT(rule->HasRelation(source_idOnly_1, dest_1) ==
370  CPPUNIT_ASSERT(rule->HasRelation(source_1, dest_1) == mitk::PropertyRelationRuleBase::RelationType::Connected_ID);
371 
372  CPPUNIT_ASSERT(rule->HasRelation(source_1, dest_2) == mitk::PropertyRelationRuleBase::RelationType::None);
373 
374 
375  CPPUNIT_ASSERT(abstractRule->HasRelation(source_1, unRelated) == mitk::PropertyRelationRuleBase::RelationType::None);
376  CPPUNIT_ASSERT(abstractRule->HasRelation(unRelated, dest_1) == mitk::PropertyRelationRuleBase::RelationType::None);
377  CPPUNIT_ASSERT(abstractRule->HasRelation(source_otherRule, dest_1) == mitk::PropertyRelationRuleBase::RelationType::None);
378  CPPUNIT_ASSERT(abstractRule->HasRelation(source_otherPurpose, dest_1) ==
380 
381  CPPUNIT_ASSERT(abstractRule->HasRelation(source_implicit_1, dest_1) ==
383  CPPUNIT_ASSERT(abstractRule->HasRelation(source_data_1, dest_1) ==
385  CPPUNIT_ASSERT(abstractRule->HasRelation(source_idOnly_1, dest_1) ==
387  CPPUNIT_ASSERT(abstractRule->HasRelation(source_1, dest_1) == mitk::PropertyRelationRuleBase::RelationType::Connected_ID);
388 
389  CPPUNIT_ASSERT(abstractRule->HasRelation(source_1, dest_2) == mitk::PropertyRelationRuleBase::RelationType::Connected_ID);
390  }
391 
392  void GetExistingRelations()
393  {
394  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (source is nullptr) does not throw.",
395  rule->GetExistingRelations(nullptr),
396  itk::ExceptionObject);
397 
398  CPPUNIT_ASSERT(rule->GetExistingRelations(unRelated).empty());
399  CPPUNIT_ASSERT(rule->GetExistingRelations(source_otherRule).empty());
400  CPPUNIT_ASSERT(rule->GetExistingRelations(source_otherPurpose).empty());
401  CPPUNIT_ASSERT(rule->GetExistingRelations(source_implicit_1).empty());
402 
403  auto uids = rule->GetExistingRelations(source_idOnly_1);
404  CPPUNIT_ASSERT(uids.size() == 1);
405  CPPUNIT_ASSERT(uids.front() == "uid1");
406 
407  uids = rule->GetExistingRelations(source_data_1);
408  CPPUNIT_ASSERT(uids.size() == 1);
409  CPPUNIT_ASSERT(uids.front() == "uid2");
410 
411  uids = rule->GetExistingRelations(source_1);
412  CPPUNIT_ASSERT(uids.size() == 1);
413  CPPUNIT_ASSERT(uids.front() == "uid3");
414 
415 
416  CPPUNIT_ASSERT(abstractRule->GetExistingRelations(unRelated).empty());
417  CPPUNIT_ASSERT(abstractRule->GetExistingRelations(source_otherRule).empty());
418  CPPUNIT_ASSERT(abstractRule->GetExistingRelations(source_implicit_1).empty());
419 
420  uids = abstractRule->GetExistingRelations(source_idOnly_1);
421  CPPUNIT_ASSERT(uids.size() == 1);
422  CPPUNIT_ASSERT(uids.front() == "uid1");
423 
424  uids = abstractRule->GetExistingRelations(source_data_1);
425  CPPUNIT_ASSERT(uids.size() == 2);
426  CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(), "uid2") != uids.end());
427  CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(), "uid10") != uids.end());
428 
429  uids = abstractRule->GetExistingRelations(source_1);
430  CPPUNIT_ASSERT(uids.size() == 2);
431  CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(), "uid3") != uids.end());
432  CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(), "uid8") != uids.end());
433 
434  uids = abstractRule->GetExistingRelations(source_otherPurpose);
435  CPPUNIT_ASSERT(uids.size() == 1);
436  CPPUNIT_ASSERT(uids.front() == "uid9");
437  }
438 
439  void GetRelationUIDs()
440  {
441  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (source is nullptr) does not throw.",
442  rule->GetRelationUIDs(nullptr, dest_1),
443  itk::ExceptionObject);
444 
445  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (destination is nullptr) does not throw.",
446  rule->GetRelationUIDs(source_1, nullptr),
447  itk::ExceptionObject);
448 
449  CPPUNIT_ASSERT(rule->GetRelationUIDs(source_1, unRelated).empty());
450  CPPUNIT_ASSERT(rule->GetRelationUIDs(source_1, dest_2).empty());
451  CPPUNIT_ASSERT(rule->GetRelationUIDs(unRelated, dest_1).empty());
452  CPPUNIT_ASSERT(rule->GetRelationUIDs(source_otherRule, dest_1).empty());
453  CPPUNIT_ASSERT(rule->GetRelationUIDs(source_otherPurpose, dest_1).empty());
454 
455  CPPUNIT_ASSERT(rule->GetRelationUIDs(source_idOnly_1, dest_1).front() == "uid1");
456  CPPUNIT_ASSERT(rule->GetRelationUIDs(source_data_1, dest_1).front() == "uid2");
457  auto uids = rule->GetRelationUIDs(source_1, dest_1);
458  CPPUNIT_ASSERT(uids.size() == 1);
459  CPPUNIT_ASSERT(uids.front() == "uid3");
460 
461  CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(source_1, unRelated).empty());
462  CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(unRelated, dest_1).empty());
463  CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(source_otherRule, dest_1).empty());
464  CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(source_otherPurpose, dest_1).front() == "uid9");
465 
466  CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(source_idOnly_1, dest_1).front() == "uid1");
467  uids = abstractRule->GetRelationUIDs(source_data_1, dest_1);
468  CPPUNIT_ASSERT(uids.size() == 1);
469  CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(), "uid2") != uids.end());
470  uids = abstractRule->GetRelationUIDs(source_1, dest_1);
471  CPPUNIT_ASSERT(uids.size() == 1);
472  CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(), "uid3") != uids.end());
473  uids = abstractRule->GetRelationUIDs(source_1, dest_2);
474  CPPUNIT_ASSERT(uids.size() == 1);
475  CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(), "uid8") != uids.end());
476  }
477 
478  void GetSourceCandidateIndicator()
479  {
480  auto predicate = rule->GetSourceCandidateIndicator();
481 
482  CPPUNIT_ASSERT(predicate->CheckNode(mitk::DataNode::New()));
483  CPPUNIT_ASSERT(!predicate->CheckNode(nullptr));
484  }
485 
486  void GetDestinationCandidateIndicator()
487  {
488  auto predicate = rule->GetDestinationCandidateIndicator();
489 
490  CPPUNIT_ASSERT(predicate->CheckNode(this->dest_1_Node));
491  CPPUNIT_ASSERT(!predicate->CheckNode(mitk::DataNode::New()));
492  CPPUNIT_ASSERT(!predicate->CheckNode(nullptr));
493  }
494 
495  void GetConnectedSourcesDetector()
496  {
497  auto predicate = rule->GetConnectedSourcesDetector();
498 
499  CPPUNIT_ASSERT(!predicate->CheckNode(nullptr));
500  CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
501  CPPUNIT_ASSERT(!predicate->CheckNode(source_implicit_1_Node));
502  CPPUNIT_ASSERT(predicate->CheckNode(source_data_1_Node));
503  CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1_Node));
504  CPPUNIT_ASSERT(predicate->CheckNode(source_1_Node));
505 
506  CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule_Node));
507  CPPUNIT_ASSERT(!predicate->CheckNode(source_otherPurpose_Node));
508 
509 
510  auto predicate2 = abstractRule->GetConnectedSourcesDetector();
511 
512  CPPUNIT_ASSERT(!predicate2->CheckNode(nullptr));
513  CPPUNIT_ASSERT(!predicate2->CheckNode(unRelated_Node));
514  CPPUNIT_ASSERT(!predicate2->CheckNode(source_implicit_1_Node));
515  CPPUNIT_ASSERT(predicate2->CheckNode(source_data_1_Node));
516  CPPUNIT_ASSERT(predicate2->CheckNode(source_idOnly_1_Node));
517  CPPUNIT_ASSERT(predicate2->CheckNode(source_1_Node));
518 
519  CPPUNIT_ASSERT(!predicate2->CheckNode(source_otherRule_Node));
520  CPPUNIT_ASSERT(predicate2->CheckNode(source_otherPurpose_Node));
521  }
522 
523  void GetSourcesDetector()
524  {
525  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (destination is nullptr) does not throw.",
526  rule->GetSourcesDetector(nullptr),
527  itk::ExceptionObject);
528 
529  auto predicate = rule->GetSourcesDetector(dest_1);
530 
531  CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
532  CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule_Node));
533  CPPUNIT_ASSERT(!predicate->CheckNode(source_otherPurpose_Node));
534 
535  CPPUNIT_ASSERT(predicate->CheckNode(source_implicit_1_Node));
536  CPPUNIT_ASSERT(predicate->CheckNode(source_data_1_Node));
537  CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1_Node));
538  CPPUNIT_ASSERT(predicate->CheckNode(source_1_Node));
539 
540  predicate = rule->GetSourcesDetector(dest_1, mitk::PropertyRelationRuleBase::RelationType::Connected_Data);
541 
542  CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
543  CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule_Node));
544  CPPUNIT_ASSERT(!predicate->CheckNode(source_otherPurpose_Node));
545 
546  CPPUNIT_ASSERT(!predicate->CheckNode(source_implicit_1_Node));
547  CPPUNIT_ASSERT(predicate->CheckNode(source_data_1_Node));
548  CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1_Node));
549  CPPUNIT_ASSERT(predicate->CheckNode(source_1_Node));
550 
551  predicate = rule->GetSourcesDetector(dest_1, mitk::PropertyRelationRuleBase::RelationType::Connected_ID);
552 
553  CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
554  CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule_Node));
555  CPPUNIT_ASSERT(!predicate->CheckNode(source_otherPurpose_Node));
556 
557  CPPUNIT_ASSERT(!predicate->CheckNode(source_implicit_1_Node));
558  CPPUNIT_ASSERT(!predicate->CheckNode(source_data_1_Node));
559  CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1_Node));
560  CPPUNIT_ASSERT(predicate->CheckNode(source_1_Node));
561 
562  predicate = rule->GetSourcesDetector(dest_2, mitk::PropertyRelationRuleBase::RelationType::Implicit_Data);
563 
564  CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
565  CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule_Node));
566  CPPUNIT_ASSERT(!predicate->CheckNode(source_otherPurpose_Node));
567 
568  CPPUNIT_ASSERT(!predicate->CheckNode(source_implicit_1_Node));
569  CPPUNIT_ASSERT(!predicate->CheckNode(source_data_1_Node));
570  CPPUNIT_ASSERT(!predicate->CheckNode(source_idOnly_1_Node));
571  CPPUNIT_ASSERT(!predicate->CheckNode(source_1_Node));
572 
573  predicate = abstractRule->GetSourcesDetector(dest_1, mitk::PropertyRelationRuleBase::RelationType::Connected_ID);
574 
575  CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
576  CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule_Node));
577  CPPUNIT_ASSERT(predicate->CheckNode(source_otherPurpose_Node));
578 
579  CPPUNIT_ASSERT(!predicate->CheckNode(source_implicit_1_Node));
580  CPPUNIT_ASSERT(!predicate->CheckNode(source_data_1_Node));
581  CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1_Node));
582  CPPUNIT_ASSERT(predicate->CheckNode(source_1_Node));
583 
584  predicate = abstractRule->GetSourcesDetector(dest_1);
585 
586  CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
587  CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule_Node));
588  CPPUNIT_ASSERT(predicate->CheckNode(source_otherPurpose_Node));
589 
590  CPPUNIT_ASSERT(predicate->CheckNode(source_implicit_1_Node));
591  CPPUNIT_ASSERT(predicate->CheckNode(source_data_1_Node));
592  CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1_Node));
593  CPPUNIT_ASSERT(predicate->CheckNode(source_1_Node));
594  }
595 
596  void GetDestinationsDetector()
597  {
598  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (source is nullptr) does not throw.",
599  rule->GetDestinationsDetector(nullptr),
600  itk::ExceptionObject);
601 
602  auto predicate = rule->GetDestinationsDetector(source_otherRule);
603  CPPUNIT_ASSERT(!predicate->CheckNode(dest_1_Node));
604 
605  predicate = rule->GetDestinationsDetector(source_otherPurpose);
606  CPPUNIT_ASSERT(!predicate->CheckNode(dest_1_Node));
607 
608  predicate = rule->GetDestinationsDetector(source_implicit_1);
609  CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
610  predicate =
611  rule->GetDestinationsDetector(source_implicit_1, mitk::PropertyRelationRuleBase::RelationType::Connected_Data);
612  CPPUNIT_ASSERT(!predicate->CheckNode(dest_1_Node));
613 
614  predicate = rule->GetDestinationsDetector(source_data_1);
615  CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
616  predicate =
617  rule->GetDestinationsDetector(source_data_1, mitk::PropertyRelationRuleBase::RelationType::Connected_Data);
618  CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
619  predicate =
620  rule->GetDestinationsDetector(source_data_1, mitk::PropertyRelationRuleBase::RelationType::Connected_ID);
621  CPPUNIT_ASSERT(!predicate->CheckNode(dest_1_Node));
622 
623  predicate = rule->GetDestinationsDetector(source_idOnly_1);
624  CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
625  predicate =
626  rule->GetDestinationsDetector(source_idOnly_1, mitk::PropertyRelationRuleBase::RelationType::Connected_Data);
627  CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
628  predicate =
629  rule->GetDestinationsDetector(source_idOnly_1, mitk::PropertyRelationRuleBase::RelationType::Connected_ID);
630  CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
631 
632  predicate = rule->GetDestinationsDetector(source_1);
633  CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
634  CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
635  CPPUNIT_ASSERT(!predicate->CheckNode(dest_2_Node));
636  predicate =
637  rule->GetDestinationsDetector(source_1, mitk::PropertyRelationRuleBase::RelationType::Connected_Data);
638  CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
639  CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
640  CPPUNIT_ASSERT(!predicate->CheckNode(dest_2_Node));
641  predicate =
642  rule->GetDestinationsDetector(source_1, mitk::PropertyRelationRuleBase::RelationType::Connected_ID);
643  CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
644  CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
645  CPPUNIT_ASSERT(!predicate->CheckNode(dest_2_Node));
646 
647  predicate = abstractRule->GetDestinationsDetector(source_otherPurpose);
648  CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
649  predicate = abstractRule->GetDestinationsDetector(source_otherPurpose);
650  CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
651  }
652 
653  void GetDestinationDetector()
654  {
655  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (source is nullptr) does not throw.",
656  rule->GetDestinationDetector(nullptr, "uid1"),
657  itk::ExceptionObject);
658 
659  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (relation uid is invalid) does not throw.",
660  rule->GetDestinationDetector(source_1, "invalid uid"),
661  itk::ExceptionObject);
662 
663  auto predicate = rule->GetDestinationDetector(source_1, "uid3");
664  CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
665  CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
666  CPPUNIT_ASSERT(!predicate->CheckNode(dest_2_Node));
667  }
668 
669  void Connect()
670  {
671  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (source is nullptr) does not throw.",
672  rule->Connect(nullptr, dest_1),
673  itk::ExceptionObject);
674 
675  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (destination is nullptr) does not throw.",
676  rule->Connect(source_1, nullptr),
677  itk::ExceptionObject);
678 
679  // check upgrade of an implicit connection
680  CPPUNIT_ASSERT(rule->HasRelation(source_implicit_1, dest_1) ==
682  rule->Connect(source_implicit_1, dest_1);
683  CPPUNIT_ASSERT(rule->HasRelation(source_implicit_1, dest_1) ==
685  auto dcmRefs = GetReferenceSequenceIndices(source_implicit_1, dest_1);
686  CPPUNIT_ASSERT_MESSAGE("Additional dicom reference was defined instead of using the existing one.", dcmRefs.size() == 1);
687  CPPUNIT_ASSERT_MESSAGE("Dicom reference is not correct.", IsCorrectDICOMReference(source_implicit_1, "dest_1", "image", "Test", 0));
688 
689  // check upgrade and reuse of an data connection (no new relation should be generated).
690  CPPUNIT_ASSERT(rule->HasRelation(source_data_1, dest_1) ==
692  rule->Connect(source_data_1, dest_1);
693  CPPUNIT_ASSERT(rule->HasRelation(source_data_1, dest_1) ==
695 
696  auto relUID = rule->GetRelationUIDs(source_data_1, dest_1);
697  CPPUNIT_ASSERT(relUID.size() == 1);
698 
699  std::string name = "MITK.Relations.1.destinationUID";
700  auto prop = source_data_1->GetProperty(name.c_str());
701  CPPUNIT_ASSERT_MESSAGE(
702  "Destination uid was not stored with the correct key. Already existing session should be used.", prop);
703  CPPUNIT_ASSERT_MESSAGE("Incorrect destination uid was stored.", prop->GetValueAsString() == dest_1->GetUID());
704 
705  name = "MITK.Relations.1.ruleID";
706  prop = source_data_1->GetProperty(name.c_str());
707  CPPUNIT_ASSERT_MESSAGE("Incorrect ruleID was stored.", prop->GetValueAsString() == rule->GetRuleID());
708 
709  name = "MITK.Relations.1.SourceImageSequenceItem";
710  prop = source_data_1->GetProperty(name.c_str());
711  CPPUNIT_ASSERT_MESSAGE("Incorrect destination uid was stored.", prop->GetValueAsString() == "0");
712 
713  dcmRefs = GetReferenceSequenceIndices(source_data_1, dest_1);
714  CPPUNIT_ASSERT_MESSAGE("Additional dicom reference was defined instead of using the existing one.", dcmRefs.size() == 1);
715  CPPUNIT_ASSERT_MESSAGE("Dicom reference is not correct.", IsCorrectDICOMReference(source_data_1, "dest_1", "image", "Test", 0));
716 
717  // check actualization of an id only connection
718  rule->Connect(source_idOnly_1, dest_1);
719  CPPUNIT_ASSERT(rule->HasRelation(source_idOnly_1, dest_1) ==
721  CPPUNIT_ASSERT_MESSAGE("Additional relation was defined instead of updating exting one.",
722  rule->GetExistingRelations(source_1).size() == 1);
723 
724  // check actualization of an existing connection
725  rule->Connect(source_1, dest_1);
726  CPPUNIT_ASSERT(rule->HasRelation(source_1, dest_1) == mitk::PropertyRelationRuleBase::RelationType::Connected_ID);
727  CPPUNIT_ASSERT_MESSAGE("Additional relation was defined instead of updating exting one.",
728  rule->GetExistingRelations(source_1).size() == 1);
729  name = "MITK.Relations.1.destinationUID";
730  prop = source_1->GetProperty(name.c_str());
731  CPPUNIT_ASSERT_MESSAGE(
732  "Destination uid was not stored with the correct key. Already existing session should be used.", prop);
733  CPPUNIT_ASSERT_MESSAGE("Incorrect destination uid was stored.", prop->GetValueAsString() == dest_1->GetUID());
734 
735  name = "MITK.Relations.1.ruleID";
736  prop = source_1->GetProperty(name.c_str());
737  CPPUNIT_ASSERT_MESSAGE("Incorrect ruleID was stored.", prop->GetValueAsString() == rule->GetRuleID());
738 
739  name = "MITK.Relations.1.SourceImageSequenceItem";
740  prop = source_1->GetProperty(name.c_str());
741  CPPUNIT_ASSERT_MESSAGE("Incorrect destination uid was stored.", prop->GetValueAsString() == "0");
742 
743  dcmRefs = GetReferenceSequenceIndices(source_1, dest_1);
744  CPPUNIT_ASSERT_MESSAGE("Additional dicom reference was defined instead of using the existing one.", dcmRefs.size() == 1);
745  CPPUNIT_ASSERT_MESSAGE("Dicom reference is not correct.", IsCorrectDICOMReference(source_1, "dest_1", "image", "Test", 0));
746 
747  // check creation of an new connection
748  rule->Connect(unRelated, dest_1);
749  CPPUNIT_ASSERT(rule->HasRelation(unRelated, dest_1) == mitk::PropertyRelationRuleBase::RelationType::Connected_ID);
750  CPPUNIT_ASSERT_MESSAGE("Relation was not defined instead of updating exting one.",
751  rule->GetExistingRelations(unRelated).size() == 1);
752  name = "MITK.Relations.1.destinationUID";
753  prop = unRelated->GetProperty(name.c_str());
754  CPPUNIT_ASSERT_MESSAGE("Incorrect destination uid was stored.", prop->GetValueAsString() == dest_1->GetUID());
755 
756  name = "MITK.Relations.1.ruleID";
757  prop = unRelated->GetProperty(name.c_str());
758  CPPUNIT_ASSERT_MESSAGE("Incorrect ruleID was stored.", prop->GetValueAsString() == rule->GetRuleID());
759 
760  name = "MITK.Relations.1.SourceImageSequenceItem";
761  prop = unRelated->GetProperty(name.c_str());
762  CPPUNIT_ASSERT_MESSAGE("Incorrect destination uid was stored.", prop->GetValueAsString() == "0");
763 
764  dcmRefs = GetReferenceSequenceIndices(unRelated, dest_1);
765  CPPUNIT_ASSERT_MESSAGE("Additional dicom reference was defined instead of using the existing one.", dcmRefs.size() == 1);
766  CPPUNIT_ASSERT_MESSAGE("Dicom reference squence is corrupted. Should be just an index 0.", dcmRefs[0] == "0");
767  CPPUNIT_ASSERT_MESSAGE("Dicom reference is not correct.", IsCorrectDICOMReference(unRelated, "dest_1", "image", "Test", 0));
768 
769  // check creation of a 2nd connection of the same purpose
770  rule->Connect(unRelated, dest_2);
771  CPPUNIT_ASSERT(rule->HasRelation(unRelated, dest_2) == mitk::PropertyRelationRuleBase::RelationType::Connected_ID);
772  CPPUNIT_ASSERT_MESSAGE("Additional relation was not defined.",
773  rule->GetExistingRelations(unRelated).size() == 2);
774  name = "MITK.Relations.1.destinationUID";
775  prop = unRelated->GetProperty(name.c_str());
776  CPPUNIT_ASSERT_MESSAGE("Incorrect destination uid was stored.", prop->GetValueAsString() == dest_1->GetUID());
777 
778  name = "MITK.Relations.1.ruleID";
779  prop = unRelated->GetProperty(name.c_str());
780  CPPUNIT_ASSERT_MESSAGE("Incorrect ruleID was stored.", prop->GetValueAsString() == rule->GetRuleID());
781 
782  name = "MITK.Relations.1.SourceImageSequenceItem";
783  prop = unRelated->GetProperty(name.c_str());
784  CPPUNIT_ASSERT_MESSAGE("Incorrect destination uid was stored.", prop->GetValueAsString() == "0");
785 
786  name = "MITK.Relations.2.destinationUID";
787  prop = unRelated->GetProperty(name.c_str());
788  CPPUNIT_ASSERT_MESSAGE("Incorrect destination uid was stored.", prop->GetValueAsString() == dest_2->GetUID());
789 
790  name = "MITK.Relations.2.ruleID";
791  prop = unRelated->GetProperty(name.c_str());
792  CPPUNIT_ASSERT_MESSAGE("Incorrect ruleID was stored.", prop->GetValueAsString() == rule->GetRuleID());
793 
794  name = "MITK.Relations.2.SourceImageSequenceItem";
795  prop = unRelated->GetProperty(name.c_str());
796  CPPUNIT_ASSERT_MESSAGE("Incorrect destination uid was stored.", prop->GetValueAsString() == "1");
797 
798 
799  dcmRefs = GetReferenceSequenceIndices(unRelated, dest_2);
800  CPPUNIT_ASSERT_MESSAGE("Additional dicom reference was not defined.", dcmRefs.size() == 1);
801  CPPUNIT_ASSERT_MESSAGE("Dicom reference is not correct.", IsCorrectDICOMReference(unRelated, "dest_1", "image", "Test", 0));
802  CPPUNIT_ASSERT_MESSAGE("Dicom reference is not correct.", IsCorrectDICOMReference(unRelated, "dest_2", "image", "Test", 1));
803  }
804 
805  void Disconnect()
806  {
807  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (source is nullptr) does not throw.",
808  rule->Disconnect(nullptr, dest_1),
809  itk::ExceptionObject);
810 
811  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (destination is nullptr) does not throw.",
812  rule->Disconnect(source_1, nullptr),
813  itk::ExceptionObject);
814 
815  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (destination is nullptr) does not throw.",
816  rule->Disconnect(nullptr, "uid"),
817  itk::ExceptionObject);
818 
819  CPPUNIT_ASSERT(rule->HasRelation(source_1, unRelated) == mitk::PropertyRelationRuleBase::RelationType::None);
820  rule->Disconnect(source_1, unRelated);
821  CPPUNIT_ASSERT(rule->HasRelation(source_1, unRelated) == mitk::PropertyRelationRuleBase::RelationType::None);
822  CPPUNIT_ASSERT_MESSAGE("Other relationdata property was removed.", IsCorrectDICOMReference(source_1, "dest_1", "image", "Test", 0));
823 
824  //check if index correction is correct, when disconnecting
825  rule->Connect(source_1, dest_2);
826  rule->Connect(source_1, unRelated);
827  rule->Disconnect(source_1, dest_2);
828  CPPUNIT_ASSERT(rule->HasRelation(source_1, dest_2) == mitk::PropertyRelationRuleBase::RelationType::None);
829  CPPUNIT_ASSERT(this->hasRelationProperties(source_1, "1"));
830  CPPUNIT_ASSERT(this->hasRelationProperties(source_1, "2"));
831  CPPUNIT_ASSERT(!this->hasRelationProperties(source_1, "3"));
832  CPPUNIT_ASSERT(this->hasRelationProperties(source_1, "4"));
833  CPPUNIT_ASSERT_MESSAGE("Dicom reference to dest_1 has been removed.", IsCorrectDICOMReference(source_1, "dest_1", "image", "Test", 0));
834  CPPUNIT_ASSERT_MESSAGE("Dicom reference to dest_2 (other purpose) has been removed or has not a corrected sequence index (1 instead of 2).", IsCorrectDICOMReference(source_1, "dest_2", "image", "otherpurpose", 1));
835  CPPUNIT_ASSERT_MESSAGE("Dicom reference to unRelated has been removed or has not a corrected sequence index (1 instead of 2).", IsCorrectDICOMReference(source_1, "unRelated", "image", "Test", 2));
836 
837  std::string name = "MITK.Relations.4.destinationUID";
838  auto prop = source_1->GetProperty(name.c_str());
839  CPPUNIT_ASSERT_MESSAGE(
840  "Destination uid was not stored with the correct key. Already existing session should be used.", prop);
841  CPPUNIT_ASSERT_MESSAGE("Incorrect destination uid was stored.", prop->GetValueAsString() == unRelated->GetUID());
842  name = "MITK.Relations.4.SourceImageSequenceItem";
843  prop = source_1->GetProperty(name.c_str());
844  CPPUNIT_ASSERT_MESSAGE("SourceImageSequenceItem was not actualized correctly.", prop->GetValueAsString() == "2");
845 
846  rule->Disconnect(source_otherPurpose, dest_1);
847  CPPUNIT_ASSERT_MESSAGE("Data of other rule purpose was removed.", this->hasRelationProperties(source_otherPurpose, "1"));
848  }
849 
850  void Connect_abstract()
851  {
852  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (abstract does not connect) does not throw.",
853  abstractRule->Connect(nullptr, dest_1),
854  itk::ExceptionObject);
855 
856  CPPUNIT_ASSERT_THROW_MESSAGE("Violated precondition (abstract does not connect) does not throw.",
857  abstractRule->Connect(source_1, nullptr),
858  itk::ExceptionObject);
859  }
860 
861  void Disconnect_abstract()
862  {
863 
864  CPPUNIT_ASSERT(abstractRule->HasRelation(source_1, dest_2) == mitk::PropertyRelationRuleBase::RelationType::Connected_ID);
865  abstractRule->Disconnect(source_1, dest_2);
866  CPPUNIT_ASSERT(abstractRule->HasRelation(source_1, dest_2) == mitk::PropertyRelationRuleBase::RelationType::None);
867  CPPUNIT_ASSERT(!this->hasRelationProperties(source_1, "2"));
868 
869  CPPUNIT_ASSERT(abstractRule->HasRelation(source_1, dest_1) == mitk::PropertyRelationRuleBase::RelationType::Connected_ID);
870  abstractRule->Disconnect(source_1, dest_1);
871  CPPUNIT_ASSERT(abstractRule->HasRelation(source_1, dest_1) == mitk::PropertyRelationRuleBase::RelationType::None);
872  CPPUNIT_ASSERT(!this->hasRelationProperties(source_1, "1"));
873 
874  abstractRule->Disconnect(source_otherPurpose, dest_1);
875  CPPUNIT_ASSERT_MESSAGE("Data of other rule type was removed.", !this->hasRelationProperties(source_otherPurpose, "1"));
876  }
877 
878 };
879 
880 MITK_TEST_SUITE_REGISTRATION(mitkSourceImageRelationRule)
MITKCORE_EXPORT std::string PropertyKeyPathToPropertyName(const PropertyKeyPath &tagPath)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
std::string MITKCORE_EXPORT GeneratePropertyNameForDICOMTag(unsigned int group, unsigned int element)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
PropertyKeyPath & AddElement(const ElementNameType &name)
virtual BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true) const =0
Get property by its key.
const NodeInfo & GetNode(const PathIndexType &index) const
PropertyKeyPath & AddSelection(const ElementNameType &name, ItemSelectionIndex index)
static Pointer New()
virtual std::vector< std::string > GetPropertyKeys(const std::string &contextName="", bool includeDefaultContext=false) const =0
Query keys of existing properties.
Test fixture for parameterized tests.
MITKCORE_EXPORT PropertyKeyPath PropertyNameToPropertyKeyPath(const std::string &propertyName)
static Pointer New()
Class that can be used to specify nested or wild carded property keys. E.g. for the use in context of...
static Pointer New()
MITKCORE_EXPORT std::string PropertyKeyPathToPropertyRegEx(const PropertyKeyPath &tagPath)
virtual void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false)=0
Add new or change existent property.
PropertyKeyPath & AddAnySelection(const ElementNameType &name)