public void testDeserializeWithoutBlockDeviceMappingOrMetadata() throws Exception { ImageContainer container = gson.fromJson(stringFromResource("image_details_without_metadata.json"), ImageContainer.class); assertNotNull(container.image.getMetadata()); assertEquals(container.image.getMetadata().size(), 0); assertNotNull(container.image.getBlockDeviceMapping()); assertEquals(0, container.image.getBlockDeviceMapping().size()); }
public void testDeserializeWithBlockDeviceMappingAndMetadata() throws Exception { ImageContainer container = gson.fromJson(stringFromResource("image_details_with_block_device_mapping.json"), ImageContainer.class); // Note that the block device mapping keys are removed from the metadata by the adapter. assertNotNull(container.image.getMetadata()); assertEquals(container.image.getMetadata().size(), 2); assertEquals("Gold", container.image.getMetadata().get("ImageType")); assertEquals("1.5", container.image.getMetadata().get("ImageVersion")); assertNotNull(container.image.getBlockDeviceMapping()); assertEquals(container.image.getBlockDeviceMapping().size(), 1); assertEquals(Integer.valueOf(2), getOnlyElement(container.image.getBlockDeviceMapping()).getBootIndex()); assertEquals("snapshot", getOnlyElement(container.image.getBlockDeviceMapping()).getSourceType()); }
public void testDeserializeWithoutBlockDeviceMapping() throws Exception { ImageContainer container = gson.fromJson(stringFromResource("image_details.json"), ImageContainer.class); assertNotNull(container.image.getMetadata()); assertEquals(container.image.getMetadata().size(), 2); assertEquals("Gold", container.image.getMetadata().get("ImageType")); assertEquals("1.5", container.image.getMetadata().get("ImageVersion")); assertNotNull(container.image.getBlockDeviceMapping()); assertEquals(0, container.image.getBlockDeviceMapping().size()); }
public void testImageWithBlockDeviceMapping() throws Exception { MockWebServer server = mockOpenStackServer(); server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/image_list_with_block_device_mapping.json")))); try { NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova"); ImageApi imageApi = novaApi.getImageApiForZone("RegionOne"); FluentIterable<? extends Image> images = imageApi.listInDetail().concat(); Image img = images.get(0); assertNotNull(img.getMetadata()); assertEquals(10, img.getMetadata().size()); assertNotNull(img.getBlockDeviceMapping()); assertEquals(1, img.getBlockDeviceMapping().size()); BlockDeviceMapping blockDeviceMapping = img.getBlockDeviceMapping().get(0); assertEquals("snapshot", blockDeviceMapping.getSourceType()); assertEquals(Integer.valueOf(2), blockDeviceMapping.getBootIndex()); } finally { server.shutdown(); } } }