Search in sources :

Example 11 with JsonRpcResponse

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

the class MarshallingTestCase method testVolumeCreate.

@SuppressWarnings("unchecked")
@Test
public void testVolumeCreate() throws Exception {
    // Given
    String json = "{\"jsonrpc\": \"2.0\", \"id\": \"e8ea1fa9-d819-4c41-ae9c-b103a236fb29\", \"result\": {\"uuid\": \"4f84eef5-8f8b-4732-babd-0a860cf0d1b9\"}}";
    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).withIgnoreResponseKey();
    // Then
    OneUuidReturn oneuuid = new OneUuidReturn(map);
    assertEquals("Done", oneuuid.getStatus().message);
    assertEquals(0, oneuuid.getStatus().code);
    assertEquals("4f84eef5-8f8b-4732-babd-0a860cf0d1b9", UUID.fromString(oneuuid.uuid).toString());
}
Also used : JsonRpcResponse(org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse) JsonRpcRequest(org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest) OneUuidReturn(org.ovirt.engine.core.vdsbroker.irsbroker.OneUuidReturn) JsonRpcClient(org.ovirt.vdsm.jsonrpc.client.JsonRpcClient) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 12 with JsonRpcResponse

use of org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse 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 13 with JsonRpcResponse

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

the class MarshallingTestCase method testStoragePoolInfo.

@SuppressWarnings("unchecked")
@Test
public void testStoragePoolInfo() throws Exception {
    // Given
    String json = "{\"jsonrpc\": \"2.0\", \"id\": \"609b5787-ab3a-485b-8ed8-0bc9a27eda27\", \"result\": {\"info\": {\"spm_id\": 1, \"master_uuid\": \"05a0ad59-1259-4353-b40b-34eb80d8590a\"," + " \"name\": \"Default\", \"version\": \"0\", \"domains\": \"05a0ad59-1259-4353-b40b-34eb80d8590a:Active,6ca00a0d-3f1d-4762-b5ff-c58a6a0a0324:Active,4192b643-fae9-4c1c-8b8b-9c9c6cc10523:Active\", " + "\"pool_status\": \"connected\", \"isoprefix\": \"/rhev/data-center/mnt/192.168.1.10:_export_iso/6ca00a0d-3f1d-4762-b5ff-c58a6a0a0324/images/11111111-1111-1111-1111-111111111111\", " + "\"type\": \"NFS\", \"master_ver\": 1, \"lver\": 0}, \"dominfo\": {\"05a0ad59-1259-4353-b40b-34eb80d8590a\": {\"status\": \"Active\", \"diskfree\": \"43887099904\", \"isoprefix\": \"\"," + " \"alerts\": [], \"disktotal\": \"52710866944\", \"version\": 0}, \"6ca00a0d-3f1d-4762-b5ff-c58a6a0a0324\": {\"status\": \"Active\", \"diskfree\": \"43887099904\", \"isoprefix\": " + "\"/rhev/data-center/mnt/192.168.1.10:_export_iso/6ca00a0d-3f1d-4762-b5ff-c58a6a0a0324/images/11111111-1111-1111-1111-111111111111\", \"alerts\": [], \"disktotal\": \"52710866944\", " + "\"version\": 0}, \"4192b643-fae9-4c1c-8b8b-9c9c6cc10523\": {\"status\": \"Active\", \"isoprefix\": \"\", \"alerts\": [], \"version\": -1}}}}";
    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).withIgnoreResponseKey();
    // Then
    StoragePoolInfo storagePoolInfo = new StoragePoolInfo(map);
    assertEquals("Done", storagePoolInfo.getStatus().message);
    assertEquals(0, storagePoolInfo.getStatus().code);
    Set<String> keys = storagePoolInfo.domainsList.keySet();
    assertEquals(3, keys.size());
    assertTrue(keys.contains("05a0ad59-1259-4353-b40b-34eb80d8590a"));
    assertTrue(keys.contains("6ca00a0d-3f1d-4762-b5ff-c58a6a0a0324"));
    assertTrue(keys.contains("4192b643-fae9-4c1c-8b8b-9c9c6cc10523"));
    Map<String, Object> info = storagePoolInfo.storagePoolInfo;
    assertEquals("/rhev/data-center/mnt/192.168.1.10:_export_iso/6ca00a0d-3f1d-4762-b5ff-c58a6a0a0324/images/11111111-1111-1111-1111-111111111111", info.get("isoprefix"));
}
Also used : JsonRpcResponse(org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse) JsonRpcRequest(org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest) StoragePoolInfo(org.ovirt.engine.core.vdsbroker.irsbroker.StoragePoolInfo) JsonRpcClient(org.ovirt.vdsm.jsonrpc.client.JsonRpcClient) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (org.codehaus.jackson.map.ObjectMapper)13 Test (org.junit.Test)13 JsonRpcClient (org.ovirt.vdsm.jsonrpc.client.JsonRpcClient)13 JsonRpcRequest (org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest)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