use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class PrivilegeDistributionRequestAuthorizationStrategyTest method testNoPermissionOnAdd.
@Test(expected = DistributionException.class)
public void testNoPermissionOnAdd() throws Exception {
String jcrPrivilege = "somePermission";
PrivilegeDistributionRequestAuthorizationStrategy strategy = new PrivilegeDistributionRequestAuthorizationStrategy(jcrPrivilege);
DistributionRequest distributionRequest = mock(DistributionRequest.class);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
Session session = mock(Session.class);
AccessControlManager acm = mock(AccessControlManager.class);
Privilege privilege = mock(Privilege.class);
when(acm.privilegeFromName(jcrPrivilege)).thenReturn(privilege);
when(session.getAccessControlManager()).thenReturn(acm);
when(resourceResolver.adaptTo(Session.class)).thenReturn(session);
String[] paths = new String[] { "/foo" };
for (String path : paths) {
when(acm.hasPrivileges(path, new Privilege[] { privilege })).thenReturn(false);
}
when(distributionRequest.getPaths()).thenReturn(paths);
when(distributionRequest.getRequestType()).thenReturn(DistributionRequestType.ADD);
strategy.checkPermission(resourceResolver, distributionRequest);
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class PrivilegeDistributionRequestAuthorizationStrategyTest method testCheckPermissionWithoutSession.
@Test(expected = DistributionException.class)
public void testCheckPermissionWithoutSession() throws Exception {
String jcrPrivilege = "foo";
PrivilegeDistributionRequestAuthorizationStrategy strategy = new PrivilegeDistributionRequestAuthorizationStrategy(jcrPrivilege);
DistributionRequest distributionRequest = mock(DistributionRequest.class);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
strategy.checkPermission(resourceResolver, distributionRequest);
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class LocalDistributionPackageExporterTest method testExport.
@Test
public void testExport() throws Exception {
DistributionPackageBuilder packageBuilder = mock(DistributionPackageBuilder.class);
when(packageBuilder.createPackage(any(ResourceResolver.class), any(DistributionRequest.class))).thenReturn(mock(DistributionPackage.class));
LocalDistributionPackageExporter localdistributionPackageExporter = new LocalDistributionPackageExporter(packageBuilder);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
final List<DistributionPackage> distributionPackages = new ArrayList<DistributionPackage>();
localdistributionPackageExporter.exportPackages(resourceResolver, distributionRequest, new DistributionPackageProcessor() {
@Override
public void process(DistributionPackage distributionPackage) {
distributionPackages.add(distributionPackage);
}
@Override
public List<DistributionResponse> getAllResponses() {
return null;
}
@Override
public int getPackagesCount() {
return 0;
}
@Override
public long getPackagesSize() {
return 0;
}
});
assertNotNull(distributionPackages);
assertEquals(1, distributionPackages.size());
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class AvroContentSerializerTest method testExtractShallow.
@Test
public void testExtractShallow() throws Exception {
AvroContentSerializer avroContentSerializer = new AvroContentSerializer("avro");
DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/libs");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
NavigableMap<String, List<String>> nodeFilters = new TreeMap<String, List<String>>();
NavigableMap<String, List<String>> propertyFilters = new TreeMap<String, List<String>>();
try {
DistributionExportFilter filter = DistributionExportFilter.createFilter(request, nodeFilters, propertyFilters);
avroContentSerializer.exportToStream(resourceResolver, new DistributionExportOptions(request, filter), outputStream);
byte[] bytes = outputStream.toByteArray();
assertNotNull(bytes);
assertTrue(bytes.length > 0);
} finally {
outputStream.close();
}
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class AvroContentSerializerTest method testBuildAndInstallOnMultipleShallowPaths.
@Test
public void testBuildAndInstallOnMultipleShallowPaths() throws Exception {
String type = "avro";
DistributionContentSerializer contentSerializer = new AvroContentSerializer(type);
String tempFilesFolder = "target";
String[] nodeFilters = new String[0];
String[] propertyFilters = new String[0];
DistributionPackageBuilder packageBuilder = new FileDistributionPackageBuilder(type, contentSerializer, tempFilesFolder, null, nodeFilters, propertyFilters);
DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/libs/sub", "/libs/sameLevel");
DistributionPackage distributionPackage = packageBuilder.createPackage(resourceResolver, request);
Resource resource = resourceResolver.getResource("/libs/sub");
resourceResolver.delete(resource);
resource = resourceResolver.getResource("/libs/sameLevel");
resourceResolver.delete(resource);
resourceResolver.commit();
assertTrue(packageBuilder.installPackage(resourceResolver, distributionPackage));
assertNotNull(resourceResolver.getResource("/libs"));
assertNotNull(resourceResolver.getResource("/libs/sub"));
assertNotNull(resourceResolver.getResource("/libs/sameLevel"));
}
Aggregations