replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / notification / unittest / NSConsumerSimulator.h
index d6e5d69..161a9ee 100644 (file)
@@ -37,10 +37,12 @@ private:
     std::shared_ptr<OC::OCResource> m_msgResource;
     std::shared_ptr<OC::OCResource> m_topicResource;
 
+    bool isTopicPost;
+
 public:
     NSConsumerSimulator()
     : m_messageFunc(), m_syncFunc(),
-      m_syncResource() { };
+      m_syncResource(), isTopicPost(false) { };
     ~NSConsumerSimulator() = default;
 
     NSConsumerSimulator(const NSConsumerSimulator &) = delete;
@@ -51,7 +53,7 @@ public:
 
     void findProvider()
     {
-        OC::OCPlatform::findResource("", std::string("/oic/res?rt=oic.r.notification"),
+        OC::OCPlatform::findResource("", std::string("/oic/res?rt=x.org.iotivity.notification"),
                 OCConnectivityType::CT_DEFAULT,
                 std::bind(&NSConsumerSimulator::findResultCallback, this, std::placeholders::_1),
                 OC::QualityOfService::LowQos);
@@ -65,9 +67,9 @@ public:
         }
 
         OC::OCRepresentation rep;
-        rep.setValue("PROVIDER_ID", providerID);
-        rep.setValue("MESSAGE_ID", id);
-        rep.setValue("STATE", type);
+        rep.setValue("x.org.iotivity.ns.providerid", providerID);
+        rep.setValue("x.org.iotivity.ns.messageid", id);
+        rep.setValue("x.org.iotivity.ns.state", type);
 
         m_syncResource->post(rep, OC::QueryParamsMap(), &onPost, OC::QualityOfService::LowQos);
     }
@@ -97,8 +99,8 @@ private:
     {
         if(resource->uri() == "/notification")
         {
-            resource->get(OC::QueryParamsMap(),
-                    std::bind(&NSConsumerSimulator::onGet, this,
+            resource->get(std::string("x.org.iotivity.notification"), std::string("oic.if.baseline"),
+                    OC::QueryParamsMap(), std::bind(&NSConsumerSimulator::onGet, this,
                             std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
                             resource), OC::QualityOfService::LowQos);
         }
@@ -108,12 +110,12 @@ private:
             std::shared_ptr<OC::OCResource> resource)
     {
         OC::QueryParamsMap map;
-        map.insert(std::pair<std::string,std::string>(std::string("consumerid"),
+        map.insert(std::pair<std::string,std::string>(std::string("x.org.iotivity.ns.consumerid"),
                 std::string("123456789012345678901234567890123456")));
 
         try
         {
-            std::vector<std::string> rts{"oic.r.notification"};
+            std::vector<std::string> rts{"x.org.iotivity.notification"};
 
             m_msgResource
                 = OC::OCPlatform::constructResourceObject(
@@ -153,17 +155,18 @@ private:
             const OC::OCRepresentation &rep , const int & /*eCode*/, const int &,
             std::shared_ptr<OC::OCResource> )
     {
-        if (rep.getUri() == "/notification/message" && rep.hasAttribute("MESSAGE_ID")
-                && rep.getValue<int>("MESSAGE_ID") != 1)
+        if (rep.getUri() == "/notification/message" && rep.hasAttribute("x.org.iotivity.ns.messageid")
+                && rep.getValue<int>("x.org.iotivity.ns.messageid") != 1)
         {
-            m_messageFunc(int(rep.getValue<int>("MESSAGE_ID")),
-                          std::string(rep.getValueToString("TITLE")),
-                          std::string(rep.getValueToString("CONTENT")),
-                          std::string(rep.getValueToString("SOURCE")));
+            m_messageFunc(int(rep.getValue<int>("x.org.iotivity.ns.messageid")),
+                          std::string(rep.getValueToString("x.org.iotivity.ns.title")),
+                          std::string(rep.getValueToString("x.org.iotivity.ns.contenttext")),
+                          std::string(rep.getValueToString("x.org.iotivity.ns.source")));
 
-            if(rep.getValue<int>("MESSAGE_ID") == 3)
+            if(rep.getValue<int>("x.org.iotivity.ns.messageid") == 3)
             {
-                m_topicResource->get(OC::QueryParamsMap(),
+                m_topicResource->get(std::string("x.org.iotivity.notification"),
+                        std::string("oic.if.baseline"), OC::QueryParamsMap(),
                         std::bind(&NSConsumerSimulator::onTopicGet, this, std::placeholders::_1,
                                 std::placeholders::_2, std::placeholders::_3, m_topicResource),
                                 OC::QualityOfService::LowQos);
@@ -171,14 +174,49 @@ private:
         }
         else if (rep.getUri() == "/notification/sync")
         {
-            m_syncFunc(int(rep.getValue<int>("STATE")), int(rep.getValue<int>("ID")));
+            m_syncFunc(int(rep.getValue<int>("x.org.iotivity.ns.state")), int(rep.getValue<int>("x.org.iotivity.ns.messageid")));
         }
     }
 
     void onTopicGet(const OC::HeaderOptions &/*headerOption*/,
-            const OC::OCRepresentation & /*rep*/ , const int /*eCode*/,
+            const OC::OCRepresentation & rep , const int /*eCode*/,
             std::shared_ptr<OC::OCResource> /*resource*/)
     {
+
+        if(!isTopicPost)
+        {
+            isTopicPost = true;
+            OC::OCRepresentation postRep;
+
+            std::vector<OC::OCRepresentation> topicArr =
+                            rep.getValue<std::vector<OC::OCRepresentation>>("x.org.iotivity.ns.topiclist");
+
+            std::vector<OC::OCRepresentation> postTopicArr;
+
+            for(std::vector<OC::OCRepresentation>::iterator it = topicArr.begin();
+                    it != topicArr.end(); ++it)
+            {
+                /* std::cout << *it; ... */
+                OC::OCRepresentation topic = *it;
+                OC::OCRepresentation postTopic;
+
+                postTopic.setValue("x.org.iotivity.ns.topicname", topic.getValueToString("x.org.iotivity.ns.topicname"));
+                postTopic.setValue("x.org.iotivity.ns.topicstate", (int) topic.getValue<int>("x.org.iotivity.ns.topicstate"));
+
+                postTopicArr.push_back(topic);
+
+//                std::cout << "tName : " << tName << std::endl;
+//                std::cout << "tState : " << tState << std::endl;
+            }
+
+            postRep.setValue<std::vector<OC::OCRepresentation>>
+                ("x.org.iotivity.ns.topiclist", postTopicArr);
+
+            OC::QueryParamsMap map;
+            map.insert(std::pair<std::string,std::string>(std::string("x.org.iotivity.ns.consumerid"),
+                    std::string("123456789012345678901234567890123456")));
+            m_topicResource->post(postRep, map, &onPost, OC::QualityOfService::LowQos);
+        }
     }
 
     OCStackResult msgResourceCancelObserve(OC::QualityOfService qos)