/**
  * waits until given BundleDeployment is not in PENDING or IN_PROGRESS state, then returns
  * BundleDeployment instance, which is going to be either SUCCESS or FAILURE
  *
  * @param deployment
  * @return
  */
 private BundleDeployment waitForBundleDeployment(BundleDeployment deployment) {
   while (deployment.getStatus().equals(BundleDeploymentStatus.IN_PROGRESS)
       || deployment.getStatus().equals(BundleDeploymentStatus.PENDING)) {
     try {
       Thread.currentThread().join(3 * 1000);
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
     BundleDeploymentCriteria criteria = new BundleDeploymentCriteria();
     criteria.addFilterId(deployment.getId());
     deployment =
         bundleManager.findBundleDeploymentsByCriteria(client.getSubject(), criteria).get(0);
   }
   return deployment;
 }