PeerImportTemplateTask implements Callable<PrepareTemplatesResponse> { @Override public PrepareTemplatesResponse call() throws Exception { Map<String, Set<String>> rhTemplates = new HashMap<>(); for ( Node node : nodes ) { Set<String> templates = rhTemplates.get( node.getHostId() ); if ( templates == null ) { templates = Sets.newHashSet(); rhTemplates.put( node.getHostId(), templates ); } templates.add( node.getTemplateId() ); } PrepareTemplatesResponse response = peer.prepareTemplates( new PrepareTemplatesRequest( environmentId, cdnToken, rhTemplates ) ); for ( String message : response.getMessages() ) { trackerOperation.addLog( message ); } if ( response.hasSucceeded() ) { trackerOperation.addLog( String.format( "Template import succeeded on peer %s", peer.getName() ) ); } else { trackerOperation.addLog( String.format( "Template import failed on peer %s", peer.getName() ) ); throw new ActionFailedException( String.format( "Template import failed on peer %s", peer.getName() ) ); } return response; } PeerImportTemplateTask( final String environmentId, final Peer peer, final Set<Node> nodes,
                                   final String cdnToken, final TrackerOperation trackerOperation ); @Override PrepareTemplatesResponse call();  }
@Test public void testCall() throws Exception { try { task.call(); fail( "ActionFailedException expected" ); } catch ( ActionFailedException e ) { } doReturn( true ).when( response ).hasSucceeded(); assertNotNull( task.call() ); }