VsphereImageStoreImage implements Image { @Override public long addDisk(String fileName, InputStream inputStream) throws IOException, VmdkFormatException, NameTakenException, InternalException { if (!inputStream.markSupported()) { inputStream = new BufferedInputStream(inputStream); } int singleExtentSize = VmdkMetadata.getSingleExtentSize(inputStream); String imagePath = getImageFilePath(fileName); logger.info("write to {}", imagePath); nfcClient.putStreamOptimizedDisk(imagePath, inputStream); return singleExtentSize * 512L; } VsphereImageStoreImage(NfcClient nfcClient, String uploadFolder, String imageId); @Override String getImageId(); @Override String getUploadFolder(); @Override long addFile(String fileName, InputStream inputStream, long fileSize); @Override long addDisk(String fileName, InputStream inputStream); @Override void close();  }
@Test public void testAddDiskImage() throws Exception { NfcClient nfcClient = mock(NfcClient.class); doReturn(nfcClient).when(imageStore).getNfcClient(any(HostServiceTicket.class)); when(nfcClient.putStreamOptimizedDisk( eq(String.format("[%s] tmp_upload_%s/%s.vmdk", imageDatastore, imageId, imageId)), any(InputStream.class))) .thenReturn(1000L); when(hostClient.getNfcServiceTicket(anyString())).thenReturn(serviceTicketResponse); when(hostClient.createImage(imageId, imageDatastore)).thenReturn(new CreateImageResponse(CreateImageResultCode.OK)); Image imageFolder = spy(imageStore.createImage(imageId)); imageFolder.addDisk("disk1.vmdk", inputStream); verify(hostClient).createImage(imageId, imageDatastore); }