use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.
the class TestRemoteProcessGroupAuditor method updateProcessGroupConfiguration.
@SuppressWarnings("unchecked")
private Collection<Action> updateProcessGroupConfiguration(RemoteProcessGroupDTO inputRPGDTO, RemoteProcessGroup existingRPG) throws Throwable {
final RemoteProcessGroupAuditor auditor = new RemoteProcessGroupAuditor();
final ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
final String remoteProcessGroupId = "remote-process-group-id";
inputRPGDTO.setId(remoteProcessGroupId);
final String targetUrl = "http://localhost:8080/nifi";
when(existingRPG.getTargetUri()).thenReturn(targetUrl);
final RemoteProcessGroupDAO remoteProcessGroupDAO = mock(RemoteProcessGroupDAO.class);
when(remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupId)).thenReturn(existingRPG);
// Setup updatedRPG mock based on inputRPGDTO.
final RemoteProcessGroup updatedRPG = mock(RemoteProcessGroup.class);
when(updatedRPG.getIdentifier()).thenReturn(remoteProcessGroupId);
when(updatedRPG.isTransmitting()).thenReturn(inputRPGDTO.isTransmitting());
when(updatedRPG.getCommunicationsTimeout()).thenReturn(inputRPGDTO.getCommunicationsTimeout());
when(updatedRPG.getYieldDuration()).thenReturn(inputRPGDTO.getYieldDuration());
when(updatedRPG.getTransportProtocol()).thenReturn(SiteToSiteTransportProtocol.valueOf(inputRPGDTO.getTransportProtocol()));
when(updatedRPG.getProxyHost()).thenReturn(inputRPGDTO.getProxyHost());
when(updatedRPG.getProxyPort()).thenReturn(inputRPGDTO.getProxyPort());
when(updatedRPG.getProxyUser()).thenReturn(inputRPGDTO.getProxyUser());
when(updatedRPG.getProxyPassword()).thenReturn(inputRPGDTO.getProxyPassword());
when(joinPoint.proceed()).thenReturn(updatedRPG);
// Capture added actions so that those can be asserted later.
final AuditService auditService = mock(AuditService.class);
final AtomicReference<Collection<Action>> addedActions = new AtomicReference<>();
doAnswer(invocation -> {
Collection<Action> actions = invocation.getArgumentAt(0, Collection.class);
addedActions.set(actions);
return null;
}).when(auditService).addActions(any());
auditor.setAuditService(auditService);
auditor.auditUpdateProcessGroupConfiguration(joinPoint, inputRPGDTO, remoteProcessGroupDAO);
final Collection<Action> actions = addedActions.get();
// Assert common action values.
if (actions != null) {
actions.forEach(action -> {
assertEquals(remoteProcessGroupId, action.getSourceId());
assertEquals("user-id", action.getUserIdentity());
assertEquals(targetUrl, ((RemoteProcessGroupDetails) action.getComponentDetails()).getUri());
assertNotNull(action.getTimestamp());
});
}
return actions;
}
use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.
the class TestRemoteProcessGroupAuditor method testDisableTransmission.
@Test
public void testDisableTransmission() throws Throwable {
final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
when(existingRPG.isTransmitting()).thenReturn(true);
final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
inputRPGDTO.setTransmitting(false);
final Collection<Action> actions = updateProcessGroupConfiguration(inputRPGDTO, existingRPG);
assertEquals(1, actions.size());
final Action action = actions.iterator().next();
assertEquals(Operation.Stop, action.getOperation());
assertNull(action.getActionDetails());
}
use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.
the class TestRemoteProcessGroupAuditor method testEnableTransmission.
@Test
public void testEnableTransmission() throws Throwable {
final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
when(existingRPG.isTransmitting()).thenReturn(false);
final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
inputRPGDTO.setTransmitting(true);
final Collection<Action> actions = updateProcessGroupConfiguration(inputRPGDTO, existingRPG);
assertEquals(1, actions.size());
final Action action = actions.iterator().next();
assertEquals(Operation.Start, action.getOperation());
assertNull(action.getActionDetails());
}
use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.
the class TestRemoteProcessGroupAuditor method testConfigureYieldDuration.
@Test
public void testConfigureYieldDuration() throws Throwable {
final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
when(existingRPG.getYieldDuration()).thenReturn("10 sec");
final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
inputRPGDTO.setYieldDuration("11 sec");
final Collection<Action> actions = updateProcessGroupConfiguration(inputRPGDTO, existingRPG);
assertEquals(1, actions.size());
final Action action = actions.iterator().next();
assertEquals(Operation.Configure, action.getOperation());
assertConfigureDetails(action.getActionDetails(), "Yield Duration", existingRPG.getYieldDuration(), inputRPGDTO.getYieldDuration());
}
use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.
the class TestRemoteProcessGroupAuditor method testConfigureProxyUserClear.
@Test
public void testConfigureProxyUserClear() throws Throwable {
final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
when(existingRPG.getProxyUser()).thenReturn("proxy-user");
final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
inputRPGDTO.setProxyUser(null);
final Collection<Action> actions = updateProcessGroupConfiguration(inputRPGDTO, existingRPG);
assertEquals(1, actions.size());
final Action action = actions.iterator().next();
assertEquals(Operation.Configure, action.getOperation());
assertConfigureDetails(action.getActionDetails(), "Proxy User", existingRPG.getProxyUser(), inputRPGDTO.getProxyUser());
}
Aggregations