use of org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse 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());
}
use of org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse 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);
}
use of org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse 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"));
}
use of org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse 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"));
}
use of org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse 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"));
}
Aggregations