コード例 #1
0
 /** Mock a good {@link StoragePoolIsoMap}. */
 private void mockStoragePoolIsoMap() {
   StoragePoolIsoMap spim = new StoragePoolIsoMap();
   when(storagePoolIsoMapDao.get(any(StoragePoolIsoMapId.class))).thenReturn(spim);
 }
コード例 #2
0
  @Test
  public void statusSetInMap() {
    Guid storageDomainId = Guid.newGuid();
    Guid poolId = Guid.newGuid();
    AttachStorageDomainToPoolParameters params =
        new AttachStorageDomainToPoolParameters(storageDomainId, poolId);
    AttachStorageDomainToPoolCommand<AttachStorageDomainToPoolParameters> cmd =
        spy(new AttachStorageDomainToPoolCommand<>(params));

    doNothing().when(cmd).attemptToActivateDomain();
    doReturn(Collections.emptyList()).when(cmd).connectHostsInUpToDomainStorageServer();
    doReturn(isoMapDao).when(cmd).getStoragePoolIsoMapDao();
    doReturn(storagePoolDao).when(cmd).getStoragePoolDao();
    doReturn(vdsDao).when(cmd).getVdsDao();
    doReturn(storageDomainDao).when(cmd).getStorageDomainDao();
    doReturn(storageDomainStaticDao).when(cmd).getStorageDomainStaticDao();
    doReturn(vdsBrokerFrontend).when(cmd).getVdsBroker();

    StoragePool pool = new StoragePool();
    pool.setId(poolId);
    pool.setStatus(StoragePoolStatus.Up);
    when(storagePoolDao.get(any(Guid.class))).thenReturn(pool);
    when(isoMapDao.get(any(StoragePoolIsoMapId.class))).thenReturn(map);
    when(storageDomainDao.getForStoragePool(any(Guid.class), any(Guid.class)))
        .thenReturn(new StorageDomain());
    when(storageDomainStaticDao.get(any(Guid.class))).thenReturn(new StorageDomainStatic());
    doReturn(pool.getId()).when(cmd).getStoragePoolIdFromVds();
    doReturn(backendInternal).when(cmd).getBackend();
    VdcReturnValueBase vdcReturnValue = new VdcReturnValueBase();
    vdcReturnValue.setSucceeded(true);
    when(backendInternal.runInternalAction(
            any(VdcActionType.class),
            any(VdcActionParametersBase.class),
            any(CommandContext.class)))
        .thenReturn(vdcReturnValue);
    StorageDomainStatic storageDomain = new StorageDomainStatic();
    storageDomain.setId(Guid.newGuid());
    storageDomain.setStorageDomainType(StorageDomainType.ImportExport);
    mockGetStorageDomainInfoVdsCommand(storageDomain);
    mockAttachStorageDomainVdsCommand();
    when(vdsDao.get(any(Guid.class))).thenReturn(vds);
    doReturn(Collections.emptyList())
        .when(cmd)
        .getEntitiesFromStorageOvfDisk(storageDomainId, pool.getId());
    doReturn(Collections.emptyList()).when(cmd).getAllOVFDisks(storageDomainId, pool.getId());
    doAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(InvocationOnMock invocation) throws Throwable {
                map = (StoragePoolIsoMap) invocation.getArguments()[0];
                return null;
              }
            })
        .when(isoMapDao)
        .save(any(StoragePoolIsoMap.class));

    cmd.setCompensationContext(mock(CompensationContext.class));
    cmd.executeCommand();
    assertNotNull(map);
    assertEquals(StorageDomainStatus.Maintenance, map.getStatus());
  }