CommandProcessor implements RestProcessor { void notifyAgent( ResourceHostInfo resourceHostInfo ) { WebClient webClient = null; javax.ws.rs.core.Response response = null; try { webClient = getWebClient( resourceHostInfo ); response = webClient.form( new Form() ); if ( response.getStatus() == javax.ws.rs.core.Response.Status.OK.getStatusCode() || response.getStatus() == javax.ws.rs.core.Response.Status.ACCEPTED.getStatusCode() ) { hostRegistry.updateResourceHostEntryTimestamp( resourceHostInfo.getId() ); } } finally { RestUtil.close( response, webClient ); } } 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 testNotifyAgent() throws Exception { WebClient webClient = mock( WebClient.class ); Response response = mock( Response.class ); doReturn( "IP" ).when( resourceHostInfo ).getAddress(); doReturn( webClient ).when( commandProcessor ).getWebClient( resourceHostInfo ); doReturn( response ).when( webClient ).form( any( Form.class ) ); doReturn( Response.Status.ACCEPTED.getStatusCode() ).when( response ).getStatus(); commandProcessor.notifyAgent( resourceHostInfo ); verify( hostRegistry ).updateResourceHostEntryTimestamp( HOST_ID ); }