@Test
 public void checkStorageDomainNotEqualWithStatusActive() {
   setStorageDomainStatus(StorageDomainStatus.Active);
   assertFalse(cmd.checkStorageDomainStatusNotEqual(StorageDomainStatus.Active));
   List<String> messages = cmd.getReturnValue().getCanDoActionMessages();
   assertEquals(messages.size(), 2);
   assertEquals(
       messages.get(0),
       VdcBllMessages.ACTION_TYPE_FAILED_STORAGE_DOMAIN_STATUS_ILLEGAL2.toString());
   assertEquals(messages.get(1), String.format("$status %1$s", StorageDomainStatus.Active));
 }
 @Test
 public void statusNotInList() {
   setStorageDomainStatus(StorageDomainStatus.InActive);
   assertFalse(
       cmd.checkStorageDomainStatus(
           StorageDomainStatus.Locked, StorageDomainStatus.Active, StorageDomainStatus.Unknown));
   assertTrue(commandHasInvalidStatusMessage());
 }
 @Test
 public void canDetachMaintenanceDomain() {
   setStorageDomainStatus(StorageDomainStatus.InActive);
   storagePoolExists();
   masterDomainIsUp();
   isNotLocalData();
   canDetachDomain();
   assertTrue(cmd.canDetachDomain(false, false, false));
 }
 @SuppressWarnings("unchecked")
 @Override
 protected boolean canDoAction() {
   super.canDoAction();
   addCanDoActionMessage(VdcBllMessages.VAR__ACTION__EXTEND);
   boolean returnValue =
       CheckStorageDomain() && checkStorageDomainStatus(StorageDomainStatus.Active);
   if (returnValue
       && (getStorageDomain().getstorage_type() == StorageType.NFS
           || getStorageDomain().getstorage_type() == StorageType.UNKNOWN)) {
     addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
     returnValue = false;
   } else {
     final ConnectAllHostsToLunCommandReturnValue connectResult =
         (ConnectAllHostsToLunCommandReturnValue)
             Backend.getInstance()
                 .runInternalAction(
                     VdcActionType.ConnectAllHostsToLun,
                     new ExtendSANStorageDomainParameters(
                         getParameters().getStorageDomainId(), getParameters().getLunIds()));
     if (!connectResult.getSucceeded()) {
       addCanDoActionMessage(VdcBllMessages.ERROR_CANNOT_EXTEND_CONNECTION_FAILED);
       if (connectResult.getFailedVds() != null) {
         getReturnValue()
             .getCanDoActionMessages()
             .add(String.format("$hostName %1s", connectResult.getFailedVds().getvds_name()));
       }
       if (connectResult.getFailedLun() != null) {
         getReturnValue()
             .getCanDoActionMessages()
             .add(String.format("$lun %1s", connectResult.getFailedLun().getLUN_id()));
       }
       returnValue = false;
     } else {
       // use luns list from connect command
       getParameters().setLunsList((ArrayList<LUNs>) connectResult.getActionReturnValue());
     }
   }
   return returnValue;
 }
 private void storagePoolExists() {
   when(cmd.checkStoragePool()).thenReturn(true);
 }
 @Test
 public void checkStorageDomainNotEqualWithNonActiveStatus() {
   setStorageDomainStatus(StorageDomainStatus.Maintenance);
   assertTrue(cmd.checkStorageDomainStatusNotEqual(StorageDomainStatus.Active));
 }
 @Test
 public void statusNotMatch() {
   setStorageDomainStatus(StorageDomainStatus.InActive);
   assertFalse(cmd.checkStorageDomainStatus(StorageDomainStatus.Active));
   assertTrue(commandHasInvalidStatusMessage());
 }
 private void setStorageDomainStatus(StorageDomainStatus status) {
   storage_domains domain = new storage_domains();
   domain.setstatus(status);
   when(cmd.getStorageDomain()).thenReturn(domain);
 }
 private boolean commandHasInvalidStatusMessage() {
   return cmd.getReturnValue()
       .getCanDoActionMessages()
       .contains(VdcBllMessages.ACTION_TYPE_FAILED_STORAGE_DOMAIN_STATUS_ILLEGAL.toString());
 }