Github user MikeThomsen commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2560#discussion_r175286257
  
    --- Diff: 
nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java
 ---
    @@ -96,6 +99,125 @@ public void testValidators() {
             Assert.assertEquals(0, results.size());
         }
     
    +    @Test
    +    public void testQueryAndUpdateKey() {
    +        runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "_id");
    +        runner.setProperty(PutMongo.UPDATE_QUERY, "{}");
    +        runner.assertNotValid();
    +    }
    +
    +    @Test
    +    public void testNoQueryAndNoUpdateKey() {
    +        runner.removeProperty(PutMongo.UPDATE_QUERY);
    +        runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "");
    +        runner.assertNotValid();
    +    }
    +
    +    @Test
    +    public void testBlankUpdateKey() {
    +        runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "  ");
    +        runner.assertNotValid();
    +    }
    +
    +    @Test
    +    public void testUpdateQuery() {
    +        Document document = new Document()
    +            .append("name", "John Smith")
    +            .append("department", "Engineering");
    +        collection.insertOne(document);
    +        String updateBody = "{\n" +
    +            "\t\"$set\": {\n" +
    +            "\t\t\"email\": \"[email protected]\",\n" +
    +            "\t\t\"grade\": \"Sr. Principle Eng.\"\n" +
    +            "\t},\n" +
    +            "\t\"$inc\": {\n" +
    +            "\t\t\"writes\": 1\n" +
    +            "\t}\n" +
    +            "}";
    +        Map<String, String> attr = new HashMap<>();
    +        attr.put("mongo.update.query", document.toJson());
    +        runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "");
    +        runner.setProperty(PutMongo.UPDATE_MODE, 
PutMongo.UPDATE_WITH_OPERATORS);
    +        runner.setProperty(PutMongo.MODE, PutMongo.MODE_UPDATE);
    +        runner.setProperty(PutMongo.UPDATE_QUERY, "${mongo.update.query}");
    +        runner.setValidateExpressionUsage(true);
    +        runner.enqueue(updateBody, attr);
    +        updateTests(document);
    +    }
    +
    +    @Test
    +    public void testUpdateBySimpleKey() {
    +        Document document = new Document()
    +            .append("name", "John Smith")
    +            .append("department", "Engineering");
    +        collection.insertOne(document);
    +        String updateBody = "{\n" +
    +            "\t\"name\": \"John Smith\",\n" +
    +            "\t\"$set\": {\n" +
    +            "\t\t\"email\": \"[email protected]\",\n" +
    +            "\t\t\"grade\": \"Sr. Principle Eng.\"\n" +
    +            "\t},\n" +
    +            "\t\"$inc\": {\n" +
    +            "\t\t\"writes\": 1\n" +
    +            "\t}\n" +
    +            "}";
    +        runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "name");
    +        runner.setProperty(PutMongo.UPDATE_MODE, 
PutMongo.UPDATE_WITH_OPERATORS);
    +        runner.setProperty(PutMongo.MODE, PutMongo.MODE_UPDATE);
    +        runner.setValidateExpressionUsage(true);
    +        runner.enqueue(updateBody);
    +        updateTests(document);
    +    }
    +
    +    @Test
    --- End diff --
    
    Yeah. I'm adding 2 at the moment. One for update by keys and one for query.


---

Reply via email to