@Override
 public BackendInternal getBackend() {
   BackendInternal backend = mock(BackendInternal.class);
   when(backend.runInternalQuery(
           eq(VdcQueryType.GetVmsFromExportDomain), any(VdcQueryParametersBase.class)))
       .thenReturn(createVmQueryResult());
   when(backend.runInternalQuery(
           eq(VdcQueryType.IsVmWithSameNameExist), any(VdcQueryParametersBase.class)))
       .thenReturn(createDuplicateResult());
   return backend;
 }
Example #2
0
  private boolean runQuery(HttpServletResponse response, String sessionID) {
    boolean returnValue = false;

    log.debug("Calling ValidateSession query");

    VdcQueryReturnValue queryReturnValue =
        backend.runInternalQuery(
            VdcQueryType.ValidateSession, new VdcQueryParametersBase(sessionID));

    if (queryReturnValue != null) {
      returnValue = queryReturnValue.getSucceeded();

      if (returnValue) {
        DbUser user = queryReturnValue.getReturnValue();

        // We get the user name only in case the validation succeeded, and the user is an
        // administrator
        if (user.isAdmin()) {
          log.debug("Getting user name");
          printUPNToResponse(response, getUPN(user));
        } else {
          log.error("User '{}' is not authorized to perform operation", user.getLoginName());
          returnValue = false;
        }
      }
    } else {
      log.error("Got NULL from backend.RunQuery");
    }

    return returnValue;
  }
  private void setupMock() throws Exception {
    vdsBrokerFrontend = mock(VDSBrokerFrontend.class);
    clusterUtils = mock(ClusterUtils.class);
    vdsDaoMock = mock(VdsDao.class);
    vdsGroupDaoMock = mock(VdsGroupDao.class);
    dbUtils = mock(GlusterDBUtils.class);
    backendInternal = mock(BackendInternal.class);

    doReturn(vdsBrokerFrontend).when(getQuery()).getResourceManager();
    doReturn(clusterUtils).when(getQuery()).getClusterUtils();
    doReturn(dbUtils).when(getQuery()).getDbUtils();
    doReturn(getVds(VDSStatus.Up)).when(clusterUtils).getUpServer(CLUSTER_ID);
    doReturn(backendInternal).when(getQuery()).getBackend();

    VDSReturnValue returnValue = getVDSReturnValue();
    when(vdsBrokerFrontend.RunVdsCommand(
            eq(VDSCommandType.GlusterServersList), any(VDSParametersBase.class)))
        .thenReturn(returnValue);
    VdcQueryReturnValue vdcReturnValue = getVdcReturnValue();
    when(backendInternal.runInternalQuery(
            eq(VdcQueryType.GetServerSSHKeyFingerprint),
            any(VdcQueryParametersBase.class),
            any(EngineContext.class)))
        .thenReturn(vdcReturnValue);
    doReturn(params.getClusterId()).when(getQueryParameters()).getClusterId();
    doReturn(true).when(getQueryParameters()).isServerKeyFingerprintRequired();

    doReturn(vdsDaoMock).when(clusterUtils).getVdsDao();
    doReturn(vdsGroupDaoMock).when(getQuery()).getVdsGroupDao();
    doReturn(serversList).when(vdsDaoMock).getAllForVdsGroup(CLUSTER_ID);
  }