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