Search in sources :

Example 1 with QueryParametersBase

use of org.ovirt.engine.core.common.queries.QueryParametersBase in project ovirt-engine by oVirt.

the class FrontendTest method testrunQuery_failure_404_with_pending_3times.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a search query, with *win* as the parameter, searching for VMs</li>
 *   <li>Immediately, before returning a failure result, call the same run query again, total 3 times</li>
 *   <li>The callback is NOT marked to handle failures</li>
 *   <li>Force a failure with an HTTP status code = 404 (file not found)</li>
 *   <li>Check to make sure only one query is called. Due to the second and third being a duplicate</li>
 *   <li>Check to make sure the appropriate query start and query complete events are fired</li>
 * </ol>
 */
@Test
public void testrunQuery_failure_404_with_pending_3times() {
    // $NON-NLS-1$
    QueryParametersBase testParameters = new SearchParameters("*win*", SearchType.VM);
    frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false);
    frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false);
    frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false);
    StatusCodeException exception = new StatusCodeException(HttpServletResponse.SC_NOT_FOUND, // $NON-NLS-1$
    "404 status code");
    // Repeat 4 times, because of retries.
    for (int i = 1; i < RETRY_COUNT; i++) {
        // Verify that only one request is executed, until the first one is complete.
        verify(mockService, times(i)).runQuery(eq(QueryType.Search), eq(testParameters), callback.capture());
        // Call the failure handler.
        callback.getValue().onFailure(exception);
    }
    verify(mockEventsHandler, atLeastOnce()).runQueryFailed(null);
    verifyAsyncQueryFailed();
}
Also used : SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) StatusCodeException(com.google.gwt.user.client.rpc.StatusCodeException) Test(org.junit.Test)

Example 2 with QueryParametersBase

use of org.ovirt.engine.core.common.queries.QueryParametersBase in project ovirt-engine by oVirt.

the class FrontendTest method testrunMultipleQueries_multiple_success_and_failure.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a multiple search query, with multiple requests, with *win* or *lin* as the parameter,
 *   searching for VMs</li>
 *   <li>Return success, the success status is succeeded, with a failure in the result set</li>
 *   <li>Check to make sure the appropriate query start and query complete events are fired</li>
 * </ol>
 */
@Test
public void testrunMultipleQueries_multiple_success_and_failure() {
    // Don't immediately call process until both queries are in the queue.
    fakeScheduler.setThreshold(2);
    ArrayList<QueryType> queryTypeList = new ArrayList<>();
    queryTypeList.add(QueryType.Search);
    queryTypeList.add(QueryType.Search);
    ArrayList<QueryParametersBase> queryParamsList = new ArrayList<>();
    // $NON-NLS-1$
    queryParamsList.add(new SearchParameters("*win*", SearchType.VM));
    // $NON-NLS-1$
    queryParamsList.add(new SearchParameters("*lin*", SearchType.VM));
    // $NON-NLS-1$
    frontend.runMultipleQueries(queryTypeList, queryParamsList, mockMultipleQueryCallback, ASYNC_OPERATION_TARGET);
    verify(mockService).runMultipleQueries(eq(queryTypeList), eq(queryParamsList), callbackMultipleQueries.capture());
    // Call the failure handler.
    List<QueryReturnValue> result = new ArrayList<>();
    result.add(new QueryReturnValue());
    result.get(0).setSucceeded(false);
    result.add(new QueryReturnValue());
    result.get(1).setSucceeded(true);
    ArgumentCaptor<FrontendMultipleQueryAsyncResult> multipleResultCaptor = ArgumentCaptor.forClass(FrontendMultipleQueryAsyncResult.class);
    callbackMultipleQueries.getValue().onSuccess((ArrayList<QueryReturnValue>) result);
    verify(mockMultipleQueryCallback).executed(multipleResultCaptor.capture());
    assertEquals(// $NON-NLS-1$
    "callback result much match", // $NON-NLS-1$
    result, multipleResultCaptor.getValue().getReturnValues());
    verifyAsyncQuerySucceeded();
}
Also used : SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) ArrayList(java.util.ArrayList) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) QueryType(org.ovirt.engine.core.common.queries.QueryType) FrontendMultipleQueryAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult) Test(org.junit.Test)

Example 3 with QueryParametersBase

use of org.ovirt.engine.core.common.queries.QueryParametersBase in project ovirt-engine by oVirt.

the class FrontendTest method testrunQuery_success_not_succeeded_eventshandler_callbackhandler.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a search query, with *win* as the parameter, searching for VMs</li>
 *   <li>The callback is marked to handle failures</li>
 *   <li>The failure is a not logged in failure</li>
 *   <li>Return success, but the success status is !succeeded (business logic failure/not logged in)</li>
 *   <li>Make sure the proper model is passed to the callback failure handler</li>
 *   <li>Check to make sure the appropriate query start and query complete events are fired</li>
 * </ol>
 */
@Test
public void testrunQuery_success_not_succeeded_eventshandler_callbackhandler() {
    Object mockModel = new Object();
    when(mockAsyncQuery.isHandleFailure()).thenReturn(true);
    when(mockAsyncQuery.getModel()).thenReturn(mockModel);
    // $NON-NLS-1$
    QueryParametersBase testParameters = new SearchParameters("*win*", SearchType.VM);
    frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false);
    verify(mockService).runQuery(eq(QueryType.Search), eq(testParameters), callback.capture());
    QueryReturnValue mockReturnValue = new QueryReturnValue();
    // $NON-NLS-1$
    mockReturnValue.setExceptionString("USER_IS_NOT_LOGGED_IN");
    // Return value set to failure
    mockReturnValue.setSucceeded(false);
    callback.getValue().onSuccess(mockReturnValue);
    // Make sure the not logged in event is called
    verify(mockFrontendNotLoggedInEvent).raise(Frontend.class, EventArgs.EMPTY);
    verify(mockAsyncCallback).onSuccess(mockReturnValue);
    verifyAsyncQuerySucceeded();
}
Also used : SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) Test(org.junit.Test)

Example 4 with QueryParametersBase

use of org.ovirt.engine.core.common.queries.QueryParametersBase in project ovirt-engine by oVirt.

the class FrontendTest method testrunQuery_failure_404_with_pending_5times.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a search query, with *win* as the parameter, searching for VMs</li>
 *   <li>Immediately, before returning a failure result, call the same run query again, total 5 times</li>
 *   <li>The callback is NOT marked to handle failures</li>
 *   <li>Force a failure with an HTTP status code = 404 (file not found)</li>
 *   <li>Check to make sure only one query is called. Due to the rest being a duplicate</li>
 *   <li>Check to make sure the appropriate query start and query complete events are fired</li>
 * </ol>
 */
@Test
public void testrunQuery_failure_404_with_pending_5times() {
    // $NON-NLS-1$
    QueryParametersBase testParameters = new SearchParameters("*win*", SearchType.VM);
    frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false);
    frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false);
    frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false);
    frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false);
    frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false);
    StatusCodeException exception = new StatusCodeException(HttpServletResponse.SC_NOT_FOUND, // $NON-NLS-1$
    "404 status code");
    // Repeat 4 times, because of retries.
    for (int i = 1; i < RETRY_COUNT; i++) {
        // Verify that only one request is executed, until the first one is complete.
        verify(mockService, times(i)).runQuery(eq(QueryType.Search), eq(testParameters), callback.capture());
        // Call the failure handler.
        callback.getValue().onFailure(exception);
    }
    verify(mockEventsHandler, atLeastOnce()).runQueryFailed(null);
    verifyAsyncQueryFailed();
}
Also used : SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) StatusCodeException(com.google.gwt.user.client.rpc.StatusCodeException) Test(org.junit.Test)

Example 5 with QueryParametersBase

use of org.ovirt.engine.core.common.queries.QueryParametersBase in project ovirt-engine by oVirt.

the class FrontendTest method testrunMultipleQueries_ignored_failure_multiple.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a multiple search query, with multiple requests, with *win* or *lin* as the parameter, searching for
 *    VMs</li>
 *   <li>Force a special failure with an HTTP status code = 0, this is an ignored failure (escape key pressed)</li>
 *   <li>Check to make sure the appropriate query start and query complete events are fired</li>
 * </ol>
 */
@Test
public void testrunMultipleQueries_ignored_failure_multiple() {
    // Don't immediately call process until both queries are in the queue.
    fakeScheduler.setThreshold(2);
    ArrayList<QueryType> queryTypeList = new ArrayList<>();
    queryTypeList.add(QueryType.Search);
    queryTypeList.add(QueryType.Search);
    ArrayList<QueryParametersBase> queryParamsList = new ArrayList<>();
    // $NON-NLS-1$
    queryParamsList.add(new SearchParameters("*win*", SearchType.VM));
    // $NON-NLS-1$
    queryParamsList.add(new SearchParameters("*lin*", SearchType.VM));
    // $NON-NLS-1$
    frontend.runMultipleQueries(queryTypeList, queryParamsList, mockMultipleQueryCallback, ASYNC_OPERATION_TARGET);
    // $NON-NLS-1$
    StatusCodeException exception = new StatusCodeException(0, "0 status code");
    // Repeat 4 times, because of retries.
    for (int i = 1; i < RETRY_COUNT; i++) {
        // Reset the count so we can re-add both entries again.
        fakeScheduler.resetCount();
        verify(mockService, times(i)).runMultipleQueries(eq(queryTypeList), eq(queryParamsList), callbackMultipleQueries.capture());
        // Call the failure handler.
        callbackMultipleQueries.getValue().onFailure(exception);
    }
    verify(mockFrontendFailureEvent, never()).raise(eq(Frontend.class), any());
    verifyAsyncQueryFailed();
}
Also used : SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) ArrayList(java.util.ArrayList) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) StatusCodeException(com.google.gwt.user.client.rpc.StatusCodeException) QueryType(org.ovirt.engine.core.common.queries.QueryType) Test(org.junit.Test)

Aggregations

QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)89 ArrayList (java.util.ArrayList)41 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)40 QueryType (org.ovirt.engine.core.common.queries.QueryType)37 Test (org.junit.Test)33 StorageServerConnectionQueryParametersBase (org.ovirt.engine.core.common.queries.StorageServerConnectionQueryParametersBase)22 SearchParameters (org.ovirt.engine.core.common.queries.SearchParameters)18 List (java.util.List)15 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)15 Guid (org.ovirt.engine.core.compat.Guid)13 HashMap (java.util.HashMap)11 StatusCodeException (com.google.gwt.user.client.rpc.StatusCodeException)9 HashSet (java.util.HashSet)7 Map (java.util.Map)6 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)6 Frontend (org.ovirt.engine.ui.frontend.Frontend)6 Collection (java.util.Collection)5 Quota (org.ovirt.engine.core.common.businessentities.Quota)5 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)5 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)5