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



##########
File path: 
nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java
##########
@@ -61,9 +64,9 @@
     static {
         CAL = Calendar.getInstance();
         DOCUMENTS = Lists.newArrayList(
-            new Document("_id", "doc_1").append("a", 1).append("b", 
2).append("c", 3),
-            new Document("_id", "doc_2").append("a", 1).append("b", 
2).append("c", 4).append("date_field", CAL.getTime()),
-            new Document("_id", "doc_3").append("a", 1).append("b", 3)
+                new Document("_id", "doc_1").append("a", 1).append("b", 
2).append("c", 3),

Review comment:
       Was this done by IDE auto-indentation or because the earlier version did 
not match the general indentation? There are also similar places in the other 
classes.

##########
File path: 
nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java
##########
@@ -668,4 +671,53 @@ 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);
+            System.out.println("dropping user");

Review comment:
       Better would be to use a logger.

##########
File path: 
nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/GetMongo.java
##########
@@ -253,7 +278,14 @@ public void onTrigger(final ProcessContext context, final 
ProcessSession session
                     });
 
                     outgoingFlowFile = 
session.putAllAttributes(outgoingFlowFile, attributes);
-                    session.getProvenanceReporter().receive(outgoingFlowFile, 
getURI(context));
+                    String uriPass="";
+                    if (context.getProperty(USER_NAME).getValue() != null) {
+                        uriPass = "mongodb://" + 
context.getProperty(USER_NAME).getValue() + ":" + 
context.getProperty(PASSWORD).getValue() + "@" + getURI(context).substring(10);
+

Review comment:
       Remove this empty line.

##########
File path: 
nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java
##########
@@ -668,4 +671,53 @@ 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);
+            System.out.println("dropping user");
+        }
+        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);

Review comment:
       To stay consistent, add a space between the arguments. There are also 
other similar places in this class.




----------------------------------------------------------------
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