CommandProcessor implements RestProcessor { @Override public void handleResponse( final Response response ) { try { Preconditions.checkNotNull( response ); CommandProcess commandProcess = commands.get( response.getCommandId() ); if ( commandProcess != null ) { LOG.debug( "Response: {}", response ); commandProcess.processResponse( response ); } else { LOG.warn( String.format( "Callback not found for response: %s", jsonUtil.to( response ) ) ); } ResourceHostInfo resourceHostInfo = getResourceHostInfo( response.getId() ); hostRegistry.updateResourceHostEntryTimestamp( resourceHostInfo.getId() ); } catch ( Exception e ) { LOG.error( "Error processing response", e ); } } CommandProcessor( final HostRegistry hostRegistry, final IdentityManager identityManager ); void addListener( HeartbeatListener listener ); void removeListener( HeartbeatListener listener ); void dispose(); @Override void handleHeartbeat( final HeartBeat heartBeat ); @Override Set<String> getRequests( final String hostId ); @Override void handleResponse( final Response response );  }
@Test public void testHandleResponse() throws Exception { io.subutai.common.command.Response response = mock( io.subutai.common.command.Response.class ); doReturn( resourceHostInfo ).when( commandProcessor ).getResourceHostInfo( anyString() ); commandProcessor.handleResponse( response ); verify( jsonUtil ).to( response ); doReturn( process ).when( commands ).get( anyString() ); commandProcessor.handleResponse( response ); verify( hostRegistry, times( 2 ) ).updateResourceHostEntryTimestamp( anyString() ); }