Ejemplo n.º 1
0
  private AddVmCommand<AddVmParameters> createCommand(VM vm) {
    AddVmParameters param = new AddVmParameters(vm);
    AddVmCommand<AddVmParameters> cmd =
        new AddVmCommand<AddVmParameters>(
            param, CommandContext.createContext(param.getSessionId())) {

          @Override
          protected void initUser() {
            // Stub for testing
          }

          @Override
          protected void initTemplateDisks() {
            // Stub for testing
          }

          @Override
          protected void initStoragePoolId() {
            // stub for testing
          }

          @Override
          public VmTemplate getVmTemplate() {
            return createVmTemplate();
          }
        };
    cmd = spy(cmd);
    mockDaos(cmd);
    mockBackend(cmd);
    doReturn(new Cluster()).when(cmd).getCluster();
    generateStorageToDisksMap(cmd);
    initDestSDs(cmd);
    storageDomainValidator = mock(StorageDomainValidator.class);
    doReturn(ValidationResult.VALID).when(storageDomainValidator).isDomainWithinThresholds();
    doReturn(storageDomainValidator)
        .when(cmd)
        .createStorageDomainValidator(any(StorageDomain.class));
    return cmd;
  }
Ejemplo n.º 2
0
  protected AddVmFromTemplateCommand<AddVmParameters> createVmFromTemplateCommand(VM vm) {
    AddVmParameters param = new AddVmParameters();
    param.setVm(vm);
    AddVmFromTemplateCommand<AddVmParameters> concrete =
        new AddVmFromTemplateCommand<AddVmParameters>(
            param, CommandContext.createContext(param.getSessionId())) {
          @Override
          protected void initUser() {
            // Stub for testing
          }

          @Override
          protected void initTemplateDisks() {
            // Stub for testing
          }

          @Override
          protected void initStoragePoolId() {
            // Stub for testing
          }

          @Override
          public VmTemplate getVmTemplate() {
            return createVmTemplate();
          }
        };
    AddVmFromTemplateCommand<AddVmParameters> result = spy(concrete);
    doReturn(true).when(result).checkNumberOfMonitors();
    doReturn(createVmTemplate()).when(result).getVmTemplate();
    doReturn(true).when(result).validateCustomProperties(any(VmStatic.class), anyList());
    mockDaos(result);
    mockBackend(result);
    initCommandMethods(result);
    result.poolPerDc = this.macPoolPerDc;
    result.postConstruct();
    return result;
  }