public static void deserialize(SerializationStreamReader streamReader, QueryReturnValue instance) throws SerializationException { instance.setSucceeded(streamReader.readBoolean()); instance.setExceptionString(streamReader.readString()); instance.setReturnValue(ObjectSerializer.deserialize(streamReader)); }
private void setUpDiskProfilesQueryExpectations(Object failure) { QueryReturnValue queryResult = new QueryReturnValue(); queryResult.setSucceeded(failure == null); List<org.ovirt.engine.core.common.businessentities.profiles.DiskProfile> entities = new ArrayList<>(); if (failure == null) { for (int i = 0; i < NAMES.length; i++) { entities.add(getEntity(i)); } queryResult.setReturnValue(entities); } else { if (failure instanceof String) { queryResult.setExceptionString((String) failure); setUpL10nExpectations((String) failure); } else if (failure instanceof Exception) { when(backend.runQuery(eq(listQueryType), any())).thenThrow((Exception) failure); return; } } when(backend.runQuery(eq(listQueryType), any())).thenReturn(queryResult); }
private void setUpCpuProfilesQueryExpectations(Object failure) { QueryReturnValue queryResult = new QueryReturnValue(); queryResult.setSucceeded(failure == null); List<org.ovirt.engine.core.common.businessentities.profiles.CpuProfile> entities = new ArrayList<>(); if (failure == null) { for (int i = 0; i < NAMES.length; i++) { entities.add(getEntity(i)); } queryResult.setReturnValue(entities); } else { if (failure instanceof String) { queryResult.setExceptionString((String) failure); setUpL10nExpectations((String) failure); } else if (failure instanceof Exception) { when(backend.runQuery(eq(listQueryType), any())).thenThrow((Exception) failure); return; } } when(backend.runQuery(eq(listQueryType), any())).thenReturn(queryResult); }
private void setUpMacPoolsQueryExpectations(Object failure) { QueryReturnValue queryResult = new QueryReturnValue(); queryResult.setSucceeded(failure == null); List<org.ovirt.engine.core.common.businessentities.MacPool> entities = new ArrayList<>(); if (failure == null) { for (int i = 0; i < NAMES.length; i++) { entities.add(getEntity(i)); } queryResult.setReturnValue(entities); } else { if (failure instanceof String) { queryResult.setExceptionString((String) failure); setUpL10nExpectations((String) failure); } else if (failure instanceof Exception) { when(backend.runQuery(eq(listQueryType), any())).thenThrow((Exception) failure); return; } } when(backend.runQuery(eq(listQueryType), any())).thenReturn(queryResult); }
private void setUpBricksQueryExpectations(Object failure) { QueryReturnValue queryResult = new QueryReturnValue(); queryResult.setSucceeded(failure == null); List<GlusterBrickEntity> entities = new ArrayList<>(); if (failure == null) { for (int i = 0; i < NAMES.length; i++) { entities.add(getEntity(i)); } queryResult.setReturnValue(entities); } else { if (failure instanceof String) { queryResult.setExceptionString((String) failure); setUpL10nExpectations((String) failure); } else if (failure instanceof Exception) { when(backend.runQuery(eq(QueryType.GetGlusterVolumeBricks), any())).thenThrow((Exception) failure); return; } } when(backend.runQuery(eq(QueryType.GetGlusterVolumeBricks), any())).thenReturn(queryResult); }
private void setUpVnicProfilesQueryExpectations(Object failure) { QueryReturnValue queryResult = new QueryReturnValue(); queryResult.setSucceeded(failure == null); List<org.ovirt.engine.core.common.businessentities.network.VnicProfile> entities = new ArrayList<>(); if (failure == null) { for (int i = 0; i < NAMES.length; i++) { entities.add(getEntity(i)); } queryResult.setReturnValue(entities); } else { if (failure instanceof String) { queryResult.setExceptionString((String) failure); setUpL10nExpectations((String) failure); } else if (failure instanceof Exception) { when(backend.runQuery(eq(listQueryType), any())).thenThrow((Exception) failure); return; } } when(backend.runQuery(eq(listQueryType), any())).thenReturn(queryResult); }
private void setUpHooksQueryExpectations(Object failure) { QueryReturnValue queryResult = new QueryReturnValue(); queryResult.setSucceeded(failure == null); List<GlusterHookEntity> entities = new ArrayList<>(); if (failure == null) { for (int i = 0; i < NAMES.length; i++) { entities.add(getEntity(i)); } queryResult.setReturnValue(entities); } else { if (failure instanceof String) { queryResult.setExceptionString((String) failure); setUpL10nExpectations((String)failure); } else if (failure instanceof Exception) { when(backend.runQuery(eq(QueryType.GetGlusterHooks), any())).thenThrow((Exception) failure); return; } } when(backend.runQuery(eq(QueryType.GetGlusterHooks), any())).thenReturn(queryResult); } }
private void setUpNetworkAttachmentsQueryExpectations(Object failure) { setUpVerifyHostExpectations(); QueryReturnValue queryResult = new QueryReturnValue(); queryResult.setSucceeded(failure == null); List<NetworkAttachment> entities = new ArrayList<>(); if (failure == null) { for (int i = 0; i < GUIDS.length; i++) { entities.add(getEntity(i)); } queryResult.setReturnValue(entities); } else { if (failure instanceof String) { queryResult.setExceptionString((String) failure); setUpL10nExpectations((String) failure); } else if (failure instanceof Exception) { when(backend.runQuery(eq(listQueryType), any())).thenThrow((Exception) failure); return; } } when(backend.runQuery(eq(listQueryType), any())).thenReturn(queryResult); }
/** * 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>A success converter defined</li> * <li>Check that the converted value is returned to the callback</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_converter() { Object mockModel = new Object(); Object mockResultModel = new Object(); Object mockConvertedModel = new Object(); when(mockAsyncQuery.getModel()).thenReturn(mockModel); when(mockAsyncQuery.getConverter()).thenReturn(mockConverter); QueryParametersBase testParameters = new SearchParameters("*win*", SearchType.VM); //$NON-NLS-1$ frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false); verify(mockService).runQuery(eq(QueryType.Search), eq(testParameters), callback.capture()); QueryReturnValue mockReturnValue = new QueryReturnValue(); mockReturnValue.setReturnValue(mockResultModel); mockReturnValue.setExceptionString("USER_IS_NOT_LOGGED_IN"); //$NON-NLS-1$ when(mockConverter.convert(mockResultModel)).thenReturn(mockConvertedModel); // Return value set to success mockReturnValue.setSucceeded(true); callback.getValue().onSuccess(mockReturnValue); verify(mockAsyncCallback).onSuccess(mockConvertedModel); verifyAsyncQuerySucceeded(); }
/** * 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 NOT, 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_noeventshandler_nocallbackhandler() { QueryParametersBase testParameters = new SearchParameters("*win*", SearchType.VM); //$NON-NLS-1$ frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false); verify(mockService).runQuery(eq(QueryType.Search), eq(testParameters), callback.capture()); QueryReturnValue mockReturnValue = new QueryReturnValue(); mockReturnValue.setExceptionString("Fake failure for test"); //$NON-NLS-1$ // Return value set to failure mockReturnValue.setSucceeded(false); callback.getValue().onSuccess(mockReturnValue); // Make sure the not logged in event is never called, as the failure is not a USER_IS_NOT_LOGGED_IN verify(mockFrontendNotLoggedInEvent, never()).raise(Frontend.class, EventArgs.EMPTY); verifyAsyncQuerySucceeded(); }
protected void setUpQueryExpectations(String query, Object failure) throws Exception { QueryReturnValue queryResult = new QueryReturnValue(); SearchParameters params = new SearchParameters(prefix + query, searchType); queryResult.setSucceeded(failure == null); if (failure == null) { List<Q> entities = new ArrayList<>(); for (int i = 0; i < NAMES.length; i++) { entities.add(getEntity(i)); } queryResult.setReturnValue(entities); when(backend.runQuery(eq(QueryType.Search), eqSearchParams(params))).thenReturn( queryResult); } else { if (failure instanceof String) { queryResult.setExceptionString((String) failure); setUpL10nExpectations((String)failure); when(backend.runQuery(eq(QueryType.Search), eqSearchParams(params))).thenReturn( queryResult); } else if (failure instanceof Exception) { when(backend.runQuery(eq(QueryType.Search), eqSearchParams(params))).thenThrow((Exception) failure); } } enqueueInteraction(() -> verify(backend, atLeastOnce()).runQuery(eq(QueryType.Search), eqSearchParams(params))); }
/** * 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); QueryParametersBase testParameters = new SearchParameters("*win*", SearchType.VM); //$NON-NLS-1$ frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false); verify(mockService).runQuery(eq(QueryType.Search), eq(testParameters), callback.capture()); QueryReturnValue mockReturnValue = new QueryReturnValue(); mockReturnValue.setExceptionString("USER_IS_NOT_LOGGED_IN"); //$NON-NLS-1$ // 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(); }
/** * 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 result, call the same run query again</li> * <li>Return success, the success status is succeeded</li> * <li>No success converter defined</li> * <li>Make sure that the result callback is called only once</li> * <li>Check to make sure the appropriate query start and query complete events are fired</li> * </ol> */ @Test public void testrunQuery_success_succeeded_multiple_same_eventshandler_noconverter() { Object mockModel = new Object(); when(mockAsyncQuery.getModel()).thenReturn(mockModel); QueryParametersBase testParameters = new SearchParameters("*win*", SearchType.VM); //$NON-NLS-1$ frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false); frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false); verify(mockService).runQuery(eq(QueryType.Search), eq(testParameters), callback.capture()); QueryReturnValue mockReturnValue = new QueryReturnValue(); mockReturnValue.setExceptionString("USER_IS_NOT_LOGGED_IN"); //$NON-NLS-1$ // Return value set to success mockReturnValue.setSucceeded(true); callback.getValue().onSuccess(mockReturnValue); verify(mockAsyncCallback).onSuccess(mockReturnValue); verifyAsyncQuerySucceeded(); }
/** * 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() { QueryParametersBase testParameters = new SearchParameters("*win*", SearchType.VM); //$NON-NLS-1$ frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false); verify(mockService).runQuery(eq(QueryType.Search), eq(testParameters), callback.capture()); QueryReturnValue mockReturnValue = new QueryReturnValue(); mockReturnValue.setExceptionString("USER_IS_NOT_LOGGED_IN"); //$NON-NLS-1$ // 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(); }
} else { if (failure instanceof String) { queryResult.setExceptionString((String) failure); setUpL10nExpectations((String) failure); when(backend.runQuery(eq(query),
} else { if (failure instanceof String) { queryResult.setExceptionString((String) failure); setUpL10nExpectations((String) failure); when(backend.runQuery(eq(query),
protected void setUpEntityQueryExpectations(QueryType query, Class<? extends QueryParametersBase> queryClass, String[] queryNames, Object[] queryValues, Object queryReturn, Object failure) { QueryReturnValue queryResult = new QueryReturnValue(); queryResult.setSucceeded(failure == null); if (failure == null) { queryResult.setReturnValue(queryReturn); when(backend.runQuery(eq(query), eqParams(queryClass, addSession(queryNames), addSession(queryValues)))).thenReturn(queryResult); } else { if (failure instanceof String) { queryResult.setExceptionString((String) failure); setUpL10nExpectations((String) failure); when(backend.runQuery(eq(query), eqParams(queryClass, addSession(queryNames), addSession(queryValues)))).thenReturn(queryResult); } else if (failure instanceof Exception) { when(backend.runQuery(eq(query), eqParams(queryClass, addSession(queryNames), addSession(queryValues)))) .thenThrow((Exception) failure); } } if (queryClass != GetPermissionsForObjectParameters.class) { enqueueInteraction(() -> verify(backend, atLeastOnce()).runQuery(eq(query), eqParams(queryClass, addSession(queryNames), addSession(queryValues)))); } }
private QueryReturnValue generateDescriptorResponse() throws Exception { org.ovirt.engine.core.common.businessentities.GraphicsType graphicsType = BackendGraphicsConsoleHelper.asGraphicsType(consoleId); ConsoleOptions consoleOptions = new ConsoleOptions(graphicsType); consoleOptions.setVmId(guid); QueryReturnValue configuredOptionsReturnValue = runQuery( QueryType.ConfigureConsoleOptions, new ConfigureConsoleOptionsParams(consoleOptions, true) ); if (!configuredOptionsReturnValue.getSucceeded()) { QueryReturnValue returnValue = new QueryReturnValue(); returnValue.setSucceeded(false); returnValue.setExceptionString(configuredOptionsReturnValue.getExceptionString()); return returnValue; } return runQuery( QueryType.GetConsoleDescriptorFile, new ConsoleOptionsParams(configuredOptionsReturnValue.getReturnValue()) ); }