changeset 2847:2da68edacab6

unit testing of SplitStudyJob
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 28 Sep 2018 19:17:04 +0200
parents d386abc18133
children dd3914a44b87
files OrthancServer/ServerJobs/SplitStudyJob.cpp OrthancServer/ServerJobs/SplitStudyJob.h UnitTestsSources/MultiThreadingTests.cpp
diffstat 3 files changed, 105 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/ServerJobs/SplitStudyJob.cpp	Fri Sep 28 18:36:20 2018 +0200
+++ b/OrthancServer/ServerJobs/SplitStudyJob.cpp	Fri Sep 28 19:17:04 2018 +0200
@@ -242,6 +242,23 @@
   }
 
 
+  bool SplitStudyJob::LookupTargetSeriesUid(std::string& uid,
+                                            const std::string& series) const
+  {
+    SeriesUidMap::const_iterator found = seriesUidMap_.find(series);
+
+    if (found == seriesUidMap_.end())
+    {
+      return false;
+    }
+    else
+    {
+      uid = found->second;
+      return true;
+    }
+  }
+
+
   void SplitStudyJob::Remove(const DicomTag& tag)
   {
     if (IsStarted())
@@ -265,6 +282,23 @@
     CheckAllowedTag(tag);
     replacements_[tag] = value;
   }
+
+
+  bool SplitStudyJob::LookupReplacement(std::string& value,
+                                        const DicomTag& tag) const
+  {
+    Replacements::const_iterator found = replacements_.find(tag);
+
+    if (found == replacements_.end())
+    {
+      return false;
+    }
+    else
+    {
+      value = found->second;
+      return true;
+    }
+  }
   
     
   void SplitStudyJob::GetPublicContent(Json::Value& value)
--- a/OrthancServer/ServerJobs/SplitStudyJob.h	Fri Sep 28 18:36:20 2018 +0200
+++ b/OrthancServer/ServerJobs/SplitStudyJob.h	Fri Sep 28 19:17:04 2018 +0200
@@ -78,6 +78,16 @@
       return sourceStudy_;
     }
 
+    const std::string& GetTargetStudy() const
+    {
+      return targetStudy_;
+    }
+
+    const std::string& GetTargetStudyUid() const
+    {
+      return targetStudyUid_;
+    }
+
     void AddSourceSeries(const std::string& series);
 
     bool IsKeepSource() const
@@ -87,11 +97,22 @@
     
     void SetKeepSource(bool keep);
 
+    bool LookupTargetSeriesUid(std::string& uid,
+                               const std::string& series) const;
+
     void Replace(const DicomTag& tag,
                  const std::string& value);
     
+    bool LookupReplacement(std::string& value,
+                           const DicomTag& tag) const;
+
     void Remove(const DicomTag& tag);
     
+    bool IsRemoved(const DicomTag& tag) const
+    {
+      return removals_.find(tag) != removals_.end();
+    }
+
     void SetOrigin(const DicomInstanceOrigin& origin);
 
     void SetOrigin(const RestApiCall& call);
--- a/UnitTestsSources/MultiThreadingTests.cpp	Fri Sep 28 18:36:20 2018 +0200
+++ b/UnitTestsSources/MultiThreadingTests.cpp	Fri Sep 28 19:17:04 2018 +0200
@@ -1036,8 +1036,8 @@
     ASSERT_FALSE(job.HasTrailingStep());
     ASSERT_FALSE(job.IsTrailingStepDone());
     job.Start();
-    job.Step();
-    job.Step();
+    ASSERT_EQ(JobStepCode_Continue, job.Step().GetCode());
+    ASSERT_EQ(JobStepCode_Continue, job.Step().GetCode());
 
     {
       DummyUnserializer unserializer;
@@ -1573,27 +1573,58 @@
   }
 
   {
-    ASSERT_THROW(SplitStudyJob(GetContext(), std::string("nope")), OrthancException);
+    std::string a, b, c;
+
+    {
+      ASSERT_THROW(SplitStudyJob(GetContext(), std::string("nope")), OrthancException);
 
-    SplitStudyJob job(GetContext(), study);
-    job.SetKeepSource(true);
-    job.AddSourceSeries(series);
-    ASSERT_THROW(job.AddSourceSeries("nope"), OrthancException);
-    job.SetOrigin(DicomInstanceOrigin::FromLua());
+      SplitStudyJob job(GetContext(), study);
+      job.SetKeepSource(true);
+      job.AddSourceSeries(series);
+      ASSERT_THROW(job.AddSourceSeries("nope"), OrthancException);
+      job.SetOrigin(DicomInstanceOrigin::FromLua());
+      job.Replace(DICOM_TAG_PATIENT_NAME, "hello");
+      job.Remove(DICOM_TAG_PATIENT_BIRTH_DATE);
+      ASSERT_THROW(job.Replace(DICOM_TAG_SERIES_DESCRIPTION, "nope"), OrthancException);
+      ASSERT_THROW(job.Remove(DICOM_TAG_SERIES_DESCRIPTION), OrthancException);
     
-    ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
-    ASSERT_TRUE(job.Serialize(s));
-  }
+      ASSERT_TRUE(job.GetTargetStudy().empty());
+      a = job.GetTargetStudyUid();
+      ASSERT_TRUE(job.LookupTargetSeriesUid(b, series));
+
+      job.Start();
+      ASSERT_EQ(JobStepCode_Continue, job.Step().GetCode());
+      ASSERT_EQ(JobStepCode_Success, job.Step().GetCode());
+
+      c = job.GetTargetStudy();
+      ASSERT_FALSE(c.empty());
+
+      ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
+      ASSERT_TRUE(job.Serialize(s));
+    }
+
+    {
+      std::auto_ptr<IJob> job;
+      job.reset(unserializer.UnserializeJob(s));
 
-  {
-    std::auto_ptr<IJob> job;
-    job.reset(unserializer.UnserializeJob(s));
+      SplitStudyJob& tmp = dynamic_cast<SplitStudyJob&>(*job);
+      ASSERT_TRUE(tmp.IsKeepSource());
+      ASSERT_EQ(study, tmp.GetSourceStudy());
+      ASSERT_EQ(a, tmp.GetTargetStudyUid());
+      ASSERT_EQ(RequestOrigin_Lua, tmp.GetOrigin().GetRequestOrigin());
 
-    SplitStudyJob& tmp = dynamic_cast<SplitStudyJob&>(*job);
-    ASSERT_TRUE(tmp.IsKeepSource());
-    ASSERT_EQ(study, tmp.GetSourceStudy());
-    ASSERT_EQ(RequestOrigin_Lua, tmp.GetOrigin().GetRequestOrigin());
-    //ASSERT_TRUE(tmp.GetModification().IsRemoved(DICOM_TAG_STUDY_DESCRIPTION));
+      std::string s;
+      ASSERT_EQ(c, tmp.GetTargetStudy());
+      ASSERT_FALSE(tmp.LookupTargetSeriesUid(s, "nope"));
+      ASSERT_TRUE(tmp.LookupTargetSeriesUid(s, series));
+      ASSERT_EQ(b, s);
+
+      ASSERT_FALSE(tmp.LookupReplacement(s, DICOM_TAG_STUDY_DESCRIPTION));
+      ASSERT_TRUE(tmp.LookupReplacement(s, DICOM_TAG_PATIENT_NAME));
+      ASSERT_EQ("hello", s);
+      ASSERT_FALSE(tmp.IsRemoved(DICOM_TAG_PATIENT_NAME));
+      ASSERT_TRUE(tmp.IsRemoved(DICOM_TAG_PATIENT_BIRTH_DATE));
+    }
   }
 }