diff UnitTestsSources/RestApiTests.cpp @ 2823:807169f85ba9

OrthancPluginGetPeerUserProperty()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 Sep 2018 15:38:18 +0200
parents dc7330089736
children 0e1b79bc4a2d
line wrap: on
line diff
--- a/UnitTestsSources/RestApiTests.cpp	Mon Sep 17 12:08:49 2018 +0200
+++ b/UnitTestsSources/RestApiTests.cpp	Tue Sep 18 15:38:18 2018 +0200
@@ -603,3 +603,43 @@
     ASSERT_FALSE(p2.LookupHttpHeader(s, "nope"));
   }
 }
+
+
+TEST(WebServiceParameters, UserProperties)
+{
+  Json::Value v = Json::nullValue;
+
+  {
+    WebServiceParameters p;
+    p.SetUrl("http://localhost:8042/");
+    ASSERT_FALSE(p.IsAdvancedFormatNeeded());
+
+    ASSERT_THROW(p.AddUserProperty("Url", "nope"), OrthancException);
+    p.AddUserProperty("Hello", "world");
+    p.AddUserProperty("a", "b");
+    ASSERT_TRUE(p.IsAdvancedFormatNeeded());
+
+    p.Serialize(v, false, true);
+
+    p.ClearUserProperties();
+    ASSERT_FALSE(p.IsAdvancedFormatNeeded());
+  }
+
+  {
+    WebServiceParameters p(v);
+    ASSERT_TRUE(p.IsAdvancedFormatNeeded());
+    ASSERT_TRUE(p.GetHttpHeaders().empty());
+
+    std::set<std::string> tmp;
+    p.ListUserProperties(tmp);
+    ASSERT_EQ(2u, tmp.size());
+    ASSERT_NE(tmp.find("a"), tmp.end());
+    ASSERT_NE(tmp.find("Hello"), tmp.end());
+    ASSERT_EQ(tmp.find("hello"), tmp.end());
+
+    std::string s;
+    ASSERT_TRUE(p.LookupUserProperty(s, "a"));      ASSERT_TRUE(s == "b");
+    ASSERT_TRUE(p.LookupUserProperty(s, "Hello"));  ASSERT_TRUE(s == "world");
+    ASSERT_FALSE(p.LookupUserProperty(s, "hello"));
+  }
+}