@Test public void testDeployAssets() throws Exception { final org.uberfire.java.nio.file.Path asset1Path = mock(org.uberfire.java.nio.file.Path.class); final org.uberfire.java.nio.file.Path asset2Path = mock(org.uberfire.java.nio.file.Path.class); when(path.resolve(eq(ASSET1_NAME))).thenReturn(asset1Path); when(path.resolve(eq(ASSET2_NAME))).thenReturn(asset2Path); when(ioService.exists(eq(path))).thenReturn(false); final String message = "deploy-message"; final ArgumentCaptor<byte[]> bytesCaptor1 = ArgumentCaptor.forClass(byte[].class); final ArgumentCaptor<byte[]> bytesCaptor2 = ArgumentCaptor.forClass(byte[].class); tested.deploy(path, new BackendFileSystemManager.Assets(Arrays.asList(asset1, asset2)), message); verify(ioService, times(1)).createDirectories(eq(path)); verify(ioService, times(1)).startBatch(eq(fileSystem)); verify(ioService, times(1)).write(eq(asset1Path), bytesCaptor1.capture(), any(CommentedOption.class)); verify(ioService, times(1)).write(eq(asset2Path), bytesCaptor2.capture(), any(CommentedOption.class)); verify(optionFactory, times(2)).makeCommentedOption(eq(message)); verify(ioService, times(1)).endBatch(); final byte[] bytes1 = bytesCaptor1.getValue(); final String expectedContent1 = new String(bytes1, BackendFileSystemManager.UT8); Assert.assertEquals(ASSET1_CONTENT, expectedContent1); final byte[] bytes2 = bytesCaptor2.getValue(); final String expectedContent2 = new String(bytes2, BackendFileSystemManager.UT8); Assert.assertEquals(ASSET2_CONTENT, expectedContent2); }
public void deploy(final org.uberfire.java.nio.file.Path global, final Assets assets, final String message) { if (!ioService.exists(global)) { ioService.createDirectories(global); } try { ioService.startBatch(global.getFileSystem()); for (final Asset asset : assets.assets) { final org.uberfire.java.nio.file.Path assetPath = global.resolve(asset.fileName); final InputStream resource = asset.stream; final ByteArrayOutputStream os = new ByteArrayOutputStream(); final byte[] chunk = new byte[4096]; int bytesRead; while ((bytesRead = resource.read(chunk)) > 0) { os.write(chunk, 0, bytesRead); } os.flush(); resource.close(); ioService.write(assetPath, os.toByteArray(), optionFactory.makeCommentedOption(message)); } } catch (final Exception e) { LOG.error("Error while deploying assets.", e); } finally { ioService.endBatch(); } }
BackendFileSystemManager { public void deploy(final org.uberfire.java.nio.file.Path global, final Assets assets, final String message) { if (!ioService.exists(global)) { ioService.createDirectories(global); } try { ioService.startBatch(global.getFileSystem()); for (final Asset asset : assets.assets) { final org.uberfire.java.nio.file.Path assetPath = global.resolve(asset.fileName); final InputStream resource = asset.stream; final ByteArrayOutputStream os = new ByteArrayOutputStream(); final byte[] chunk = new byte[4096]; int bytesRead; while ((bytesRead = resource.read(chunk)) > 0) { os.write(chunk, 0, bytesRead); } os.flush(); resource.close(); ioService.write(assetPath, os.toByteArray(), optionFactory.makeCommentedOption(message)); } } catch (final Exception e) { LOG.error("Error while deploying assets.", e); } finally { ioService.endBatch(); } } }
BackendFileSystemManager { public void deploy(final org.uberfire.java.nio.file.Path global, final Assets assets, final String message) { if (!ioService.exists(global)) { ioService.createDirectories(global); } try { ioService.startBatch(global.getFileSystem()); for (final Asset asset : assets.assets) { final org.uberfire.java.nio.file.Path assetPath = global.resolve(asset.fileName); final InputStream resource = asset.stream; final ByteArrayOutputStream os = new ByteArrayOutputStream(); final byte[] chunk = new byte[4096]; int bytesRead; while ((bytesRead = resource.read(chunk)) > 0) { os.write(chunk, 0, bytesRead); } os.flush(); resource.close(); ioService.write(assetPath, os.toByteArray(), optionFactory.makeCommentedOption(message)); } } catch (final Exception e) { LOG.error("Error while deploying assets.", e); } finally { ioService.endBatch(); } } protected  BackendFileSystemManager(); @Inject  BackendFileSystemManager(final @Named("ioStrategy") IOService ioService,
                                    final CommentedOptionFactory optionFactory); }
BackendFileSystemManager { public void deploy(final org.uberfire.java.nio.file.Path global, final Assets assets, final String message) { if (!ioService.exists(global)) { ioService.createDirectories(global); } try { ioService.startBatch(global.getFileSystem()); for (final Asset asset : assets.assets) { final org.uberfire.java.nio.file.Path assetPath = global.resolve(asset.fileName); final InputStream resource = asset.stream; final ByteArrayOutputStream os = new ByteArrayOutputStream(); final byte[] chunk = new byte[4096]; int bytesRead; while ((bytesRead = resource.read(chunk)) > 0) { os.write(chunk, 0, bytesRead); } os.flush(); resource.close(); ioService.write(assetPath, os.toByteArray(), optionFactory.makeCommentedOption(message)); } } catch (final Exception e) { LOG.error("Error while deploying assets.", e); } finally { ioService.endBatch(); } } protected  BackendFileSystemManager(); @Inject  BackendFileSystemManager(final @Named("ioStrategy") IOService ioService,
                                    final CommentedOptionFactory optionFactory); void deploy(final org.uberfire.java.nio.file.Path global,
                       final Assets assets,
                       final String message); String getPathRelativeToApp(final String path); void findAndDeployFiles(final File directory,
                                   final org.uberfire.java.nio.file.Path targetPath); void findAndDeployFiles(final File directory,
                                   final FilenameFilter filter,
                                   final org.uberfire.java.nio.file.Path targetPath); IOService getIoService(); }
BackendFileSystemManager { public void deploy(final org.uberfire.java.nio.file.Path global, final Assets assets, final String message) { if (!ioService.exists(global)) { ioService.createDirectories(global); } try { ioService.startBatch(global.getFileSystem()); for (final Asset asset : assets.assets) { final org.uberfire.java.nio.file.Path assetPath = global.resolve(asset.fileName); final InputStream resource = asset.stream; final ByteArrayOutputStream os = new ByteArrayOutputStream(); final byte[] chunk = new byte[4096]; int bytesRead; while ((bytesRead = resource.read(chunk)) > 0) { os.write(chunk, 0, bytesRead); } os.flush(); resource.close(); ioService.write(assetPath, os.toByteArray(), optionFactory.makeCommentedOption(message)); } } catch (final Exception e) { LOG.error("Error while deploying assets.", e); } finally { ioService.endBatch(); } } protected  BackendFileSystemManager(); @Inject  BackendFileSystemManager(final @Named("ioStrategy") IOService ioService,
                                    final CommentedOptionFactory optionFactory); void deploy(final org.uberfire.java.nio.file.Path global,
                       final Assets assets,
                       final String message); String getPathRelativeToApp(final String path); void findAndDeployFiles(final File directory,
                                   final org.uberfire.java.nio.file.Path targetPath); void findAndDeployFiles(final File directory,
                                   final FilenameFilter filter,
                                   final org.uberfire.java.nio.file.Path targetPath); IOService getIoService(); static final Charset UT8; static final String UT8_ENC; }