RemoteResourceManager { public void deployResources() { StringBuilder command = new StringBuilder(); List<Resource> deployedResources = new ArrayList<Resource>(managedResources.size()); for(Resource resource : managedResources) { checkNotNull(resource); if(resource.isUploaded() && !resource.isDeployed()) { String remoteFile = getRemoteFile(resource); if(resource.isUnzipContents()) { command.append("unzip "); command.append(remoteFile); command.append(" -d "); command.append(resource.getRemoteDeploymentDirectory()); command.append(";"); } else { command.append("cp "); command.append(remoteFile); command.append(" "); command.append(resource.getRemoteDeploymentDirectory()); command.append(";"); } deployedResources.add(resource); } } try { execute(command.toString()); for(Resource resource : deployedResources) { logger.info("Deployed {} to ssh: new Object[]{resource.getName(), sshClient.getHost(), sshClient.getPort(), resource.getRemoteDeploymentDirectory()}); resource.setDeployed(true); } } catch(SSHClientException ex) { logger.warn("Error deploying resources {} to ssh: new Object[]{deployedResources, sshClient.getHost(), sshClient.getPort(), ex}); } } RemoteResourceManager(SSHClient sshClient, String remoteResourcesDirPath, 
            String remoteResourcesDirName, String remoteSeparator);  RemoteResourceManager(SSHClient sshClient); void addResource(Resource resource); void removeResource(Resource resource); void uploadResources(); void deployResources(); void prepareResourceDirectory(); String getRemoteFile(Resource resource); static final String DEFAULT_REMOTE_RESOURCES_DIR_NAME; static final String DEFAULT_REMOTE_SEPARATOR; }
@Test public void testDeployResources() throws SSHClientException { resourceManager.addResource(dummyResource); resourceManager.addResource(uploadedUndeployedResource); when(dummyResource.isUploaded()).thenReturn(Boolean.TRUE); when(uploadedUndeployedResource.isUploaded()).thenReturn(Boolean.TRUE); resourceManager.deployResources(); String pattern = String.format(".*%s.*%s.*%s.*%s.*", DUMMY_RESOURCE_NAME, DUMMY_RESOURCE_DEPLOYMENT_DIR, UPLOADED_UNDEPLOYED_RESOURCE_NAME, DUMMY_RESOURCE_DEPLOYMENT_DIR); verify(sshClient).executeWithResultSilent(matches(pattern)); when(dummyResource.isDeployed()).thenReturn(Boolean.TRUE); when(uploadedUndeployedResource.isDeployed()).thenReturn(Boolean.TRUE); resourceManager.addResource(dummyResource2); when(dummyResource2.isUploaded()).thenReturn(Boolean.TRUE); resourceManager.deployResources(); String pattern2 = String.format(".*%s.*%s.*", DUMMY_RESOURCE_NAME + 2, DUMMY_RESOURCE_DEPLOYMENT_DIR); verify(sshClient).executeWithResultSilent(matches(pattern2)); verify(sshClient, times(1)).executeWithResultSilent(matches(pattern)); }