Search in sources :

Example 1 with JsonRpcClient

use of org.ovirt.vdsm.jsonrpc.client.JsonRpcClient in project ovirt-engine by oVirt.

the class MarshallingTestCase method testGetIsoListWithImage.

@SuppressWarnings("unchecked")
@Test
public void testGetIsoListWithImage() throws Exception {
    // Given
    String json = "{\"jsonrpc\": \"2.0\", \"id\": \"8d38c4c9-3fdb-4663-993a-dc65488875bb\", \"result\": [\"Fedora-Live-Desktop-x86_64-19-1.iso\"]}";
    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("isolist").withResponseType(Object[].class);
    // Then
    FileStatsReturn isoList = new FileStatsReturn(map);
    assertEquals("Done", isoList.getStatus().message);
    assertEquals(0, isoList.getStatus().code);
    assertEquals(1, isoList.getFileStats().size());
    assertEquals("Fedora-Live-Desktop-x86_64-19-1.iso", isoList.getFileStats().keySet().iterator().next());
}
Also used : JsonRpcResponse(org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse) JsonRpcRequest(org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest) FileStatsReturn(org.ovirt.engine.core.vdsbroker.irsbroker.FileStatsReturn) JsonRpcClient(org.ovirt.vdsm.jsonrpc.client.JsonRpcClient) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 2 with JsonRpcClient

use of org.ovirt.vdsm.jsonrpc.client.JsonRpcClient in project ovirt-engine by oVirt.

the class MarshallingTestCase method testActivateDomain.

@SuppressWarnings("unchecked")
@Test
public void testActivateDomain() throws Exception {
    // Given
    String json = "{\"jsonrpc\": \"2.0\", \"id\": \"5ba8294b-afd7-4810-968d-607703a7bd93\", \"result\": true}";
    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("storageStatus").withResponseType(String.class);
    // Then
    StorageStatusReturn storageStatus = new StorageStatusReturn(map);
    assertEquals("Done", storageStatus.getStatus().message);
    assertEquals(0, storageStatus.getStatus().code);
    assertEquals("true", storageStatus.storageStatus);
}
Also used : JsonRpcResponse(org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse) StorageStatusReturn(org.ovirt.engine.core.vdsbroker.irsbroker.StorageStatusReturn) JsonRpcRequest(org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest) JsonRpcClient(org.ovirt.vdsm.jsonrpc.client.JsonRpcClient) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 3 with JsonRpcClient

use of org.ovirt.vdsm.jsonrpc.client.JsonRpcClient in project ovirt-engine by oVirt.

the class MarshallingTestCase method testAddDomain.

@SuppressWarnings("unchecked")
@Test
public void testAddDomain() throws Exception {
    // Given
    String json = "{\"jsonrpc\": \"2.0\", \"id\": \"4b0838b3-f940-4780-b2f0-fd56c1fbc573\", \"result\": [{\"status\": 0, \"id\": \"00000000-0000-0000-0000-000000000000\"}]}";
    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("statuslist").withResponseType(Object[].class);
    // Then
    ServerConnectionStatusReturn status = new ServerConnectionStatusReturn(map);
    assertEquals("Done", status.getStatus().message);
    assertEquals(0, status.getStatus().code);
    assertEquals(1, status.statusList.length);
    Map<String, Object> result = status.statusList[0];
    assertEquals(0, result.get("status"));
    assertEquals("00000000-0000-0000-0000-000000000000", result.get("id"));
}
Also used : JsonRpcResponse(org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse) JsonRpcRequest(org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest) ServerConnectionStatusReturn(org.ovirt.engine.core.vdsbroker.vdsbroker.ServerConnectionStatusReturn) JsonRpcClient(org.ovirt.vdsm.jsonrpc.client.JsonRpcClient) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 4 with JsonRpcClient

use of org.ovirt.vdsm.jsonrpc.client.JsonRpcClient in project ovirt-engine by oVirt.

the class MarshallingTestCase method testVdsStatsError.

@SuppressWarnings("unchecked")
@Test
public void testVdsStatsError() throws Exception {
    // Given
    String json = "{\"jsonrpc\": \"2.0\", \"id\": \"4d2d6215-3159-4c03-8066-5148cfa09587\", \"error\": {\"message\":" + " \"'NoneType' object has no attribute 'statistics'\", \"code\": -32603}}";
    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);
    // Then
    Map<String, Object> status = (Map<String, Object>) map.get("status");
    assertTrue(!status.isEmpty());
    assertEquals("'NoneType' object has no attribute 'statistics'", status.get("message"));
    assertEquals(-32603, status.get("code"));
}
Also used : JsonRpcResponse(org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse) JsonRpcRequest(org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest) JsonRpcClient(org.ovirt.vdsm.jsonrpc.client.JsonRpcClient) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 5 with JsonRpcClient

use of org.ovirt.vdsm.jsonrpc.client.JsonRpcClient in project ovirt-engine by oVirt.

the class MarshallingTestCase method testGetVMList.

@SuppressWarnings("unchecked")
@Test
public void testGetVMList() throws Exception {
    // Given
    String json = "{\"jsonrpc\": \"2.0\", \"id\": \"e32621e5-753f-45b8-b071-2eb929408efd\", \"result\": [{\"status\": \"Up\", \"vmId\": \"dd4d61c3-5128-4c26-ae71-0dbe5081ea93\"}]}";
    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);
    // Then
    VMListReturn vmList = new VMListReturn(map);
    assertEquals("Done", vmList.status.message);
    assertEquals(0, vmList.status.code);
    assertEquals(1, vmList.vmList.length);
    assertEquals("dd4d61c3-5128-4c26-ae71-0dbe5081ea93", vmList.vmList[0].get("vmId"));
    assertEquals("Up", vmList.vmList[0].get("status"));
}
Also used : JsonRpcResponse(org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse) JsonRpcRequest(org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest) 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)

Aggregations

JsonRpcClient (org.ovirt.vdsm.jsonrpc.client.JsonRpcClient)15 Test (org.junit.Test)14 JsonRpcRequest (org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest)14 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)13 JsonRpcResponse (org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse)13 VMListReturn (org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn)4 HashMap (java.util.HashMap)3 Status (org.ovirt.engine.core.vdsbroker.vdsbroker.Status)3 Map (java.util.Map)2 FileStatsReturn (org.ovirt.engine.core.vdsbroker.irsbroker.FileStatsReturn)2 OneUuidReturn (org.ovirt.engine.core.vdsbroker.irsbroker.OneUuidReturn)1 StoragePoolInfo (org.ovirt.engine.core.vdsbroker.irsbroker.StoragePoolInfo)1 StorageStatusReturn (org.ovirt.engine.core.vdsbroker.irsbroker.StorageStatusReturn)1 IQNListReturn (org.ovirt.engine.core.vdsbroker.vdsbroker.IQNListReturn)1 ServerConnectionStatusReturn (org.ovirt.engine.core.vdsbroker.vdsbroker.ServerConnectionStatusReturn)1 VDSInfoReturn (org.ovirt.engine.core.vdsbroker.vdsbroker.VDSInfoReturn)1 RequestBuilder (org.ovirt.vdsm.jsonrpc.client.RequestBuilder)1 ResponseWorker (org.ovirt.vdsm.jsonrpc.client.internal.ResponseWorker)1 ReactorClient (org.ovirt.vdsm.jsonrpc.client.reactors.ReactorClient)1