GitHub PullRequestReviewCommentEvent at 2014-03-26 19:40:39
Repository: fiware-orion
Actor: kzangeli
Payload: {"comment":{"url":"https://api.github.com/repos/telefonicaid/fiware-orion/pulls/comments/10994890","id":10994890,"diff_hunk":"@@ -3119,6 +3121,144 @@ static BSONObj getAttr(std::vector<BSONElement> attrs, std::string name, std::st\n \n /* ****************************************************************************\n *\n+* delete1Ent0Attr -\n+*/\n+TEST(mongoUpdateContextRequest, delete1Ent0Attr)\n+{\n+    HttpStatusCode         ms;\n+    UpdateContextRequest   req;\n+    UpdateContextResponse  res;\n+\n+    /* Prepare database */\n+    prepareDatabase();\n+\n+    /* Forge the request (from \"inside\" to \"outside\") */\n+    ContextElement ce;\n+    ce.entityId.fill(\"E1\", \"T1\", \"false\");\n+    req.contextElementVector.push_back(&ce);\n+    req.updateActionType.set(\"DELETE\");\n+\n+    /* Prepare mock */\n+    TimerMock* timerMock = new TimerMock();\n+    ON_CALL(*timerMock, getCurrentTime())\n+            .WillByDefault(Return(1360232700));\n+    setTimer(timerMock);\n+\n+    /* Invoke the function in mongoBackend library */\n+    ms = mongoUpdateContext(&req, &res);\n+\n+    /* Check response is as expected */\n+    EXPECT_EQ(SccOk, ms);\n+\n+    EXPECT_EQ(0, res.errorCode.code);\n+    EXPECT_EQ(0, res.errorCode.reasonPhrase.size());\n+    EXPECT_EQ(0, res.errorCode.details.size());\n+\n+    ASSERT_EQ(1, res.contextElementResponseVector.size());\n+    /* Context Element response # 1 */\n+    EXPECT_EQ(\"E1\", RES_CER(0).entityId.id);\n+    EXPECT_EQ(\"T1\", RES_CER(0).entityId.type);\n+    EXPECT_EQ(\"false\", RES_CER(0).entityId.isPattern) << \"wrong entity isPattern (context element response #1)\";\n+    ASSERT_EQ(0, RES_CER(0).contextAttributeVector.size());\n+    EXPECT_EQ(SccOk, RES_CER_STATUS(0).code);\n+    EXPECT_EQ(\"OK\", RES_CER_STATUS(0).reasonPhrase);\n+    EXPECT_EQ(0, RES_CER_STATUS(0).details.size());\n+\n+    /* Check that every involved collection at MongoDB is as expected */\n+    /* Note we are using EXPECT_STREQ() for some cases, as Mongo Driver returns const char*, not string\n+     * objects (see http://code.google.com/p/googletest/wiki/Primer#String_Comparison) */\n+\n+    DBClientConnection* connection = getMongoConnection();\n+\n+    /* entities collection */\n+    BSONObj ent;\n+    std::vector<BSONElement> attrs;\n+    ASSERT_EQ(4, connection->count(ENTITIES_COLL, BSONObj()));\n+\n+    ent = connection->findOne(ENTITIES_COLL, BSON(\"_id.id\" << \"E2\" << \"_id.type\" << \"T2\"));\n+    EXPECT_STREQ(\"E2\", C_STR_FIELD(ent.getObjectField(\"_id\"), \"id\"));\n+    EXPECT_STREQ(\"T2\", C_STR_FIELD(ent.getObjectField(\"_id\"), \"type\"));\n+    EXPECT_FALSE(ent.hasField(\"modDate\"));\n+    attrs = ent.getField(\"attrs\").Array();\n+    ASSERT_EQ(2, attrs.size());\n+    BSONObj a3 = getAttr(attrs, \"A3\", \"TA3\");\n+    BSONObj a4 = getAttr(attrs, \"A4\", \"TA4\");\n+    EXPECT_STREQ(\"A3\", C_STR_FIELD(a3, \"name\"));\n+    EXPECT_STREQ(\"TA3\", C_STR_FIELD(a3, \"type\"));\n+    EXPECT_STREQ(\"val3\", C_STR_FIELD(a3, \"value\"));\n+    EXPECT_FALSE(a3.hasField(\"modDate\"));\n+    EXPECT_STREQ(\"A4\", C_STR_FIELD(a4, \"name\"));\n+    EXPECT_STREQ(\"TA4\", C_STR_FIELD(a4, \"type\"));\n+    EXPECT_FALSE(a4.hasField(\"value\"));\n+    EXPECT_FALSE(a4.hasField(\"modDate\"));\n+\n+    ent = connection->findOne(ENTITIES_COLL, BSON(\"_id.id\" << \"E3\" << \"_id.type\" << \"T3\"));\n+    EXPECT_STREQ(\"E3\", C_STR_FIELD(ent.getObjectField(\"_id\"), \"id\"));\n+    EXPECT_STREQ(\"T3\", C_STR_FIELD(ent.getObjectField(\"_id\"), \"type\"));\n+    EXPECT_FALSE(ent.hasField(\"modDate\"));\n+    attrs = ent.getField(\"attrs\").Array();\n+    ASSERT_EQ(2, attrs.size());\n+    BSONObj a5 = getAttr(attrs, \"A5\", \"TA5\");\n+    BSONObj a6 = getAttr(attrs, \"A6\", \"TA6\");\n+    EXPECT_STREQ(\"A5\", C_STR_FIELD(a5, \"name\"));\n+    EXPECT_STREQ(\"TA5\", C_STR_FIELD(a5, \"type\"));\n+    EXPECT_STREQ(\"val5\", C_STR_FIELD(a5, \"value\"));\n+    EXPECT_FALSE(a5.hasField(\"modDate\"));\n+    EXPECT_STREQ(\"A6\", C_STR_FIELD(a6, \"name\"));\n+    EXPECT_STREQ(\"TA6\", C_STR_FIELD(a6, \"type\"));\n+    EXPECT_FALSE(a6.hasField(\"value\"));\n+    EXPECT_FALSE(a6.hasField(\"modDate\"));\n+\n+    ent = connection->findOne(ENTITIES_COLL, BSON(\"_id.id\" << \"E1\" << \"_id.type\" << \"T1bis\"));\n+    EXPECT_STREQ(\"E1\", C_STR_FIELD(ent.getObjectField(\"_id\"), \"id\"));\n+    EXPECT_STREQ(\"T1bis\", C_STR_FIELD(ent.getObjectField(\"_id\"), \"type\"));\n+    EXPECT_FALSE(ent.hasField(\"modDate\"));\n+    attrs = ent.getField(\"attrs\").Array();\n+    ASSERT_EQ(1, attrs.size());\n+    BSONObj a1 = getAttr(attrs, \"A1\", \"TA1\");\n+    EXPECT_STREQ(\"A1\", C_STR_FIELD(a1, \"name\"));\n+    EXPECT_STREQ(\"TA1\",C_STR_FIELD(a1, \"type\"));\n+    EXPECT_STREQ(\"val1bis2\", C_STR_FIELD(a1, \"value\"));\n+    EXPECT_FALSE(a1.hasField(\"modDate\"));\n+\n+    /* Note \"_id.type: {$exists: false}\" is a way for querying for entities without type */\n+    ent = connection->findOne(ENTITIES_COLL, BSON(\"_id.id\" << \"E1\" << \"_id.type\" << BSON(\"$exists\" << false)));\n+    EXPECT_STREQ(\"E1\", C_STR_FIELD(ent.getObjectField(\"_id\"), \"id\"));\n+    EXPECT_FALSE(ent.getObjectField(\"_id\").hasField(\"type\"));\n+    EXPECT_FALSE(ent.hasField(\"modDate\"));\n+    attrs = ent.getField(\"attrs\").Array();\n+    ASSERT_EQ(4, attrs.size());\n+    a1 = getAttr(attrs, \"A1\", \"TA1\");\n+    BSONObj a2 = getAttr(attrs, \"A2\", \"TA2\");\n+    BSONObj a1bis = getAttr(attrs, \"A1\", \"TA1bis\");\n+    BSONObj a1nt = getAttr(attrs, \"A1\", \"\");\n+    EXPECT_STREQ(\"A1\", C_STR_FIELD(a1, \"name\"));\n+    EXPECT_STREQ(\"TA1\",C_STR_FIELD(a1, \"type\"));\n+    EXPECT_STREQ(\"val1-nt\", C_STR_FIELD(a1, \"value\"));\n+    EXPECT_FALSE(a1.hasField(\"modDate\"));\n+    EXPECT_STREQ(\"A2\", C_STR_FIELD(a2, \"name\"));\n+    EXPECT_STREQ(\"TA2\", C_STR_FIELD(a2, \"type\"));\n+    EXPECT_FALSE(a2.hasField(\"value\"));\n+    EXPECT_FALSE(a2.hasField(\"modDate\"));\n+    EXPECT_STREQ(\"A1\", C_STR_FIELD(a1bis, \"name\"));\n+    EXPECT_STREQ(\"TA1bis\",C_STR_FIELD(a1bis, \"type\"));\n+    EXPECT_STREQ(\"val1bis-nt\", C_STR_FIELD(a1bis, \"value\"));\n+    EXPECT_FALSE(a1bis.hasField(\"modDate\"));\n+    EXPECT_STREQ(\"A1\", C_STR_FIELD(a1nt, \"name\"));\n+    EXPECT_STREQ(\"\",C_STR_FIELD(a1nt, \"type\"));\n+    EXPECT_STREQ(\"val1bis1-nt\", C_STR_FIELD(a1nt, \"value\"));\n+    EXPECT_FALSE(a1nt.hasField(\"modDate\"));\n+\n+    /* Release connection */\n+    mongoDisconnect();\n+\n+    /* Release mock */\n+    delete timerMock;","path":"test/unittests/mongoBackend/mongoUpdateContext_test.cpp","position":147,"original_position":147,"commit_id":"d03ca67e158d24a5c73ef46bfd66453f7791abc9","original_commit_id":"d03ca67e158d24a5c73ef46bfd66453f7791abc9","user":{"login":"kzangeli","id":5338380,"avatar_url":"https://avatars.githubusercontent.com/u/5338380?","gravatar_id":"219ceb8e935c4c592687383e471b6310","url":"https://api.github.com/users/kzangeli","html_url":"https://github.com/kzangeli","followers_url":"https://api.github.com/users/kzangeli/followers","following_url":"https://api.github.com/users/kzangeli/following{/other_user}","gists_url":"https://api.github.com/users/kzangeli/gists{/gist_id}","starred_url":"https://api.github.com/users/kzangeli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kzangeli/subscriptions","organizations_url":"https://api.github.com/users/kzangeli/orgs","repos_url":"https://api.github.com/users/kzangeli/repos","events_url":"https://api.github.com/users/kzangeli/events{/privacy}","received_events_url":"https://api.github.com/users/kzangeli/received_events","type":"User","site_admin":false},"body":"utExit ...","created_at":"2014-03-26T19:40:39Z","updated_at":"2014-03-26T19:40:39Z","html_url":"https://github.com/telefonicaid/fiware-orion/pull/294#discussion_r10994890","pull_request_url":"https://api.github.com/repos/telefonicaid/fiware-orion/pulls/294","_links":{"self":{"href":"https://api.github.com/repos/telefonicaid/fiware-orion/pulls/comments/10994890"},"html":{"href":"https://github.com/telefonicaid/fiware-orion/pull/294#discussion_r10994890"},"pull_request":{"href":"https://api.github.com/repos/telefonicaid/fiware-orion/pulls/294"}}}}