From 65533d90a8936fedb7b54a78f0b8feee35e8f838 Mon Sep 17 00:00:00 2001 From: Fermin Galan Marquez Date: Mon, 3 Sep 2018 11:01:21 +0200 Subject: [PATCH 01/10] FIX refactor of NGSIv2 rendering method for the sake of homogenity and simplicity --- src/lib/apiTypesV2/Attribute.cpp | 26 +- src/lib/apiTypesV2/Attribute.h | 3 +- src/lib/apiTypesV2/Entity.cpp | 285 +++++++++++++++--- src/lib/apiTypesV2/Entity.h | 13 +- src/lib/apiTypesV2/EntityVector.cpp | 6 +- src/lib/common/JsonHelper.cpp | 90 +++--- src/lib/common/JsonHelper.h | 16 +- src/lib/common/limits.h | 8 - src/lib/common/macroSubstitute.cpp | 16 +- src/lib/common/string.cpp | 116 +------ src/lib/common/string.h | 33 +- src/lib/common/tag.cpp | 22 +- src/lib/logMsg/time.h | 1 - src/lib/ngsi/ContextAttribute.cpp | 231 ++++++-------- src/lib/ngsi/ContextAttribute.h | 10 +- src/lib/ngsi/ContextAttributeVector.cpp | 194 +----------- src/lib/ngsi/ContextAttributeVector.h | 6 +- src/lib/ngsi/ContextElement.cpp | 261 +++++++++++++++- src/lib/ngsi/ContextElement.h | 10 +- src/lib/ngsi/ContextElementResponseVector.cpp | 2 - src/lib/ngsi/Metadata.cpp | 50 +-- src/lib/ngsi/Metadata.h | 2 +- src/lib/ngsi/MetadataVector.cpp | 46 +-- src/lib/ngsi/MetadataVector.h | 3 +- src/lib/orionTypes/EntityType.cpp | 20 +- src/lib/orionTypes/EntityTypeResponse.cpp | 18 +- src/lib/parse/CompoundValueNode.cpp | 222 ++++---------- src/lib/parse/CompoundValueNode.h | 3 +- .../serviceRoutinesV2/getAllSubscriptions.cpp | 2 +- src/lib/serviceRoutinesV2/getEntity.cpp | 2 +- .../getEntityAttributeValue.cpp | 12 +- .../serviceRoutinesV2/getRegistrations.cpp | 2 +- .../cases/0000_ipv6_support/ipv6_only.test | 2 +- .../entity_dates_overridden_by_user_subs.test | 7 +- .../GET_v2_ent_attr_val_options_text.test | 4 +- .../time_measure_stats.test | 8 +- .../previous_value_with_compounds.test | 8 +- .../2750_complex_service_path.test | 2 +- .../2750_common_metrics/2750_forwards.test | 2 +- .../2750_reset_metrics.test | 22 +- .../2750_totalPayloadAsMetric.test | 4 +- .../empty_maps_in_metrics.test | 4 +- 42 files changed, 848 insertions(+), 946 deletions(-) diff --git a/src/lib/apiTypesV2/Attribute.cpp b/src/lib/apiTypesV2/Attribute.cpp index 2e9c497fed..2b1e368fd3 100644 --- a/src/lib/apiTypesV2/Attribute.cpp +++ b/src/lib/apiTypesV2/Attribute.cpp @@ -29,6 +29,7 @@ #include "common/errorMessages.h" #include "common/RenderFormat.h" #include "common/string.h" +#include "common/JsonHelper.h" #include "ngsi10/QueryContextResponse.h" #include "apiTypesV2/Attribute.h" @@ -48,8 +49,7 @@ std::string Attribute::render HttpStatusCode* scP, // out parameter (pass-through) bool keyValues, // in parameter const std::string& metadataList, // in parameter - RequestType requestType, // in parameter - bool comma // in parameter + RequestType requestType // in parameter ) { RenderFormat renderFormat = (keyValues == true)? NGSI_V2_KEYVALUES : NGSI_V2_NORMALIZED; @@ -76,18 +76,16 @@ std::string Attribute::render stringSplit(metadataList, ',', metadataFilter); } - out = "{"; - - // First parameter (isLastElement) is 'true' as it is the last and only element - out += pcontextAttribute->toJson(true, renderFormat, metadataFilter, requestType); - - out += "}"; - } - - - if (comma) - { - out += ","; + if (renderFormat == NGSI_V2_KEYVALUES) + { + JsonHelper jh; + jh.addRaw(pcontextAttribute->name, pcontextAttribute->toJsonValue()); + out = jh.str(); + } + else // NGSI_V2_NORMALIZED + { + out = pcontextAttribute->toJson(metadataFilter); + } } return out; diff --git a/src/lib/apiTypesV2/Attribute.h b/src/lib/apiTypesV2/Attribute.h index f754435f29..ea97fdd069 100644 --- a/src/lib/apiTypesV2/Attribute.h +++ b/src/lib/apiTypesV2/Attribute.h @@ -61,8 +61,7 @@ class Attribute HttpStatusCode* scP, bool keyValues, const std::string& metadataList, - RequestType requestType, - bool comma = false); + RequestType requestType); void fill(QueryContextResponse* qcrsP, std::string attrName); }; diff --git a/src/lib/apiTypesV2/Entity.cpp b/src/lib/apiTypesV2/Entity.cpp index c7e9393a88..8f49d48022 100644 --- a/src/lib/apiTypesV2/Entity.cpp +++ b/src/lib/apiTypesV2/Entity.cpp @@ -31,6 +31,7 @@ #include "common/tag.h" #include "common/string.h" #include "common/globals.h" +#include "common/JsonHelper.h" #include "common/errorMessages.h" #include "rest/uriParamNames.h" #include "alarmMgr/alarmMgr.h" @@ -61,6 +62,119 @@ Entity::~Entity() } +/* **************************************************************************** +* +* Entity::filterAttributes - +* +* Filter attributes vector in order to get the effective attribute vector to +* render. +* +* dateCreatedOption and dateModifiedOption are due to deprecated ways of requesting +* date in response. If used, the date is added at the end. +* +* FIXME P3: this methods is complex. It should be refactored +* FIXME P3: maybe dateCreated and dateModified should be pre-included in the attributes +* vector, so all three (dateCreated, dateModified and dateExpires) could be processed in +* a similar way. +*/ +void Entity::filterAttributes +( + const std::vector& attrsFilter, + bool dateCreatedOption, + bool dateModifiedOption +) +{ + bool dateCreatedAdded = false; + bool dateModifiedAdded = false; + + if (attrsFilter.size () != 0) + { + if (std::find(attrsFilter.begin(), attrsFilter.end(), ALL_ATTRS) != attrsFilter.end()) + { + // Not filtering, just adding dateCreated and dateModified if needed + if ((creDate != 0) && (std::find(attrsFilter.begin(), attrsFilter.end(), DATE_CREATED) != attrsFilter.end())) + { + ContextAttribute* caP = new ContextAttribute(DATE_CREATED, DATE_TYPE, creDate); + attributeVector.push_back(caP); + dateCreatedAdded = true; + } + if ((modDate != 0) && (std::find(attrsFilter.begin(), attrsFilter.end(), DATE_MODIFIED) != attrsFilter.end())) + { + ContextAttribute* caP = new ContextAttribute(DATE_MODIFIED, DATE_TYPE, modDate); + attributeVector.push_back(caP); + dateModifiedAdded = true; + } + } + else + { + // Reorder attributes in the same order they are in attrsFilter, excluding the ones + // note there (i.e. filtering them out) and giving special treatment to creation + // and modification dates + // + // The (attributeVector.lookup(DATE_XXXX) == -1) check is to give preference to user + // defined attributes (see + // https://fiware-orion.readthedocs.io/en/master/user/ngsiv2_implementation_notes/index.html#datemodified-and-datecreated-attributes) + + std::vector caNewV; + + for (unsigned int ix = 0; ix < attrsFilter.size(); ix++) + { + std::string attrsFilterItem = attrsFilter[ix]; + if ((creDate != 0) && (attrsFilterItem == DATE_CREATED) && (attributeVector.lookup(DATE_CREATED) == -1)) + { + ContextAttribute* caP = new ContextAttribute(DATE_CREATED, DATE_TYPE, creDate); + caNewV.push_back(caP); + dateCreatedAdded = true; + } + else if ((modDate != 0) && (attrsFilterItem == DATE_MODIFIED) && (attributeVector.lookup(DATE_MODIFIED) == -1)) + { + ContextAttribute* caP = new ContextAttribute(DATE_MODIFIED, DATE_TYPE, modDate); + caNewV.push_back(caP); + dateModifiedAdded = true; + } + // Actual attribute filtering only takes place if '*' was not used + else + { + int found = attributeVector.lookup(attrsFilterItem); + if (found != -1) + { + caNewV.push_back(attributeVector.vec[found]); + attributeVector.vec.erase(attributeVector.vec.begin() + found); + } + } + } + + // All the remainder elements in attributeVector need to be released, + // before overriding the vector with caNewV + attributeVector.release(); + + attributeVector.vec = caNewV; + } + } + + // Legacy support for options=dateCreated and opations=dateModified + if (dateCreatedOption && !dateCreatedAdded && (creDate != 0)) + { + ContextAttribute* caP = new ContextAttribute(DATE_CREATED, DATE_TYPE, creDate); + attributeVector.push_back(caP); + } + if (dateModifiedOption && !dateModifiedAdded && (modDate != 0)) + { + ContextAttribute* caP = new ContextAttribute(DATE_MODIFIED, DATE_TYPE, modDate); + attributeVector.push_back(caP); + } + + // Removing dateExpires if not explictely included in the filter + bool includeDateExpires = (std::find(attrsFilter.begin(), attrsFilter.end(), DATE_EXPIRES) != attrsFilter.end()); + int found; + if (!includeDateExpires && ((found = attributeVector.lookup(DATE_EXPIRES)) != -1)) + { + attributeVector.vec[found]->release(); + attributeVector.vec.erase(attributeVector.vec.begin() + found); + } +} + + /* **************************************************************************** * @@ -75,8 +189,7 @@ Entity::~Entity() std::string Entity::render ( std::map& uriParamOptions, - std::map& uriParam, - bool comma + std::map& uriParam ) { if ((oe.details != "") || ((oe.reasonPhrase != "OK") && (oe.reasonPhrase != ""))) @@ -90,7 +203,6 @@ std::string Entity::render else if (uriParamOptions[OPT_VALUES] == true) { renderFormat = NGSI_V2_VALUES; } else if (uriParamOptions[OPT_UNIQUE_VALUES] == true) { renderFormat = NGSI_V2_UNIQUE_VALUES; } - std::string out; std::vector metadataFilter; std::vector attrsFilter; @@ -104,72 +216,147 @@ std::string Entity::render stringSplit(uriParam[URI_PARAM_ATTRS], ',', attrsFilter); } - // Add special attributes representing entity dates - // Note 'uriParamOptions[DATE_CREATED/DATE_MODIFIED] ||' is needed due to backward compability - if ((creDate != 0) && (uriParamOptions[DATE_CREATED] || (std::find(attrsFilter.begin(), attrsFilter.end(), DATE_CREATED) != attrsFilter.end()))) - { - ContextAttribute* caP = new ContextAttribute(DATE_CREATED, DATE_TYPE, creDate); - attributeVector.push_back(caP); - } - if ((modDate != 0) && (uriParamOptions[DATE_MODIFIED] || (std::find(attrsFilter.begin(), attrsFilter.end(), DATE_MODIFIED) != attrsFilter.end()))) + // Get the effective vector of attributes to render + // FIXME PR: given this is "destructive", maybe this should be done before calling render logic, no in the render itself + // FIXME PR: this should be moved to mongoBackend, so it returns the entity as it has to be rendered... however, note that + // we are adding some attributes (DATE_MODIFIED and DATE_CREATED) here. Not sure how to solve it... + filterAttributes(attrsFilter, uriParamOptions[DATE_CREATED], uriParamOptions[DATE_MODIFIED]); + + std::string out; + switch (renderFormat) { - ContextAttribute* caP = new ContextAttribute(DATE_MODIFIED, DATE_TYPE, modDate); - attributeVector.push_back(caP); + case NGSI_V2_VALUES: + out = toJsonValues(); + break; + case NGSI_V2_UNIQUE_VALUES: + out = toJsonUniqueValues(); + break; + case NGSI_V2_KEYVALUES: + out = toJsonKeyvalues(); + break; + default: // NGSI_V2_NORMALIZED + out = toJsonNormalized(metadataFilter); + break; } - if ((renderFormat == NGSI_V2_VALUES) || (renderFormat == NGSI_V2_UNIQUE_VALUES)) + return out; +} + + + +/* **************************************************************************** +* +* Entity::toJsonValues - +*/ +std::string Entity::toJsonValues(void) +{ + std::string out = "["; + + for (unsigned int ix = 0; ix < attributeVector.size(); ix++) { - out = "["; - if (attributeVector.size() != 0) + ContextAttribute* caP = attributeVector[ix]; + out += caP->toJsonValue(); + + if (ix != attributeVector.size() - 1) { - out += attributeVector.toJson(renderFormat, attrsFilter, metadataFilter, false); + out += ","; } - out += "]"; } - else - { - out = "{"; - if (renderId) - { - out += JSON_VALUE("id", id); - out += ","; + out += "]"; - /* This is needed for entities coming from NGSIv1 (which allows empty or missing types) */ - out += JSON_STR("type") + ":" + ((type != "")? JSON_STR(type) : JSON_STR(DEFAULT_ENTITY_TYPE)); - } + return out; +} + + + +/* **************************************************************************** +* +* Entity::toJsonUniqueValues - +*/ +std::string Entity::toJsonUniqueValues(void) +{ + std::string out = "["; - std::string attrsOut; - if (attributeVector.size() != 0) + std::map uniqueMap; + + for (unsigned int ix = 0; ix < attributeVector.size(); ix++) + { + ContextAttribute* caP = attributeVector[ix]; + + std::string value = caP->toJsonValue(); + + if (uniqueMap[value] == true) { - attrsOut += attributeVector.toJson(renderFormat, attrsFilter, metadataFilter, false); + // Already rendered. Skip. + continue; } - - // - // Note that just attributeVector.size() != 0 (used in previous versions) cannot be used - // as ciP->uriParam["attrs"] filter could remove all the attributes - // - if (attrsOut != "") + else { - if (renderId) - { - out += "," + attrsOut; - } - else - { - out += attrsOut; - } + out += value; + uniqueMap[value] = true; } - out += "}"; + out += ","; + } + + // The substrig trick removes the final ",". It is not very smart, but it saves + // a second pass on the vector, once the "unicity" has been calculated in the hashmap + return out.substr(0, out.length() - 1 ) + "]"; +} + + + +/* **************************************************************************** +* +* Entity::toJsonKeyvalues - +*/ +std::string Entity::toJsonKeyvalues(void) +{ + JsonHelper jh; + + if (renderId) + { + jh.addString("id", id); + + /* This is needed for entities coming from NGSIv1 (which allows empty or missing types) */ + jh.addString("type", (type != "")? type : DEFAULT_ENTITY_TYPE); } - if (comma) + for (unsigned int ix = 0; ix < attributeVector.size(); ix++) { - out += ","; + ContextAttribute* caP = attributeVector[ix]; + jh.addRaw(caP->name, caP->toJsonValue()); } - return out; + return jh.str(); +} + + + +/* **************************************************************************** +* +* Entity::toJsonNormalized - +*/ +std::string Entity::toJsonNormalized(const std::vector& metadataFilter) +{ + JsonHelper jh; + + if (renderId) + { + jh.addString("id", id); + + /* This is needed for entities coming from NGSIv1 (which allows empty or missing types) */ + jh.addString("type", (type != "")? type : DEFAULT_ENTITY_TYPE); + } + + for (unsigned int ix = 0; ix < attributeVector.size(); ix++) + { + ContextAttribute* caP = attributeVector[ix]; + jh.addRaw(caP->name, caP->toJson(metadataFilter)); + } + + return jh.str(); } diff --git a/src/lib/apiTypesV2/Entity.h b/src/lib/apiTypesV2/Entity.h index d2cf7952a0..6e8674a0c9 100644 --- a/src/lib/apiTypesV2/Entity.h +++ b/src/lib/apiTypesV2/Entity.h @@ -67,8 +67,7 @@ class Entity ~Entity(); std::string render(std::map& uriParamOptions, - std::map& uriParam, - bool comma = false); + std::map& uriParam); std::string check(RequestType requestType); void release(void); @@ -82,6 +81,16 @@ class Entity void fill(QueryContextResponse* qcrsP); void hideIdAndType(bool hide = true); + + private: + void filterAttributes (const std::vector& attrsFilter, + bool dateCreatedOption, + bool dateModifiedOption); + + std::string toJsonValues(void); + std::string toJsonUniqueValues(void); + std::string toJsonKeyvalues(void); + std::string toJsonNormalized(const std::vector& metadataFilter); }; #endif // SRC_LIB_APITYPESV2_ENTITY_H_ diff --git a/src/lib/apiTypesV2/EntityVector.cpp b/src/lib/apiTypesV2/EntityVector.cpp index 7f2af4baeb..c244b35947 100644 --- a/src/lib/apiTypesV2/EntityVector.cpp +++ b/src/lib/apiTypesV2/EntityVector.cpp @@ -57,11 +57,11 @@ std::string EntityVector::render std::string out; - out += "["; + out += "[" + vec[0]->render(uriParamOptions, uriParam); - for (unsigned int ix = 0; ix < vec.size(); ++ix) + for (unsigned int ix = 1; ix < vec.size(); ++ix) { - out += vec[ix]->render(uriParamOptions, uriParam, ix != vec.size() - 1); + out += "," + vec[ix]->render(uriParamOptions, uriParam); } out += "]"; diff --git a/src/lib/common/JsonHelper.cpp b/src/lib/common/JsonHelper.cpp index 0378386efe..38fe1ed965 100644 --- a/src/lib/common/JsonHelper.cpp +++ b/src/lib/common/JsonHelper.cpp @@ -40,9 +40,9 @@ */ std::string toJsonString(const std::string& input) { - std::ostringstream ss; + std::string ss; - ss << '"'; + ss = '"'; for (std::string::const_iterator iter = input.begin(); iter != input.end(); ++iter) { /* FIXME P3: This function ensures that if the DB holds special characters (which are @@ -63,13 +63,13 @@ std::string toJsonString(const std::string& input) */ switch (char ch = *iter) { - case '\\': ss << "\\\\"; break; - case '"': ss << "\\\""; break; - case '\b': ss << "\\b"; break; - case '\f': ss << "\\f"; break; - case '\n': ss << "\\n"; break; - case '\r': ss << "\\r"; break; - case '\t': ss << "\\t"; break; + case '\\': ss += "\\\\"; break; + case '"': ss += "\\\""; break; + case '\b': ss += "\\b"; break; + case '\f': ss += "\\f"; break; + case '\n': ss += "\\n"; break; + case '\r': ss += "\\r"; break; + case '\t': ss += "\\t"; break; default: /* Converting the rest of special chars 0-31 to \u00xx. Note that 0x80 - 0xFF are untouched as they * correspond to UTF-8 multi-byte characters */ @@ -77,20 +77,20 @@ std::string toJsonString(const std::string& input) { static const char intToHex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' } ; - ss << "\\u00" << intToHex[(ch & 0xF0) >> 4] << intToHex[ch & 0x0F]; + ss += "\\u00" + intToHex[(ch & 0xF0) >> 4] + intToHex[ch & 0x0F]; } else { - ss << ch; + ss += ch; } break; } // end-switch } // end-for - ss << '"'; + ss += '"'; - return ss.str(); + return ss; } @@ -111,15 +111,15 @@ std::string vectorToJson(std::vector &list) return "[" + toJsonString(list[0]) + "]"; default: - std::ostringstream os; - os << '['; - os << toJsonString(list[0]); + std::string os; + os = '['; + os += toJsonString(list[0]); for (std::vector::size_type i = 1; i != list.size(); ++i) { - os << ',' << toJsonString(list[i]); + os += ',' + toJsonString(list[i]); } - os << ']'; - return os.str(); + os += ']'; + return os; } } @@ -131,10 +131,10 @@ std::string vectorToJson(std::vector &list) */ std::string objectToJson(std::map& list) { - std::ostringstream os; - bool firstTime = true; + std::string os; + bool firstTime = true; - os << '{'; + os = '{'; for (std::map::const_iterator it = list.begin(); it != list.end(); ++it) { @@ -147,15 +147,15 @@ std::string objectToJson(std::map& list) } else { - os << ','; + os += ','; } - os << toJsonString(key) << ':' << toJsonString(value); + os += toJsonString(key) + ':' + toJsonString(value); } - os << '}'; + os += '}'; - return os.str(); + return os; } @@ -166,7 +166,7 @@ std::string objectToJson(std::map& list) */ JsonHelper::JsonHelper(): empty(true) { - ss << '{'; + ss += '{'; } @@ -179,9 +179,9 @@ void JsonHelper::addString(const std::string& key, const std::string& value) { if (!empty) { - ss << ','; + ss += ','; } - ss << toJsonString(key) << ':' << toJsonString(value); + ss += toJsonString(key) + ':' + toJsonString(value); empty = false; } @@ -196,9 +196,9 @@ void JsonHelper::addRaw(const std::string& key, const std::string& value) { if (!empty) { - ss << ','; + ss += ','; } - ss << toJsonString(key) << ':' << value; + ss += toJsonString(key) + ':' + value; empty = false; } @@ -213,9 +213,11 @@ void JsonHelper::addNumber(const std::string& key, long long value) { if (!empty) { - ss << ','; + ss += ','; } - ss << toJsonString(key) << ':' << value; + // FIXME P7: double2str() used double as argument, but value is long long. + // However .test regression shows that it works... weird? + ss += toJsonString(key) + ':' + double2string(value); empty = false; } @@ -230,22 +232,16 @@ void JsonHelper::addNumber(const std::string& key, long long value) * should be used instead. * See issue #3058 */ -void JsonHelper::addNumber(const std::string& key, float value) +void JsonHelper::addNumber(const std::string& key, double value) { - unsigned int oldPrecision = ss.precision(); - ss << std::fixed << std::setprecision(decimalDigits(value)); - if (!empty) { - ss << ','; + ss += ','; } - ss << toJsonString(key) << ':' << value; - - // Reset stream to old parameters (whichever they are...) - ss.unsetf(std::ios_base::fixed); - ss << std::setprecision(oldPrecision); + ss += toJsonString(key) + ':' + double2string(value); empty = false; + } @@ -258,9 +254,9 @@ void JsonHelper::addDate(const std::string& key, long long timestamp) { if (!empty) { - ss << ','; + ss += ','; } - ss << toJsonString(key) << ':' << toJsonString(isodate2str(timestamp)); + ss += toJsonString(key) + ':' + toJsonString(isodate2str(timestamp)); empty = false; } @@ -284,6 +280,6 @@ void JsonHelper::addBool(const std::string& key, bool b) */ std::string JsonHelper::str() { - ss << '}'; - return ss.str(); + ss += '}'; + return ss; } diff --git a/src/lib/common/JsonHelper.h b/src/lib/common/JsonHelper.h index 97dd9155d1..ea449d914d 100644 --- a/src/lib/common/JsonHelper.h +++ b/src/lib/common/JsonHelper.h @@ -39,15 +39,15 @@ class JsonHelper void addString(const std::string& key, const std::string& value); void addRaw(const std::string& key, const std::string& value); void addNumber(const std::string& key, long long value); - void addNumber(const std::string& key, float value); + void addNumber(const std::string& key, double value); void addDate(const std::string& key, long long timestamp); void addBool(const std::string& key, bool b); std::string str(); private: - std::ostringstream ss; - bool empty; + std::string ss; + bool empty; }; @@ -74,15 +74,15 @@ std::string vectorToJson(std::vector &list) return "[]"; } - std::ostringstream ss; + std::string ss; - ss << '[' << list[0].toJson(); + ss += '[' + list[0].toJson(); for (size_type i = 1; i != list.size(); ++i) { - ss << ',' << list[i].toJson(); + ss += ',' + list[i].toJson(); } - ss << ']'; - return ss.str(); + ss += ']'; + return ss; } template <> diff --git a/src/lib/common/limits.h b/src/lib/common/limits.h index 5a345d74f1..5cfa308ce6 100644 --- a/src/lib/common/limits.h +++ b/src/lib/common/limits.h @@ -211,12 +211,4 @@ -/* **************************************************************************** -* -* Precision constants - -*/ -#define PRECISION_DIGITS 9 -#define PRECISION 0.000000001 // it corresponds to 9 digits - - #endif // SRC_LIB_COMMON_LIMITS_H_ diff --git a/src/lib/common/macroSubstitute.cpp b/src/lib/common/macroSubstitute.cpp index 3257ad6c15..1cf47f6785 100644 --- a/src/lib/common/macroSubstitute.cpp +++ b/src/lib/common/macroSubstitute.cpp @@ -51,7 +51,7 @@ static void attributeValue(std::string* valueP, const std::vectorvalueType == orion::ValueTypeNumber) { - *valueP = toString(vec[ix]->numberValue); + *valueP = double2string(vec[ix]->numberValue); } else if (vec[ix]->valueType == orion::ValueTypeBoolean) { @@ -70,19 +70,7 @@ static void attributeValue(std::string* valueP, const std::vectorcompoundValueP) { - if (vec[ix]->compoundValueP->valueType == orion::ValueTypeVector) - { - *valueP = "[" + vec[ix]->compoundValueP->toJson(true, true) + "]"; - } - else if (vec[ix]->compoundValueP->valueType == orion::ValueTypeObject) - { - *valueP = "{" + vec[ix]->compoundValueP->toJson(true, true) + "}"; - } - else - { - LM_E(("Runtime Error (attribute is of object type but its compound is of invalid type)")); - *valueP = ""; - } + *valueP = vec[ix]->compoundValueP->toJson(true); } else { diff --git a/src/lib/common/string.cpp b/src/lib/common/string.cpp index 61ae1970e3..d076164ad8 100644 --- a/src/lib/common/string.cpp +++ b/src/lib/common/string.cpp @@ -925,121 +925,11 @@ bool str2double(const char* s, double* dP) /* **************************************************************************** * -* decimalDigits -* -* This function counts the number of decimal digits of a given float, to a maximum of -* PRECISION_DIGITS. The algorithm is inspired in http://stackoverflow.com/a/1083316/1485926 -* but with a "cutting condition" needed due to float representation may have an infinite -* number of decimals, e.g. 3.14 could be internally coded as 3.1399999. -* -* FIXME #2425: this function is not perfect and could be improved. For example, -* considering the following -* -* "A1": 42.9, -* "A2": 42.99, -* "A3": 42.999, -* "A4": 42.9999, -* "A5": 42.99999, -* "A6": 42.999999, -* "A7": 42.9999999, -* "A8": 42.99999999, -* "A9": 42.999999999, -* "A10": 42.9999999999,, -* -* "A1": 42.1, -* "A2": 42.01, -* "A3": 42.001, -* "A4": 42.0001, -* "A5": 42.00001, -* "A6": 42.000001, -* "A7": 42.0000001, -* "A8": 42.00000001, -* "A9": 42.000000001, -* "A10": 42.0000000001, -* -* what we get is: -* -* "A1": 42.9, -* "A2": 42.99, -* "A3": 42.999, -* "A4": 42.9999, -* "A5": 42.99999, -* "A6": 42.999999000, (fail) -* "A7": 42.999999900, (fail) -* "A8": 42.999999990, (fail) -* "A9": 42.999999999, -* "A10": 43.000000000, (fail, although probably not due to this function but the caller) -* -* "A1": 42.1, -* "A2": 42.01, -* "A3": 42.001, -* "A4": 42.0001, -* "A5": 42.00001, -* "A6": 42.000001000, (fail) -* "A7": 42.000000100, (fail) -* "A8": 42.000000010, (fail) -* "A9": 42, (fail) -* "A10": 42, +* double2string * */ -unsigned int decimalDigits(double d) +std::string double2string(double f) { - unsigned int digits = 0; - - double intPart; - double decimalPart = fabs(modf(d, &intPart)); - - while (decimalPart > PRECISION) - { - digits++; - decimalPart *= 10; - decimalPart = modf(decimalPart, &intPart); - if (fabs(1 - decimalPart ) < PRECISION) - { - // Using a greater threshold (e.g. 0.01) would cause rounding errors, - // e.g. 42.9999 -> 43. This can be easily checked with the - // cases/2176_not_print_spurious_decimals/one_to_nine_decimals.test test - // (try to use PRECISION * 10 and check how the test fails). - // - break; - } - } - - if (digits > PRECISION_DIGITS) - { - return PRECISION_DIGITS; - } - else - { - return digits; - } -} - - -/* **************************************************************************** -* -* toString -* -* Specialized version of the template for the double type -*/ -template <> std::string toString(double f) -{ -#if 0 - std::ostringstream ss; - - unsigned int digits = decimalDigits(f); - if (digits > 0) - { - ss << std::fixed << std::setprecision(digits); - } - - ss << f; - - return ss.str(); -#else - - // This is a quick fix, while discussion on https://github.com/apinf/fiware-orion/pull/32 continues - char buf[STRING_SIZE_FOR_DOUBLE]; int bufSize = sizeof(buf); @@ -1079,8 +969,6 @@ template <> std::string toString(double f) } return std::string(buf); - -#endif } diff --git a/src/lib/common/string.h b/src/lib/common/string.h index e3f7681f1b..4bd996ee69 100644 --- a/src/lib/common/string.h +++ b/src/lib/common/string.h @@ -166,39 +166,12 @@ extern std::string servicePathCheck(const char* servicePath); extern bool str2double(const char* s, double* dP = NULL); - -/* **************************************************************************** -* -* decimalDigits -* -*/ -extern unsigned int decimalDigits(double d); - - - -/* **************************************************************************** -* -* toString - -* -* If the generic ostringstream-based implementation would have performance -* problems in the future, a set of per-type specialized functions could be -* used without changing the toString() usage interface from existing callers +/***************************************************************************** * -* In fact, we currently have an specialized function for float, although not -* due to performance (but due to special treatment of decimal numbers in the -* float case) +* double2string - * */ -template std::string toString(T t) -{ - std::ostringstream ss; - - ss << t; - - return ss.str(); -} - -template <> std::string toString(float f); +extern std::string double2string(double f); diff --git a/src/lib/common/tag.cpp b/src/lib/common/tag.cpp index 7a1dbd7459..5b43d91aa3 100644 --- a/src/lib/common/tag.cpp +++ b/src/lib/common/tag.cpp @@ -152,7 +152,7 @@ char* htmlEscape(const char* s) */ std::string jsonInvalidCharsTransformation(const std::string& input) { - std::ostringstream ss; + std::string ss; for (std::string::const_iterator iter = input.begin(); iter != input.end(); ++iter) { @@ -175,13 +175,13 @@ std::string jsonInvalidCharsTransformation(const std::string& input) */ switch (char ch = *iter) { - case '\\': ss << "\\\\"; break; - case '"': ss << "\\\""; break; - case '\b': ss << "\\b"; break; - case '\f': ss << "\\f"; break; - case '\n': ss << "\\n"; break; - case '\r': ss << "\\r"; break; - case '\t': ss << "\\t"; break; + case '\\': ss += "\\\\"; break; + case '"': ss += "\\\""; break; + case '\b': ss += "\\b"; break; + case '\f': ss += "\\f"; break; + case '\n': ss += "\\n"; break; + case '\r': ss += "\\r"; break; + case '\t': ss += "\\t"; break; default: /* Converting the rest of special chars 0-31 to \u00xx. Note that 0x80 - 0xFF are untouched as they @@ -190,18 +190,18 @@ std::string jsonInvalidCharsTransformation(const std::string& input) { static const char intToHex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' } ; - ss << "\\u00" << intToHex[(ch & 0xF0) >> 4] << intToHex[ch & 0x0F]; + ss += "\\u00" + intToHex[(ch & 0xF0) >> 4] + intToHex[ch & 0x0F]; } else { - ss << ch; + ss += ch; } break; } // end-switch } // end-for - return ss.str(); + return ss; } diff --git a/src/lib/logMsg/time.h b/src/lib/logMsg/time.h index 97e6c34d21..15423648e3 100644 --- a/src/lib/logMsg/time.h +++ b/src/lib/logMsg/time.h @@ -30,7 +30,6 @@ #include // struct timeval #include #include // std::string -#include // std::ostringstream diff --git a/src/lib/ngsi/ContextAttribute.cpp b/src/lib/ngsi/ContextAttribute.cpp index bb8e3efd20..72bc2ee1d8 100644 --- a/src/lib/ngsi/ContextAttribute.cpp +++ b/src/lib/ngsi/ContextAttribute.cpp @@ -33,6 +33,7 @@ #include "common/tag.h" #include "common/limits.h" #include "common/RenderFormat.h" +#include "common/JsonHelper.h" #include "alarmMgr/alarmMgr.h" #include "orionTypes/OrionValueType.h" #include "parse/forbiddenChars.h" @@ -584,7 +585,7 @@ std::string ContextAttribute::renderAsJsonObject } else // regular number { - effectiveValue = toString(numberValue); + effectiveValue = double2string(numberValue); withoutQuotes = true; } break; @@ -713,7 +714,7 @@ std::string ContextAttribute::render } else // regular number { - effectiveValue = toString(numberValue); + effectiveValue = double2string(numberValue); withoutQuotes = true; } break; @@ -769,17 +770,9 @@ std::string ContextAttribute::render * * toJson - * -* FIXME: Refactor this method in order to simplify the code paths of the rendering process */ -std::string ContextAttribute::toJson -( - bool isLastElement, - RenderFormat renderFormat, - const std::vector& metadataFilter, - RequestType requestType -) +std::string ContextAttribute::toJson(const std::vector& metadataFilter) { - std::string out; // Add special metadata representing attribute dates if ((creDate != 0) && (std::find(metadataFilter.begin(), metadataFilter.end(), NGSI_MD_DATECREATED) != metadataFilter.end())) @@ -793,143 +786,124 @@ std::string ContextAttribute::toJson metadataVector.push_back(mdP); } - if ((renderFormat == NGSI_V2_VALUES) || (renderFormat == NGSI_V2_KEYVALUES) || (renderFormat == NGSI_V2_UNIQUE_VALUES)) + JsonHelper jh; + + // + // type + // + // This is needed for entities coming from NGSIv1 (which allows empty or missing types) + // + std::string defType = defaultType(valueType); + + if (compoundValueP && compoundValueP->isVector()) { - out = (renderFormat == NGSI_V2_KEYVALUES)? JSON_STR(name) + ":" : ""; + defType = defaultType(orion::ValueTypeVector); + } - if (compoundValueP != NULL) - { - if (compoundValueP->isObject()) - { - out += "{" + compoundValueP->toJson(true, true) + "}"; - } - else if (compoundValueP->isVector()) - { - out += "[" + compoundValueP->toJson(true, true) + "]"; - } - } - else if (valueType == orion::ValueTypeNumber) - { - if ((type == DATE_TYPE) || (type == DATE_TYPE_ALT)) - { - out += JSON_STR(isodate2str(numberValue)); - } - else // regular number - { - out += toString(numberValue); - } - } - else if (valueType == orion::ValueTypeString) - { - out += JSON_STR(stringValue); - } - else if (valueType == orion::ValueTypeBoolean) + jh.addString("type", type != ""? type : defType); + + // + // value + // + if (compoundValueP != NULL) + { + jh.addRaw("value", compoundValueP->toJson(true)); + } + else if (valueType == orion::ValueTypeNumber) + { + if ((type == DATE_TYPE) || (type == DATE_TYPE_ALT)) { - out += (boolValue == true)? "true" : "false"; + jh.addString("value", isodate2str(numberValue)); } - else if (valueType == orion::ValueTypeNull) + else // regular number { - out += "null"; - } - else if (valueType == orion::ValueTypeNotGiven) - { - LM_E(("Runtime Error (value not given in compound value)")); + jh.addNumber("value", numberValue); } } - else // Render mode: normalized + else if (valueType == orion::ValueTypeString) { - if (requestType != EntityAttributeResponse) - { - out = JSON_STR(name) + ":{"; - } - - // - // type - // - // This is needed for entities coming from NGSIv1 (which allows empty or missing types) - // - std::string defType = defaultType(valueType); + jh.addString("value", stringValue); + } + else if (valueType == orion::ValueTypeBoolean) + { + jh.addBool("value", boolValue); + } + else if (valueType == orion::ValueTypeNull) + { + jh.addRaw("value", "null"); + } + else if (valueType == orion::ValueTypeNotGiven) + { + LM_E(("Runtime Error (value not given for attribute %s)", name.c_str())); + } + else + { + LM_E(("Runtime Error (invalid value type for attribute %s)", name.c_str())); + } - if (compoundValueP && compoundValueP->isVector()) - { - defType = defaultType(orion::ValueTypeVector); - } + // + // metadata + // + jh.addRaw("metadata", metadataVector.toJson(metadataFilter)); - out += (type != "")? JSON_VALUE("type", type) : JSON_VALUE("type", defType); - out += ","; + return jh.str(); +} - // - // value - // - if (compoundValueP != NULL) - { - if (compoundValueP->isObject()) - { - out += JSON_STR("value") + ":{" + compoundValueP->toJson(true, true) + "}"; - } - else if (compoundValueP->isVector()) - { - out += JSON_STR("value") + ":[" + compoundValueP->toJson(true, true) + "]"; - } - } - else if (valueType == orion::ValueTypeNumber) - { - if ((type == DATE_TYPE) || (type == DATE_TYPE_ALT)) - { - out += JSON_VALUE("value", isodate2str(numberValue));; - } - else // regular number - { - out += JSON_VALUE_NUMBER("value", toString(numberValue)); - } - } - else if (valueType == orion::ValueTypeString) - { - out += JSON_VALUE("value", stringValue); - } - else if (valueType == orion::ValueTypeBoolean) - { - out += JSON_VALUE_BOOL("value", boolValue); - } - else if (valueType == orion::ValueTypeNull) - { - out += JSON_STR("value") + ":" + "null"; - } - else if (valueType == orion::ValueTypeNotGiven) - { - LM_E(("Runtime Error (value not given in compound value)")); - } - else +/* **************************************************************************** +* +* toJsonValue - +* +* To be used by options=values and options=unique renderings +* +*/ +std::string ContextAttribute::toJsonValue(void) +{ + if (compoundValueP != NULL) + { + return compoundValueP->toJson(true); + } + else if (valueType == orion::ValueTypeNumber) + { + if ((type == DATE_TYPE) || (type == DATE_TYPE_ALT)) { - out += JSON_VALUE("value", stringValue); + return toJsonString(isodate2str(numberValue)); } - out += ","; - - // - // metadata - // - out += JSON_STR("metadata") + ":" + "{" + metadataVector.toJson(true, metadataFilter) + "}"; - - if (requestType != EntityAttributeResponse) + else // regular number { - out += "}"; + return double2string(numberValue); } } - - if (!isLastElement) + else if (valueType == orion::ValueTypeString) + { + return toJsonString(stringValue); + } + else if (valueType == orion::ValueTypeBoolean) + { + return boolValue ? "true" : "false"; + } + else if (valueType == orion::ValueTypeNull) + { + return "null"; + } + else if (valueType == orion::ValueTypeNotGiven) { - out += ","; + LM_E(("Runtime Error (value not given for attribute %s)", name.c_str())); + } + else + { + LM_E(("Runtime Error (invalid value type for attribute %s)", name.c_str())); } - return out; + return ""; } - /* **************************************************************************** * * toJsonAsValue - +* +* FIXME PR: given the new method toJsonValue() the name of this one should be changed */ std::string ContextAttribute::toJsonAsValue ( @@ -971,7 +945,7 @@ std::string ContextAttribute::toJsonAsValue } else // regular number { - out = toString(numberValue); + out = double2string(numberValue); } break; @@ -1015,14 +989,7 @@ std::string ContextAttribute::toJsonAsValue { *outMimeTypeP = outFormatSelection; - if (compoundValueP->isVector()) - { - out = "[" + compoundValueP->toJson(true, true) + "]"; - } - else // Object - { - out = "{" + compoundValueP->toJson(false, true) + "}"; - } + out = compoundValueP->toJson(true); } } @@ -1153,7 +1120,7 @@ std::string ContextAttribute::getValue(void) const break; case orion::ValueTypeNumber: - return toString(numberValue); + return double2string(numberValue); break; case orion::ValueTypeBoolean: diff --git a/src/lib/ngsi/ContextAttribute.h b/src/lib/ngsi/ContextAttribute.h index b7e8d7938b..e49cc88498 100644 --- a/src/lib/ngsi/ContextAttribute.h +++ b/src/lib/ngsi/ContextAttribute.h @@ -99,16 +99,18 @@ typedef struct ContextAttribute bool omitValue = false); std::string renderAsJsonObject(ApiVersion apiVersion, RequestType request, bool comma, bool omitValue = false); std::string renderAsNameString(bool comma); - std::string toJson(bool isLastElement, - RenderFormat renderFormat, - const std::vector& metadataFilter, - RequestType requestType = NoRequest); + + std::string toJson(const std::vector& metadataFilter); + + std::string toJsonValue(void); + std::string toJsonAsValue(ApiVersion apiVersion, bool acceptedTextPlain, bool acceptedJson, MimeType outFormatSelection, MimeType* outMimeTypeP, HttpStatusCode* scP); + void release(void); std::string getName(void); diff --git a/src/lib/ngsi/ContextAttributeVector.cpp b/src/lib/ngsi/ContextAttributeVector.cpp index ab666d5c04..f6aed40cbe 100644 --- a/src/lib/ngsi/ContextAttributeVector.cpp +++ b/src/lib/ngsi/ContextAttributeVector.cpp @@ -34,6 +34,7 @@ #include "common/tag.h" #include "common/string.h" #include "common/RenderFormat.h" +#include "common/JsonHelper.h" #include "ngsi/ContextAttributeVector.h" #include "ngsi/Request.h" @@ -72,6 +73,7 @@ static std::string addedLookup(const std::vector& added, std::strin /* **************************************************************************** * * ContextAttributeVector::toJsonTypes - +* */ std::string ContextAttributeVector::toJsonTypes(void) { @@ -85,7 +87,7 @@ std::string ContextAttributeVector::toJsonTypes(void) } // Pass 2 - generate JSON - std::string out; + JsonHelper jh; std::map >::iterator it; unsigned int ix; @@ -94,11 +96,13 @@ std::string ContextAttributeVector::toJsonTypes(void) std::string attrName = it->first; std::map attrTypes = it->second; - out += JSON_STR(attrName) + ":{" + JSON_STR("types") + ":["; + std::string out = "["; std::map::iterator jt; unsigned int jx; + JsonHelper jhTypes; + for (jt = attrTypes.begin(), jx = 0; jt != attrTypes.end(); ++jt, ++jx) { std::string type = jt->first; @@ -122,186 +126,14 @@ std::string ContextAttributeVector::toJsonTypes(void) } } - out += "]}"; - - if (ix != perAttrTypes.size() - 1) - { - out += ","; - } - } - - return out; -} - - - -/* **************************************************************************** -* -* ContextAttributeVector::toJson - -* -* Attributes named 'id' or 'type' are not rendered in API version 2, due to the -* compact way in which API v2 is rendered. Attributes named 'id' or 'type' would simply -* collide with the 'id' and 'type' of the entity itself (holder of the attribute). -* -* If anybody needs an attribute named 'id' or 'type', then API v1 -* will have to be used to retrieve that information. -*/ -std::string ContextAttributeVector::toJson -( - RenderFormat renderFormat, - const std::vector& attrsFilter, - const std::vector& metadataFilter, - bool blacklist -) const -{ - if (vec.size() == 0) - { - return ""; - } - - // Check if dateExipres has to be rendered or not - bool includeDateExpires = (std::find(attrsFilter.begin(), attrsFilter.end(), DATE_EXPIRES) != attrsFilter.end()); - - // - // Pass 1 - count the total number of attributes valid for rendering. - // - // Attributes named 'id' or 'type' are not rendered. - // This gives us a small problem in the logic here, about knowing whether the - // comma should be rendered or not. - // - // To fix this problem we need to do two passes over the vector, the first pass to - // count the number of valid attributes and the second to do the work. - // In the second pass, if the number of rendered attributes "so far" is less than the total - // number of valid attributes, then the comma must be rendered. - // - int validAttributes = 0; - std::map uniqueMap; - if ((attrsFilter.size() == 0) || (std::find(attrsFilter.begin(), attrsFilter.end(), ALL_ATTRS) != attrsFilter.end())) - { - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - if ((vec[ix]->name == "id") || (vec[ix]->name == "type")) - { - continue; - } - - if ((vec[ix]->name == DATE_EXPIRES) && !includeDateExpires) - { - continue; - } - - if ((renderFormat == NGSI_V2_UNIQUE_VALUES) && (vec[ix]->valueType == orion::ValueTypeString)) - { - if (uniqueMap[vec[ix]->stringValue] == true) - { - continue; - } - } - - ++validAttributes; - - if ((renderFormat == NGSI_V2_UNIQUE_VALUES) && (vec[ix]->valueType == orion::ValueTypeString)) - { - uniqueMap[vec[ix]->stringValue] = true; - } - } - } - else if (!blacklist) - { - for (std::vector::const_iterator it = attrsFilter.begin(); it != attrsFilter.end(); ++it) - { - if ((*it == DATE_EXPIRES) && !includeDateExpires) - { - continue; - } - - if (lookup(*it) != NULL) - { - ++validAttributes; - } - } - } - else // attrsFilter is black list - { - for (unsigned ix = 0; ix < vec.size(); ++ix) - { - if (std::find(attrsFilter.begin(), attrsFilter.end(), vec[ix]->name) == attrsFilter.end()) - { - ++validAttributes; - } - } - } - - // - // Pass 2 - do the work, helped by the value of 'validAttributes'. - // - std::string out; - int renderedAttributes = 0; - - uniqueMap.clear(); - - if (attrsFilter.size() == 0 || (std::find(attrsFilter.begin(), attrsFilter.end(), ALL_ATTRS) != attrsFilter.end())) - { - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - if ((vec[ix]->name == "id") || (vec[ix]->name == "type")) - { - continue; - } - - if ((vec[ix]->name == DATE_EXPIRES) && !includeDateExpires) - { - continue; - } - - ++renderedAttributes; - - if ((renderFormat == NGSI_V2_UNIQUE_VALUES) && (vec[ix]->valueType == orion::ValueTypeString)) - { - if (uniqueMap[vec[ix]->stringValue] == true) - { - continue; - } - } + out += "]"; - out += vec[ix]->toJson(renderedAttributes == validAttributes, renderFormat, metadataFilter); - - if ((renderFormat == NGSI_V2_UNIQUE_VALUES) && (vec[ix]->valueType == orion::ValueTypeString)) - { - uniqueMap[vec[ix]->stringValue] = true; - } - } - } - else if (!blacklist) - { - for (std::vector::const_iterator it = attrsFilter.begin(); it != attrsFilter.end(); ++it) - { - ContextAttribute* caP = lookup(*it); - if (caP != NULL) - { - if ((caP->name == DATE_EXPIRES) && !includeDateExpires) - { - continue; - } + jhTypes.addRaw("types", out); - ++renderedAttributes; - out += caP->toJson(renderedAttributes == validAttributes, renderFormat, metadataFilter); - } - } - } - else // attrsFilter is black list - { - for (unsigned ix = 0; ix < vec.size(); ++ix) - { - if (std::find(attrsFilter.begin(), attrsFilter.end(), vec[ix]->name) == attrsFilter.end()) - { - ++renderedAttributes; - out += vec[ix]->toJson(renderedAttributes == validAttributes, renderFormat, metadataFilter); - } - } + jh.addRaw(attrName, jhTypes.str()); } - return out; + return jh.str(); } @@ -507,15 +339,15 @@ void ContextAttributeVector::fill(ContextAttributeVector* cavP, bool useDefaultT * * lookup - */ -ContextAttribute* ContextAttributeVector::lookup(const std::string& attributeName) const +int ContextAttributeVector::lookup(const std::string& attributeName) const { for (unsigned int ix = 0; ix < vec.size(); ++ix) { if (vec[ix]->name == attributeName) { - return vec[ix]; + return ix; } } - return NULL; + return -1; } diff --git a/src/lib/ngsi/ContextAttributeVector.h b/src/lib/ngsi/ContextAttributeVector.h index aa9bfeb15c..57bf591162 100644 --- a/src/lib/ngsi/ContextAttributeVector.h +++ b/src/lib/ngsi/ContextAttributeVector.h @@ -49,7 +49,7 @@ typedef struct ContextAttributeVector unsigned int size(void) const; void release(void); void fill(struct ContextAttributeVector* cavP, bool useDefaultType = false); - ContextAttribute* lookup(const std::string& attributeName) const; + int lookup(const std::string& attributeName) const; ContextAttribute* operator[](unsigned int ix) const; @@ -63,10 +63,6 @@ typedef struct ContextAttributeVector bool omitValue = false, bool attrsAsName = false); - std::string toJson(RenderFormat renderFormat, - const std::vector& attrsFilter, - const std::vector& metadataV, - bool blacklist) const; std::string toJsonTypes(void); } ContextAttributeVector; diff --git a/src/lib/ngsi/ContextElement.cpp b/src/lib/ngsi/ContextElement.cpp index 8896ed7181..d35d994cf3 100644 --- a/src/lib/ngsi/ContextElement.cpp +++ b/src/lib/ngsi/ContextElement.cpp @@ -32,6 +32,7 @@ #include "common/globals.h" #include "common/tag.h" #include "common/string.h" +#include "common/JsonHelper.h" #include "ngsi/EntityId.h" #include "ngsi/Request.h" @@ -110,9 +111,129 @@ std::string ContextElement::render +/* **************************************************************************** +* +* ContextElement::filterAttributes - +* +* Filter attributes vector in order to get the effective attribute vector to +* render. +* +* dateCreatedOption and dateModifiedOption are due to deprecated ways of requesting +* date in response. If used, the date is added at the end. +* +* FIXME PR: lot of duplicated code from Entity NGSIv2 class but we don't care +* as NGSIv1 code is deprecated. The duplication will be solved when NGSIv1 gets removed +*/ +void ContextElement::filterAttributes(const std::vector& attrsFilter, bool blacklist) +{ + + if (attrsFilter.size () != 0) + { + if (std::find(attrsFilter.begin(), attrsFilter.end(), ALL_ATTRS) != attrsFilter.end()) + { + // No filtering, just adding dateCreated and dateModified if needed (only in no blacklist case) + // + // The (contextAttributeVector.lookup(DATE_XXXX) == -1) check is to give preference to user + // defined attributes (see + // https://fiware-orion.readthedocs.io/en/master/user/ngsiv2_implementation_notes/index.html#datemodified-and-datecreated-attributes) + + if (!blacklist) + { + if ((entityId.creDate != 0) && (std::find(attrsFilter.begin(), attrsFilter.end(), DATE_CREATED) != attrsFilter.end()) && (contextAttributeVector.lookup(DATE_CREATED) == -1)) + { + ContextAttribute* caP = new ContextAttribute(DATE_CREATED, DATE_TYPE, entityId.creDate); + contextAttributeVector.push_back(caP); + } + if ((entityId.modDate != 0) && (std::find(attrsFilter.begin(), attrsFilter.end(), DATE_MODIFIED) != attrsFilter.end()) && (contextAttributeVector.lookup(DATE_MODIFIED) == -1)) + { + ContextAttribute* caP = new ContextAttribute(DATE_MODIFIED, DATE_TYPE, entityId.modDate); + contextAttributeVector.push_back(caP); + } + } + } + else + { + // Processing depend on blacklist + // + // 1. If blacklist == true, go through the contextAttributeVector, taking only its elements + // not in attrsFilter + // 2. If blacklist == false, reorder attributes in the same order they are in attrsFilter, excluding + // the ones not there (i.e. filtering them out) and giving special treatment to creation + // and modification dates + + if (blacklist) + { + std::vector caNewV; + for (unsigned int ix = 0; ix < contextAttributeVector.size(); ix++) + { + ContextAttribute* caP = contextAttributeVector[ix]; + if (std::find(attrsFilter.begin(), attrsFilter.end(), caP->name) == attrsFilter.end()) + { + caNewV.push_back(caP); + } + else + { + caP->release(); + } + } + contextAttributeVector.vec = caNewV; + } + else + { + std::vector caNewV; + + for (unsigned int ix = 0; ix < attrsFilter.size(); ix++) + { + std::string attrsFilterItem = attrsFilter[ix]; + if ((entityId.creDate != 0) && (attrsFilterItem == DATE_CREATED) && (contextAttributeVector.lookup(DATE_CREATED) == -1)) + { + ContextAttribute* caP = new ContextAttribute(DATE_CREATED, DATE_TYPE, entityId.creDate); + caNewV.push_back(caP); + } + else if ((entityId.modDate != 0) && (attrsFilterItem == DATE_MODIFIED) && (contextAttributeVector.lookup(DATE_MODIFIED) == -1)) + { + ContextAttribute* caP = new ContextAttribute(DATE_MODIFIED, DATE_TYPE, entityId.modDate); + caNewV.push_back(caP); + } + // Actual attribute filtering only takes place if '*' was not used + else + { + int found = contextAttributeVector.lookup(attrsFilterItem); + if (found != -1) + { + caNewV.push_back(contextAttributeVector.vec[found]); + contextAttributeVector.vec.erase(contextAttributeVector.vec.begin() + found); + } + } + } + + // All the remainder elements in attributeVector need to be released, + // before overriding the vector with caNewV + contextAttributeVector.release(); + + contextAttributeVector.vec = caNewV; + + } + } + } + + // Removing dateExpires if not explictely included in the filter + bool includeDateExpires = (std::find(attrsFilter.begin(), attrsFilter.end(), DATE_EXPIRES) != attrsFilter.end()); + int found; + if (!blacklist && !includeDateExpires && ((found = contextAttributeVector.lookup(DATE_EXPIRES)) != -1)) + { + contextAttributeVector.vec[found]->release(); + contextAttributeVector.vec.erase(contextAttributeVector.vec.begin() + found); + } +} + + /* **************************************************************************** * * ContextElement::toJson - +* +* FIXME PR: lot of duplicated code from Entity NGSIv2 class but we don't care +* as NGSIv1 code is deprecated. The duplication will be solved when NGSIv1 gets removed */ std::string ContextElement::toJson ( @@ -120,29 +241,157 @@ std::string ContextElement::toJson const std::vector& attrsFilter, const std::vector& metadataFilter, bool blacklist -) const +) { + // Get the effective vector of attributes to render + filterAttributes(attrsFilter, blacklist); + std::string out; + switch (renderFormat) + { + case NGSI_V2_VALUES: + out = toJsonValues(); + break; + case NGSI_V2_UNIQUE_VALUES: + out = toJsonUniqueValues(); + break; + case NGSI_V2_KEYVALUES: + out = toJsonKeyvalues(); + break; + default: // NGSI_V2_NORMALIZED + out = toJsonNormalized(metadataFilter); + break; + } + + return out; +} + + +/* **************************************************************************** +* +* ContextElement::toJsonValues - +* +* FIXME PR: lot of duplicated code from Entity NGSIv2 class but we don't care +* as NGSIv1 code is deprecated. The duplication will be solved when NGSIv1 gets removed +*/ +std::string ContextElement::toJsonValues(void) +{ + std::string out = "["; - if (renderFormat != NGSI_V2_VALUES) + for (unsigned int ix = 0; ix < contextAttributeVector.size(); ix++) { - out += entityId.toJson(); - if (contextAttributeVector.size() != 0) + ContextAttribute* caP = contextAttributeVector[ix]; + out += caP->toJsonValue(); + + if (ix != contextAttributeVector.size() - 1) { out += ","; } } - if (contextAttributeVector.size() != 0) + out += "]"; + + return out; +} + + + +/* **************************************************************************** +* +* ContextElement::toJsonUniqueValues - +* +* FIXME PR: lot of duplicated code from Entity NGSIv2 class but we don't care +* as NGSIv1 code is deprecated. The duplication will be solved when NGSIv1 gets removed +*/ +std::string ContextElement::toJsonUniqueValues(void) +{ + std::string out = "["; + + std::map uniqueMap; + + for (unsigned int ix = 0; ix < contextAttributeVector.size(); ix++) { - out += contextAttributeVector.toJson(renderFormat, attrsFilter, metadataFilter, blacklist); + ContextAttribute* caP = contextAttributeVector[ix]; + + std::string value = caP->toJsonValue(); + + if (uniqueMap[value] == true) + { + // Already rendered. Skip. + continue; + } + else + { + out += value; + uniqueMap[value] = true; + } + + if (ix != contextAttributeVector.size() - 1) + { + out += ","; + } } + out += "]"; + return out; } +/* **************************************************************************** +* +* ContextElement::toJsonKeyvalues - +* +* FIXME PR: lot of duplicated code from Entity NGSIv2 class but we don't care +* as NGSIv1 code is deprecated. The duplication will be solved when NGSIv1 gets removed +*/ +std::string ContextElement::toJsonKeyvalues(void) +{ + JsonHelper jh; + + jh.addString("id", entityId.id); + + /* This is needed for entities coming from NGSIv1 (which allows empty or missing types) */ + jh.addString("type", (entityId.type != "")? entityId.type : DEFAULT_ENTITY_TYPE); + + for (unsigned int ix = 0; ix < contextAttributeVector.size(); ix++) + { + ContextAttribute* caP = contextAttributeVector[ix]; + jh.addRaw(caP->name, caP->toJsonValue()); + } + + return jh.str(); +} + + + +/* **************************************************************************** +* +* ContextElement::toJsonNormalized - +* +* FIXME PR: lot of duplicated code from Entity NGSIv2 class but we don't care +* as NGSIv1 code is deprecated. The duplication will be solved when NGSIv1 gets removed +*/ +std::string ContextElement::toJsonNormalized(const std::vector& metadataFilter) +{ + JsonHelper jh; + + jh.addString("id", entityId.id); + + /* This is needed for entities coming from NGSIv1 (which allows empty or missing types) */ + jh.addString("type", (entityId.type != "")? entityId.type : DEFAULT_ENTITY_TYPE); + + for (unsigned int ix = 0; ix < contextAttributeVector.size(); ix++) + { + ContextAttribute* caP = contextAttributeVector[ix]; + jh.addRaw(caP->name, caP->toJson(metadataFilter)); + } + + return jh.str(); +} + + /* **************************************************************************** * * ContextElement::getAttribute diff --git a/src/lib/ngsi/ContextElement.h b/src/lib/ngsi/ContextElement.h index 861aa41d00..07c9867162 100644 --- a/src/lib/ngsi/ContextElement.h +++ b/src/lib/ngsi/ContextElement.h @@ -57,7 +57,7 @@ typedef struct ContextElement std::string toJson(RenderFormat renderFormat, const std::vector& attrsFilter, const std::vector& metadataFilter, - bool blacklist = false) const; + bool blacklist = false); void release(void); void fill(const struct ContextElement& ce); void fill(ContextElement* ceP, bool useDefaultType = false); @@ -65,6 +65,14 @@ typedef struct ContextElement ContextAttribute* getAttribute(const std::string& attrName); std::string check(ApiVersion apiVersion, RequestType requestType); + + private: + void filterAttributes(const std::vector& attrsFilter, bool blacklist); + + std::string toJsonValues(void); + std::string toJsonUniqueValues(void); + std::string toJsonKeyvalues(void); + std::string toJsonNormalized(const std::vector& metadataFilter); } ContextElement; #endif // SRC_LIB_NGSI_CONTEXTELEMENT_H_ diff --git a/src/lib/ngsi/ContextElementResponseVector.cpp b/src/lib/ngsi/ContextElementResponseVector.cpp index d004987e7b..fedf436d67 100644 --- a/src/lib/ngsi/ContextElementResponseVector.cpp +++ b/src/lib/ngsi/ContextElementResponseVector.cpp @@ -86,9 +86,7 @@ std::string ContextElementResponseVector::toJson for (unsigned int ix = 0; ix < vec.size(); ++ix) { - out += (renderFormat == NGSI_V2_VALUES)? "[": "{"; out += vec[ix]->toJson(renderFormat, attrsFilter, metadataFilter, blacklist); - out += (renderFormat == NGSI_V2_VALUES)? "]": "}"; if (ix != vec.size() - 1) { diff --git a/src/lib/ngsi/Metadata.cpp b/src/lib/ngsi/Metadata.cpp index 487818e50d..1d1f469b14 100644 --- a/src/lib/ngsi/Metadata.cpp +++ b/src/lib/ngsi/Metadata.cpp @@ -32,6 +32,7 @@ #include "common/limits.h" #include "common/tag.h" #include "common/string.h" +#include "common/JsonHelper.h" #include "alarmMgr/alarmMgr.h" #include "orionTypes/OrionValueType.h" @@ -427,7 +428,7 @@ std::string Metadata::toStringValue(void) const } else // regular number { - return toString(numberValue); + return double2string(numberValue); } break; @@ -458,11 +459,9 @@ std::string Metadata::toStringValue(void) const * * toJson - */ -std::string Metadata::toJson(bool isLastElement) +std::string Metadata::toJson(void) { - std::string out; - - out = JSON_STR(name) + ":{"; + JsonHelper jh; /* This is needed for entities coming from NGSIv1 (which allows empty or missing types) */ std::string defType = defaultType(valueType); @@ -472,62 +471,45 @@ std::string Metadata::toJson(bool isLastElement) defType = defaultType(orion::ValueTypeVector); } - out += (type != "")? JSON_VALUE("type", type) : JSON_VALUE("type", defType); - out += ","; + jh.addString("type", (type != "")? type : defType); - if (valueType == orion::ValueTypeString) + if (compoundValueP != NULL) + { + jh.addRaw("value", compoundValueP->toJson(true)); + } + else if (valueType == orion::ValueTypeString) { - out += JSON_VALUE("value", stringValue); + jh.addString("value", stringValue); } else if (valueType == orion::ValueTypeNumber) { - std::string effectiveValue; - if ((type == DATE_TYPE) || (type == DATE_TYPE_ALT)) { - effectiveValue = JSON_STR(isodate2str(numberValue)); + jh.addDate("value", numberValue); } else // regular number { - effectiveValue = toString(numberValue); + jh.addNumber("value", numberValue); } - out += JSON_VALUE_NUMBER("value", effectiveValue); } else if (valueType == orion::ValueTypeBoolean) { - out += JSON_VALUE_BOOL("value", boolValue); + jh.addBool("value", boolValue); } else if (valueType == orion::ValueTypeNull) { - out += JSON_STR("value") + ":null"; - } - else if (valueType == orion::ValueTypeObject) - { - if ((compoundValueP->isObject()) || (compoundValueP->isVector())) - { - compoundValueP->renderName = true; - out += compoundValueP->toJson(isLastElement, false); - } + jh.addRaw("value", "null"); } else if (valueType == orion::ValueTypeNotGiven) { LM_E(("Runtime Error (value not given for metadata %s)", name.c_str())); - out += JSON_VALUE("value", stringValue); } else { LM_E(("Runtime Error (invalid value type for metadata %s)", name.c_str())); - out += JSON_VALUE("value", stringValue); - } - - out += "}"; - - if (!isLastElement) - { - out += ","; } - return out; + return jh.str(); } diff --git a/src/lib/ngsi/Metadata.h b/src/lib/ngsi/Metadata.h index ca82ed5c45..b8b1802919 100644 --- a/src/lib/ngsi/Metadata.h +++ b/src/lib/ngsi/Metadata.h @@ -90,7 +90,7 @@ typedef struct Metadata ~Metadata(); std::string render(bool comma); - std::string toJson(bool isLastElement); + std::string toJson(void); void release(void); void fill(const struct Metadata& md); std::string toStringValue(void) const; diff --git a/src/lib/ngsi/MetadataVector.cpp b/src/lib/ngsi/MetadataVector.cpp index bcd307866b..399333b187 100644 --- a/src/lib/ngsi/MetadataVector.cpp +++ b/src/lib/ngsi/MetadataVector.cpp @@ -32,6 +32,7 @@ #include "common/globals.h" #include "common/tag.h" #include "common/string.h" +#include "common/JsonHelper.h" #include "ngsi/MetadataVector.h" #include "mongoBackend/dbFieldEncoding.h" @@ -101,44 +102,17 @@ bool MetadataVector::matchFilter(const std::string& mdName, const std::vector& metadataFilter) +std::string MetadataVector::toJson(const std::vector& metadataFilter) { if (vec.size() == 0) { - return ""; - } - - - // - // Pass 1 - count the total number of metadatas valid for rendering. - // - // Metadatas named 'value' or 'type' are not rendered. - // This gives us a small problem in the logic here, about knowing whether the - // comma should be rendered or not. - // - // To fix this problem we need to do two passes over the vector, the first pass to - // count the number of valid metadatas and the second to do the work. - // In the second pass, if the number of rendered metadatas "so far" is less than the total - // number of valid metadatas, then the comma must be rendered. - // - int validMetadatas = 0; - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - if ((vec[ix]->name == "value") || (vec[ix]->name == "type") || !(matchFilter(vec[ix]->name, metadataFilter))) - { - continue; - } - - ++validMetadatas; + return "{}"; } + JsonHelper jh; - // - // And this is pass 2, where the real work is done. - // - std::string out; - int renderedMetadatas = 0; for (unsigned int ix = 0; ix < vec.size(); ++ix) { if ((vec[ix]->name == "value") || (vec[ix]->name == "type") || !(matchFilter(vec[ix]->name, metadataFilter))) @@ -146,16 +120,10 @@ std::string MetadataVector::toJson(bool isLastElement, const std::vectortoJson(renderedMetadatas == validMetadatas); + jh.addRaw(vec[ix]->name, vec[ix]->toJson()); } - if (!isLastElement) - { - out += ","; - } - - return out; + return jh.str(); } diff --git a/src/lib/ngsi/MetadataVector.h b/src/lib/ngsi/MetadataVector.h index a3507bd95c..e4e850ffd2 100644 --- a/src/lib/ngsi/MetadataVector.h +++ b/src/lib/ngsi/MetadataVector.h @@ -46,8 +46,7 @@ typedef struct MetadataVector MetadataVector(void); std::string render(bool comma); - std::string toJson(bool isLastElement, - const std::vector& metadataFilter); + std::string toJson(const std::vector& metadataFilter); std::string check(ApiVersion apiVersion); void push_back(Metadata* item); diff --git a/src/lib/orionTypes/EntityType.cpp b/src/lib/orionTypes/EntityType.cpp index 05ba35db7c..26f62fb1f3 100755 --- a/src/lib/orionTypes/EntityType.cpp +++ b/src/lib/orionTypes/EntityType.cpp @@ -31,6 +31,7 @@ #include "common/tag.h" #include "common/limits.h" +#include "common/JsonHelper.h" #include "ngsi/Request.h" #include "orionTypes/EntityType.h" @@ -143,24 +144,15 @@ void EntityType::release(void) */ std::string EntityType::toJson(bool includeType) { - std::string out = "{"; - char countV[STRING_SIZE_FOR_INT]; - - snprintf(countV, sizeof(countV), "%lld", count); + JsonHelper jh; if (includeType) { - out += JSON_VALUE("type", type) + ","; + jh.addString("type", type); } - out += JSON_STR("attrs") + ":"; - - out += "{"; - out += contextAttributeVector.toJsonTypes(); - out += "}"; + jh.addRaw("attrs", contextAttributeVector.toJsonTypes()); + jh.addNumber("count", count); - out += "," + JSON_STR("count") + ":" + countV; - out += "}"; - - return out; + return jh.str(); } diff --git a/src/lib/orionTypes/EntityTypeResponse.cpp b/src/lib/orionTypes/EntityTypeResponse.cpp index 9f8537fe84..34e91c856b 100755 --- a/src/lib/orionTypes/EntityTypeResponse.cpp +++ b/src/lib/orionTypes/EntityTypeResponse.cpp @@ -32,6 +32,7 @@ #include "common/globals.h" #include "common/tag.h" #include "common/limits.h" +#include "common/JsonHelper.h" #include "alarmMgr/alarmMgr.h" #include "ngsi/Request.h" @@ -115,19 +116,10 @@ void EntityTypeResponse::release(void) */ std::string EntityTypeResponse::toJson(void) { - std::string out = "{"; - char countV[STRING_SIZE_FOR_INT]; + JsonHelper jh; - snprintf(countV, sizeof(countV), "%lld", entityType.count); + jh.addRaw("attrs", entityType.contextAttributeVector.toJsonTypes()); + jh.addNumber("count", entityType.count); - out += JSON_STR("attrs") + ":"; - - out += "{"; - out += entityType.contextAttributeVector.toJsonTypes(); - out += "}"; - - out += "," + JSON_STR("count") + ":" + countV; - out += "}"; - - return out; + return jh.str(); } diff --git a/src/lib/parse/CompoundValueNode.cpp b/src/lib/parse/CompoundValueNode.cpp index d5744a9dc8..61cfd73247 100644 --- a/src/lib/parse/CompoundValueNode.cpp +++ b/src/lib/parse/CompoundValueNode.cpp @@ -30,6 +30,7 @@ #include "common/globals.h" #include "common/string.h" #include "common/tag.h" +#include "common/JsonHelper.h" #include "alarmMgr/alarmMgr.h" #include "parse/forbiddenChars.h" @@ -679,7 +680,7 @@ std::string CompoundValueNode::render(ApiVersion apiVersion, bool noComma, bool if (apiVersion == V2) { - return toJson(true, false); // FIXME P8: The info on comma-after-or-not is not available here ... + return toJson(true); } if (valueType == orion::ValueTypeString) @@ -690,7 +691,7 @@ std::string CompoundValueNode::render(ApiVersion apiVersion, bool noComma, bool else if (valueType == orion::ValueTypeNumber) { LM_T(LmtCompoundValueRender, ("I am a number (%s)", name.c_str())); - out = valueTag(key, toString(numberValue), jsonComma, container->valueType == orion::ValueTypeVector, true); + out = valueTag(key, double2string(numberValue), jsonComma, container->valueType == orion::ValueTypeVector, true); } else if (valueType == orion::ValueTypeBoolean) { @@ -818,201 +819,92 @@ std::string CompoundValueNode::render(ApiVersion apiVersion, bool noComma, bool /* **************************************************************************** * -* toJson - +* CompoundValueNode:toJson * -* FIXME P3: isLastElement is not used and should be removed */ -std::string CompoundValueNode::toJson(bool isLastElement, bool comma) +std::string CompoundValueNode::toJson(bool toplevel) { - std::string out = ""; - bool jsonComma = false; - std::string key = name; + std::string out; - if (container != NULL) + switch(valueType) { - if (!container->childV.empty()) - { - if (siblingNo < ((int) container->childV.size() - 1)) - { - jsonComma = true; - } - } + case orion::ValueTypeString: + out = toJsonString(stringValue); + break; - if (container->valueType == orion::ValueTypeVector) - { - key = "item"; - } - } + case orion::ValueTypeNumber: + out = double2string(numberValue); + break; - // No "comma after" if toplevel - if ((container == this) || (comma == false)) - { - jsonComma = false; - } + case orion::ValueTypeBoolean: + out = boolValue? "true" : "false"; + break; - if (valueType == orion::ValueTypeString) - { - LM_T(LmtCompoundValueRender, ("I am a String (%s)", name.c_str())); - if (container->valueType == orion::ValueTypeVector) - { - out = JSON_STR(stringValue); - } - else - { - out = JSON_STR(key) + ":" + JSON_STR(stringValue); - } - } - else if (valueType == orion::ValueTypeNumber) - { - LM_T(LmtCompoundValueRender, ("I am a Number (%s)", name.c_str())); - if (container->valueType == orion::ValueTypeVector) - { - out = JSON_NUMBER(toString(numberValue)); - } - else - { - out = JSON_STR(key) + ":" + JSON_NUMBER(toString(numberValue)); - } - } - else if (valueType == orion::ValueTypeBoolean) - { - LM_T(LmtCompoundValueRender, ("I am a Bool (%s)", name.c_str())); + case orion::ValueTypeNull: + out = "null"; + break; - if (container->valueType == orion::ValueTypeVector) - { - out = JSON_BOOL(boolValue); - } - else - { - out = JSON_STR(key) + ":" + JSON_BOOL(boolValue); - } - } - else if (valueType == orion::ValueTypeNull) - { - LM_T(LmtCompoundValueRender, ("I am NULL (%s)", name.c_str())); + case orion::ValueTypeVector: - if (container->valueType == orion::ValueTypeVector) + if (childV.size() == 0) { - out = "null"; + out = "[]"; } - else - { - out = JSON_STR(key) + ":" + "null"; + else { + out = "[" + childV[0]->toJson(false); + for (unsigned int ix = 1; ix < childV.size(); ix++) + { + out += "," + childV[ix]->toJson(false); + } + out += "]"; } - } - else if (valueType == orion::ValueTypeNotGiven) - { - LM_E(("Runtime Error (value not given (%s))", name.c_str())); - if (container->valueType == orion::ValueTypeVector) + break; + + case orion::ValueTypeObject: + if (childV.size() == 0) { - out = "null"; + out = "{}"; } else { - out = JSON_STR(key) + ":" + "not given"; - } - } - else if ((valueType == orion::ValueTypeVector) && (renderName == true)) - { - out += JSON_STR(name) + ":["; - for (uint64_t ix = 0; ix < childV.size(); ++ix) - { - out += childV[ix]->toJson(false, true); - } - - out += "]"; - } - else if ((valueType == orion::ValueTypeVector) && (container == this)) - { - // - // NOTE: Here, the '[]' are already added in the calling function - // - LM_T(LmtCompoundValueRender, ("I am a Vector (%s) and my container is TOPLEVEL", name.c_str())); - for (uint64_t ix = 0; ix < childV.size(); ++ix) - { - out += childV[ix]->toJson(ix == childV.size() - 1, true); + out = "{" + childV[0]->toJson(false); + for (unsigned int ix = 1; ix < childV.size(); ix++) + { + out += "," + childV[ix]->toJson(false); + } + out += "}"; } - } - else if ((valueType == orion::ValueTypeVector) && (container->valueType == orion::ValueTypeVector)) - { - out += "["; - - for (uint64_t ix = 0; ix < childV.size(); ++ix) + // Early return in this case, to avoid getting parentIsObject as in the + // case of root element we don't use key. Only the first call to + // toJson() uses toplevel == true + if (toplevel) { - out += childV[ix]->toJson(false, true); + return out; } + break; - out += "]"; - } - else if (valueType == orion::ValueTypeVector) - { - LM_T(LmtCompoundValueRender, ("I am a Vector (%s)", name.c_str())); - out += JSON_STR(name) + ":["; - for (uint64_t ix = 0; ix < childV.size(); ++ix) - { - out += childV[ix]->toJson(false, true); - } + case orion::ValueTypeNotGiven: + LM_E(("Runtime Error (value type not given (%s))", name.c_str())); + return ""; - out += "]"; + default: + LM_E(("Runtime Error (value type unknown (%s))", name.c_str())); + return ""; } - else if ((valueType == orion::ValueTypeObject) && (renderName == true)) - { - if (name == "toplevel") - { - name = "value"; - } - - out += JSON_STR(name) + ":{"; - for (uint64_t ix = 0; ix < childV.size(); ++ix) - { - out += childV[ix]->toJson(ix == childV.size() - 1, true); - } + bool parentIsObject = (container->valueType == orion::ValueTypeObject); - out += "}"; - } - else if ((valueType == orion::ValueTypeObject) && (container->valueType == orion::ValueTypeVector)) + if (parentIsObject) { - LM_T(LmtCompoundValueRender, ("I am an Object (%s) and my container is a Vector", name.c_str())); - out += "{"; - for (uint64_t ix = 0; ix < childV.size(); ++ix) - { - out += childV[ix]->toJson(ix == childV.size() - 1, true); - } - - out += "}"; + return toJsonString(name) + ":" + out; } - else if (valueType == orion::ValueTypeObject) + else { - if (rootP != this) - { - LM_T(LmtCompoundValueRender, ("I am an Object (%s) and my container is NOT a Vector", name.c_str())); - out += JSON_STR(name) + ":{"; - - for (uint64_t ix = 0; ix < childV.size(); ++ix) - { - out += childV[ix]->toJson(ix == childV.size() - 1, true); - } - - out += "}"; - } - else - { - LM_T(LmtCompoundValueRender, ("I am the TREE ROOT (%s: %d children)", name.c_str(), childV.size())); - for (uint64_t ix = 0; ix < childV.size(); ++ix) - { - out += childV[ix]->toJson(true, true); - } - } + return out; } - - out += jsonComma? "," : ""; - - return out; } - /* **************************************************************************** * * clone - diff --git a/src/lib/parse/CompoundValueNode.h b/src/lib/parse/CompoundValueNode.h index 803fe1ba34..a48044c21c 100644 --- a/src/lib/parse/CompoundValueNode.h +++ b/src/lib/parse/CompoundValueNode.h @@ -161,7 +161,8 @@ class CompoundValueNode std::string check(void); std::string finish(void); std::string render(ApiVersion apiVersion, bool noComma = false, bool noTag = false); - std::string toJson(bool isLastElement, bool comma); + + std::string toJson(bool toplevel); void shortShow(const std::string& indent); void show(const std::string& indent); diff --git a/src/lib/serviceRoutinesV2/getAllSubscriptions.cpp b/src/lib/serviceRoutinesV2/getAllSubscriptions.cpp index e89d049d30..8f4b50b099 100644 --- a/src/lib/serviceRoutinesV2/getAllSubscriptions.cpp +++ b/src/lib/serviceRoutinesV2/getAllSubscriptions.cpp @@ -83,7 +83,7 @@ std::string getAllSubscriptions if ((ciP->uriParamOptions["count"])) { ciP->httpHeader.push_back(HTTP_FIWARE_TOTAL_COUNT); - ciP->httpHeaderValue.push_back(toString(count)); + ciP->httpHeaderValue.push_back(double2string(count)); } std::string out; diff --git a/src/lib/serviceRoutinesV2/getEntity.cpp b/src/lib/serviceRoutinesV2/getEntity.cpp index 369f927210..5f2d265a73 100644 --- a/src/lib/serviceRoutinesV2/getEntity.cpp +++ b/src/lib/serviceRoutinesV2/getEntity.cpp @@ -101,7 +101,7 @@ std::string getEntity entity.fill(&parseDataP->qcrs.res); std::string answer; - TIMED_RENDER(answer = entity.render(ciP->uriParamOptions, ciP->uriParam, false)); + TIMED_RENDER(answer = entity.render(ciP->uriParamOptions, ciP->uriParam)); if (parseDataP->qcrs.res.errorCode.code == SccOk && parseDataP->qcrs.res.contextElementResponseVector.size() > 1) { diff --git a/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp b/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp index 664038e953..47cf3abf0f 100644 --- a/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp +++ b/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp @@ -112,23 +112,13 @@ std::string getEntityAttributeValue &(ciP->httpStatusCode), ciP->uriParamOptions[OPT_KEY_VALUES], ciP->uriParam[URI_PARAM_METADATA], - EntityAttributeValueRequest, - false)); + EntityAttributeValueRequest)); } else { if (attribute.pcontextAttribute->compoundValueP != NULL) { TIMED_RENDER(answer = attribute.pcontextAttribute->compoundValueP->render(ciP->apiVersion)); - - if (attribute.pcontextAttribute->compoundValueP->isObject()) - { - answer = "{" + answer + "}"; - } - else if (attribute.pcontextAttribute->compoundValueP->isVector()) - { - answer = "[" + answer + "]"; - } } else { diff --git a/src/lib/serviceRoutinesV2/getRegistrations.cpp b/src/lib/serviceRoutinesV2/getRegistrations.cpp index 4183c3bfc2..9926c3a471 100644 --- a/src/lib/serviceRoutinesV2/getRegistrations.cpp +++ b/src/lib/serviceRoutinesV2/getRegistrations.cpp @@ -84,7 +84,7 @@ std::string getRegistrations if ((ciP->uriParamOptions["count"])) { ciP->httpHeader.push_back(HTTP_FIWARE_TOTAL_COUNT); - ciP->httpHeaderValue.push_back(toString(count)); + ciP->httpHeaderValue.push_back(double2string(count)); } TIMED_RENDER(out = vectorToJson(registrationV)); diff --git a/test/functionalTest/cases/0000_ipv6_support/ipv6_only.test b/test/functionalTest/cases/0000_ipv6_support/ipv6_only.test index 0a57e702df..d971f7878b 100644 --- a/test/functionalTest/cases/0000_ipv6_support/ipv6_only.test +++ b/test/functionalTest/cases/0000_ipv6_support/ipv6_only.test @@ -155,4 +155,4 @@ Date: REGEX(.*) brokerStop CB accumulatorStop ${LISTENER_PORT} accumulatorStop ${LISTENER2_PORT} -#dbDrop CB +dbDrop CB diff --git a/test/functionalTest/cases/0876_entity_dates/entity_dates_overridden_by_user_subs.test b/test/functionalTest/cases/0876_entity_dates/entity_dates_overridden_by_user_subs.test index b94501f10c..a50d43c606 100644 --- a/test/functionalTest/cases/0876_entity_dates/entity_dates_overridden_by_user_subs.test +++ b/test/functionalTest/cases/0876_entity_dates/entity_dates_overridden_by_user_subs.test @@ -432,7 +432,7 @@ Date: REGEX(.*) ======================================================================================================================= POST http://localhost:REGEX(\d+)/notify Fiware-Servicepath: / -Content-Length: 279 +Content-Length: 362 User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) Ngsiv2-Attrsformat: normalized Host: localhost:REGEX(\d+) @@ -462,6 +462,11 @@ Fiware-Correlator: REGEX([0-9a-f\-]{36}) "type": "Text", "value": "bar" }, + "dateModified": { + "metadata": {}, + "type": "DateTime", + "value": "REGEX(20[1|2]\d-\d\d-\d\dT\d\d:\d\d:\d\d.\d\dZ)" + }, "id": "E2", "type": "T" } diff --git a/test/functionalTest/cases/1179_options_test/GET_v2_ent_attr_val_options_text.test b/test/functionalTest/cases/1179_options_test/GET_v2_ent_attr_val_options_text.test index e61cef5052..2be9c42801 100644 --- a/test/functionalTest/cases/1179_options_test/GET_v2_ent_attr_val_options_text.test +++ b/test/functionalTest/cases/1179_options_test/GET_v2_ent_attr_val_options_text.test @@ -58,7 +58,7 @@ echo echo -echo "02. GET /v2/entities/E!/attrs/a_string/value" +echo "02. GET /v2/entities/E1/attrs/a_string/value" echo "============================================" orionCurl --url /v2/entities/E1/attrs/a_string/value --out text echo @@ -104,7 +104,7 @@ Date: REGEX(.*) -02. GET /v2/entities/E!/attrs/a_string/value +02. GET /v2/entities/E1/attrs/a_string/value ============================================ HTTP/1.1 200 OK Content-Length: 12 diff --git a/test/functionalTest/cases/1367_time_measures/time_measure_stats.test b/test/functionalTest/cases/1367_time_measures/time_measure_stats.test index 2a01cc3720..85ea92df97 100644 --- a/test/functionalTest/cases/1367_time_measures/time_measure_stats.test +++ b/test/functionalTest/cases/1367_time_measures/time_measure_stats.test @@ -217,7 +217,7 @@ echo 01. Second call to GET /statistics (gives time stat of FIRST request for /statistics) ===================================================================================== HTTP/1.1 200 OK -Content-Length: 127 +Content-Length: REGEX(.*) Content-Type: application/json Fiware-Correlator: REGEX([0-9a-f\-]{36}) Date: REGEX(.*) @@ -326,7 +326,7 @@ Date: REGEX(.*) 03. GET /statistics =================== HTTP/1.1 200 OK -Content-Length: 451 +Content-Length: REGEX(.*) Content-Type: application/json Fiware-Correlator: REGEX([0-9a-f\-]{36}) Date: REGEX(.*) @@ -370,7 +370,7 @@ Date: REGEX(.*) 05. GET /statistics =================== HTTP/1.1 200 OK -Content-Length: 477 +Content-Length: REGEX(\d+) Content-Type: application/json Fiware-Correlator: REGEX([0-9a-f\-]{36}) Date: REGEX(.*) @@ -435,7 +435,7 @@ Date: REGEX(.*) 07. GET /statistics =================== HTTP/1.1 200 OK -Content-Length: 422 +Content-Length: REGEX(.*) Content-Type: application/json Fiware-Correlator: REGEX([0-9a-f\-]{36}) Date: REGEX(.*) diff --git a/test/functionalTest/cases/2507_csub_metadata_field/previous_value_with_compounds.test b/test/functionalTest/cases/2507_csub_metadata_field/previous_value_with_compounds.test index f3316267d6..f19e6bc012 100644 --- a/test/functionalTest/cases/2507_csub_metadata_field/previous_value_with_compounds.test +++ b/test/functionalTest/cases/2507_csub_metadata_field/previous_value_with_compounds.test @@ -265,7 +265,7 @@ Date: REGEX(.*) ============================================================================================== POST http://localhost:REGEX(\d+)/notify Fiware-Servicepath: / -Content-Length: 220 +Content-Length: 217 User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) Ngsiv2-Attrsformat: normalized Host: localhost:REGEX(\d+) @@ -279,13 +279,13 @@ Fiware-Correlator: REGEX([0-9a-f\-]{36}) "A": { "metadata": { "previousValue": { - "toplevel": [ + "type": "ComplexVector", + "value": [ 1, { "b": "foo" } - ], - "type": "ComplexVector" + ] } }, "type": "ComplexObject", diff --git a/test/functionalTest/cases/2750_common_metrics/2750_complex_service_path.test b/test/functionalTest/cases/2750_common_metrics/2750_complex_service_path.test index 58c631dbb6..87af2c62a0 100644 --- a/test/functionalTest/cases/2750_common_metrics/2750_complex_service_path.test +++ b/test/functionalTest/cases/2750_common_metrics/2750_complex_service_path.test @@ -125,7 +125,7 @@ Date: REGEX(.*) 05. Ask for Metrics, see A1 and A2 as service paths, as well as two 'root service path' ======================================================================================= HTTP/1.1 200 OK -Content-Length: REGEX((842|850)) +Content-Length: REGEX(\d+) Content-Type: application/json Fiware-Correlator: REGEX([0-9a-f\-]{36}) Date: REGEX(.*) diff --git a/test/functionalTest/cases/2750_common_metrics/2750_forwards.test b/test/functionalTest/cases/2750_common_metrics/2750_forwards.test index 773b791eba..a25e744135 100644 --- a/test/functionalTest/cases/2750_common_metrics/2750_forwards.test +++ b/test/functionalTest/cases/2750_common_metrics/2750_forwards.test @@ -304,7 +304,7 @@ Date: REGEX(.*) 09. Ask for metrics, see 1 error in outgoing transactions ========================================================= HTTP/1.1 200 OK -Content-Length: 1908 +Content-Length: REGEX(\d+) Content-Type: application/json Fiware-Correlator: REGEX([0-9a-f\-]{36}) Date: REGEX(.*) diff --git a/test/functionalTest/cases/2750_common_metrics/2750_reset_metrics.test b/test/functionalTest/cases/2750_common_metrics/2750_reset_metrics.test index a19a2cad84..aaa3f8673c 100644 --- a/test/functionalTest/cases/2750_common_metrics/2750_reset_metrics.test +++ b/test/functionalTest/cases/2750_common_metrics/2750_reset_metrics.test @@ -146,7 +146,7 @@ Date: REGEX(.*) 04. Ask for Metrics, see 1 Incoming Transaction (the reset-request in step 03 :-) ================================================================================= HTTP/1.1 200 OK -Content-Length: 332 +Content-Length: REGEX(\d+) Content-Type: application/json Fiware-Correlator: REGEX([0-9a-f\-]{36}) Date: REGEX(.*) @@ -184,7 +184,7 @@ Date: REGEX(.*) 05. Ask for Metrics, with ?reset=true to reset after responding =============================================================== HTTP/1.1 200 OK -Content-Length: 620 +Content-Length: REGEX(\d+) Content-Type: application/json Fiware-Correlator: REGEX([0-9a-f\-]{36}) Date: REGEX(.*) @@ -198,13 +198,13 @@ Date: REGEX(.*) "serviceTime": REGEX(.*) }, "root-subserv": { - "incomingTransactionResponseSize": 332, + "incomingTransactionResponseSize": 320, "incomingTransactions": 1, "serviceTime": REGEX(.*) } }, "sum": { - "incomingTransactionResponseSize": 332, + "incomingTransactionResponseSize": 320, "incomingTransactions": 2, "serviceTime": REGEX(.*) } @@ -217,13 +217,13 @@ Date: REGEX(.*) "serviceTime": REGEX(.*) }, "root-subserv": { - "incomingTransactionResponseSize": 332, + "incomingTransactionResponseSize": 320, "incomingTransactions": 1, "serviceTime": REGEX(.*) } }, "sum": { - "incomingTransactionResponseSize": 332, + "incomingTransactionResponseSize": 320, "incomingTransactions": 2, "serviceTime": REGEX(.*) } @@ -234,7 +234,7 @@ Date: REGEX(.*) 06. Ask for Metrics, see 1 Incoming Transaction (step 05) ========================================================= HTTP/1.1 200 OK -Content-Length: 456 +Content-Length: REGEX(\d+) Content-Type: application/json Fiware-Correlator: REGEX([0-9a-f\-]{36}) Date: REGEX(.*) @@ -244,13 +244,13 @@ Date: REGEX(.*) "default-service": { "subservs": { "SP5": { - "incomingTransactionResponseSize": 620, + "incomingTransactionResponseSize": REGEX(\d+), "incomingTransactions": 1, "serviceTime": REGEX(.*) } }, "sum": { - "incomingTransactionResponseSize": 620, + "incomingTransactionResponseSize": REGEX(\d+), "incomingTransactions": 1, "serviceTime": REGEX(.*) } @@ -259,13 +259,13 @@ Date: REGEX(.*) "sum": { "subservs": { "SP5": { - "incomingTransactionResponseSize": 620, + "incomingTransactionResponseSize": REGEX(\d+), "incomingTransactions": 1, "serviceTime": REGEX(.*) } }, "sum": { - "incomingTransactionResponseSize": 620, + "incomingTransactionResponseSize": REGEX(\d+), "incomingTransactions": 1, "serviceTime": REGEX(.*) } diff --git a/test/functionalTest/cases/2750_common_metrics/2750_totalPayloadAsMetric.test b/test/functionalTest/cases/2750_common_metrics/2750_totalPayloadAsMetric.test index 512472b128..73f76062b5 100644 --- a/test/functionalTest/cases/2750_common_metrics/2750_totalPayloadAsMetric.test +++ b/test/functionalTest/cases/2750_common_metrics/2750_totalPayloadAsMetric.test @@ -241,7 +241,7 @@ Date: REGEX(.*) 06. Ask for Metrics, see 6 Incoming Transactions, and 150 bytes in incomingTransactionRequestSize ================================================================================================= HTTP/1.1 200 OK -Content-Length: 931 +Content-Length: REGEX(\d+) Content-Type: application/json Fiware-Correlator: REGEX([0-9a-f\-]{36}) Date: REGEX(.*) @@ -317,7 +317,7 @@ Date: REGEX(.*) 08. Ask for Metrics, see 8, and see incomingTransactionResponseSize =================================================================== HTTP/1.1 200 OK -Content-Length: 1145 +Content-Length: REGEX(\d+) Content-Type: application/json Fiware-Correlator: REGEX([0-9a-f\-]{36}) Date: REGEX(.*) diff --git a/test/functionalTest/cases/2846_empty_maps_in_metrics/empty_maps_in_metrics.test b/test/functionalTest/cases/2846_empty_maps_in_metrics/empty_maps_in_metrics.test index 500de06988..22c9a9292e 100644 --- a/test/functionalTest/cases/2846_empty_maps_in_metrics/empty_maps_in_metrics.test +++ b/test/functionalTest/cases/2846_empty_maps_in_metrics/empty_maps_in_metrics.test @@ -94,7 +94,7 @@ Date: REGEX(.*) 03. GET metrics and reset metrics at the same time ================================================== HTTP/1.1 200 OK -Content-Length: 678 +Content-Length: REGEX(\d+) Content-Type: application/json Fiware-Correlator: REGEX([0-9a-f\-]{36}) Date: REGEX(.*) @@ -150,7 +150,7 @@ Date: REGEX(.*) 04. GET metrics, see no 'emptied reported items' ================================================ HTTP/1.1 200 OK -Content-Length: 461 +Content-Length: REGEX(\d+) Content-Type: application/json Fiware-Correlator: REGEX([0-9a-f\-]{36}) Date: REGEX(.*) From d34e43f7a70eff0c4e99233d844dbce758c32094 Mon Sep 17 00:00:00 2001 From: Fermin Galan Marquez Date: Wed, 5 Sep 2018 13:24:08 +0200 Subject: [PATCH 02/10] FIX comments in the code --- src/lib/apiTypesV2/Entity.cpp | 22 ++++++++++++++------- src/lib/ngsi/ContextAttribute.cpp | 3 ++- src/lib/ngsi/ContextElement.cpp | 32 +++++++++++++++++++------------ 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/lib/apiTypesV2/Entity.cpp b/src/lib/apiTypesV2/Entity.cpp index 8f49d48022..6d1b23e005 100644 --- a/src/lib/apiTypesV2/Entity.cpp +++ b/src/lib/apiTypesV2/Entity.cpp @@ -72,10 +72,19 @@ Entity::~Entity() * dateCreatedOption and dateModifiedOption are due to deprecated ways of requesting * date in response. If used, the date is added at the end. * -* FIXME P3: this methods is complex. It should be refactored -* FIXME P3: maybe dateCreated and dateModified should be pre-included in the attributes -* vector, so all three (dateCreated, dateModified and dateExpires) could be processed in -* a similar way. +* FIXME P7: some comments regarding this function +* +* - Code should be integrated with the one on ContextElement::filterAttributes(). However, +* this is probable a sub-task of the more general task of changing ContextElement to use +* Entity class internally +* - The function is pretty long and complex. It should be refactored to simplify it +* - Related with this simplification maybe dateCreated and dateModified should be pre-included +* in the attributes vector, so all three (dateCreated, dateModified and dateExpires) could be +* processed in a similar way. +* - This function shouldn't be called from toJson() code. The mongoBackend should deal with +* attributeVector preparation. Thus, either we leave the function heare and mongoBackend calls +* Entity::filterAttributes() or the logic is moved to mongoBackend (to be decided when we face +* this FIXME). */ void Entity::filterAttributes ( @@ -217,9 +226,8 @@ std::string Entity::render } // Get the effective vector of attributes to render - // FIXME PR: given this is "destructive", maybe this should be done before calling render logic, no in the render itself - // FIXME PR: this should be moved to mongoBackend, so it returns the entity as it has to be rendered... however, note that - // we are adding some attributes (DATE_MODIFIED and DATE_CREATED) here. Not sure how to solve it... + // FIXME P7: filterAttributes will be moved and invoking it would not be needed from toJson() + // (see comment in filterAttributes) filterAttributes(attrsFilter, uriParamOptions[DATE_CREATED], uriParamOptions[DATE_MODIFIED]); std::string out; diff --git a/src/lib/ngsi/ContextAttribute.cpp b/src/lib/ngsi/ContextAttribute.cpp index 72bc2ee1d8..8c6f8ed88d 100644 --- a/src/lib/ngsi/ContextAttribute.cpp +++ b/src/lib/ngsi/ContextAttribute.cpp @@ -903,7 +903,8 @@ std::string ContextAttribute::toJsonValue(void) * * toJsonAsValue - * -* FIXME PR: given the new method toJsonValue() the name of this one should be changed +* FIXME P7: toJsonValue() and toJsonAsValue() are very similar and may be confusing. +* Try to find a couple of names different and meaningful enough */ std::string ContextAttribute::toJsonAsValue ( diff --git a/src/lib/ngsi/ContextElement.cpp b/src/lib/ngsi/ContextElement.cpp index d35d994cf3..25bd195456 100644 --- a/src/lib/ngsi/ContextElement.cpp +++ b/src/lib/ngsi/ContextElement.cpp @@ -121,8 +121,9 @@ std::string ContextElement::render * dateCreatedOption and dateModifiedOption are due to deprecated ways of requesting * date in response. If used, the date is added at the end. * -* FIXME PR: lot of duplicated code from Entity NGSIv2 class but we don't care -* as NGSIv1 code is deprecated. The duplication will be solved when NGSIv1 gets removed +* FIXME P7: duplicated code in Entity::filterAttributes(). However, this +* will be solved if ContextElement is refactored to use Entity as internal representation +* for entities. */ void ContextElement::filterAttributes(const std::vector& attrsFilter, bool blacklist) { @@ -232,8 +233,9 @@ void ContextElement::filterAttributes(const std::vector& attrsFilt * * ContextElement::toJson - * -* FIXME PR: lot of duplicated code from Entity NGSIv2 class but we don't care -* as NGSIv1 code is deprecated. The duplication will be solved when NGSIv1 gets removed +* FIXME P7: duplicated code in Entity::toJson(). However, this +* will be solved if ContextElement is refactored to use Entity as internal representation +* for entities. */ std::string ContextElement::toJson ( @@ -244,6 +246,8 @@ std::string ContextElement::toJson ) { // Get the effective vector of attributes to render + // FIXME P7: filterAttributes will be moved and invoking it would not be needed from toJson() + // (see comment in filterAttributes) filterAttributes(attrsFilter, blacklist); std::string out; @@ -271,8 +275,9 @@ std::string ContextElement::toJson * * ContextElement::toJsonValues - * -* FIXME PR: lot of duplicated code from Entity NGSIv2 class but we don't care -* as NGSIv1 code is deprecated. The duplication will be solved when NGSIv1 gets removed +* FIXME P7: duplicated code in Entity::toJsonValues(). However, this +* will be solved if ContextElement is refactored to use Entity as internal representation +* for entities. */ std::string ContextElement::toJsonValues(void) { @@ -300,8 +305,9 @@ std::string ContextElement::toJsonValues(void) * * ContextElement::toJsonUniqueValues - * -* FIXME PR: lot of duplicated code from Entity NGSIv2 class but we don't care -* as NGSIv1 code is deprecated. The duplication will be solved when NGSIv1 gets removed +* FIXME P7: duplicated code in toJsonUniqueValues::filterAttributes(). However, this +* will be solved if ContextElement is refactored to use Entity as internal representation +* for entities. */ std::string ContextElement::toJsonUniqueValues(void) { @@ -343,8 +349,9 @@ std::string ContextElement::toJsonUniqueValues(void) * * ContextElement::toJsonKeyvalues - * -* FIXME PR: lot of duplicated code from Entity NGSIv2 class but we don't care -* as NGSIv1 code is deprecated. The duplication will be solved when NGSIv1 gets removed +* FIXME P7: duplicated code in Entity::toJsonKeyValues(). However, this +* will be solved if ContextElement is refactored to use Entity as internal representation +* for entities. */ std::string ContextElement::toJsonKeyvalues(void) { @@ -370,8 +377,9 @@ std::string ContextElement::toJsonKeyvalues(void) * * ContextElement::toJsonNormalized - * -* FIXME PR: lot of duplicated code from Entity NGSIv2 class but we don't care -* as NGSIv1 code is deprecated. The duplication will be solved when NGSIv1 gets removed +* FIXME P7: duplicated code in Entity::toJsonNormalized(). However, this +* will be solved if ContextElement is refactored to use Entity as internal representation +* for entities. */ std::string ContextElement::toJsonNormalized(const std::vector& metadataFilter) { From 1a5045e2d677e72b23a14d3303c051ce097bde33 Mon Sep 17 00:00:00 2001 From: Fermin Galan Marquez Date: Wed, 5 Sep 2018 16:32:39 +0200 Subject: [PATCH 03/10] FIX code style --- src/lib/apiTypesV2/Attribute.cpp | 2 +- src/lib/apiTypesV2/Entity.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/apiTypesV2/Attribute.cpp b/src/lib/apiTypesV2/Attribute.cpp index 2b1e368fd3..039e1bb748 100644 --- a/src/lib/apiTypesV2/Attribute.cpp +++ b/src/lib/apiTypesV2/Attribute.cpp @@ -82,7 +82,7 @@ std::string Attribute::render jh.addRaw(pcontextAttribute->name, pcontextAttribute->toJsonValue()); out = jh.str(); } - else // NGSI_V2_NORMALIZED + else // NGSI_V2_NORMALIZED { out = pcontextAttribute->toJson(metadataFilter); } diff --git a/src/lib/apiTypesV2/Entity.h b/src/lib/apiTypesV2/Entity.h index 6e8674a0c9..a5d77789c1 100644 --- a/src/lib/apiTypesV2/Entity.h +++ b/src/lib/apiTypesV2/Entity.h @@ -83,9 +83,9 @@ class Entity void hideIdAndType(bool hide = true); private: - void filterAttributes (const std::vector& attrsFilter, - bool dateCreatedOption, - bool dateModifiedOption); + void filterAttributes(const std::vector& attrsFilter, + bool dateCreatedOption, + bool dateModifiedOption); std::string toJsonValues(void); std::string toJsonUniqueValues(void); From a99e4d69b0218f7129593809336d4b510ac1ae35 Mon Sep 17 00:00:00 2001 From: Fermin Galan Marquez Date: Wed, 5 Sep 2018 17:03:20 +0200 Subject: [PATCH 04/10] ADD CNR entries --- CHANGES_NEXT_RELEASE | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 7f5a507d0d..4f9b307465 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,4 +1,6 @@ - Fix: GET /v2/subscriptions and GET /v2/subscriptions/{id} crashes for permanent subscriptions created before version 1.13.0 (#3256) - Hardening: Mongo driver now compiled using --use-sasl-client --ssl to enable proper DB authentication mechanisms - Fix: correct error payload using errorCode (previously orionError was used) in POST /v1/queryContext and POST /v1/updateContext in some cases +- Fix: bug in metadata compound value rendering in NGSIv2 (sometimes "toplevel" key was wrongly inserted in the resulting JSON object) - Hardening: modification of the URL parsing mechanism, making it more efficient, and the source code easier to follow (#3109, step 1) +- Hardening: refactor NGSIv2 rendering code (throughput increase up to 33%/365% in entities/subscriptions rendering intensive scenarios) (#1298) From 295296bfa8f6ec71dd105dd4741f4cf2c88facee Mon Sep 17 00:00:00 2001 From: Fermin Galan Marquez Date: Wed, 5 Sep 2018 21:13:45 +0200 Subject: [PATCH 05/10] FIX issues raised in code review --- src/lib/apiTypesV2/Entity.cpp | 22 +++++++++++----------- src/lib/ngsi/ContextAttributeVector.cpp | 4 ++-- src/lib/ngsi/ContextAttributeVector.h | 2 +- src/lib/ngsi/ContextElement.cpp | 22 +++++++++++----------- src/lib/parse/CompoundValueNode.cpp | 2 +- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/lib/apiTypesV2/Entity.cpp b/src/lib/apiTypesV2/Entity.cpp index 6d1b23e005..0620c5c0ea 100644 --- a/src/lib/apiTypesV2/Entity.cpp +++ b/src/lib/apiTypesV2/Entity.cpp @@ -116,9 +116,9 @@ void Entity::filterAttributes } else { - // Reorder attributes in the same order they are in attrsFilter, excluding the ones - // note there (i.e. filtering them out) and giving special treatment to creation - // and modification dates + // Reorder attributes in the same order they are in attrsFilter (attributes not + // in attrsFilter are filtered out). Creation and modification dates have a special + // treatment // // The (attributeVector.lookup(DATE_XXXX) == -1) check is to give preference to user // defined attributes (see @@ -129,13 +129,13 @@ void Entity::filterAttributes for (unsigned int ix = 0; ix < attrsFilter.size(); ix++) { std::string attrsFilterItem = attrsFilter[ix]; - if ((creDate != 0) && (attrsFilterItem == DATE_CREATED) && (attributeVector.lookup(DATE_CREATED) == -1)) + if ((creDate != 0) && (attrsFilterItem == DATE_CREATED) && (attributeVector.get(DATE_CREATED) == -1)) { ContextAttribute* caP = new ContextAttribute(DATE_CREATED, DATE_TYPE, creDate); caNewV.push_back(caP); dateCreatedAdded = true; } - else if ((modDate != 0) && (attrsFilterItem == DATE_MODIFIED) && (attributeVector.lookup(DATE_MODIFIED) == -1)) + else if ((modDate != 0) && (attrsFilterItem == DATE_MODIFIED) && (attributeVector.get(DATE_MODIFIED) == -1)) { ContextAttribute* caP = new ContextAttribute(DATE_MODIFIED, DATE_TYPE, modDate); caNewV.push_back(caP); @@ -144,7 +144,7 @@ void Entity::filterAttributes // Actual attribute filtering only takes place if '*' was not used else { - int found = attributeVector.lookup(attrsFilterItem); + int found = attributeVector.get(attrsFilterItem); if (found != -1) { caNewV.push_back(attributeVector.vec[found]); @@ -153,7 +153,7 @@ void Entity::filterAttributes } } - // All the remainder elements in attributeVector need to be released, + // All the remaining elements in attributeVector need to be released, // before overriding the vector with caNewV attributeVector.release(); @@ -161,7 +161,7 @@ void Entity::filterAttributes } } - // Legacy support for options=dateCreated and opations=dateModified + // Legacy support for options=dateCreated and options=dateModified if (dateCreatedOption && !dateCreatedAdded && (creDate != 0)) { ContextAttribute* caP = new ContextAttribute(DATE_CREATED, DATE_TYPE, creDate); @@ -173,10 +173,10 @@ void Entity::filterAttributes attributeVector.push_back(caP); } - // Removing dateExpires if not explictely included in the filter + // Removing dateExpires if not explicitly included in the filter bool includeDateExpires = (std::find(attrsFilter.begin(), attrsFilter.end(), DATE_EXPIRES) != attrsFilter.end()); int found; - if (!includeDateExpires && ((found = attributeVector.lookup(DATE_EXPIRES)) != -1)) + if (!includeDateExpires && ((found = attributeVector.get(DATE_EXPIRES)) != -1)) { attributeVector.vec[found]->release(); attributeVector.vec.erase(attributeVector.vec.begin() + found); @@ -308,7 +308,7 @@ std::string Entity::toJsonUniqueValues(void) out += ","; } - // The substrig trick removes the final ",". It is not very smart, but it saves + // The substring trick replaces final "," by "]". It is not very smart, but it saves // a second pass on the vector, once the "unicity" has been calculated in the hashmap return out.substr(0, out.length() - 1 ) + "]"; } diff --git a/src/lib/ngsi/ContextAttributeVector.cpp b/src/lib/ngsi/ContextAttributeVector.cpp index f6aed40cbe..a4fc02817c 100644 --- a/src/lib/ngsi/ContextAttributeVector.cpp +++ b/src/lib/ngsi/ContextAttributeVector.cpp @@ -337,9 +337,9 @@ void ContextAttributeVector::fill(ContextAttributeVector* cavP, bool useDefaultT /* **************************************************************************** * -* lookup - +* get - */ -int ContextAttributeVector::lookup(const std::string& attributeName) const +int ContextAttributeVector::get(const std::string& attributeName) const { for (unsigned int ix = 0; ix < vec.size(); ++ix) { diff --git a/src/lib/ngsi/ContextAttributeVector.h b/src/lib/ngsi/ContextAttributeVector.h index 57bf591162..e08c6633ef 100644 --- a/src/lib/ngsi/ContextAttributeVector.h +++ b/src/lib/ngsi/ContextAttributeVector.h @@ -49,7 +49,7 @@ typedef struct ContextAttributeVector unsigned int size(void) const; void release(void); void fill(struct ContextAttributeVector* cavP, bool useDefaultType = false); - int lookup(const std::string& attributeName) const; + int get(const std::string& attributeName) const; ContextAttribute* operator[](unsigned int ix) const; diff --git a/src/lib/ngsi/ContextElement.cpp b/src/lib/ngsi/ContextElement.cpp index 25bd195456..d5361a3e58 100644 --- a/src/lib/ngsi/ContextElement.cpp +++ b/src/lib/ngsi/ContextElement.cpp @@ -140,12 +140,12 @@ void ContextElement::filterAttributes(const std::vector& attrsFilt if (!blacklist) { - if ((entityId.creDate != 0) && (std::find(attrsFilter.begin(), attrsFilter.end(), DATE_CREATED) != attrsFilter.end()) && (contextAttributeVector.lookup(DATE_CREATED) == -1)) + if ((entityId.creDate != 0) && (std::find(attrsFilter.begin(), attrsFilter.end(), DATE_CREATED) != attrsFilter.end()) && (contextAttributeVector.get(DATE_CREATED) == -1)) { ContextAttribute* caP = new ContextAttribute(DATE_CREATED, DATE_TYPE, entityId.creDate); contextAttributeVector.push_back(caP); } - if ((entityId.modDate != 0) && (std::find(attrsFilter.begin(), attrsFilter.end(), DATE_MODIFIED) != attrsFilter.end()) && (contextAttributeVector.lookup(DATE_MODIFIED) == -1)) + if ((entityId.modDate != 0) && (std::find(attrsFilter.begin(), attrsFilter.end(), DATE_MODIFIED) != attrsFilter.end()) && (contextAttributeVector.get(DATE_MODIFIED) == -1)) { ContextAttribute* caP = new ContextAttribute(DATE_MODIFIED, DATE_TYPE, entityId.modDate); contextAttributeVector.push_back(caP); @@ -158,9 +158,9 @@ void ContextElement::filterAttributes(const std::vector& attrsFilt // // 1. If blacklist == true, go through the contextAttributeVector, taking only its elements // not in attrsFilter - // 2. If blacklist == false, reorder attributes in the same order they are in attrsFilter, excluding - // the ones not there (i.e. filtering them out) and giving special treatment to creation - // and modification dates + // 2. If blacklist == false, reorder attributes in the same order they are in + // attrsFilter (attributes not in attrsFilter are filtered out). Creation and modification + // dates have a special treatment if (blacklist) { @@ -186,12 +186,12 @@ void ContextElement::filterAttributes(const std::vector& attrsFilt for (unsigned int ix = 0; ix < attrsFilter.size(); ix++) { std::string attrsFilterItem = attrsFilter[ix]; - if ((entityId.creDate != 0) && (attrsFilterItem == DATE_CREATED) && (contextAttributeVector.lookup(DATE_CREATED) == -1)) + if ((entityId.creDate != 0) && (attrsFilterItem == DATE_CREATED) && (contextAttributeVector.get(DATE_CREATED) == -1)) { ContextAttribute* caP = new ContextAttribute(DATE_CREATED, DATE_TYPE, entityId.creDate); caNewV.push_back(caP); } - else if ((entityId.modDate != 0) && (attrsFilterItem == DATE_MODIFIED) && (contextAttributeVector.lookup(DATE_MODIFIED) == -1)) + else if ((entityId.modDate != 0) && (attrsFilterItem == DATE_MODIFIED) && (contextAttributeVector.get(DATE_MODIFIED) == -1)) { ContextAttribute* caP = new ContextAttribute(DATE_MODIFIED, DATE_TYPE, entityId.modDate); caNewV.push_back(caP); @@ -199,7 +199,7 @@ void ContextElement::filterAttributes(const std::vector& attrsFilt // Actual attribute filtering only takes place if '*' was not used else { - int found = contextAttributeVector.lookup(attrsFilterItem); + int found = contextAttributeVector.get(attrsFilterItem); if (found != -1) { caNewV.push_back(contextAttributeVector.vec[found]); @@ -208,7 +208,7 @@ void ContextElement::filterAttributes(const std::vector& attrsFilt } } - // All the remainder elements in attributeVector need to be released, + // All the remaining elements in attributeVector need to be released, // before overriding the vector with caNewV contextAttributeVector.release(); @@ -218,10 +218,10 @@ void ContextElement::filterAttributes(const std::vector& attrsFilt } } - // Removing dateExpires if not explictely included in the filter + // Removing dateExpires if not explicitly included in the filter bool includeDateExpires = (std::find(attrsFilter.begin(), attrsFilter.end(), DATE_EXPIRES) != attrsFilter.end()); int found; - if (!blacklist && !includeDateExpires && ((found = contextAttributeVector.lookup(DATE_EXPIRES)) != -1)) + if (!blacklist && !includeDateExpires && ((found = contextAttributeVector.get(DATE_EXPIRES)) != -1)) { contextAttributeVector.vec[found]->release(); contextAttributeVector.vec.erase(contextAttributeVector.vec.begin() + found); diff --git a/src/lib/parse/CompoundValueNode.cpp b/src/lib/parse/CompoundValueNode.cpp index 61cfd73247..13e621208f 100644 --- a/src/lib/parse/CompoundValueNode.cpp +++ b/src/lib/parse/CompoundValueNode.cpp @@ -826,7 +826,7 @@ std::string CompoundValueNode::toJson(bool toplevel) { std::string out; - switch(valueType) + switch (valueType) { case orion::ValueTypeString: out = toJsonString(stringValue); From c9faf327f4052388a6ecd93b5d02adbf42480452 Mon Sep 17 00:00:00 2001 From: Fermin Galan Marquez Date: Thu, 6 Sep 2018 16:20:15 +0200 Subject: [PATCH 06/10] FIX memory leak --- src/lib/apiTypesV2/Entity.cpp | 1 + src/lib/ngsi/ContextElement.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/lib/apiTypesV2/Entity.cpp b/src/lib/apiTypesV2/Entity.cpp index 0620c5c0ea..e1c00ebe6f 100644 --- a/src/lib/apiTypesV2/Entity.cpp +++ b/src/lib/apiTypesV2/Entity.cpp @@ -179,6 +179,7 @@ void Entity::filterAttributes if (!includeDateExpires && ((found = attributeVector.get(DATE_EXPIRES)) != -1)) { attributeVector.vec[found]->release(); + delete attributeVector.vec[found]; attributeVector.vec.erase(attributeVector.vec.begin() + found); } } diff --git a/src/lib/ngsi/ContextElement.cpp b/src/lib/ngsi/ContextElement.cpp index d5361a3e58..5f20b214fb 100644 --- a/src/lib/ngsi/ContextElement.cpp +++ b/src/lib/ngsi/ContextElement.cpp @@ -175,6 +175,7 @@ void ContextElement::filterAttributes(const std::vector& attrsFilt else { caP->release(); + delete caP; } } contextAttributeVector.vec = caNewV; @@ -224,6 +225,7 @@ void ContextElement::filterAttributes(const std::vector& attrsFilt if (!blacklist && !includeDateExpires && ((found = contextAttributeVector.get(DATE_EXPIRES)) != -1)) { contextAttributeVector.vec[found]->release(); + delete contextAttributeVector.vec[found]; contextAttributeVector.vec.erase(contextAttributeVector.vec.begin() + found); } } From 7a311724390fcb71b73148c00b66abf50bb903b7 Mon Sep 17 00:00:00 2001 From: Fermin Galan Marquez Date: Thu, 6 Sep 2018 22:56:48 +0200 Subject: [PATCH 07/10] FIX filterAttribute() must be invoked before in the notification processing logic --- src/lib/mongoBackend/MongoCommonUpdate.cpp | 10 +++++----- src/lib/mongoBackend/MongoGlobal.cpp | 15 ++++++++------ src/lib/ngsi/ContextElement.cpp | 20 +++++++++++-------- src/lib/ngsi/ContextElement.h | 6 ++---- src/lib/ngsi/ContextElementResponse.cpp | 6 ++---- src/lib/ngsi/ContextElementResponse.h | 4 +--- src/lib/ngsi/ContextElementResponseVector.cpp | 6 ++---- src/lib/ngsi/ContextElementResponseVector.h | 4 +--- src/lib/ngsi10/NotifyContextRequest.cpp | 6 ++---- src/lib/ngsi10/NotifyContextRequest.h | 4 +--- src/lib/ngsiNotify/Notifier.cpp | 18 +++++------------ src/lib/ngsiNotify/Notifier.h | 9 ++------- src/lib/ngsiNotify/QueueNotifier.cpp | 8 ++------ src/lib/ngsiNotify/QueueNotifier.h | 4 +--- .../subscriptions_onchange.test | 4 ++-- .../subscriptions_onchange_nocache.test | 4 ++-- .../subscription_sequence_onchange.test | 4 ++-- ...ubscription_sequence_onchange_nocache.test | 4 ++-- .../entity_dates_overridden_by_user_subs.test | 7 +------ 19 files changed, 56 insertions(+), 87 deletions(-) diff --git a/src/lib/mongoBackend/MongoCommonUpdate.cpp b/src/lib/mongoBackend/MongoCommonUpdate.cpp index 6894155e83..ec5f46c1a1 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.cpp +++ b/src/lib/mongoBackend/MongoCommonUpdate.cpp @@ -1688,7 +1688,6 @@ static bool processOnChangeConditionForUpdateContext std::string tenant, const std::string& xauthToken, const std::string& fiwareCorrelator, - const std::vector& attrsOrder, const ngsiv2::HttpInfo& httpInfo, bool blacklist = false ) @@ -1699,6 +1698,8 @@ static bool processOnChangeConditionForUpdateContext cer.contextElement.entityId.fill(¬ifyCerP->contextElement.entityId); /* Fill NotifyContextRequest with cerP, filtering by attrL */ + // FIXME P8: review this. Given that filterAttributes() is called on the notifyCerP in the calling + // method, maybe this can be simplified (or removed) for (unsigned int ix = 0; ix < notifyCerP->contextElement.contextAttributeVector.size(); ix++) { ContextAttribute* caP = notifyCerP->contextElement.contextAttributeVector[ix]; @@ -1746,9 +1747,7 @@ static bool processOnChangeConditionForUpdateContext xauthToken, fiwareCorrelator, renderFormat, - attrsOrder, - metadataV, - blacklist); + metadataV); return true; } @@ -2052,6 +2051,8 @@ static bool processSubscriptions setDateModifiedMetadata(notifyCerP); } + // Get the effective vector of attributes to render + notifyCerP->contextElement.filterAttributes(tSubP->attrL.stringV, tSubP->blacklist); /* Send notification */ LM_T(LmtSubCache, ("NOT ignored: %s", tSubP->cacheSubId.c_str())); @@ -2066,7 +2067,6 @@ static bool processSubscriptions tenant, xauthToken, fiwareCorrelator, - tSubP->attrL.stringV, tSubP->httpInfo, tSubP->blacklist); diff --git a/src/lib/mongoBackend/MongoGlobal.cpp b/src/lib/mongoBackend/MongoGlobal.cpp index 6afa904467..b532b74963 100644 --- a/src/lib/mongoBackend/MongoGlobal.cpp +++ b/src/lib/mongoBackend/MongoGlobal.cpp @@ -2165,6 +2165,12 @@ static bool processOnChangeConditionForSubscription return false; } + // Get the effective vectors of attributes to render (per context element) + for (unsigned int ix = 0; ix < rawCerV.size() ; ix++) + { + rawCerV[ix]->contextElement.filterAttributes(attrsOrder, blacklist); + } + /* Prune "not found" CERs */ pruneContextElements(rawCerV, &ncr.contextElementResponseVector); @@ -2230,9 +2236,7 @@ static bool processOnChangeConditionForSubscription xauthToken, fiwareCorrelator, renderFormat, - attrsOrder, - metadataV, - blacklist); + metadataV); allCerV.release(); ncr.contextElementResponseVector.release(); @@ -2249,9 +2253,8 @@ static bool processOnChangeConditionForSubscription xauthToken, fiwareCorrelator, renderFormat, - attrsOrder, - metadataV, - blacklist); + metadataV); + ncr.contextElementResponseVector.release(); return true; diff --git a/src/lib/ngsi/ContextElement.cpp b/src/lib/ngsi/ContextElement.cpp index 5f20b214fb..d0845fb4e8 100644 --- a/src/lib/ngsi/ContextElement.cpp +++ b/src/lib/ngsi/ContextElement.cpp @@ -200,12 +200,23 @@ void ContextElement::filterAttributes(const std::vector& attrsFilt // Actual attribute filtering only takes place if '*' was not used else { +#if 0 + // FIXME #3168: to be enabled once metadata ID get removed int found = contextAttributeVector.get(attrsFilterItem); if (found != -1) { caNewV.push_back(contextAttributeVector.vec[found]); contextAttributeVector.vec.erase(contextAttributeVector.vec.begin() + found); } +#else + int found = contextAttributeVector.get(attrsFilterItem); + while (found != -1) + { + caNewV.push_back(contextAttributeVector.vec[found]); + contextAttributeVector.vec.erase(contextAttributeVector.vec.begin() + found); + found = contextAttributeVector.get(attrsFilterItem); + } +#endif } } @@ -242,16 +253,9 @@ void ContextElement::filterAttributes(const std::vector& attrsFilt std::string ContextElement::toJson ( RenderFormat renderFormat, - const std::vector& attrsFilter, - const std::vector& metadataFilter, - bool blacklist + const std::vector& metadataFilter ) { - // Get the effective vector of attributes to render - // FIXME P7: filterAttributes will be moved and invoking it would not be needed from toJson() - // (see comment in filterAttributes) - filterAttributes(attrsFilter, blacklist); - std::string out; switch (renderFormat) { diff --git a/src/lib/ngsi/ContextElement.h b/src/lib/ngsi/ContextElement.h index 07c9867162..e6f1229ff8 100644 --- a/src/lib/ngsi/ContextElement.h +++ b/src/lib/ngsi/ContextElement.h @@ -55,9 +55,7 @@ typedef struct ContextElement std::string render(ApiVersion apiVersion, bool asJsonObject, RequestType requestType, bool comma, bool omitAttributeValues = false); std::string toJson(RenderFormat renderFormat, - const std::vector& attrsFilter, - const std::vector& metadataFilter, - bool blacklist = false); + const std::vector& metadataFilter); void release(void); void fill(const struct ContextElement& ce); void fill(ContextElement* ceP, bool useDefaultType = false); @@ -66,9 +64,9 @@ typedef struct ContextElement std::string check(ApiVersion apiVersion, RequestType requestType); - private: void filterAttributes(const std::vector& attrsFilter, bool blacklist); +private: std::string toJsonValues(void); std::string toJsonUniqueValues(void); std::string toJsonKeyvalues(void); diff --git a/src/lib/ngsi/ContextElementResponse.cpp b/src/lib/ngsi/ContextElementResponse.cpp index 079f34f690..7cd436ae63 100644 --- a/src/lib/ngsi/ContextElementResponse.cpp +++ b/src/lib/ngsi/ContextElementResponse.cpp @@ -350,14 +350,12 @@ std::string ContextElementResponse::render std::string ContextElementResponse::toJson ( RenderFormat renderFormat, - const std::vector& attrsFilter, - const std::vector& metadataFilter, - bool blacklist + const std::vector& metadataFilter ) { std::string out; - out = contextElement.toJson(renderFormat, attrsFilter, metadataFilter, blacklist); + out = contextElement.toJson(renderFormat, metadataFilter); return out; } diff --git a/src/lib/ngsi/ContextElementResponse.h b/src/lib/ngsi/ContextElementResponse.h index 6b7ddc9308..913269725f 100644 --- a/src/lib/ngsi/ContextElementResponse.h +++ b/src/lib/ngsi/ContextElementResponse.h @@ -71,9 +71,7 @@ typedef struct ContextElementResponse bool comma = false, bool omitAttributeValues = false); std::string toJson(RenderFormat renderFormat, - const std::vector& attrsFilter, - const std::vector& metadataFilter, - bool blacklist = false); + const std::vector& metadataFilter); void release(void); std::string check(ApiVersion apiVersion, diff --git a/src/lib/ngsi/ContextElementResponseVector.cpp b/src/lib/ngsi/ContextElementResponseVector.cpp index fedf436d67..0f9a9a4f10 100644 --- a/src/lib/ngsi/ContextElementResponseVector.cpp +++ b/src/lib/ngsi/ContextElementResponseVector.cpp @@ -77,16 +77,14 @@ std::string ContextElementResponseVector::render std::string ContextElementResponseVector::toJson ( RenderFormat renderFormat, - const std::vector& attrsFilter, - const std::vector& metadataFilter, - bool blacklist + const std::vector& metadataFilter ) { std::string out; for (unsigned int ix = 0; ix < vec.size(); ++ix) { - out += vec[ix]->toJson(renderFormat, attrsFilter, metadataFilter, blacklist); + out += vec[ix]->toJson(renderFormat, metadataFilter); if (ix != vec.size() - 1) { diff --git a/src/lib/ngsi/ContextElementResponseVector.h b/src/lib/ngsi/ContextElementResponseVector.h index 18553f2dce..5981d3f92a 100644 --- a/src/lib/ngsi/ContextElementResponseVector.h +++ b/src/lib/ngsi/ContextElementResponseVector.h @@ -48,9 +48,7 @@ typedef struct ContextElementResponseVector bool omitAttributeValues = false); std::string toJson(RenderFormat renderFormat, - const std::vector& attrsFilter, - const std::vector& metadataFilter, - bool blacklist = false); + const std::vector& metadataFilter); void push_back(ContextElementResponse* item); unsigned int size(void) const; ContextElementResponse* lookup(EntityId* eP, HttpStatusCode code = SccNone); diff --git a/src/lib/ngsi10/NotifyContextRequest.cpp b/src/lib/ngsi10/NotifyContextRequest.cpp index 6c3bb381df..d364930bc7 100644 --- a/src/lib/ngsi10/NotifyContextRequest.cpp +++ b/src/lib/ngsi10/NotifyContextRequest.cpp @@ -67,9 +67,7 @@ std::string NotifyContextRequest::render(ApiVersion apiVersion, bool asJsonObjec std::string NotifyContextRequest::toJson ( RenderFormat renderFormat, - const std::vector& attrsFilter, - const std::vector& metadataFilter, - bool blacklist + const std::vector& metadataFilter ) { if ((renderFormat != NGSI_V2_NORMALIZED) && (renderFormat != NGSI_V2_KEYVALUES) && (renderFormat != NGSI_V2_VALUES)) @@ -88,7 +86,7 @@ std::string NotifyContextRequest::toJson out += ","; out += JSON_STR("data") + ":["; - out += contextElementResponseVector.toJson(renderFormat, attrsFilter, metadataFilter, blacklist); + out += contextElementResponseVector.toJson(renderFormat, metadataFilter); out += "]"; out += "}"; diff --git a/src/lib/ngsi10/NotifyContextRequest.h b/src/lib/ngsi10/NotifyContextRequest.h index a42d274716..b5869173d3 100644 --- a/src/lib/ngsi10/NotifyContextRequest.h +++ b/src/lib/ngsi10/NotifyContextRequest.h @@ -47,9 +47,7 @@ typedef struct NotifyContextRequest std::string render(ApiVersion apiVersion, bool asJsonObject); std::string toJson(RenderFormat renderFormat, - const std::vector& attrsFilter, - const std::vector& metadataFilter, - bool blacklist = false); + const std::vector& metadataFilter); std::string check(ApiVersion apiVersion, const std::string& predetectedError); void release(void); NotifyContextRequest* clone(void); diff --git a/src/lib/ngsiNotify/Notifier.cpp b/src/lib/ngsiNotify/Notifier.cpp index b760590b8e..ca53f1f7b0 100644 --- a/src/lib/ngsiNotify/Notifier.cpp +++ b/src/lib/ngsiNotify/Notifier.cpp @@ -70,9 +70,7 @@ void Notifier::sendNotifyContextRequest const std::string& xauthToken, const std::string& fiwareCorrelator, RenderFormat renderFormat, - const std::vector& attrsOrder, - const std::vector& metadataFilter, - bool blackList + const std::vector& metadataFilter ) { pthread_t tid; @@ -82,9 +80,7 @@ void Notifier::sendNotifyContextRequest xauthToken, fiwareCorrelator, renderFormat, - attrsOrder, - metadataFilter, - blackList); + metadataFilter); if (!paramsV->empty()) // al least one param, an empty vector means an error occurred { @@ -190,7 +186,6 @@ static std::vector* buildSenderParamsCustom const std::string& xauthToken, const std::string& fiwareCorrelator, RenderFormat renderFormat, - const std::vector& attrsOrder, const std::vector& metadataFilter ) { @@ -250,7 +245,7 @@ static std::vector* buildSenderParamsCustom } else { - payload = ncr.toJson(renderFormat, attrsOrder, metadataFilter); + payload = ncr.toJson(renderFormat, metadataFilter); } mimeType = "application/json"; @@ -395,9 +390,7 @@ std::vector* Notifier::buildSenderParams const std::string& xauthToken, const std::string& fiwareCorrelator, RenderFormat renderFormat, - const std::vector& attrsOrder, - const std::vector& metadataFilter, - bool blackList + const std::vector& metadataFilter ) { ConnectionInfo ci; @@ -434,7 +427,6 @@ std::vector* Notifier::buildSenderParams xauthToken, fiwareCorrelator, renderFormat, - attrsOrder, metadataFilter); } @@ -483,7 +475,7 @@ std::vector* Notifier::buildSenderParams } else { - payloadString = ncrP->toJson(renderFormat, attrsOrder, metadataFilter, blackList); + payloadString = ncrP->toJson(renderFormat, metadataFilter); } /* Parse URL */ diff --git a/src/lib/ngsiNotify/Notifier.h b/src/lib/ngsiNotify/Notifier.h index eaa92f17d3..7dd879f66f 100644 --- a/src/lib/ngsiNotify/Notifier.h +++ b/src/lib/ngsiNotify/Notifier.h @@ -53,9 +53,7 @@ class Notifier const std::string& xauthToken, const std::string& fiwareCorrelator, RenderFormat renderFormat, - const std::vector& attrsOrder, - const std::vector& metadataFilter, - bool blackList); + const std::vector& metadataFilter); virtual void sendNotifyContextAvailabilityRequest(NotifyContextAvailabilityRequest* ncr, const std::string& url, @@ -69,10 +67,7 @@ class Notifier const std::string& xauthToken, const std::string& fiwareCorrelator, RenderFormat renderFormat, - const std::vector& attrsOrder, - const std::vector& metadataFilter, - bool blackList - ); + const std::vector& metadataFilter); }; #endif // SRC_LIB_NGSINOTIFY_NOTIFIER_H_ diff --git a/src/lib/ngsiNotify/QueueNotifier.cpp b/src/lib/ngsiNotify/QueueNotifier.cpp index b8ada5230a..0fc094295c 100644 --- a/src/lib/ngsiNotify/QueueNotifier.cpp +++ b/src/lib/ngsiNotify/QueueNotifier.cpp @@ -68,9 +68,7 @@ void QueueNotifier::sendNotifyContextRequest const std::string& xauthToken, const std::string& fiwareCorrelator, RenderFormat renderFormat, - const std::vector& attrsOrder, - const std::vector& metadataFilter, - bool blacklist + const std::vector& metadataFilter ) { std::vector* paramsV = Notifier::buildSenderParams(ncr, @@ -79,9 +77,7 @@ void QueueNotifier::sendNotifyContextRequest xauthToken, fiwareCorrelator, renderFormat, - attrsOrder, - metadataFilter, - blacklist); + metadataFilter); size_t notificationsNum = paramsV->size(); for (unsigned ix = 0; ix < notificationsNum; ix++) diff --git a/src/lib/ngsiNotify/QueueNotifier.h b/src/lib/ngsiNotify/QueueNotifier.h index 3829c61370..b7edee5274 100644 --- a/src/lib/ngsiNotify/QueueNotifier.h +++ b/src/lib/ngsiNotify/QueueNotifier.h @@ -57,9 +57,7 @@ class QueueNotifier : public Notifier const std::string& xauthToken, const std::string& fiwareCorrelator, RenderFormat renderFormat, - const std::vector& attrsOrder, - const std::vector& metadataFilter, - bool blacklist); + const std::vector& metadataFilter); int start(); private: diff --git a/test/functionalTest/cases/0000_ngsi10_convenience/subscriptions_onchange.test b/test/functionalTest/cases/0000_ngsi10_convenience/subscriptions_onchange.test index 642c721360..dbbc4c3c09 100644 --- a/test/functionalTest/cases/0000_ngsi10_convenience/subscriptions_onchange.test +++ b/test/functionalTest/cases/0000_ngsi10_convenience/subscriptions_onchange.test @@ -38,8 +38,8 @@ payload='{ } ], "attributes": [ - "temperature", - "ligthstatus" + "ligthstatus", + "temperature" ], "reference": "http://127.0.0.1:'${LISTENER_PORT}'/notify", "duration": "PT1H", diff --git a/test/functionalTest/cases/0000_ngsi10_convenience/subscriptions_onchange_nocache.test b/test/functionalTest/cases/0000_ngsi10_convenience/subscriptions_onchange_nocache.test index 8acac7b4c0..85f003f775 100644 --- a/test/functionalTest/cases/0000_ngsi10_convenience/subscriptions_onchange_nocache.test +++ b/test/functionalTest/cases/0000_ngsi10_convenience/subscriptions_onchange_nocache.test @@ -39,8 +39,8 @@ payload='{ } ], "attributes": [ - "temperature", - "ligthstatus" + "ligthstatus", + "temperature" ], "reference": "http://127.0.0.1:'${LISTENER_PORT}'/notify", "duration": "PT1H", diff --git a/test/functionalTest/cases/0000_ngsi10_subscriptions/subscription_sequence_onchange.test b/test/functionalTest/cases/0000_ngsi10_subscriptions/subscription_sequence_onchange.test index d87384952b..592bf84614 100644 --- a/test/functionalTest/cases/0000_ngsi10_subscriptions/subscription_sequence_onchange.test +++ b/test/functionalTest/cases/0000_ngsi10_subscriptions/subscription_sequence_onchange.test @@ -38,8 +38,8 @@ payload='{ } ], "attributes": [ - "temperature", - "lightstatus" + "lightstatus", + "temperature" ], "reference": "http://127.0.0.1:'${LISTENER_PORT}'/notify", "duration": "PT1H", diff --git a/test/functionalTest/cases/0000_ngsi10_subscriptions/subscription_sequence_onchange_nocache.test b/test/functionalTest/cases/0000_ngsi10_subscriptions/subscription_sequence_onchange_nocache.test index 6303416fc5..8e536d4637 100644 --- a/test/functionalTest/cases/0000_ngsi10_subscriptions/subscription_sequence_onchange_nocache.test +++ b/test/functionalTest/cases/0000_ngsi10_subscriptions/subscription_sequence_onchange_nocache.test @@ -40,8 +40,8 @@ payload='{ } ], "attributes": [ - "temperature", - "lightstatus" + "lightstatus", + "temperature" ], "reference": "http://127.0.0.1:'${LISTENER_PORT}'/notify", "duration": "PT1H", diff --git a/test/functionalTest/cases/0876_entity_dates/entity_dates_overridden_by_user_subs.test b/test/functionalTest/cases/0876_entity_dates/entity_dates_overridden_by_user_subs.test index a50d43c606..b94501f10c 100644 --- a/test/functionalTest/cases/0876_entity_dates/entity_dates_overridden_by_user_subs.test +++ b/test/functionalTest/cases/0876_entity_dates/entity_dates_overridden_by_user_subs.test @@ -432,7 +432,7 @@ Date: REGEX(.*) ======================================================================================================================= POST http://localhost:REGEX(\d+)/notify Fiware-Servicepath: / -Content-Length: 362 +Content-Length: 279 User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) Ngsiv2-Attrsformat: normalized Host: localhost:REGEX(\d+) @@ -462,11 +462,6 @@ Fiware-Correlator: REGEX([0-9a-f\-]{36}) "type": "Text", "value": "bar" }, - "dateModified": { - "metadata": {}, - "type": "DateTime", - "value": "REGEX(20[1|2]\d-\d\d-\d\dT\d\d:\d\d:\d\d.\d\dZ)" - }, "id": "E2", "type": "T" } From f4bfb3db83ad7d7ae3cd09cee24dd7de20380215 Mon Sep 17 00:00:00 2001 From: Fermin Galan Marquez Date: Fri, 7 Sep 2018 11:48:04 +0200 Subject: [PATCH 08/10] FIX broken unit tests due to function signature change --- test/unittests/commonMocks.h | 12 +- ...mongoSubscribeContextAvailability_test.cpp | 2 +- .../mongoSubscribeContext_test.cpp | 200 ++-------- .../mongoUnsubscribeContext_test.cpp | 8 +- .../mongoUpdateContextSubscription_test.cpp | 161 +++----- ..._withOnchangeSubscriptionsNoCache_test.cpp | 308 +++------------ ...Context_withOnchangeSubscriptions_test.cpp | 354 +++--------------- 7 files changed, 188 insertions(+), 857 deletions(-) diff --git a/test/unittests/commonMocks.h b/test/unittests/commonMocks.h index 13f035a32a..8d23656693 100644 --- a/test/unittests/commonMocks.h +++ b/test/unittests/commonMocks.h @@ -223,15 +223,13 @@ class NotifierMock : public Notifier */ } - MOCK_METHOD9(sendNotifyContextRequest, void(NotifyContextRequest* ncr, + MOCK_METHOD7(sendNotifyContextRequest, void(NotifyContextRequest* ncr, const ngsiv2::HttpInfo& httpInfo, const std::string& tenant, const std::string& xauthToken, const std::string& fiwareCorrelator, RenderFormat renderFormat, - const std::vector& attrsFilter, - const std::vector& metadataFilter, - bool blacklist)); + const std::vector& metadataFilter)); MOCK_METHOD5(sendNotifyContextAvailabilityRequest, void(NotifyContextAvailabilityRequest* ncar, const std::string& url, @@ -246,11 +244,9 @@ class NotifierMock : public Notifier const std::string& xauthToken, const std::string& fiwareCorrelator, RenderFormat renderFormat, - const std::vector& attrsFilter, - const std::vector& metadataFilter, - bool blacklist = false) + const std::vector& metadataFilter) { - Notifier::sendNotifyContextRequest(ncr, httpInfo, tenant, xauthToken, fiwareCorrelator, renderFormat, attrsFilter, metadataFilter, blacklist); + Notifier::sendNotifyContextRequest(ncr, httpInfo, tenant, xauthToken, fiwareCorrelator, renderFormat, metadataFilter); } void parent_sendNotifyContextAvailabilityRequest(NotifyContextAvailabilityRequest* ncar, diff --git a/test/unittests/mongoBackend/mongoSubscribeContextAvailability_test.cpp b/test/unittests/mongoBackend/mongoSubscribeContextAvailability_test.cpp index 8fc28c85cb..5053ac0f22 100644 --- a/test/unittests/mongoBackend/mongoSubscribeContextAvailability_test.cpp +++ b/test/unittests/mongoBackend/mongoSubscribeContextAvailability_test.cpp @@ -2518,7 +2518,7 @@ TEST(mongoSubscribeContextAvailability, MongoDbInsertFail) .WillByDefault(Throw(e)); NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)).Times(0); + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)).Times(0); setNotifier(notifierMock); TimerMock* timerMock = new TimerMock(); diff --git a/test/unittests/mongoBackend/mongoSubscribeContext_test.cpp b/test/unittests/mongoBackend/mongoSubscribeContext_test.cpp index b8b48e9bb2..c2fce03a0b 100644 --- a/test/unittests/mongoBackend/mongoSubscribeContext_test.cpp +++ b/test/unittests/mongoBackend/mongoSubscribeContext_test.cpp @@ -292,7 +292,7 @@ TEST(mongoSubscribeContext, Ent1_Attr0_C1) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -372,7 +372,7 @@ TEST(mongoSubscribeContext, Ent1_AttrN_C1) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -456,7 +456,7 @@ TEST(mongoSubscribeContext, Ent1_Attr0_CN) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -540,7 +540,7 @@ TEST(mongoSubscribeContext, Ent1_Attr0_CNbis) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -622,7 +622,7 @@ TEST(mongoSubscribeContext, Ent1_AttrN_CN) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -713,7 +713,7 @@ TEST(mongoSubscribeContext, Ent1_AttrN_CNbis) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -802,7 +802,7 @@ TEST(mongoSubscribeContext, EntN_Attr0_C1) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -888,7 +888,7 @@ TEST(mongoSubscribeContext, EntN_AttrN_C1) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -978,7 +978,7 @@ TEST(mongoSubscribeContext, EntN_Attr0_CN) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -1068,7 +1068,7 @@ TEST(mongoSubscribeContext, EntN_Attr0_CNbis) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -1156,7 +1156,7 @@ TEST(mongoSubscribeContext, EntN_AttrN_CN) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -1250,7 +1250,7 @@ TEST(mongoSubscribeContext, EntN_AttrN_CNbis) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -1356,7 +1356,6 @@ TEST(mongoSubscribeContext, matchEnt1_Attr0_C1) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); @@ -1366,9 +1365,7 @@ TEST(mongoSubscribeContext, matchEnt1_Attr0_C1) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); @@ -1460,7 +1457,6 @@ TEST(mongoSubscribeContext, matchEnt1_Attr0_C1_JSON) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); @@ -1470,9 +1466,7 @@ TEST(mongoSubscribeContext, matchEnt1_Attr0_C1_JSON) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1561,22 +1555,16 @@ TEST(mongoSubscribeContext, matchEnt1_AttrN_C1) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1669,22 +1657,16 @@ TEST(mongoSubscribeContext, matchEnt1_AttrN_C1_disjoint) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1793,22 +1775,16 @@ TEST(mongoSubscribeContext, matchEnt1NoType_AttrN_C1) expectedNcr.contextElementResponseVector.push_back(cer3P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1917,22 +1893,16 @@ TEST(mongoSubscribeContext, matchEnt1NoType_AttrN_C1_disjoint) expectedNcr.contextElementResponseVector.push_back(cer3P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2033,22 +2003,16 @@ TEST(mongoSubscribeContext, matchEnt1Pattern_AttrN_C1) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2149,22 +2113,16 @@ TEST(mongoSubscribeContext, matchEnt1Pattern_AttrN_C1_disjoint) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2279,22 +2237,16 @@ TEST(mongoSubscribeContext, matchEnt1PatternNoType_AttrN_C1) expectedNcr.contextElementResponseVector.push_back(cer4P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2409,22 +2361,16 @@ TEST(mongoSubscribeContext, matchEnt1PatternNoType_AttrN_C1_disjoint) expectedNcr.contextElementResponseVector.push_back(cer4P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2519,7 +2465,6 @@ TEST(mongoSubscribeContext, matchEnt1_Attr0_CN) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); @@ -2529,9 +2474,7 @@ TEST(mongoSubscribeContext, matchEnt1_Attr0_CN) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2626,7 +2569,6 @@ TEST(mongoSubscribeContext, matchEnt1_Attr0_CN_partial) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); @@ -2636,9 +2578,7 @@ TEST(mongoSubscribeContext, matchEnt1_Attr0_CN_partial) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2734,7 +2674,6 @@ TEST(mongoSubscribeContext, matchEnt1_Attr0_CNbis) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); @@ -2744,9 +2683,7 @@ TEST(mongoSubscribeContext, matchEnt1_Attr0_CNbis) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2836,12 +2773,8 @@ TEST(mongoSubscribeContext, matchEnt1_AttrN_CN_disjoint) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; - ngsiv2::HttpInfo httpInfo("http://notify.me"); - - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); + ngsiv2::HttpInfo httpInfo("http://notify.me"); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), @@ -2849,9 +2782,7 @@ TEST(mongoSubscribeContext, matchEnt1_AttrN_CN_disjoint) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2948,22 +2879,16 @@ TEST(mongoSubscribeContext, matchEnt1_AttrN_CN_partial) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3060,22 +2985,16 @@ TEST(mongoSubscribeContext, matchEnt1_AttrN_CN_partial_disjoint) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3172,22 +3091,16 @@ TEST(mongoSubscribeContext, matchEnt1_AttrN_CNbis) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3284,12 +3197,8 @@ TEST(mongoSubscribeContext, matchEnt1_AttrN_CN) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; - ngsiv2::HttpInfo httpInfo("http://notify.me"); - - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); + ngsiv2::HttpInfo httpInfo("http://notify.me"); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), @@ -3297,9 +3206,7 @@ TEST(mongoSubscribeContext, matchEnt1_AttrN_CN) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3410,7 +3317,6 @@ TEST(mongoSubscribeContext, matchEntN_Attr0_C1) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); @@ -3420,9 +3326,7 @@ TEST(mongoSubscribeContext, matchEntN_Attr0_C1) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3524,22 +3428,16 @@ TEST(mongoSubscribeContext, matchEntN_AttrN_C1) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3649,7 +3547,6 @@ TEST(mongoSubscribeContext, matchEntN_Attr0_CN) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); @@ -3659,9 +3556,7 @@ TEST(mongoSubscribeContext, matchEntN_Attr0_CN) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3772,7 +3667,6 @@ TEST(mongoSubscribeContext, matchEntN_Attr0_CNbis) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); @@ -3782,9 +3676,7 @@ TEST(mongoSubscribeContext, matchEntN_Attr0_CNbis) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3888,22 +3780,16 @@ TEST(mongoSubscribeContext, matchEntN_AttrN_CN) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -4011,22 +3897,16 @@ TEST(mongoSubscribeContext, matchEntN_AttrN_CNbis) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -4119,7 +3999,7 @@ TEST(mongoSubscribeContext, defaultDuration) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -4204,7 +4084,7 @@ TEST(mongoSubscribeContext, MongoDbInsertFail) .WillByDefault(Throw(e)); NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); diff --git a/test/unittests/mongoBackend/mongoUnsubscribeContext_test.cpp b/test/unittests/mongoBackend/mongoUnsubscribeContext_test.cpp index 5bae17b331..ebf159d8f4 100644 --- a/test/unittests/mongoBackend/mongoUnsubscribeContext_test.cpp +++ b/test/unittests/mongoBackend/mongoUnsubscribeContext_test.cpp @@ -116,7 +116,7 @@ TEST(mongoUnsubscribeContext, subscriptionNotFound) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -156,7 +156,7 @@ TEST(mongoUnsubscribeContext, unsubscribe) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -205,7 +205,7 @@ TEST(mongoUnsubscribeContext, MongoDbFindOneFail) .WillByDefault(Throw(e)); NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -277,7 +277,7 @@ TEST(mongoUnsubscribeContext, MongoDbRemoveFail) .WillByDefault(Throw(e)); NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); diff --git a/test/unittests/mongoBackend/mongoUpdateContextSubscription_test.cpp b/test/unittests/mongoBackend/mongoUpdateContextSubscription_test.cpp index b48c43c1fa..115de4d5b6 100644 --- a/test/unittests/mongoBackend/mongoUpdateContextSubscription_test.cpp +++ b/test/unittests/mongoBackend/mongoUpdateContextSubscription_test.cpp @@ -432,7 +432,7 @@ TEST(mongoUpdateContextSubscription, subscriptionNotFound) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -475,7 +475,7 @@ TEST(mongoUpdateContextSubscription, updateDuration) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -567,7 +567,7 @@ TEST(mongoUpdateContextSubscription, updateThrottling) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -641,7 +641,7 @@ TEST(mongoUpdateContextSubscription, clearThrottling) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -717,7 +717,7 @@ TEST(mongoUpdateContextSubscription, Ent1_Attr0_C1) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -796,7 +796,7 @@ TEST(mongoUpdateContextSubscription, Ent1_AttrN_C1) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -876,7 +876,7 @@ TEST(mongoUpdateContextSubscription, Ent1_Attr0_CN) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -958,7 +958,7 @@ TEST(mongoUpdateContextSubscription, Ent1_Attr0_CNbis) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -1038,7 +1038,7 @@ TEST(mongoUpdateContextSubscription, Ent1_AttrN_CN) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -1123,7 +1123,7 @@ TEST(mongoUpdateContextSubscription, Ent1_AttrN_CNbis) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -1207,7 +1207,7 @@ TEST(mongoUpdateContextSubscription, EntN_Attr0_C1) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -1289,7 +1289,7 @@ TEST(mongoUpdateContextSubscription, EntN_AttrN_C1) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -1373,7 +1373,7 @@ TEST(mongoUpdateContextSubscription, EntN_Attr0_CN) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -1461,7 +1461,7 @@ TEST(mongoUpdateContextSubscription, EntN_Attr0_CNbis) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -1543,7 +1543,7 @@ TEST(mongoUpdateContextSubscription, EntN_AttrN_CN) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -1629,7 +1629,7 @@ TEST(mongoUpdateContextSubscription, EntN_AttrN_CNbis) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -1727,7 +1727,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1_Attr0_C1) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); @@ -1737,9 +1736,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1_Attr0_C1) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1826,7 +1823,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1_Attr0_C1_JSON) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); @@ -1836,9 +1832,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1_Attr0_C1_JSON) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1923,7 +1917,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1_AttrN_C1) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -1933,9 +1926,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1_AttrN_C1) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2023,7 +2014,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1_AttrN_C1_disjoint) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -2033,9 +2023,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1_AttrN_C1_disjoint) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2138,7 +2126,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1NoType_AttrN_C1) expectedNcr.contextElementResponseVector.push_back(cer3P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -2148,9 +2135,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1NoType_AttrN_C1) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2253,7 +2238,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1NoType_AttrN_C1_disjoint) expectedNcr.contextElementResponseVector.push_back(cer3P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -2263,9 +2247,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1NoType_AttrN_C1_disjoint) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2360,7 +2342,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1Pattern_AttrN_C1) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -2370,9 +2351,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1Pattern_AttrN_C1) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2467,7 +2446,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1Pattern_AttrN_C1_disjoint) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -2477,9 +2455,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1Pattern_AttrN_C1_disjoint) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2588,7 +2564,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1PatternNoType_AttrN_C1) expectedNcr.contextElementResponseVector.push_back(cer4P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -2598,9 +2573,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1PatternNoType_AttrN_C1) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2709,7 +2682,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1PatternNoType_AttrN_C1_disjoint) expectedNcr.contextElementResponseVector.push_back(cer4P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -2719,9 +2691,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1PatternNoType_AttrN_C1_disjoint) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2811,7 +2781,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1_Attr0_CN) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); @@ -2821,9 +2790,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1_Attr0_CN) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2915,7 +2882,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1_Attr0_CN_partial) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); @@ -2925,9 +2891,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1_Attr0_CN_partial) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3020,7 +2984,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1_Attr0_CNbis) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); @@ -3030,9 +2993,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1_Attr0_CNbis) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3120,7 +3081,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1_AttrN_CN_disjoint) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -3130,9 +3090,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1_AttrN_CN_disjoint) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3224,7 +3182,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1_AttrN_CN_partial) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -3234,9 +3191,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1_AttrN_CN_partial) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3328,7 +3283,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1_AttrN_CN_partial_disjoint) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -3338,9 +3292,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1_AttrN_CN_partial_disjoint) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3432,7 +3384,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1_AttrN_CNbis) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -3442,9 +3393,7 @@ TEST(mongoUpdateContextSubscription, matchEnt1_AttrN_CNbis) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3536,7 +3485,6 @@ TEST(mongoUpdateContextSubscription, matchEnt1_AttrN_CN) expectedNcr.contextElementResponseVector.push_back(cerP); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -3546,14 +3494,9 @@ TEST(mongoUpdateContextSubscription, matchEnt1_AttrN_CN) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A2"); - /* Forge the request (from "inside" to "outside") */ req.subscriptionId.set("51307b66f481db11bf860002"); NotifyCondition nc3, nc4; @@ -3656,7 +3599,6 @@ TEST(mongoUpdateContextSubscription, matchEntN_Attr0_C1) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify3.me"); @@ -3666,9 +3608,7 @@ TEST(mongoUpdateContextSubscription, matchEntN_Attr0_C1) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3765,7 +3705,6 @@ TEST(mongoUpdateContextSubscription, matchEntN_AttrN_C1) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify4.me"); @@ -3775,9 +3714,7 @@ TEST(mongoUpdateContextSubscription, matchEntN_AttrN_C1) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3880,7 +3817,6 @@ TEST(mongoUpdateContextSubscription, matchEntN_Attr0_CN) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify3.me"); @@ -3890,9 +3826,7 @@ TEST(mongoUpdateContextSubscription, matchEntN_Attr0_CN) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3997,7 +3931,6 @@ TEST(mongoUpdateContextSubscription, matchEntN_Attr0_CNbis) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify3.me"); @@ -4007,9 +3940,7 @@ TEST(mongoUpdateContextSubscription, matchEntN_Attr0_CNbis) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -4108,7 +4039,6 @@ TEST(mongoUpdateContextSubscription, matchEntN_AttrN_CN) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify4.me"); @@ -4118,9 +4048,7 @@ TEST(mongoUpdateContextSubscription, matchEntN_AttrN_CN) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -4221,7 +4149,6 @@ TEST(mongoUpdateContextSubscription, matchEntN_AttrN_CNbis) expectedNcr.contextElementResponseVector.push_back(cer2P); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify4.me"); @@ -4231,9 +4158,7 @@ TEST(mongoUpdateContextSubscription, matchEntN_AttrN_CNbis) "", "no correlator", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -4318,7 +4243,7 @@ TEST(mongoUpdateContextSubscription, updateDurationAndNotifyConditions) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -4399,7 +4324,7 @@ TEST(mongoUpdateContextSubscription, MongoDbFindOneFail) .WillByDefault(Throw(e)); NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); @@ -4465,7 +4390,7 @@ TEST(mongoUpdateContextSubscription, MongoDbUpdateFail) .WillByDefault(Return(fakeSub)); NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); diff --git a/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptionsNoCache_test.cpp b/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptionsNoCache_test.cpp index d4837264c8..698e6b403d 100644 --- a/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptionsNoCache_test.cpp +++ b/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptionsNoCache_test.cpp @@ -425,11 +425,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); ngsiv2::HttpInfo httpInfo("http://notify1.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -438,9 +434,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateMatch) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -497,11 +491,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); ngsiv2::HttpInfo httpInfo("http://notify1.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -510,9 +500,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMatch) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -566,9 +554,6 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMatch_type ngsiv2::HttpInfo httpInfo("http://notify10.me"); std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -577,9 +562,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMatch_type "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -631,11 +614,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMatch_idAn expectedNcr.subscriptionId.set("51307b66f481db11bf860011"); ngsiv2::HttpInfo httpInfo("http://notify11.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -644,9 +623,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMatch_idAn "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -698,11 +675,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_deleteMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); ngsiv2::HttpInfo httpInfo("http://notify1.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -711,9 +684,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_deleteMatch) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -770,15 +741,10 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateMatch_noTy expectedNcr1.subscriptionId.set("51307b66f481db11bf860001"); expectedNcr2.subscriptionId.set("51307b66f481db11bf860004"); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo1("http://notify1.me"); ngsiv2::HttpInfo httpInfo4("http://notify4.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr1), MatchHttpInfo(&httpInfo1), @@ -786,9 +752,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateMatch_noTy "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr2), MatchHttpInfo(&httpInfo4), @@ -796,9 +760,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateMatch_noTy "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -859,11 +821,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMatch_noTy ngsiv2::HttpInfo httpInfo1("http://notify1.me"); ngsiv2::HttpInfo httpInfo4("http://notify4.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr1), @@ -872,9 +830,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMatch_noTy "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr2), MatchHttpInfo(&httpInfo4), @@ -882,9 +838,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMatch_noTy "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -940,11 +894,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_deleteMatch_noTy ngsiv2::HttpInfo httpInfo1("http://notify1.me"); ngsiv2::HttpInfo httpInfo4("http://notify4.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr1), @@ -953,9 +903,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_deleteMatch_noTy "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr2), MatchHttpInfo(&httpInfo4), @@ -963,9 +911,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_deleteMatch_noTy "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1019,11 +965,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateMatch_patt expectedNcr.subscriptionId.set("51307b66f481db11bf860003"); ngsiv2::HttpInfo httpInfo("http://notify3.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -1032,9 +974,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateMatch_patt "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1089,11 +1029,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMatch_patt expectedNcr.subscriptionId.set("51307b66f481db11bf860003"); ngsiv2::HttpInfo httpInfo("http://notify3.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -1102,9 +1038,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMatch_patt "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1155,11 +1089,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_deleteMatch_patt expectedNcr.subscriptionId.set("51307b66f481db11bf860003"); ngsiv2::HttpInfo httpInfo("http://notify3.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -1168,9 +1098,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_deleteMatch_patt "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1223,11 +1151,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateMatch_patt expectedNcr.subscriptionId.set("51307b66f481db11bf860005"); ngsiv2::HttpInfo httpInfo("http://notify5.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -1236,9 +1160,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateMatch_patt "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1293,11 +1215,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMatch_patt expectedNcr.subscriptionId.set("51307b66f481db11bf860005"); ngsiv2::HttpInfo httpInfo("http://notify5.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -1306,9 +1224,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMatch_patt "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1359,11 +1275,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_deleteMatch_patt expectedNcr.subscriptionId.set("51307b66f481db11bf860005"); ngsiv2::HttpInfo httpInfo("http://notify5.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -1372,9 +1284,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_deleteMatch_patt "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1427,11 +1337,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateMatchDisjo expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); ngsiv2::HttpInfo httpInfo("http://notify1.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -1440,9 +1346,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateMatchDisjo "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1495,11 +1399,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMatchDisjo expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); ngsiv2::HttpInfo httpInfo("http://notify1.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -1508,9 +1408,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMatchDisjo "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1563,11 +1461,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_deleteMatchDisjo expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); ngsiv2::HttpInfo httpInfo("http://notify1.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -1576,9 +1470,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_deleteMatchDisjo "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1620,7 +1512,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateNoMatch) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)).Times(0); + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1662,7 +1554,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendNoMatch) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)).Times(0); + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1704,7 +1596,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_deleteNoMatch) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)).Times(0); + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1746,7 +1638,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateMatchWitho /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)).Times(0); + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1798,12 +1690,8 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateMixMatchNo expectedNcr.contextElementResponseVector.push_back(cerP); expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); - ngsiv2::HttpInfo httpInfo("http://notify1.me"); - std::vector attrsFilter; + ngsiv2::HttpInfo httpInfo("http://notify1.me"); std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -1812,9 +1700,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateMixMatchNo "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1884,9 +1770,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_appendMixMatchNo "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1939,11 +1823,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_deleteMixMatchNo expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); ngsiv2::HttpInfo httpInfo("http://notify1.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -1952,9 +1832,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_deleteMixMatchNo "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2022,9 +1900,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_update2Matches1N "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2081,11 +1957,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_append2Matches1N expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); ngsiv2::HttpInfo httpInfo("http://notify1.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -2094,9 +1966,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_append2Matches1N "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2149,11 +2019,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_delete2Matches1N expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); ngsiv2::HttpInfo httpInfo("http://notify1.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -2162,9 +2028,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_delete2Matches1N "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2217,11 +2081,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_updateMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); ngsiv2::HttpInfo httpInfo("http://notify2.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -2230,9 +2090,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_updateMatch) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2288,11 +2146,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_appendMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); ngsiv2::HttpInfo httpInfo("http://notify2.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -2301,9 +2155,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_appendMatch) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2354,11 +2206,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_deleteMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); ngsiv2::HttpInfo httpInfo("http://notify2.me"); - std::vector attrsFilter; - std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); + std::vector metadataFilter; NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -2367,9 +2215,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_deleteMatch) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2422,11 +2268,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_updateMatchDisjo expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); ngsiv2::HttpInfo httpInfo("http://notify2.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -2435,9 +2277,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_updateMatchDisjo "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2489,12 +2329,8 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_appendMatchDisjo expectedNcr.contextElementResponseVector.push_back(cerP); expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); - ngsiv2::HttpInfo httpInfo("http://notify2.me"); - std::vector attrsFilter; + ngsiv2::HttpInfo httpInfo("http://notify2.me"); std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -2503,9 +2339,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_appendMatchDisjo "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2558,11 +2392,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_deleteMatchDisjo expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); ngsiv2::HttpInfo httpInfo("http://notify2.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -2571,9 +2401,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_deleteMatchDisjo "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2615,7 +2443,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_updateNoMatch) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)).Times(0); + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2657,7 +2485,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_appendNoMatch) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)).Times(0); + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2699,7 +2527,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_deleteNoMatch) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)).Times(0); + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2741,7 +2569,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_updateMatchWitho /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)).Times(0); + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2794,11 +2622,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_updateMixMatchNo expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); ngsiv2::HttpInfo httpInfo("http://notify2.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -2807,9 +2631,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_updateMixMatchNo "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2866,11 +2688,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_appendMixMatchNo expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); ngsiv2::HttpInfo httpInfo("http://notify2.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -2879,9 +2697,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_appendMixMatchNo "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2934,11 +2750,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_deleteMixMatchNo expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); ngsiv2::HttpInfo httpInfo("http://notify2.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -2947,9 +2759,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_deleteMixMatchNo "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3004,11 +2814,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_update2Matches1N expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); ngsiv2::HttpInfo httpInfo("http://notify2.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -3017,9 +2823,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_update2Matches1N "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3076,11 +2880,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_append2Matches1N expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); ngsiv2::HttpInfo httpInfo("http://notify2.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -3089,9 +2889,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_append2Matches1N "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3144,11 +2942,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_delete2Matches1N expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); ngsiv2::HttpInfo httpInfo("http://notify2.me"); - std::vector attrsFilter; std::vector metadataFilter; - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -3157,9 +2951,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_delete2Matches1N "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3215,7 +3007,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, DISABLED_MongoDbQueryF .WillByDefault(Throw(e)); NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)).Times(0); + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)).Times(0); setNotifier(notifierMock); /* Set MongoDB connection */ diff --git a/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptions_test.cpp b/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptions_test.cpp index 0866b9d127..df638204b0 100644 --- a/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptions_test.cpp +++ b/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptions_test.cpp @@ -391,19 +391,13 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_updateMatch) std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -461,23 +455,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_appendMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -530,23 +517,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_deleteMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -605,24 +585,17 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_updateMatch_noType) expectedNcr2.subscriptionId.set("51307b66f481db11bf860004"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); ngsiv2::HttpInfo httpInfo2("http://notify4.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr1), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr2), MatchHttpInfo(&httpInfo2), @@ -630,9 +603,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_updateMatch_noType) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -699,24 +670,17 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_appendMatch_noType) expectedNcr2.subscriptionId.set("51307b66f481db11bf860004"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); ngsiv2::HttpInfo httpInfo2("http://notify4.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr1), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr2), MatchHttpInfo(&httpInfo2), @@ -724,9 +688,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_appendMatch_noType) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -789,25 +751,17 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_deleteMatch_noType) expectedNcr2.subscriptionId.set("51307b66f481db11bf860004"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); ngsiv2::HttpInfo httpInfo2("http://notify4.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr1), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr2), MatchHttpInfo(&httpInfo2), @@ -815,9 +769,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_deleteMatch_noType) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); @@ -879,24 +831,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_updateMatch_pattern) expectedNcr.subscriptionId.set("51307b66f481db11bf860003"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify3.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); @@ -957,23 +901,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_appendMatch_pattern) expectedNcr.subscriptionId.set("51307b66f481db11bf860003"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify3.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1028,23 +965,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_deleteMatch_pattern) expectedNcr.subscriptionId.set("51307b66f481db11bf860003"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify3.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1101,23 +1031,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_updateMatch_pattern_noT expectedNcr.subscriptionId.set("51307b66f481db11bf860005"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify5.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1176,23 +1099,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_appendMatch_pattern_noT expectedNcr.subscriptionId.set("51307b66f481db11bf860005"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify5.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1247,23 +1163,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_deleteMatch_pattern_noT expectedNcr.subscriptionId.set("51307b66f481db11bf860005"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify5.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1320,23 +1229,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_updateMatchDisjoint) expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1393,23 +1295,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_appendMatchDisjoint) expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1466,23 +1361,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_deleteMatchDisjoint) expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1528,7 +1416,6 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_updateNoMatch) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); @@ -1538,9 +1425,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_updateNoMatch) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(0); + metadataFilter)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1586,7 +1471,6 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_appendNoMatch) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); @@ -1596,9 +1480,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_appendNoMatch) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(0); + metadataFilter)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1643,7 +1525,6 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_deleteNoMatch) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); @@ -1653,9 +1534,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_deleteNoMatch) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(0); + metadataFilter)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1700,7 +1579,6 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_updateMatchWithoutChang /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); @@ -1710,9 +1588,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_updateMatchWithoutChang "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(0); + metadataFilter)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1768,13 +1644,8 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_updateMixMatchNoMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; - ngsiv2::HttpInfo httpInfo("http://notify1.me"); - - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); + ngsiv2::HttpInfo httpInfo("http://notify1.me"); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), @@ -1782,9 +1653,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_updateMixMatchNoMatch) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1845,23 +1714,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_appendMixMatchNoMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1918,23 +1780,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_deleteMixMatchNoMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -1994,23 +1849,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_update2Matches1Notifica expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2073,23 +1921,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_append2Matches1Notifica expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2147,23 +1988,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_delete2Matches1Notifica expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify1.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2220,23 +2054,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_updateMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2296,23 +2123,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_appendMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2367,23 +2187,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_deleteMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2440,23 +2253,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_updateMatchDisjoint) expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2514,23 +2320,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_appendMatchDisjoint) expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2587,23 +2386,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_deleteMatchDisjoint) expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2649,7 +2441,6 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_updateNoMatch) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -2659,9 +2450,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_updateNoMatch) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(0); + metadataFilter)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2706,7 +2495,6 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_appendNoMatch) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -2716,9 +2504,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_appendNoMatch) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(0); + metadataFilter)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2763,7 +2549,6 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_deleteNoMatch) /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -2773,9 +2558,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_deleteNoMatch) "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(0); + metadataFilter)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2820,7 +2603,6 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_updateMatchWithoutChang /* Prepare mock */ NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); @@ -2830,9 +2612,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_updateMatchWithoutChang "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(0); + metadataFilter)).Times(0); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2888,23 +2668,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_updateMixMatchNoMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -2965,23 +2738,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_appendMixMatchNoMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3038,23 +2804,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_deleteMixMatchNoMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3113,23 +2872,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_update2Matches1Notifica expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3191,23 +2943,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_append2Matches1Notifica expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3265,23 +3010,16 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, CondN_delete2Matches1Notifica expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); NotifierMock* notifierMock = new NotifierMock(); - std::vector attrsFilter; std::vector metadataFilter; ngsiv2::HttpInfo httpInfo("http://notify2.me"); - attrsFilter.push_back("A1"); - attrsFilter.push_back("A3"); - attrsFilter.push_back("A4"); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), "", "", "", NGSI_V1_LEGACY, - attrsFilter, - metadataFilter, - false)).Times(1); + metadataFilter)).Times(1); setNotifier(notifierMock); /* Forge the request (from "inside" to "outside") */ @@ -3341,7 +3079,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, DISABLED_MongoDbQueryFail) .WillByDefault(Throw(e)); NotifierMock* notifierMock = new NotifierMock(); - EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _, _, _)) + EXPECT_CALL(*notifierMock, sendNotifyContextRequest(_, _, _, _, _, _, _)) .Times(0); setNotifier(notifierMock); From d213ea4763a9f5ea911142cc5a93a64f395a3d24 Mon Sep 17 00:00:00 2001 From: Fermin Galan Marquez Date: Fri, 7 Sep 2018 12:21:44 +0200 Subject: [PATCH 09/10] FIX code style --- .../mongoBackend/mongoSubscribeContext_test.cpp | 4 ++-- ...Context_withOnchangeSubscriptionsNoCache_test.cpp | 12 ++++++------ ...oUpdateContext_withOnchangeSubscriptions_test.cpp | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/unittests/mongoBackend/mongoSubscribeContext_test.cpp b/test/unittests/mongoBackend/mongoSubscribeContext_test.cpp index c2fce03a0b..5c9d0b101f 100644 --- a/test/unittests/mongoBackend/mongoSubscribeContext_test.cpp +++ b/test/unittests/mongoBackend/mongoSubscribeContext_test.cpp @@ -2774,7 +2774,7 @@ TEST(mongoSubscribeContext, matchEnt1_AttrN_CN_disjoint) NotifierMock* notifierMock = new NotifierMock(); std::vector metadataFilter; - ngsiv2::HttpInfo httpInfo("http://notify.me"); + ngsiv2::HttpInfo httpInfo("http://notify.me"); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), @@ -3198,7 +3198,7 @@ TEST(mongoSubscribeContext, matchEnt1_AttrN_CN) NotifierMock* notifierMock = new NotifierMock(); std::vector metadataFilter; - ngsiv2::HttpInfo httpInfo("http://notify.me"); + ngsiv2::HttpInfo httpInfo("http://notify.me"); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), diff --git a/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptionsNoCache_test.cpp b/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptionsNoCache_test.cpp index 698e6b403d..e56089ebb2 100644 --- a/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptionsNoCache_test.cpp +++ b/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptionsNoCache_test.cpp @@ -393,9 +393,9 @@ static void prepareDatabaseWithNoTypeSubscriptions(void) */ #define CHECK_LAST_NOTIFICATION(subId, timestamp) \ { \ - DBClientBase* connection = getMongoConnection(); \ - BSONObj sub = connection->findOne(SUBSCRIBECONTEXT_COLL, BSON("_id" << OID(subId))); \ - EXPECT_EQ(timestamp, sub.getIntField("lastNotification")); \ + DBClientBase* connection = getMongoConnection(); + BSONObj sub = connection->findOne(SUBSCRIBECONTEXT_COLL, BSON("_id" << OID(subId))); + EXPECT_EQ(timestamp, sub.getIntField("lastNotification")); } @@ -1690,7 +1690,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, Cond1_updateMixMatchNo expectedNcr.contextElementResponseVector.push_back(cerP); expectedNcr.subscriptionId.set("51307b66f481db11bf860001"); - ngsiv2::HttpInfo httpInfo("http://notify1.me"); + ngsiv2::HttpInfo httpInfo("http://notify1.me"); std::vector metadataFilter; NotifierMock* notifierMock = new NotifierMock(); @@ -2206,7 +2206,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_deleteMatch) expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); ngsiv2::HttpInfo httpInfo("http://notify2.me"); - std::vector metadataFilter; + std::vector metadataFilter; NotifierMock* notifierMock = new NotifierMock(); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), @@ -2329,7 +2329,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptionsNoCache, CondN_appendMatchDisjo expectedNcr.contextElementResponseVector.push_back(cerP); expectedNcr.subscriptionId.set("51307b66f481db11bf860002"); - ngsiv2::HttpInfo httpInfo("http://notify2.me"); + ngsiv2::HttpInfo httpInfo("http://notify2.me"); std::vector metadataFilter; NotifierMock* notifierMock = new NotifierMock(); diff --git a/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptions_test.cpp b/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptions_test.cpp index df638204b0..c0018c4a4c 100644 --- a/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptions_test.cpp +++ b/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptions_test.cpp @@ -1645,7 +1645,7 @@ TEST(mongoUpdateContext_withOnchangeSubscriptions, Cond1_updateMixMatchNoMatch) NotifierMock* notifierMock = new NotifierMock(); std::vector metadataFilter; - ngsiv2::HttpInfo httpInfo("http://notify1.me"); + ngsiv2::HttpInfo httpInfo("http://notify1.me"); EXPECT_CALL(*notifierMock, sendNotifyContextRequest(MatchNcr(&expectedNcr), MatchHttpInfo(&httpInfo), From 3ba239f6199b9ddc34d1e673f8680053dbf8b0b0 Mon Sep 17 00:00:00 2001 From: Fermin Galan Marquez Date: Fri, 7 Sep 2018 12:40:47 +0200 Subject: [PATCH 10/10] FIX broken utests --- ...oUpdateContext_withOnchangeSubscriptionsNoCache_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptionsNoCache_test.cpp b/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptionsNoCache_test.cpp index e56089ebb2..b5ea60a9d2 100644 --- a/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptionsNoCache_test.cpp +++ b/test/unittests/mongoBackend/mongoUpdateContext_withOnchangeSubscriptionsNoCache_test.cpp @@ -393,9 +393,9 @@ static void prepareDatabaseWithNoTypeSubscriptions(void) */ #define CHECK_LAST_NOTIFICATION(subId, timestamp) \ { \ - DBClientBase* connection = getMongoConnection(); - BSONObj sub = connection->findOne(SUBSCRIBECONTEXT_COLL, BSON("_id" << OID(subId))); - EXPECT_EQ(timestamp, sub.getIntField("lastNotification")); + DBClientBase* connection = getMongoConnection(); \ + BSONObj sub = connection->findOne(SUBSCRIBECONTEXT_COLL, BSON("_id" << OID(subId))); \ + EXPECT_EQ(timestamp, sub.getIntField("lastNotification")); \ }