@Test(expectedExceptions = RuntimeException.class) public void testAddFileImage() throws Exception { NfcClient nfcClient = mock(NfcClient.class); doReturn(nfcClient).when(imageStore).getNfcClient(any(HostServiceTicket.class)); when(nfcClient.putFile(anyString(), anyLong())).thenThrow(new RuntimeException("PutFile called")); when(hostClient.getNfcServiceTicket(anyString())).thenReturn(serviceTicketResponse); Image imageFolder = spy(imageStore.createImage(imageId)); imageFolder.addFile("test.ecv", null, 0); }
@Override public long addFile(String fileName, InputStream inputStream, long fileSize) throws IOException, NameTakenException, InternalException { try { String imagePath = getImageFilePath(fileName); logger.info("write to {}", imagePath); try (NfcFileOutputStream outputStream = nfcClient.putFile(imagePath, fileSize)) { for (int i = 0; i < fileSize; i++) { outputStream.write(inputStream.read()); } } return fileSize; } finally { if (inputStream != null) { inputStream.close(); } } }
VsphereImageStoreImage implements Image { @Override public long addFile(String fileName, InputStream inputStream, long fileSize) throws IOException, NameTakenException, InternalException { try { String imagePath = getImageFilePath(fileName); logger.info("write to {}", imagePath); try (NfcFileOutputStream outputStream = nfcClient.putFile(imagePath, fileSize)) { for (int i = 0; i < fileSize; i++) { outputStream.write(inputStream.read()); } } return fileSize; } finally { if (inputStream != null) { inputStream.close(); } } } }
VsphereImageStoreImage implements Image { @Override public long addFile(String fileName, InputStream inputStream, long fileSize) throws IOException, NameTakenException, InternalException { try { String imagePath = getImageFilePath(fileName); logger.info("write to {}", imagePath); try (NfcFileOutputStream outputStream = nfcClient.putFile(imagePath, fileSize)) { for (int i = 0; i < fileSize; i++) { outputStream.write(inputStream.read()); } } return fileSize; } finally { if (inputStream != null) { inputStream.close(); } } } VsphereImageStoreImage(NfcClient nfcClient, String uploadFolder, String imageId); }
VsphereImageStoreImage implements Image { @Override public long addFile(String fileName, InputStream inputStream, long fileSize) throws IOException, NameTakenException, InternalException { try { String imagePath = getImageFilePath(fileName); logger.info("write to {}", imagePath); try (NfcFileOutputStream outputStream = nfcClient.putFile(imagePath, fileSize)) { for (int i = 0; i < fileSize; i++) { outputStream.write(inputStream.read()); } } return fileSize; } finally { if (inputStream != null) { inputStream.close(); } } } 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(); }
VsphereImageStoreImage implements Image { @Override public long addFile(String fileName, InputStream inputStream, long fileSize) throws IOException, NameTakenException, InternalException { try { String imagePath = getImageFilePath(fileName); logger.info("write to {}", imagePath); try (NfcFileOutputStream outputStream = nfcClient.putFile(imagePath, fileSize)) { for (int i = 0; i < fileSize; i++) { outputStream.write(inputStream.read()); } } return fileSize; } finally { if (inputStream != null) { inputStream.close(); } } } 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();  }