private File extractZip( String zipFile, File destination ) throws IOException { File backupDir = null; final int bufferSize = 2048; File currentFile = destination; try (ZipInputStream zipInputStream = new ZipInputStream(resourceStream(zipFile))) { ZipEntry entry = zipInputStream.getNextEntry(); while (entry != null) { currentFile = new File(destination, entry.getName()); if (backupDir == null) { backupDir = currentFile; } if (entry.isDirectory()) { currentFile.mkdirs(); } else { FileOutputStream fos = new FileOutputStream(currentFile); byte[] buffer = new byte[bufferSize]; int numRead = 0; while ((numRead = zipInputStream.read(buffer)) > -1) { fos.write(buffer, 0, numRead); } } entry = zipInputStream.getNextEntry(); } } return backupDir; }
protected void assertFilesInWorkspace(String workspaceName) throws Exception { Session session = repository().login(workspaceName); try { for (int i = 0; i < BINARY_RESOURCES.length; i++) { String fileName = "/file_" + i; Node file = session.getNode(fileName).getNode("jcr:content"); Binary binary = file.getProperty("jcr:data").getBinary(); assertNotNull(binary); byte[] expectedContent = IoUtil.readBytes(resourceStream(BINARY_RESOURCES[i])); byte[] actualContent = IoUtil.readBytes(binary.getStream()); assertArrayEquals("Binary content to valid for " + fileName, expectedContent, actualContent); } } finally { session.logout(); } }
protected void addFilesToWorkspace(String workspaceName) throws Exception { Session session = null; try { session = repository().login(workspaceName); } catch (NoSuchWorkspaceException e) { // Create the workspace ... session().getWorkspace().createWorkspace(workspaceName); // Create a new session ... session = repository().login(workspaceName); } try { for (int i = 0; i < BINARY_RESOURCES.length; i++) { tools.uploadFile(session, "file_" + i, resourceStream(BINARY_RESOURCES[i])); } session.save(); } finally { session.logout(); } }
private void restoreBackup() throws Exception { startRepositoryWithConfiguration(resourceStream("config/backup-repo-config.json")); JcrSession session = repository().login(); Problems problems = session.getWorkspace().getRepositoryManager().restoreRepository(backupDirectory); assertNoProblems(problems); session.logout(); }