Search in sources :

Example 6 with VMListReturn

use of org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn in project ovirt-engine by oVirt.

the class MarshallingTestCase method testShortList.

@SuppressWarnings("unchecked")
@Test
public void testShortList() throws Exception {
    // Given
    String json = "{\"jsonrpc\": \"2.0\", \"id\": \"ae80f5c4-0f63-4c2e-aed6-5372f07a14c1\", \"result\": [\"e4a0fc02-c5ad-4b35-b2d0-5a4b6557c06b\"]}";
    ObjectMapper mapper = new ObjectMapper();
    JsonRpcResponse response = JsonRpcResponse.fromJsonNode(mapper.readTree(json));
    Future<JsonRpcResponse> future = mock(Future.class);
    when(future.get()).thenReturn(response);
    JsonRpcClient client = mock(JsonRpcClient.class);
    JsonRpcRequest request = mock(JsonRpcRequest.class);
    when(client.call(request)).thenReturn(future);
    // When
    Map<String, Object> map = new FutureMap(client, request).withResponseKey("vmList").withResponseType(Object[].class).withSubTypeClazz(HashMap.class).withSubtypeKey("vmId");
    // Then
    VMListReturn vmList = new VMListReturn(map);
    Status status = vmList.status;
    assertEquals("Done", status.message);
    assertEquals(0, status.code);
    assertEquals(1, vmList.vmList.length);
}
Also used : JsonRpcResponse(org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse) Status(org.ovirt.engine.core.vdsbroker.vdsbroker.Status) JsonRpcRequest(org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest) HashMap(java.util.HashMap) VMListReturn(org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn) JsonRpcClient(org.ovirt.vdsm.jsonrpc.client.JsonRpcClient) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 7 with VMListReturn

use of org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn in project ovirt-engine by oVirt.

the class JsonRpcVdsServer method getExternalVmList.

@Override
public VMListReturn getExternalVmList(String uri, String username, String password, List<String> vmsNames) {
    RequestBuilder requestBuilder = new RequestBuilder("Host.getExternalVMs").withParameter("uri", uri).withParameter("username", username).withParameter("password", password).withOptionalParameterAsList("vm_names", vmsNames);
    JsonRpcRequest request = requestBuilder.build();
    Map<String, Object> response = new FutureMap(this.client, request).withResponseKey("vmList").withResponseType(Object[].class);
    return new VMListReturn(response);
}
Also used : RequestBuilder(org.ovirt.vdsm.jsonrpc.client.RequestBuilder) JsonRpcRequest(org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest) VMListReturn(org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn)

Aggregations

VMListReturn (org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn)7 JsonRpcRequest (org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest)7 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 Test (org.junit.Test)4 JsonRpcClient (org.ovirt.vdsm.jsonrpc.client.JsonRpcClient)4 JsonRpcResponse (org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse)4 RequestBuilder (org.ovirt.vdsm.jsonrpc.client.RequestBuilder)3 Status (org.ovirt.engine.core.vdsbroker.vdsbroker.Status)2 HashMap (java.util.HashMap)1