HorizonNet commented on a change in pull request #4231:
URL: https://github.com/apache/nifi/pull/4231#discussion_r415698289



##########
File path: 
nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java
##########
@@ -668,4 +671,52 @@ public void testSendEmpty() throws Exception {
         MockFlowFile flowFile = flowFiles.get(0);
         Assert.assertEquals(0, flowFile.getSize());
     }
+
+
+    @Test
+    public void testReadUserPaswd() throws Exception {
+        final String username = "myuser";
+        final String password = "password";
+        mongoClient = new MongoClient(new MongoClientURI(MONGO_URI));
+        final MongoDatabase db = mongoClient.getDatabase(DB_NAME);
+        final BasicDBObject createUserCommand = new 
BasicDBObject("createUser", username).append("pwd", password).append("roles",
+                java.util.Collections.singletonList(new BasicDBObject("role", 
"dbOwner").append("db", DB_NAME)));
+
+        BasicDBObject getUsersInfoCommand = new BasicDBObject("usersInfo", new 
BasicDBObject("user", username).append("db", DB_NAME));
+        Document result = db.runCommand(getUsersInfoCommand);
+        BasicDBObject dropUserCommand = new BasicDBObject("dropUser", 
username);
+
+        ArrayList users = (ArrayList) result.get("users");
+        if (!users.isEmpty()) {
+            db.runCommand(dropUserCommand);
+        }
+        db.runCommand(createUserCommand);
+
+        //setting new property
+        runner.removeProperty(AbstractMongoProcessor.URI);
+        runner.setVariable("uri", "mongodb://localhost:27017/?authSource=" + 
DB_NAME);
+        runner.setProperty(AbstractMongoProcessor.URI, "${uri}");
+        runner.setProperty(GetMongo.PASSWORD, password);
+        runner.setProperty(GetMongo.USER_NAME, username);
+
+        runner.setVariable("query", "{\"_id\": \"doc_2\"}");
+        runner.setProperty(GetMongo.QUERY, "${query}");
+        runner.setProperty(GetMongo.JSON_TYPE, GetMongo.JSON_STANDARD);
+        runner.run();
+        runner.assertAllFlowFilesTransferred(GetMongo.REL_SUCCESS, 1);
+
+        List<MockFlowFile> flowFiles = 
runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS);
+        byte[] raw = runner.getContentAsByteArray(flowFiles.get(0));
+        ObjectMapper mapper = new ObjectMapper();
+        Map<String, Object> parsed = mapper.readValue(raw, Map.class);
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+
+        // Drop the user which was created
+        db.runCommand(dropUserCommand);
+
+        Assert.assertTrue(parsed.get("date_field").getClass() == String.class);
+        Assert.assertTrue(((String) 
parsed.get("date_field")).startsWith(format.format(CAL.getTime())));
+

Review comment:
       Remove empty line.

##########
File path: 
nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/GetMongo.java
##########
@@ -253,7 +278,13 @@ public void onTrigger(final ProcessContext context, final 
ProcessSession session
                     });
 
                     outgoingFlowFile = 
session.putAllAttributes(outgoingFlowFile, attributes);
-                    session.getProvenanceReporter().receive(outgoingFlowFile, 
getURI(context));
+                    String uriPass="";

Review comment:
       Please add spaces around the equals sing.

##########
File path: 
nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java
##########
@@ -668,4 +671,52 @@ public void testSendEmpty() throws Exception {
         MockFlowFile flowFile = flowFiles.get(0);
         Assert.assertEquals(0, flowFile.getSize());
     }
+
+
+    @Test
+    public void testReadUserPaswd() throws Exception {
+        final String username = "myuser";
+        final String password = "password";
+        mongoClient = new MongoClient(new MongoClientURI(MONGO_URI));
+        final MongoDatabase db = mongoClient.getDatabase(DB_NAME);
+        final BasicDBObject createUserCommand = new 
BasicDBObject("createUser", username).append("pwd", password).append("roles",
+                java.util.Collections.singletonList(new BasicDBObject("role", 
"dbOwner").append("db", DB_NAME)));
+
+        BasicDBObject getUsersInfoCommand = new BasicDBObject("usersInfo", new 
BasicDBObject("user", username).append("db", DB_NAME));
+        Document result = db.runCommand(getUsersInfoCommand);
+        BasicDBObject dropUserCommand = new BasicDBObject("dropUser", 
username);
+
+        ArrayList users = (ArrayList) result.get("users");
+        if (!users.isEmpty()) {
+            db.runCommand(dropUserCommand);
+        }
+        db.runCommand(createUserCommand);
+
+        //setting new property
+        runner.removeProperty(AbstractMongoProcessor.URI);
+        runner.setVariable("uri", "mongodb://localhost:27017/?authSource=" + 
DB_NAME);
+        runner.setProperty(AbstractMongoProcessor.URI, "${uri}");
+        runner.setProperty(GetMongo.PASSWORD, password);
+        runner.setProperty(GetMongo.USER_NAME, username);
+
+        runner.setVariable("query", "{\"_id\": \"doc_2\"}");
+        runner.setProperty(GetMongo.QUERY, "${query}");
+        runner.setProperty(GetMongo.JSON_TYPE, GetMongo.JSON_STANDARD);
+        runner.run();
+        runner.assertAllFlowFilesTransferred(GetMongo.REL_SUCCESS, 1);
+
+        List<MockFlowFile> flowFiles = 
runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS);
+        byte[] raw = runner.getContentAsByteArray(flowFiles.get(0));
+        ObjectMapper mapper = new ObjectMapper();
+        Map<String, Object> parsed = mapper.readValue(raw, Map.class);
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+
+        // Drop the user which was created
+        db.runCommand(dropUserCommand);
+
+        Assert.assertTrue(parsed.get("date_field").getClass() == String.class);
+        Assert.assertTrue(((String) 
parsed.get("date_field")).startsWith(format.format(CAL.getTime())));
+
+    }
+

Review comment:
       Ditto.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to