This is an automated email from the ASF dual-hosted git repository.

tpalfy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new dfdd86cff7 NIFI-10793 Comment is not populated when process group is 
created via API
dfdd86cff7 is described below

commit dfdd86cff7b6145a537ebb19114ca938fef35d55
Author: krisztina-zsihovszki <[email protected]>
AuthorDate: Fri Nov 11 11:14:59 2022 +0100

    NIFI-10793 Comment is not populated when process group is created via API
    
    This closes #6653.
    
    Signed-off-by: Tamas Palfy <[email protected]>
---
 .../nifi/web/dao/impl/StandardProcessGroupDAO.java |  4 +
 .../web/dao/impl/TestStandardProcessGroupDAO.java  | 99 ++++++++++++++++++++++
 2 files changed, 103 insertions(+)

diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardProcessGroupDAO.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardProcessGroupDAO.java
index f349fb2f8e..e42a135d2e 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardProcessGroupDAO.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardProcessGroupDAO.java
@@ -82,6 +82,10 @@ public class StandardProcessGroupDAO extends ComponentDAO 
implements ProcessGrou
             group.setPosition(new Position(processGroup.getPosition().getX(), 
processGroup.getPosition().getY()));
         }
 
+        if (processGroup.getComments() != null) {
+            group.setComments(processGroup.getComments());
+        }
+
         final ParameterContextReferenceEntity parameterContextReference = 
processGroup.getParameterContext();
         if (parameterContextReference != null && 
parameterContextReference.getId() != null) {
             final ParameterContext parameterContext = 
flowController.getFlowManager().getParameterContextManager().getParameterContext(parameterContextReference.getId());
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/dao/impl/TestStandardProcessGroupDAO.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/dao/impl/TestStandardProcessGroupDAO.java
new file mode 100644
index 0000000000..6bf86e3411
--- /dev/null
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/dao/impl/TestStandardProcessGroupDAO.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.web.dao.impl;
+
+import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.nifi.connectable.Position;
+import org.apache.nifi.controller.FlowController;
+import org.apache.nifi.groups.ProcessGroup;
+import org.apache.nifi.parameter.ParameterContext;
+import org.apache.nifi.web.api.dto.PositionDTO;
+import org.apache.nifi.web.api.dto.ProcessGroupDTO;
+import org.apache.nifi.web.api.entity.ParameterContextReferenceEntity;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+public class TestStandardProcessGroupDAO {
+    private static final String PARENT_PROCESS_GROUP_ID = "parentId";
+    private static final String PROCESS_GROUP_ID = "pgId";
+    private static final String PROCESS_GROUP_NAME = "pgName";
+    private static final String PROCESS_GROUP_COMMENTS = "This is a comment";
+    private static final String PARAMETER_CONTEXT_ID = "parameterContextId";
+
+    private StandardProcessGroupDAO testSubject;
+
+    @Mock(answer = RETURNS_DEEP_STUBS)
+    private FlowController flowController;
+
+    @Mock
+    private ProcessGroup parentProcessGroup;
+
+    @Mock
+    private ParameterContext parameterContext;
+
+    @BeforeEach
+    void setUp() {
+        testSubject = new StandardProcessGroupDAO();
+        testSubject.setFlowController(flowController);
+
+        when(flowController
+                .getFlowManager()
+                .getGroup(PARENT_PROCESS_GROUP_ID)
+        ).thenReturn(parentProcessGroup);
+
+        when(flowController
+                .getFlowManager()
+                .getParameterContextManager()
+                .getParameterContext(PARAMETER_CONTEXT_ID)
+        ).thenReturn(parameterContext);
+    }
+
+    @Test
+    public void testCreateProcessGroup() {
+        //GIVEN
+        ParameterContextReferenceEntity parameterContextReferenceEntity = new 
ParameterContextReferenceEntity();
+        parameterContextReferenceEntity.setId(PARAMETER_CONTEXT_ID);
+
+        ProcessGroupDTO processGroupDTO = new ProcessGroupDTO();
+        processGroupDTO.setId(PROCESS_GROUP_ID);
+        processGroupDTO.setName(PROCESS_GROUP_NAME);
+        processGroupDTO.setComments(PROCESS_GROUP_COMMENTS);
+        processGroupDTO.setPosition(new PositionDTO(10.0, 20.0));
+        processGroupDTO.setParameterContext(parameterContextReferenceEntity);
+
+        //WHEN
+        ProcessGroup createdProcessGroup = 
testSubject.createProcessGroup(PARENT_PROCESS_GROUP_ID, processGroupDTO);
+
+        //THEN
+        verify(createdProcessGroup).setParent(parentProcessGroup);
+        verify(createdProcessGroup).setParameterContext(parameterContext);
+        verify(createdProcessGroup).setName(PROCESS_GROUP_NAME);
+        verify(createdProcessGroup).setComments(PROCESS_GROUP_COMMENTS);
+        verify(createdProcessGroup).setPosition(any(Position.class));
+
+        verify(parentProcessGroup).addProcessGroup(createdProcessGroup);
+    }
+}
\ No newline at end of file

Reply via email to