use of org.apache.nifi.web.dao.RemoteProcessGroupDAO 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.web.dao.RemoteProcessGroupDAO in project nifi by apache.
the class TestRemoteProcessGroupAuditor method updateProcessGroupInputPortConfiguration.
@SuppressWarnings("unchecked")
private Collection<Action> updateProcessGroupInputPortConfiguration(RemoteProcessGroupPortDTO inputRPGPortDTO, RemoteGroupPort existingRPGPort) throws Throwable {
final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
final RemoteProcessGroupAuditor auditor = new RemoteProcessGroupAuditor();
final ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
final String remoteProcessGroupId = "remote-process-group-id";
inputRPGPortDTO.setId(remoteProcessGroupId);
inputRPGPortDTO.setTargetId(remoteProcessGroupId);
final String targetUrl = "http://localhost:8080/nifi";
when(existingRPG.getIdentifier()).thenReturn(remoteProcessGroupId);
when(existingRPG.getTargetUri()).thenReturn(targetUrl);
final RemoteProcessGroupDAO remoteProcessGroupDAO = mock(RemoteProcessGroupDAO.class);
when(remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupId)).thenReturn(existingRPG);
when(existingRPG.getInputPort(eq(inputRPGPortDTO.getId()))).thenReturn(existingRPGPort);
// Setup updatedRPGPort mock based on inputRPGPortDTO.
final RemoteGroupPort updatedRPGPort = mock(RemoteGroupPort.class);
final String portName = existingRPGPort.getName();
when(updatedRPGPort.getName()).thenReturn(portName);
if (inputRPGPortDTO.isTransmitting() != null) {
when(updatedRPGPort.isRunning()).thenReturn(inputRPGPortDTO.isTransmitting());
}
when(updatedRPGPort.getMaxConcurrentTasks()).thenReturn(inputRPGPortDTO.getConcurrentlySchedulableTaskCount());
when(updatedRPGPort.isUseCompression()).thenReturn(inputRPGPortDTO.getUseCompression());
final BatchSettingsDTO batchSettings = inputRPGPortDTO.getBatchSettings();
if (batchSettings != null) {
when(updatedRPGPort.getBatchCount()).thenReturn(batchSettings.getCount());
when(updatedRPGPort.getBatchSize()).thenReturn(batchSettings.getSize());
when(updatedRPGPort.getBatchDuration()).thenReturn(batchSettings.getDuration());
}
when(joinPoint.proceed()).thenReturn(updatedRPGPort);
// 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.auditUpdateProcessGroupInputPortConfiguration(joinPoint, remoteProcessGroupId, inputRPGPortDTO, 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;
}
Aggregations