VhdProcessor extends AdapterBase implements Processor { @Override public FormatInfo process(String templatePath, ImageFormat format, String templateName) throws InternalErrorException { if (format != null) { s_logger.debug("We currently don't handle conversion from " + format + " to VHD."); return null; } String vhdPath = templatePath + File.separator + templateName + "." + ImageFormat.VHD.getFileExtension(); if (!_storage.exists(vhdPath)) { s_logger.debug("Unable to find the vhd file: " + vhdPath); return null; } File vhdFile = _storage.getFile(vhdPath); FormatInfo info = new FormatInfo(); info.format = ImageFormat.VHD; info.filename = templateName + "." + ImageFormat.VHD.getFileExtension(); info.size = _storage.getSize(vhdPath); try { info.virtualSize = getTemplateVirtualSize(vhdFile); } catch (IOException e) { s_logger.error("Unable to get the virtual size for " + vhdPath); throw new InternalErrorException("unable to get virtual size from vhd file"); } return info; }  @Override FormatInfo process(String templatePath, ImageFormat format, String templateName); @Override long getVirtualSize(File file); @Override boolean configure(String name, Map<String, Object> params);  }
@Test public void testProcess() throws Exception { String templatePath = "/tmp"; String templateName = "template"; long virtualSize = 2000; long actualSize = 1000; Mockito.when(mockStorageLayer.exists(Mockito.anyString())).thenReturn(true); File mockFile = Mockito.mock(File.class); Mockito.when(mockStorageLayer.getFile(Mockito.anyString())).thenReturn(mockFile); Mockito.when(mockStorageLayer.getSize(Mockito.anyString())).thenReturn(actualSize); Mockito.doReturn(virtualSize).when(processor).getTemplateVirtualSize((File) Mockito.any()); Processor.FormatInfo info = processor.process(templatePath, null, templateName); Assert.assertEquals(Storage.ImageFormat.VHD, info.format); Assert.assertEquals(actualSize, info.size); Assert.assertEquals(virtualSize, info.virtualSize); Assert.assertEquals(templateName + ".vhd", info.filename); }