Skip to content

Commit

Permalink
Part III of issue 1259
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Zangelin committed Sep 25, 2015
1 parent eb03a91 commit e5cc9ba
Show file tree
Hide file tree
Showing 2 changed files with 216 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/lib/jsonParseV2/parseContextAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,18 @@ std::string parseContextAttribute(ConnectionInfo* ciP, ContextAttribute* caP)
OrionError oe(SccBadRequest, "Error parsing incoming JSON buffer");

LM_E(("Bad Input (JSON Parse Error)"));
ciP->httpStatusCode = SccBadRequest;;
ciP->httpStatusCode = SccBadRequest;
return oe.render(ciP, "");
}

std::string res = parseContextAttributeObject(document, caP);
std::string r = parseContextAttributeObject(document, caP);
if (r != "OK")
{
OrionError oe(SccBadRequest, r);

ciP->httpStatusCode = SccBadRequest;
return oe.render(ciP, "");
}

return res;
return r;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U
#
# This file is part of Orion Context Broker.
#
# Orion Context Broker is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Orion Context Broker is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/.
#
# For those usages not covered by this license please contact with
# iot_support at tid dot es

# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh

--NAME--
PUT /v2/entities/eid/attrs/attr

--SHELL-INIT--
dbInit CB
brokerStart CB 0-255

--SHELL--

#
# 01. PUT /v2/entities/E1/attrs/A1 and see it fail
# 02. POST /v2/entities, creating E1 with A1
# 03. PUT /v2/entities/E1/attrs/A1 and see it work
# 04. GET /v2/entities/E1/attrs/A1
# 05. PUT /v2/entities/E1/attrs/A1 'old way' - metadatas not inside 'metadata: {}' - see it fail
# 06. PUT /v2/entities/E1/attrs/A1 'new way' - metadatas inside 'metadata: {}' - see it work
# 07. GET /v2/entities/E1/attrs/A1 to see that 06 worked
#

echo "01. PUT /v2/entities/E1/attrs/A1 and see it fail"
echo "================================================"
payload='{
"value": 12
}'
orionCurl --url /v2/entities/E1/attrs/A1 --payload "$payload" -X PUT --json
echo
echo


echo "02. POST /v2/entities, creating E1 with A1"
echo "=========================================="
payload='{
"id": "E1",
"type": "T1",
"A1": "a1"
}'
orionCurl --url /v2/entities --payload "$payload" --json
echo
echo


echo "03. PUT /v2/entities/E1/attrs/A1 and see it work"
echo "================================================"
payload='{
"value": 12
}'
orionCurl --url /v2/entities/E1/attrs/A1 --payload "$payload" -X PUT --json
echo
echo


echo "04. GET /v2/entities/E1/attrs/A1"
echo "================================"
orionCurl --url /v2/entities/E1/attrs/A1 --json
echo
echo


echo "05. PUT /v2/entities/E1/attrs/A1 'old way' - metadatas not inside 'metadata: {}' - see it fail"
echo "=============================================================================================="
payload='{
"value": 12,
"type": "AT1",
"m1": 1,
"m2": "m2"
}'
orionCurl --url /v2/entities/E1/attrs/A1 --payload "$payload" -X PUT --json
echo
echo


echo "06. PUT /v2/entities/E1/attrs/A1 'new way' - metadatas inside 'metadata: {}' - see it work"
echo "=========================================================================================="
payload='{
"value": 12,
"type": "AT1",
"metadata": {
"m1": 1,
"m2": "m2"
}
}'
orionCurl --url /v2/entities/E1/attrs/A1 --payload "$payload" -X PUT --json
echo
echo


echo "07. GET /v2/entities/E1/attrs/A1 to see that 06 worked"
echo "======================================================"
orionCurl --url /v2/entities/E1/attrs/A1 --json
echo
echo


--REGEXPECT--
01. PUT /v2/entities/E1/attrs/A1 and see it fail
================================================
HTTP/1.1 404 Not Found
Content-Length: 0
Date: REGEX(.*)



02. POST /v2/entities, creating E1 with A1
==========================================
HTTP/1.1 201 Created
Content-Length: 0
Location: /v2/entities/E1
Date: REGEX(.*)



03. PUT /v2/entities/E1/attrs/A1 and see it work
================================================
HTTP/1.1 204 No Content
Content-Length: 0
Date: REGEX(.*)



04. GET /v2/entities/E1/attrs/A1
================================
HTTP/1.1 200 OK
Content-Length: 52
Content-Type: application/json
Date: REGEX(.*)

{
"A1": {
"metadata": {},
"type": null,
"value": 12.0
}
}


05. PUT /v2/entities/E1/attrs/A1 'old way' - metadatas not inside 'metadata: {}' - see it fail
==============================================================================================
HTTP/1.1 400 Bad Request
Content-Length: 82
Content-Type: application/json
Date: REGEX(.*)

{
"description": "unrecognized property for context attribute",
"error": "BadRequest"
}


06. PUT /v2/entities/E1/attrs/A1 'new way' - metadatas inside 'metadata: {}' - see it work
==========================================================================================
HTTP/1.1 204 No Content
Content-Length: 0
Date: REGEX(.*)



07. GET /v2/entities/E1/attrs/A1 to see that 06 worked
======================================================
HTTP/1.1 200 OK
Content-Length: 120
Content-Type: application/json
Date: REGEX(.*)

{
"A1": {
"metadata": {
"m1": {
"type": null,
"value": 1.0
},
"m2": {
"type": null,
"value": "m2"
}
},
"type": "AT1",
"value": 12.0
}
}


--TEARDOWN--
brokerStop CB
dbDrop CB

0 comments on commit e5cc9ba

Please sign in to comment.