// Path: coopr-server/src/main/java/co/cask/coopr/account/Account.java
// public final class Account {
//   public static final Account SUPERADMIN = new Account(Constants.ADMIN_USER, Constants.SUPERADMIN_TENANT);
//   private final String userId;
//   private final String tenantId;
// 
//   public Account(String userId, String tenantId) {
//     Preconditions.checkArgument(userId != null && !userId.isEmpty(), "Account must have a user id.");
//     Preconditions.checkArgument(tenantId != null && !tenantId.isEmpty(), "Account must have a tenant id.");
//     this.userId = userId;
//     this.tenantId = tenantId;
//   }
// 
//   public String getUserId() {
//     return userId;
//   }
// 
//   public String getTenantId() {
//     return tenantId;
//   }
// 
//   public boolean isAdmin() {
//     return Constants.ADMIN_USER.equals(userId);
//   }
// 
//   public boolean isSuperadmin() {
//     return Constants.ADMIN_USER.equals(userId) && Constants.SUPERADMIN_TENANT.equals(tenantId);
//   }
// 
//   @Override
//   public boolean equals(Object o) {
//     if (this == o) {
//       return true;
//     }
//     if (!(o instanceof Account)) {
//       return false;
//     }
// 
//     Account other = (Account) o;
//     return Objects.equal(userId, other.userId) &&
//       Objects.equal(tenantId, other.tenantId);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hashCode(userId, tenantId);
//   }
// 
//   @Override
//   public String toString() {
//     return Objects.toStringHelper(this)
//       .add("userId", userId)
//       .add("tenantId", tenantId)
//       .toString();
//   }
// }
// 
// Path: coopr-server/src/main/java/co/cask/coopr/scheduler/ClusterAction.java
// public enum ClusterAction {
//   SOLVE_LAYOUT(Cluster.Status.TERMINATED),
//   CLUSTER_CREATE(Cluster.Status.INCOMPLETE),
//   CLUSTER_DELETE(Cluster.Status.INCOMPLETE),
//   CLUSTER_CONFIGURE(Cluster.Status.INCONSISTENT),
//   CLUSTER_CONFIGURE_WITH_RESTART(Cluster.Status.INCONSISTENT),
//   STOP_SERVICES(Cluster.Status.INCONSISTENT),
//   START_SERVICES(Cluster.Status.INCONSISTENT),
//   RESTART_SERVICES(Cluster.Status.INCONSISTENT),
//   ADD_SERVICES(Cluster.Status.INCONSISTENT);
// 
//   // these are runtime actions for services that don't change cluster state
//   public static final Set<ClusterAction> SERVICE_RUNTIME_ACTIONS = ImmutableSet.of(
//     STOP_SERVICES, START_SERVICES, RESTART_SERVICES);
//   private final Cluster.Status failureStatus;
// 
//   ClusterAction(Cluster.Status status) {
//     failureStatus = status;
//   }
// 
//   public Cluster.Status getFailureStatus() {
//     return failureStatus;
//   }
// }


import co.cask.coopr.BaseTest;
import co.cask.coopr.Entities;
import co.cask.coopr.account.Account;
import co.cask.coopr.cluster.Cluster;
import co.cask.coopr.scheduler.ClusterAction;
import com.google.common.collect.Maps;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.Map;
package co.cask.coopr.scheduler.task;



/**
 *
 */
public class TaskServiceTest extends BaseTest {
  private static TaskService taskService;

  @BeforeClass
  public static void setupTaskServiceTest() {
    taskService = injector.getInstance(TaskService.class);
  }

  @Test
  public void testOnlyDeleteFinishWipesCredentials() throws Exception {
    Account account = new Account("user", "tenant");
    String clusterId = "123";
    Cluster cluster = Cluster.builder()
      .setName("cluster1")
      .setID(clusterId)
      .setProvider(Entities.ProviderExample.RACKSPACE)
      .setClusterTemplate(Entities.ClusterTemplateExample.HDFS)
      .setAccount(account)
      .setStatus(Cluster.Status.ACTIVE)
      .build();

    // write credentials
    Map<String, Object> sensitiveFields = Maps.newHashMap();
    sensitiveFields.put("key", "keycontents");
    credentialStore.set(account.getTenantId(), clusterId, sensitiveFields);
    long jobNum = 1;

// Path: coopr-server/src/main/java/co/cask/coopr/account/Account.java
// public final class Account {
//   public static final Account SUPERADMIN = new Account(Constants.ADMIN_USER, Constants.SUPERADMIN_TENANT);
//   private final String userId;
//   private final String tenantId;
// 
//   public Account(String userId, String tenantId) {
//     Preconditions.checkArgument(userId != null && !userId.isEmpty(), "Account must have a user id.");
//     Preconditions.checkArgument(tenantId != null && !tenantId.isEmpty(), "Account must have a tenant id.");
//     this.userId = userId;
//     this.tenantId = tenantId;
//   }
// 
//   public String getUserId() {
//     return userId;
//   }
// 
//   public String getTenantId() {
//     return tenantId;
//   }
// 
//   public boolean isAdmin() {
//     return Constants.ADMIN_USER.equals(userId);
//   }
// 
//   public boolean isSuperadmin() {
//     return Constants.ADMIN_USER.equals(userId) && Constants.SUPERADMIN_TENANT.equals(tenantId);
//   }
// 
//   @Override
//   public boolean equals(Object o) {
//     if (this == o) {
//       return true;
//     }
//     if (!(o instanceof Account)) {
//       return false;
//     }
// 
//     Account other = (Account) o;
//     return Objects.equal(userId, other.userId) &&
//       Objects.equal(tenantId, other.tenantId);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hashCode(userId, tenantId);
//   }
// 
//   @Override
//   public String toString() {
//     return Objects.toStringHelper(this)
//       .add("userId", userId)
//       .add("tenantId", tenantId)
//       .toString();
//   }
// }
// 
// Path: coopr-server/src/main/java/co/cask/coopr/scheduler/ClusterAction.java
// public enum ClusterAction {
//   SOLVE_LAYOUT(Cluster.Status.TERMINATED),
//   CLUSTER_CREATE(Cluster.Status.INCOMPLETE),
//   CLUSTER_DELETE(Cluster.Status.INCOMPLETE),
//   CLUSTER_CONFIGURE(Cluster.Status.INCONSISTENT),
//   CLUSTER_CONFIGURE_WITH_RESTART(Cluster.Status.INCONSISTENT),
//   STOP_SERVICES(Cluster.Status.INCONSISTENT),
//   START_SERVICES(Cluster.Status.INCONSISTENT),
//   RESTART_SERVICES(Cluster.Status.INCONSISTENT),
//   ADD_SERVICES(Cluster.Status.INCONSISTENT);
// 
//   // these are runtime actions for services that don't change cluster state
//   public static final Set<ClusterAction> SERVICE_RUNTIME_ACTIONS = ImmutableSet.of(
//     STOP_SERVICES, START_SERVICES, RESTART_SERVICES);
//   private final Cluster.Status failureStatus;
// 
//   ClusterAction(Cluster.Status status) {
//     failureStatus = status;
//   }
// 
//   public Cluster.Status getFailureStatus() {
//     return failureStatus;
//   }
// }


// Path: coopr-server/src/test/java/co/cask/coopr/scheduler/task/TaskServiceTest.java
import co.cask.coopr.BaseTest;
import co.cask.coopr.Entities;
import co.cask.coopr.account.Account;
import co.cask.coopr.cluster.Cluster;
import co.cask.coopr.scheduler.ClusterAction;
import com.google.common.collect.Maps;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.Map;

package co.cask.coopr.scheduler.task;



/**
 *
 */
public class TaskServiceTest extends BaseTest {
  private static TaskService taskService;

  @BeforeClass
  public static void setupTaskServiceTest() {
    taskService = injector.getInstance(TaskService.class);
  }

  @Test
  public void testOnlyDeleteFinishWipesCredentials() throws Exception {
    Account account = new Account("user", "tenant");
    String clusterId = "123";
    Cluster cluster = Cluster.builder()
      .setName("cluster1")
      .setID(clusterId)
      .setProvider(Entities.ProviderExample.RACKSPACE)
      .setClusterTemplate(Entities.ClusterTemplateExample.HDFS)
      .setAccount(account)
      .setStatus(Cluster.Status.ACTIVE)
      .build();

    // write credentials
    Map<String, Object> sensitiveFields = Maps.newHashMap();
    sensitiveFields.put("key", "keycontents");
    credentialStore.set(account.getTenantId(), clusterId, sensitiveFields);
    long jobNum = 1;

    for (ClusterAction action : ClusterAction.values()) {