Skip to content

Commit

Permalink
Merge pull request #228 from telefonicaid/feature/making-entity-id-an…
Browse files Browse the repository at this point in the history
…d-type-case-sensitive

Making the entity id and type case-sensitive
  • Loading branch information
dmoranj committed Jan 29, 2016
2 parents f58e63c + 0af71ff commit 8220954
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [FEATURE] Making the STH case sensitive regarding entity identifiers and types
2 changes: 1 addition & 1 deletion lib/sth_database.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function getCollectionName4Events(params) {
'_' + attrName;
break;
}
collectionName4Events = collectionName4Events.toLowerCase();
collectionName4Events = collectionName4Events;
if (sthConfig.SHOULD_HASH) {
var limit = getHashSizeInBytes(databaseName);
if (limit < MIN_HASH_SIZE_IN_BYTES) {
Expand Down
132 changes: 125 additions & 7 deletions test/unit/sth_test_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ function dropCollectionNamesCollectionTest(done) {
/**
* Returns an URL based on certain criteria passed as arguments
* @param {string} type The type of operation
* @param {Object} options The options to apply when generating the invalid
* URL (possible keys are 'invalidPath', and an entry for each one of the accepted
* @param {Object} options The options to apply when generating the
* URL (possible keys are 'invalidPath', 'changeEntityCase', and an entry for each one of the accepted
* query params ('lastN', 'hLimit', 'hOffset', aggrMethod', 'aggrPeriod', 'dateFrom' and 'dateTo')
* @param {string} attrName The attribute name
* @returns {string}
Expand All @@ -397,8 +397,11 @@ function getURL(type, options, attrName) {
if (options && options.invalidPath) {
url += '/this/is/an/invalid/path';
} else {
url += '/STH/v1/contextEntities/type/' + sthTestConfig.ENTITY_TYPE + '/' +
'id/' + sthTestConfig.ENTITY_ID +
url += '/STH/v1/contextEntities/type/' +
((options && options.changeEntityCase) ?
sthTestConfig.ENTITY_TYPE.toLowerCase() : sthTestConfig.ENTITY_TYPE) +
'/id/' + ((options && options.changeEntityCase) ?
sthTestConfig.ENTITY_ID.toLowerCase() : sthTestConfig.ENTITY_ID) +
'/attributes/' + attrName || sthTestConfig.ATTRIBUTE_NAME;
}
if (options && (options.lastN || options.lastN === 0)) {
Expand Down Expand Up @@ -442,8 +445,47 @@ function getURL(type, options, attrName) {
}

/**
* A mocha test forcing the server to retrieve aggregated data from the database
* for the passed aggregation method and resolution
* A mocha test forcing the server to not to retrieve raw data from the database
* @param {object} params It is an object including the following properties:
* - {string} service The service
* - {string} servicePath The service path
* - {string} attrName The attribute name
* - {string} attrType The attribute type
* - {object} options To generate the URL
* @param {Function} done The mocha done() callback function
*/
function noRawDataIfEntityCaseChange(params, done) {
var service = params.service,
servicePath = params.servicePath,
attrName = params.attrName,
options = params.options;

options.changeEntityCase = true;

request({
uri: getURL(sthTestConfig.API_OPERATION.READ, options, attrName),
method: 'GET',
headers: {
'Fiware-Service': service || sthConfig.DEFAULT_SERVICE,
'Fiware-ServicePath': servicePath || sthConfig.DEFAULT_SERVICE_PATH
}
}, function (err, response, body) {
var bodyJSON = JSON.parse(body);
expect(err).to.equal(null);
expect(response.statusCode).to.equal(200);
expect(response.statusMessage).to.equal('OK');
expect(bodyJSON.contextResponses[0].contextElement.attributes[0].name).to.equal(
attrName || sthTestConfig.ATTRIBUTE_NAME);
expect(bodyJSON.contextResponses[0].contextElement.attributes[0].values).to.be.an(Array);
expect(bodyJSON.contextResponses[0].contextElement.attributes[0].values.length).to.equal(0);
expect(bodyJSON.contextResponses[0].statusCode.code).to.equal('200');
expect(bodyJSON.contextResponses[0].statusCode.reasonPhrase).to.equal('OK');
done();
});
}

/**
* A mocha test forcing the server to retrieve raw data from the database
* @param {object} params It is an object including the following properties:
* - {string} service The service
* - {string} servicePath The service path
Expand Down Expand Up @@ -491,6 +533,54 @@ function rawDataAvailableDateFilter(params, done) {
});
}

/**
* A mocha test forcing the server to retrieve no aggregated data from the database for
* the passed aggregation method and resolution
* @param {object} params It is an object including the following properties:
* - {string} service The service
* - {string} servicePath The service path
* - {string} attrName The attribute name
* - {string} attrType The attribute type
* - {string} aggrMethod The aggregation method
* - {string} resolution The resolution
* @param {string} done The mocha done() callback function
*/
function noAggregatedDataIfEntityCaseChangeTest(params, done) {
var service = params.service,
servicePath = params.servicePath,
attrName = params.attrName,
aggrMethod = params.aggrMethod,
resolution = params.resolution;

request({
uri: getURL(sthTestConfig.API_OPERATION.READ,
{
aggrMethod: aggrMethod,
aggrPeriod: resolution,
changeEntityCase: true
},
attrName
),
method: 'GET',
headers: {
'Fiware-Service': service || sthConfig.DEFAULT_SERVICE,
'Fiware-ServicePath': servicePath || sthConfig.DEFAULT_SERVICE_PATH
}
}, function (err, response, body) {
var bodyJSON = JSON.parse(body);
expect(err).to.equal(null);
expect(response.statusCode).to.equal(200);
expect(response.statusMessage).to.equal('OK');
expect(bodyJSON.contextResponses[0].contextElement.attributes[0].name).to.equal(
attrName || sthTestConfig.ATTRIBUTE_NAME);
expect(bodyJSON.contextResponses[0].contextElement.attributes[0].values).to.be.an(Array);
expect(bodyJSON.contextResponses[0].contextElement.attributes[0].values.length).to.equal(0);
expect(bodyJSON.contextResponses[0].statusCode.code).to.equal('200');
expect(bodyJSON.contextResponses[0].statusCode.reasonPhrase).to.equal('OK');
done();
});
}

/**
* A mocha test forcing the server to retrieve no aggregated data from the database for
* the passed aggregation method and resolution
Expand Down Expand Up @@ -691,13 +781,15 @@ function aggregatedDataAvailableSinceDateTest(params, done) {
*/
function rawDataRetrievalSuite(options, attrName, attrType, checkRecvTime) {
describe('should respond', function () {
var optionsWithNoDates = {},
var optionsForCaseSensitivity = {},
optionsWithNoDates = {},
optionsWithDateFrom = {},
optionsWithDateTo = {},
optionsWithFromAndToDate = {};

before(function () {
for (var prop in options) {
optionsForCaseSensitivity[prop] = options[prop];
optionsWithNoDates[prop] = options[prop];
optionsWithDateFrom[prop] = options[prop];
optionsWithDateTo[prop] = options[prop];
Expand All @@ -715,6 +807,19 @@ function rawDataRetrievalSuite(options, attrName, attrType, checkRecvTime) {
optionsWithFromAndToDate.dateTo = sthHelper.getISODateString(new Date());
});

it('without data if entity id and entity type case does not match',
noRawDataIfEntityCaseChange.bind(
null,
{
service: sthConfig.DEFAULT_SERVICE,
servicePath: sthConfig.DEFAULT_SERVICE_PATH,
attrName: attrName,
options: optionsForCaseSensitivity,
checkRecvTime: checkRecvTime
}
)
);

it('with raw data if data and no dateFrom or dateTo',
rawDataAvailableDateFilter.bind(
null,
Expand Down Expand Up @@ -777,6 +882,19 @@ function rawDataRetrievalSuite(options, attrName, attrType, checkRecvTime) {
* @param aggrMethod The aggregation method
*/
function aggregatedDataRetrievalTests(index, attrName, attrType, aggrMethod) {
it('should respond with empty aggregated data if entity id and entity type case does not match',
noAggregatedDataIfEntityCaseChangeTest.bind(
null,
{
service: sthConfig.DEFAULT_SERVICE,
servicePath: sthConfig.DEFAULT_SERVICE_PATH,
attrName: attrName,
aggrMethod: aggrMethod,
resolution: sthConfig.AGGREGATION[index]
}
)
);

it('should respond with empty aggregated data if no data since dateFrom',
noAggregatedDataSinceDateTest.bind(
null,
Expand Down

0 comments on commit 8220954

Please sign in to comment.