Search in sources :

Example 1 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue 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 2 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue 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 3 with QueryReturnValue

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

the class FrontendTest method testrunQuery_success_succeeded_eventshandler_noconverter.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a search query, with *win* as the parameter, searching for VMs</li>
 *   <li>Return success, the success status is succeeded</li>
 *   <li>No success converter defined</li>
 *   <li>Check to make sure the appropriate query start and query complete events are fired</li>
 * </ol>
 */
@Test
public void testrunQuery_success_succeeded_eventshandler_noconverter() {
    Object mockModel = new Object();
    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();
    mockReturnValue.setSucceeded(true);
    callback.getValue().onSuccess(mockReturnValue);
    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 QueryReturnValue

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

the class FrontendTest method testrunQuery_success_not_succeeded_eventshandler_nocallbackhandler.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a search query, with *win* as the parameter, searching for VMs</li>
 *   <li>The callback is NOT 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>Check to make sure the appropriate query start and query complete events are fired</li>
 * </ol>
 */
@Test
public void testrunQuery_success_not_succeeded_eventshandler_nocallbackhandler() {
    // $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);
    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 5 with QueryReturnValue

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

the class GWTRPCCommunicationProviderTest method testTransmitOperationQuery_success.

@Test
public void testTransmitOperationQuery_success() {
    QueryParametersBase testParameters = new QueryParametersBase();
    final QueryReturnValue testResult = new QueryReturnValue();
    final List<VdcOperation<QueryType, QueryParametersBase>> operationList = new ArrayList<>();
    final VdcOperation<QueryType, QueryParametersBase> testOperation = new VdcOperation<>(QueryType.Search, testParameters, new VdcOperationCallback<VdcOperation<QueryType, QueryParametersBase>, QueryReturnValue>() {

        @Override
        public void onSuccess(VdcOperation<QueryType, QueryParametersBase> operation, QueryReturnValue result) {
            // $NON-NLS-1$
            assertEquals("Test results should match", testResult, result);
            // $NON-NLS-1$
            assertEquals("Operations should match", operationList.get(0), operation);
        }

        @Override
        public void onFailure(VdcOperation<QueryType, QueryParametersBase> operation, Throwable caught) {
            // $NON-NLS-1$
            fail("Should not get here");
        }
    });
    operationList.add(testOperation);
    testProvider.transmitOperation(testOperation);
    verify(mockService).runQuery(eq(QueryType.Search), eq(testParameters), queryCallback.capture());
    queryCallback.getValue().onSuccess(testResult);
}
Also used : 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) Test(org.junit.Test)

Aggregations

QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)265 ArrayList (java.util.ArrayList)123 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)97 QueryType (org.ovirt.engine.core.common.queries.QueryType)85 List (java.util.List)74 Guid (org.ovirt.engine.core.compat.Guid)66 Frontend (org.ovirt.engine.ui.frontend.Frontend)64 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)54 VM (org.ovirt.engine.core.common.businessentities.VM)49 QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)47 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)42 HashMap (java.util.HashMap)40 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)39 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)39 Test (org.junit.Test)38 Collection (java.util.Collection)34 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)33 Map (java.util.Map)31 ActionType (org.ovirt.engine.core.common.action.ActionType)31 VDS (org.ovirt.engine.core.common.businessentities.VDS)31