public static void deserialize(SerializationStreamReader streamReader, QueryReturnValue instance) throws SerializationException { instance.setSucceeded(streamReader.readBoolean()); instance.setExceptionString(streamReader.readString()); instance.setReturnValue(ObjectSerializer.deserialize(streamReader)); }
void stubGetUserBySessionIdQuery() { QueryReturnValue returnValue = new QueryReturnValue(); returnValue.setSucceeded(true); returnValue.setReturnValue(mockUser); when(mockBackend.runQuery( eq(QueryType.GetUserBySessionId), isA(QueryParametersBase.class) )).thenReturn(returnValue); }
protected void setUpGetSystemVersionExpectations() { QueryReturnValue productRpmQueryResult = new QueryReturnValue(); productRpmQueryResult.setSucceeded(true); productRpmQueryResult.setReturnValue(SYSTEM_VERSION); when(backend.runQuery(eq(QueryType.GetConfigurationValue), getProductRPMVersionParams())).thenReturn(productRpmQueryResult); QueryReturnValue productVersionQueryResult = new QueryReturnValue(); productVersionQueryResult.setSucceeded(true); productVersionQueryResult.setReturnValue(new Version(MAJOR, MINOR, BUILD, REVISION)); when(backend.runQuery(eq(QueryType.GetProductVersion), getProductVersionParams())).thenReturn(productVersionQueryResult); }
void stubGetConfigurationValuePublicQuery() { QueryReturnValue returnValue = new QueryReturnValue(); returnValue.setSucceeded(true); returnValue.setReturnValue("1.2.3"); //$NON-NLS-1$ when(mockBackend.runPublicQuery( eq(QueryType.GetConfigurationValue), argThat(configValueParams(ConfigValues.ProductRPMVersion)) )).thenReturn(returnValue); }
protected <E> void setUpGetEntityExpectations(String query, SearchType type, E entity) { QueryReturnValue queryResult = new QueryReturnValue(); SearchParameters params = new SearchParameters(query, type); when(backend.runQuery(eq(QueryType.Search), eqSearchParams(params))).thenReturn(queryResult); enqueueInteraction( () -> verify(backend, atLeastOnce()).runQuery(eq(QueryType.Search), eqSearchParams(params))); queryResult.setSucceeded(true); List<E> entities = new ArrayList<>(); entities.add(entity); queryResult.setReturnValue(entities); }
/** * Prepares expectations so that any request to get a host by id will return a valid response, including a dummy * host object. */ private void setUpVerifyHostExpectations() { QueryReturnValue result = new QueryReturnValue(); VDS host = mock(VDS.class); result.setSucceeded(true); result.setReturnValue(host); when(backend.runQuery(eq(QueryType.GetVdsByVdsId), any())).thenReturn(result); QueryReturnValue interfacesByVdsIdResult = new QueryReturnValue(); interfacesByVdsIdResult.setSucceeded(true); VdsNetworkInterface hostNic = new VdsNetworkInterface(); hostNic.setId(HOST_NIC_ID); List<VdsNetworkInterface> hostNics = Collections.singletonList(hostNic); interfacesByVdsIdResult.setReturnValue(hostNics); when(backend.runQuery(eq(QueryType.GetVdsInterfacesByVdsId), any())).thenReturn(interfacesByVdsIdResult); } }
protected void setUpGetSystemStatisticsExpectations() { QueryReturnValue queryResult = new QueryReturnValue(); when(backend.runQuery(eq(QueryType.GetSystemStatistics), queryParams())).thenReturn(queryResult); queryResult.setSucceeded(true); queryResult.setReturnValue(setUpStats()); }
@Test public void testRunPublicQuery_GetConfigurationValue() { String sessionId = "sessionId"; //$NON-NLS-1$ QueryType queryType = QueryType.GetConfigurationValue; QueryReturnValue returnIntValue = new QueryReturnValue(); returnIntValue.setSucceeded(true); returnIntValue.setReturnValue(Integer.valueOf(255)); when(mockBackend.runPublicQuery(eq(QueryType.GetConfigurationValue), eq(mockConfigQueryParams))).thenReturn(returnIntValue); Object result = testServlet.runPublicQuery(queryType, mockConfigQueryParams, sessionId); assertThat(result, is(instanceOf(Integer.class))); verify(mockConfigQueryParams).setSessionId(sessionId); verify(mockConfigQueryParams).setFiltered(testServlet.filterQueries()); verify(mockBackend).runPublicQuery(queryType, mockConfigQueryParams); }
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 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); }
protected void setUpGetUserBySessionExpectations() { QueryReturnValue returnValue = new QueryReturnValue(); returnValue.setSucceeded(true); DbUser dbUser = new DbUser(); dbUser.setId(Guid.Empty); returnValue.setReturnValue(dbUser); when(backend.runQuery(eq(QueryType.GetUserBySessionId), eqParams(QueryParametersBase.class, new String[0], new Object[0]))).thenReturn(returnValue); QueryReturnValue productVersionQueryResult = new QueryReturnValue(); productVersionQueryResult.setSucceeded(true); productVersionQueryResult.setReturnValue(new Version(MAJOR, MINOR, BUILD, REVISION)); when(backend.runQuery(eq(QueryType.GetProductVersion), getProductVersionParams())).thenReturn(productVersionQueryResult); }
private void setAsyncTaskStatusExpectations(ArrayList<Guid> asyncTasks, ArrayList<AsyncTaskStatus> asyncStatuses, QueryReturnValue monitorResult, ActionReturnValue result) { if (asyncTasks != null) { result.setVdsmTaskIdList(asyncTasks); monitorResult.setReturnValue(asyncStatuses); when(backend.runQuery(eq(QueryType.GetTasksStatusesByTasksIDs), eqParams(GetTasksStatusesByTasksIDsParameters.class, addSession(), addSession(new Object[] {})))).thenReturn(monitorResult); } }
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 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); }
private void setJobStatusExpectations(Guid jobId, JobExecutionStatus jobStatus, QueryReturnValue monitorResult, ActionReturnValue result) { result.setJobId(jobId); if (jobId != null) { Job jobMock = mock(org.ovirt.engine.core.common.job.Job.class); when(jobMock.getStatus()).thenReturn(jobStatus); monitorResult.setReturnValue(jobMock); when(backend.runQuery(eq(QueryType.GetJobByJobId), eqParams(IdQueryParameters.class, addSession("Id"), addSession(jobId)))).thenReturn(monitorResult); enqueueInteraction(() -> verify(backend, atLeastOnce()).runQuery(eq(QueryType.GetJobByJobId), eqParams(IdQueryParameters.class, addSession("Id"), addSession(jobId)))); } }
protected <E> void setUpGetEntityExpectations(QueryType query, Class<? extends QueryParametersBase> clz, String[] names, Object[] values, E entity, boolean onceOnly) { QueryReturnValue queryResult = new QueryReturnValue(); OngoingStubbing<QueryReturnValue> stubbing = when(backend.runQuery(eq(query), eqParams(clz, addSession(names), addSession(values)))) .thenReturn(queryResult); if (onceOnly) { stubbing.thenReturn(null); } enqueueInteraction(() -> verify(backend, atLeastOnce()).runQuery(eq(query), eqParams(clz, addSession(names), addSession(values)))); queryResult.setSucceeded(true); queryResult.setReturnValue(entity); }
@Override @Test public void testList() throws Exception { UriInfo uriInfo = setUpUriExpectations(null); String[] paramNames = new String[] { "ServerConnectionId" }; Object[] paramValues = new Object[] { GUIDS[0].toString() }; QueryReturnValue queryResult = new QueryReturnValue(); when(backend.runQuery(eq(QueryType.GetStorageServerConnectionById), eqParams(StorageServerConnectionQueryParametersBase.class, addSession(paramNames), addSession(paramValues)))) .thenReturn(queryResult); queryResult.setSucceeded(true); queryResult.setReturnValue(setUpStorageServerConnection()); setUpQueryExpectations(""); collection.setUriInfo(uriInfo); verifyCollection(getCollection()); }