use of org.apache.jackrabbit.vault.packaging.PackageManager in project sling by apache.
the class FileVaultContentSerializerTest method testImportFromStream.
@Test
public void testImportFromStream() throws Exception {
Packaging packaging = mock(Packaging.class);
ImportMode importMode = ImportMode.REPLACE;
AccessControlHandling aclHandling = AccessControlHandling.IGNORE;
String[] packageRoots = new String[] { "/" };
String[] nodeFilters = new String[0];
String[] propertyFilters = new String[0];
boolean useReferences = false;
int thershold = 1024;
FileVaultContentSerializer fileVaultContentSerializer = new FileVaultContentSerializer("vlt", packaging, importMode, aclHandling, packageRoots, nodeFilters, propertyFilters, useReferences, thershold);
ResourceResolver sessionResolver = mock(ResourceResolver.class);
Session session = mock(Session.class);
File file = new File(getClass().getResource("/vlt/dp.vlt").getFile());
PackageManager pm = mock(PackageManager.class);
VaultPackage vaultPackage = mock(VaultPackage.class);
when(pm.open(any(File.class))).thenReturn(vaultPackage);
when(packaging.getPackageManager()).thenReturn(pm);
Workspace workspace = mock(Workspace.class);
ObservationManager observationManager = mock(ObservationManager.class);
when(workspace.getObservationManager()).thenReturn(observationManager);
when(session.getWorkspace()).thenReturn(workspace);
when(sessionResolver.adaptTo(Session.class)).thenReturn(session);
fileVaultContentSerializer.importFromStream(sessionResolver, new FileInputStream(file));
}
use of org.apache.jackrabbit.vault.packaging.PackageManager in project sling by apache.
the class FileVaultContentSerializerTest method testExportToStream.
@Test
public void testExportToStream() throws Exception {
Packaging packaging = mock(Packaging.class);
ImportMode importMode = ImportMode.REPLACE;
AccessControlHandling aclHandling = AccessControlHandling.IGNORE;
String[] packageRoots = new String[] { "/etc/packages" };
String[] nodeFilters = new String[0];
String[] propertyFilters = new String[0];
boolean useReferences = false;
int threshold = 1024;
FileVaultContentSerializer fileVaultContentSerializer = new FileVaultContentSerializer("vlt", packaging, importMode, aclHandling, packageRoots, nodeFilters, propertyFilters, useReferences, threshold);
ResourceResolver sessionResolver = mock(ResourceResolver.class);
Session session = mock(Session.class);
PackageManager pm = mock(PackageManager.class);
when(packaging.getPackageManager()).thenReturn(pm);
OutputStream outputStream = new ByteArrayOutputStream();
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
return null;
}
}).when(pm).assemble(same(session), any(ExportOptions.class), same(outputStream));
Workspace workspace = mock(Workspace.class);
ObservationManager observationManager = mock(ObservationManager.class);
when(workspace.getObservationManager()).thenReturn(observationManager);
when(session.getWorkspace()).thenReturn(workspace);
when(sessionResolver.adaptTo(Session.class)).thenReturn(session);
DistributionExportFilter filter = mock(DistributionExportFilter.class);
DistributionRequest request = mock(DistributionRequest.class);
when(request.getPaths()).thenReturn(new String[] { "/libs" });
when(request.getFilters("/libs")).thenReturn(new String[0]);
DistributionExportOptions exportOptions = new DistributionExportOptions(request, filter);
fileVaultContentSerializer.exportToStream(sessionResolver, exportOptions, outputStream);
}
use of org.apache.jackrabbit.vault.packaging.PackageManager in project sling by apache.
the class FileVaultContentSerializer method importFromStream.
@Override
public void importFromStream(ResourceResolver resourceResolver, InputStream inputStream) throws DistributionException {
Session session = null;
OutputStream outputStream = null;
File file = null;
boolean isTmp = true;
try {
session = getSession(resourceResolver);
ImportOptions importOptions = VltUtils.getImportOptions(aclHandling, importMode, autosaveThreshold);
if (inputStream instanceof FileDistributionPackage.PackageInputStream) {
file = ((FileDistributionPackage.PackageInputStream) inputStream).getFile();
isTmp = false;
} else {
file = File.createTempFile("distrpck-tmp-" + System.nanoTime(), "." + TYPE);
}
outputStream = new BufferedOutputStream(new FileOutputStream(file));
IOUtils.copy(inputStream, outputStream);
IOUtils.closeQuietly(outputStream);
PackageManager packageManager = packaging.getPackageManager();
VaultPackage vaultPackage = packageManager.open(file);
vaultPackage.extract(session, importOptions);
vaultPackage.close();
} catch (Exception e) {
throw new DistributionException(e);
} finally {
IOUtils.closeQuietly(outputStream);
if (isTmp) {
FileUtils.deleteQuietly(file);
}
ungetSession(session);
}
}
Aggregations