You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2020/06/02 17:25:27 UTC
[nifi] branch master updated: NIFI-7312: Enable search in variable
registry of root process group
This is an automated email from the ASF dual-hosted git repository.
markap14 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/master by this push:
new 91dd59d NIFI-7312: Enable search in variable registry of root process group
91dd59d is described below
commit 91dd59dbdfd66423f1226c7eb1e20dcd2f0ed18d
Author: Peter Gyori <pe...@gmail.com>
AuthorDate: Fri May 22 16:08:51 2020 +0200
NIFI-7312: Enable search in variable registry of root process group
This closes #4303.
Signed-off-by: Mark Payne <ma...@hotmail.com>
---
.../web/controller/ControllerSearchService.java | 4 +-
.../ProcessGroupSearchResultEnricher.java | 10 ++-
.../AbstractControllerSearchIntegrationTest.java | 8 +-
.../ControllerSearchServiceFilterTest.java | 20 +++++
.../ControllerSearchServiceIntegrationTest.java | 88 ++++++++++++++++++++++
.../ControllerSearchServiceRegressionTest.java | 12 ++-
.../controller/ControllerSearchServiceTest.java | 30 +++-----
.../ComponentSearchResultEnricherTest.java | 61 ++++++++++-----
8 files changed, 184 insertions(+), 49 deletions(-)
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerSearchService.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerSearchService.java
index ba25a98..4e022d2 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerSearchService.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerSearchService.java
@@ -88,10 +88,8 @@ public class ControllerSearchService {
final ComponentSearchResultEnricher groupResultEnricher = resultEnricherFactory.getProcessGroupResultEnricher(scope, user);
if (appliesToGroupFilter(searchQuery, scope)) {
- if (scope.getParent() != null) {
- searchComponentType(Collections.singletonList(scope), user, searchQuery, matcherForProcessGroup, groupResultEnricher, results.getProcessGroupResults());
- }
+ searchComponentType(Collections.singletonList(scope), user, searchQuery, matcherForProcessGroup, groupResultEnricher, results.getProcessGroupResults());
searchComponentType(scope.getProcessors(), user, searchQuery, matcherForProcessor, resultEnricher, results.getProcessorResults());
searchComponentType(scope.getConnections(), user, searchQuery, matcherForConnection, resultEnricher, results.getConnectionResults());
searchComponentType(scope.getRemoteProcessGroups(), user, searchQuery, matcherForRemoteProcessGroup, resultEnricher, results.getRemoteProcessGroupResults());
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/search/resultenrichment/ProcessGroupSearchResultEnricher.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/search/resultenrichment/ProcessGroupSearchResultEnricher.java
index 3c0ee4c..e45ac72 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/search/resultenrichment/ProcessGroupSearchResultEnricher.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/search/resultenrichment/ProcessGroupSearchResultEnricher.java
@@ -29,9 +29,13 @@ public class ProcessGroupSearchResultEnricher extends AbstractComponentSearchRes
@Override
public ComponentSearchResultDTO enrich(final ComponentSearchResultDTO input) {
- input.setGroupId(processGroup.getParent().getIdentifier());
- input.setParentGroup(buildResultGroup(processGroup.getParent(), user));
- input.setVersionedGroup(buildVersionedGroup(processGroup.getParent(), user));
+ if (processGroup.getParent() != null) {
+ input.setGroupId(processGroup.getParent().getIdentifier());
+ input.setParentGroup(buildResultGroup(processGroup.getParent(), user));
+ input.setVersionedGroup(buildVersionedGroup(processGroup.getParent(), user));
+ } else {
+ input.setGroupId(processGroup.getIdentifier());
+ }
return input;
}
}
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/AbstractControllerSearchIntegrationTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/AbstractControllerSearchIntegrationTest.java
index 61de4c1..6220fcb 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/AbstractControllerSearchIntegrationTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/AbstractControllerSearchIntegrationTest.java
@@ -62,8 +62,8 @@ import static org.apache.nifi.web.controller.ComponentMockUtil.getRootProcessGro
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:nifi-web-api-test-context.xml", "classpath:nifi-web-api-context.xml"})
public abstract class AbstractControllerSearchIntegrationTest {
- protected static final String ROOT_PROCESSOR_GROUP_ID = "rootId";
- protected static final String ROOT_PROCESSOR_GROUP_NAME = "rootName";
+ protected static final String ROOT_PROCESSOR_GROUP_ID = "3b9a7e60-0172-1000-5f1e-10cbc0c4d5f1";
+ protected static final String ROOT_PROCESSOR_GROUP_NAME = "NiFi Flow";
protected static final boolean AUTHORIZED = true;
protected static final boolean NOT_AUTHORIZED = false;
@@ -110,6 +110,10 @@ public abstract class AbstractControllerSearchIntegrationTest {
return givenProcessGroup(getRootProcessGroup(ROOT_PROCESSOR_GROUP_ID, ROOT_PROCESSOR_GROUP_NAME, "", AUTHORIZED, NOT_UNDER_VERSION_CONTROL));
}
+ protected ProcessGroupSetup givenRootProcessGroup(String comments) {
+ return givenProcessGroup(getRootProcessGroup(ROOT_PROCESSOR_GROUP_ID, ROOT_PROCESSOR_GROUP_NAME, comments, AUTHORIZED, NOT_UNDER_VERSION_CONTROL));
+ }
+
protected ProcessGroupSetup givenProcessGroup(final ProcessGroup processGroup) {
return new ProcessGroupSetup(processGroup);
}
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceFilterTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceFilterTest.java
index e2ff4b3..0581620 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceFilterTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceFilterTest.java
@@ -91,6 +91,26 @@ public class ControllerSearchServiceFilterTest extends AbstractControllerSearchI
}
@Test
+ public void testGroupWhenRoot() {
+ // given
+ givenRootProcessGroup()
+ .withProcessor(getProcessorNode("workingProcessor1", "processor1Name", AUTHORIZED));
+
+ givenProcessGroup(getChildProcessGroup("child1", "child1Name", "", getProcessGroup(ROOT_PROCESSOR_GROUP_ID), AUTHORIZED, NOT_UNDER_VERSION_CONTROL))
+ .withProcessor(getProcessorNode("workingProcessor2", "processor1Name", AUTHORIZED));
+
+ // when:
+ // Cannot use "group:NiFi flow" as filter since the scope is only considered until the first space in the query
+ whenExecuteSearch("group:NiFi processor1Name");
+
+ // then
+ thenResultConsists()
+ .ofProcessor(getSimpleResult("workingProcessor1", "processor1Name", ROOT_PROCESSOR_GROUP_ID, ROOT_PROCESSOR_GROUP_ID, ROOT_PROCESSOR_GROUP_NAME, "Name: processor1Name"))
+ .ofProcessor(getSimpleResult("workingProcessor2", "processor1Name", "child1", "child1", "child1Name", "Name: processor1Name"))
+ .validate(results);
+ }
+
+ @Test
public void testGroupWhenHasChildGroup() {
// given
givenRootProcessGroup()
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceIntegrationTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceIntegrationTest.java
index cb07e0d..00e27c5 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceIntegrationTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceIntegrationTest.java
@@ -55,6 +55,56 @@ import static org.apache.nifi.web.controller.ComponentMockUtil.getRemoteProcessG
public class ControllerSearchServiceIntegrationTest extends AbstractControllerSearchIntegrationTest {
@Test
+ public void testSearchForRootBasedOnID() {
+ // given
+ givenRootProcessGroup();
+
+ // when
+ whenExecuteSearch(ROOT_PROCESSOR_GROUP_ID.substring(2, 7));
+
+ // then
+ thenResultConsists()
+ .ofProcessGroup(getSimpleResult(ROOT_PROCESSOR_GROUP_ID,
+ ROOT_PROCESSOR_GROUP_NAME,
+ ROOT_PROCESSOR_GROUP_ID,
+ null,
+ null,
+ "Id: " + ROOT_PROCESSOR_GROUP_ID))
+ .validate(results);
+ }
+
+ @Test
+ public void testSearchForRootBasedOnNameAndComments() {
+ // given
+ final String commentForRoot = "test comment for " + ROOT_PROCESSOR_GROUP_NAME + " process group";
+ final String searchQuery = ROOT_PROCESSOR_GROUP_NAME;
+ final String processor2Id = "processor2";
+ final String processor2Name = "NAME2";
+ final String processor2Comment = "This comment is a test comment containing " + ROOT_PROCESSOR_GROUP_NAME;
+
+ givenRootProcessGroup(commentForRoot)
+ .withProcessor(getProcessorNode("processor1", "name1", AUTHORIZED))
+ .withProcessor(getProcessorNode(processor2Id, processor2Name, processor2Comment,
+ Optional.of("versionId"), SchedulingStrategy.TIMER_DRIVEN, ExecutionNode.ALL, ScheduledState.RUNNING, ValidationStatus.VALID,
+ new HashSet<>(),"Processor", Mockito.mock(Processor.class), new HashMap<>(), AUTHORIZED));
+
+ // when
+ whenExecuteSearch(searchQuery);
+
+ // then
+ thenResultConsists()
+ .ofProcessGroup(getSimpleResult(ROOT_PROCESSOR_GROUP_ID,
+ ROOT_PROCESSOR_GROUP_NAME,
+ ROOT_PROCESSOR_GROUP_ID,
+ null,
+ null,
+ "Name: " + ROOT_PROCESSOR_GROUP_NAME,
+ "Comments: " + commentForRoot))
+ .ofProcessor(getSimpleResultFromRoot(processor2Id, processor2Name, "Comments: " + processor2Comment))
+ .validate(results);
+ }
+
+ @Test
public void testSearchBasedOnBasicAttributes() {
// given
givenRootProcessGroup()
@@ -366,6 +416,44 @@ public class ControllerSearchServiceIntegrationTest extends AbstractControllerSe
}
@Test
+ public void testSearchBasedOnVariableRegistryInRoot() {
+ // given
+ givenRootProcessGroup();
+ final ProcessGroup childProcessGroup = getChildProcessGroup("childGroup", "childGroupName", "", getProcessGroup(ROOT_PROCESSOR_GROUP_ID), AUTHORIZED, NOT_UNDER_VERSION_CONTROL);
+ givenProcessGroup(childProcessGroup);
+
+ final Map<VariableDescriptor, String> variablesRoot = new HashMap<>();
+ variablesRoot.put(new VariableDescriptor.Builder("variableName1").build(), "variableValue1");
+
+ final ComponentVariableRegistry variableRegistryRoot = Mockito.mock(ComponentVariableRegistry.class);
+ Mockito.when(variableRegistryRoot.getVariableMap()).thenReturn(variablesRoot);
+
+ Mockito.when(getProcessGroup(ROOT_PROCESSOR_GROUP_ID).getVariableRegistry()).thenReturn(variableRegistryRoot);
+
+ final Map<VariableDescriptor, String> variablesChild = new HashMap<>();
+ variablesChild.put(new VariableDescriptor.Builder("variableName2").build(), "variableValue2");
+
+ final ComponentVariableRegistry variableRegistryChild = Mockito.mock(ComponentVariableRegistry.class);
+ Mockito.when(variableRegistryChild.getVariableMap()).thenReturn(variablesChild);
+
+ Mockito.when(childProcessGroup.getVariableRegistry()).thenReturn(variableRegistryChild);
+
+ // when
+ whenExecuteSearch("variableValue");
+
+ // then
+ thenResultConsists()
+ .ofProcessGroup(getSimpleResult(ROOT_PROCESSOR_GROUP_ID,
+ ROOT_PROCESSOR_GROUP_NAME,
+ ROOT_PROCESSOR_GROUP_ID,
+ null,
+ null,
+ "Variable Value: " + "variableValue1"))
+ .ofProcessGroup(getSimpleResultFromRoot("childGroup", "childGroupName", "Variable Value: variableValue2"))
+ .validate(results);
+ }
+
+ @Test
public void testSearchBasedOnConnectionAttributes() {
// given
final ProcessorNode processor1 = getProcessorNode("processor1", "processor1Name", AUTHORIZED);
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceRegressionTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceRegressionTest.java
index dc57a51..bf71f19 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceRegressionTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceRegressionTest.java
@@ -69,7 +69,7 @@ public class ControllerSearchServiceRegressionTest extends AbstractControllerSea
public void testTextOmniMatch() {
// given
final String omniMatch = "omniMatch";
- final ProcessGroup rootProcessGroup = getRootProcessGroup(ROOT_PROCESSOR_GROUP_ID, ROOT_PROCESSOR_GROUP_NAME, "root_no_find_omniMatch", true, false);
+ final ProcessGroup rootProcessGroup = getRootProcessGroup(ROOT_PROCESSOR_GROUP_ID, ROOT_PROCESSOR_GROUP_NAME, "root_comments_omniMatch", true, false);
final ProcessorNode processor1 = getProcessorNode(
"proc1_id_omniMatch",
@@ -265,6 +265,13 @@ public class ControllerSearchServiceRegressionTest extends AbstractControllerSea
"Variable Value: processgroup1_variable2_value_omniMatch"
);
+ final ComponentSearchResultDTO rootProcessGroupResult = getSimpleResult(ROOT_PROCESSOR_GROUP_ID, ROOT_PROCESSOR_GROUP_NAME,
+ ROOT_PROCESSOR_GROUP_ID,
+ null,
+ null,
+ "Comments: root_comments_omniMatch"
+ );
+
final RemoteProcessGroup remoteProcessGroup1 = getRemoteProcessGroup(
"remoteprocessgroup1_id_omniMatch",
"remoteprocessgroup1_name_omniMatch",
@@ -347,6 +354,7 @@ public class ControllerSearchServiceRegressionTest extends AbstractControllerSea
.ofLabel(label1Result)
.ofControllerServiceNode(controllerServiceNode1Result)
.ofProcessGroup(processGroup1Result)
+ .ofProcessGroup(rootProcessGroupResult)
.ofRemoteProcessGroup(remoteProcessGroup1Result)
.ofParameterContext(parameterContext1Result)
.ofParameter(parameterResults1)
@@ -364,7 +372,7 @@ public class ControllerSearchServiceRegressionTest extends AbstractControllerSea
// then
thenResultConsists()
- .ofProcessor(getSimpleResult("foobarId", "foobar", "rootId", "rootId", "rootName", "Id: foobarId", "Name: foobar"))
+ .ofProcessor(getSimpleResultFromRoot("foobarId", "foobar", "Id: foobarId", "Name: foobar"))
.validate(results);
}
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceTest.java
index 322d2da..c7c0efb 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/ControllerSearchServiceTest.java
@@ -170,13 +170,7 @@ public class ControllerSearchServiceTest {
testSubject.search(searchQuery, results);
// then
- thenFollowingGroupsAreSearched(Arrays.asList(
- PROCESS_GROUP_FIRST_LEVEL_A,
- PROCESS_GROUP_SECOND_LEVEL_A,
- PROCESS_GROUP_FIRST_LEVEL_B,
- PROCESS_GROUP_SECOND_LEVEL_B_1,
- PROCESS_GROUP_SECOND_LEVEL_B_2));
- thenContentOfTheFollowingGroupsAreSearched(processGroups.keySet());
+ thenFollowingGroupsAndTheirContentsAreSearched(processGroups.keySet());
}
@Test
@@ -191,6 +185,7 @@ public class ControllerSearchServiceTest {
testSubject.search(searchQuery, results);
// The authorization is not transitive, children groups might be good candidates.
thenFollowingGroupsAreSearched(Arrays.asList(
+ PROCESS_GROUP_ROOT,
PROCESS_GROUP_FIRST_LEVEL_A,
PROCESS_GROUP_SECOND_LEVEL_A,
PROCESS_GROUP_SECOND_LEVEL_B_1,
@@ -246,13 +241,7 @@ public class ControllerSearchServiceTest {
testSubject.search(searchQuery, results);
// then
- thenFollowingGroupsAreSearched(Arrays.asList(
- PROCESS_GROUP_FIRST_LEVEL_A,
- PROCESS_GROUP_SECOND_LEVEL_A,
- PROCESS_GROUP_FIRST_LEVEL_B,
- PROCESS_GROUP_SECOND_LEVEL_B_1,
- PROCESS_GROUP_SECOND_LEVEL_B_2));
- thenContentOfTheFollowingGroupsAreSearched(processGroups.keySet());
+ thenFollowingGroupsAndTheirContentsAreSearched(processGroups.keySet());
}
@@ -335,13 +324,7 @@ public class ControllerSearchServiceTest {
testSubject.search(searchQuery, results);
// then
- thenFollowingGroupsAreSearched(Arrays.asList(
- PROCESS_GROUP_FIRST_LEVEL_A,
- PROCESS_GROUP_SECOND_LEVEL_A,
- PROCESS_GROUP_FIRST_LEVEL_B,
- PROCESS_GROUP_SECOND_LEVEL_B_1,
- PROCESS_GROUP_SECOND_LEVEL_B_2));
- thenContentOfTheFollowingGroupsAreSearched(processGroups.keySet());
+ thenFollowingGroupsAndTheirContentsAreSearched(processGroups.keySet());
}
@Test
@@ -616,6 +599,11 @@ public class ControllerSearchServiceTest {
Mockito.verify(matcherForParameter, Mockito.never()).match(Mockito.any(Parameter.class), Mockito.any(SearchQuery.class));
}
+ private void thenFollowingGroupsAndTheirContentsAreSearched(final Collection<String> searchedProcessGroups) {
+ thenFollowingGroupsAreSearched(searchedProcessGroups);
+ thenContentOfTheFollowingGroupsAreSearched(searchedProcessGroups);
+ }
+
private void thenFollowingGroupsAreSearched(final Collection<String> searchedProcessGroups) {
for (final String processGroup : searchedProcessGroups) {
Mockito.verify(matcherForProcessGroup, Mockito.times(1)).match(processGroups.get(processGroup), searchQuery);
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/search/resultenrichment/ComponentSearchResultEnricherTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/search/resultenrichment/ComponentSearchResultEnricherTest.java
index 5d9b994..3da9231 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/search/resultenrichment/ComponentSearchResultEnricherTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/search/resultenrichment/ComponentSearchResultEnricherTest.java
@@ -24,7 +24,6 @@ import org.apache.nifi.parameter.ParameterContext;
import org.apache.nifi.registry.flow.VersionControlInformation;
import org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -58,26 +57,10 @@ public class ComponentSearchResultEnricherTest {
@Mock
private ParameterContext parameterContext;
- @Before
- public void setUp() {
- Mockito.when(processGroup.getIdentifier()).thenReturn(IDENTIFIER);
- Mockito.when(processGroup.getName()).thenReturn(NAME);
- Mockito.when(processGroup.isAuthorized(authorizer, RequestAction.READ, user)).thenReturn(true);
- Mockito.when(processGroup.getVersionControlInformation()).thenReturn(Mockito.mock(VersionControlInformation.class));
- Mockito.when(processGroup.getParent()).thenReturn(parentProcessGroup);
-
- Mockito.when(parentProcessGroup.getIdentifier()).thenReturn(PARENT_IDENTIFIER);
- Mockito.when(parentProcessGroup.getName()).thenReturn(PARENT_NAME);
- Mockito.when(parentProcessGroup.isAuthorized(authorizer, RequestAction.READ, user)).thenReturn(true);
- Mockito.when(parentProcessGroup.getVersionControlInformation()).thenReturn(Mockito.mock(VersionControlInformation.class));
-
- Mockito.when(parameterContext.getIdentifier()).thenReturn(CONTEXT_IDENTIFIER);
- Mockito.when(parameterContext.getName()).thenReturn(CONTEXT_NAME);
- }
-
@Test
public void testGeneralEnrichment() {
// given
+ givenProcessGroup();
final GeneralComponentSearchResultEnricher testSubject = new GeneralComponentSearchResultEnricher(processGroup, user, authorizer);
final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
@@ -100,6 +83,7 @@ public class ComponentSearchResultEnricherTest {
@Test
public void testProcessGroupEnrichment() {
// given
+ givenProcessGroup();
final ProcessGroupSearchResultEnricher testSubject = new ProcessGroupSearchResultEnricher(processGroup, user, authorizer);
final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
@@ -121,6 +105,7 @@ public class ComponentSearchResultEnricherTest {
@Test
public void testParameterEnriching() {
// given
+ givenProcessGroup();
final ParameterSearchResultEnricher testSubject = new ParameterSearchResultEnricher(parameterContext);
final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
@@ -136,6 +121,46 @@ public class ComponentSearchResultEnricherTest {
thenVersionedGroupIsNotSet(result);
}
+ @Test
+ public void testRootProcessGroupEnrichment() {
+ // given
+ givenRootProcessGroup();
+ final ProcessGroupSearchResultEnricher testSubject = new ProcessGroupSearchResultEnricher(processGroup, user, authorizer);
+ final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
+
+ // when
+ testSubject.enrich(result);
+
+ // then
+ Assert.assertEquals(IDENTIFIER, result.getGroupId());
+ Assert.assertNull(result.getId());
+ Assert.assertNull(result.getParentGroup());
+ thenVersionedGroupIsNotSet(result);
+ Assert.assertNull(result.getName());
+ Assert.assertNull(result.getMatches());
+ }
+
+ private void givenProcessGroup() {
+ Mockito.when(processGroup.getIdentifier()).thenReturn(IDENTIFIER);
+ Mockito.when(processGroup.getName()).thenReturn(NAME);
+ Mockito.when(processGroup.isAuthorized(authorizer, RequestAction.READ, user)).thenReturn(true);
+ Mockito.when(processGroup.getVersionControlInformation()).thenReturn(Mockito.mock(VersionControlInformation.class));
+ Mockito.when(processGroup.getParent()).thenReturn(parentProcessGroup);
+
+ Mockito.when(parentProcessGroup.getIdentifier()).thenReturn(PARENT_IDENTIFIER);
+ Mockito.when(parentProcessGroup.getName()).thenReturn(PARENT_NAME);
+ Mockito.when(parentProcessGroup.isAuthorized(authorizer, RequestAction.READ, user)).thenReturn(true);
+ Mockito.when(parentProcessGroup.getVersionControlInformation()).thenReturn(Mockito.mock(VersionControlInformation.class));
+
+ Mockito.when(parameterContext.getIdentifier()).thenReturn(CONTEXT_IDENTIFIER);
+ Mockito.when(parameterContext.getName()).thenReturn(CONTEXT_NAME);
+ }
+
+ private void givenRootProcessGroup() {
+ Mockito.when(processGroup.getIdentifier()).thenReturn(IDENTIFIER);
+ Mockito.when(processGroup.getParent()).thenReturn(null);
+ }
+
private void thenIdentifierIsNotSet(final ComponentSearchResultDTO result) {
Assert.assertNull(result.getGroupId());
}