Mercurial > hg > thermostat-ng > web-gateway
changeset 194:ba460d69e3b9
Fix MongoExecutor put for empty queries
Reviewed-by: jerboaa
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-July/024093.html
author | Jie Kang <jkang@redhat.com> |
---|---|
date | Thu, 13 Jul 2017 08:44:09 -0400 |
parents | 0461635570a0 |
children | 68a69b14b72a |
files | common/mongodb/src/main/java/com/redhat/thermostat/gateway/common/mongodb/executor/MongoExecutor.java tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/memory/JvmMemoryServiceIntegrationTest.java |
diffstat | 2 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/common/mongodb/src/main/java/com/redhat/thermostat/gateway/common/mongodb/executor/MongoExecutor.java Tue Jul 04 15:03:16 2017 -0400 +++ b/common/mongodb/src/main/java/com/redhat/thermostat/gateway/common/mongodb/executor/MongoExecutor.java Thu Jul 13 08:44:09 2017 -0400 @@ -101,7 +101,14 @@ BasicDBObject setObject = (BasicDBObject) inputObject.get("set"); final Bson fields = new Document("$set", setObject); - final Bson bsonQueries = MongoRequestFilters.buildQueriesFilter(queries); + + Bson bsonQueries; + if (queries != null && !queries.isEmpty()) { + bsonQueries = MongoRequestFilters.buildQueriesFilter(queries); + } else { + bsonQueries = new Document(); + } + collection.updateMany(bsonQueries, fields); metaDataContainer.setPutReqMatches(collection.count(bsonQueries));
--- a/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/memory/JvmMemoryServiceIntegrationTest.java Tue Jul 04 15:03:16 2017 -0400 +++ b/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/memory/JvmMemoryServiceIntegrationTest.java Thu Jul 13 08:44:09 2017 -0400 @@ -152,7 +152,7 @@ @Test public void testPutDataWithoutUrlQuery() throws InterruptedException, TimeoutException, ExecutionException { HttpTestUtil.addRecords(client, resourceUrl, "[{\"fakedata\":\"test\"}]"); - HttpTestUtil.testContentResponse(client, HttpMethod.PUT, resourceUrl, "{\"set\":{\"fakedata\":\"test\"}}", 400); + HttpTestUtil.testContentResponse(client, HttpMethod.PUT, resourceUrl, "{\"set\":{\"fakedata\":\"test\"}}", 200); } @Test @@ -168,7 +168,7 @@ public void testPutWithIdenticalData() throws InterruptedException, TimeoutException, ExecutionException { String expectedDataResponse = "{\"response\":[{\"fakedata\":\"test\"}]}"; HttpTestUtil.addRecords(client, resourceUrl, "[{\"fakedata\":\"test\"}]"); - HttpTestUtil.testContentResponse(client, HttpMethod.PUT, resourceUrl, "{\"set\":{\"fakedata\":\"test\"}}", 400); + HttpTestUtil.testContentResponse(client, HttpMethod.PUT, resourceUrl, "{\"set\":{\"fakedata\":\"test\"}}", 200); HttpTestUtil.testContentlessResponse(client, HttpMethod.GET, resourceUrl + "?l=5", 200, expectedDataResponse); }