HostRegistrationManagerImpl extends HostListener implements HostRegistrationManager { void checkManagement( RequestedHost requestedHost ) { try { if ( requestedHost.getStatus() == ResourceHostRegistrationStatus.REQUESTED && containsManagementContainer( requestedHost.getHostInfos() ) ) { boolean managementAlreadyApproved = false; for ( RequestedHostImpl requestedHostImpl : requestDataService.getAll() ) { if ( requestedHostImpl.getStatus() == ResourceHostRegistrationStatus.APPROVED && containsManagementContainer( requestedHostImpl.getHostInfos() ) ) { managementAlreadyApproved = true; break; } } if ( !managementAlreadyApproved ) { approveRequest( requestedHost.getId() ); } } } catch ( Exception e ) { } } HostRegistrationManagerImpl( final SecurityManager securityManager, final DaoManager daoManager ); void init(); @Override String generateContainerToken( final long ttlInMs ); @Override Boolean verifyTokenAndRegisterKey( final String token, String containerHostId, String publicKey ); void dispose(); @Override void changeRhHostname( final String rhId, String hostname ); @Override List<RequestedHost> getRequests(); @Override RequestedHost getRequest( final String requestId ); @RolesAllowed( "Resource-Management|Write" ) @Override synchronized void queueRequest( final RequestedHost requestedHost ); @Override void rejectRequest( final String requestId ); @Override void approveRequest( final String requestId ); @Override void removeRequest( final String requestId ); @Override void unblockRequest( final String requestId ); @Override void onHeartbeat( final ResourceHostInfo resourceHostInfo, final Set<QuotaAlertValue> alerts );  }
@Test public void testCheckManagement() throws Exception { RequestedHost requestedHost = mock( RequestedHost.class ); doReturn( ResourceHostRegistrationStatus.REQUESTED ).when( requestedHost ).getStatus(); doReturn( true ).when( registrationManager ).containsManagementContainer( anySet() ); registrationManager.checkManagement( requestedHost ); verify( registrationManager, never() ).approveRequest( anyString() ); doReturn( Sets.newHashSet() ).when( requestDataService ).getAll(); registrationManager.checkManagement( requestedHost ); verify( registrationManager ).approveRequest( anyString() ); }