Search in sources :

Example 21 with DistributionRequest

use of org.apache.sling.distribution.DistributionRequest in project sling by apache.

the class SimpleDistributionPackageTest method testSimplePackageFromTest.

@Test
public void testSimplePackageFromTest() throws Exception {
    DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.TEST);
    SimpleDistributionPackage createdPackage = new SimpleDistributionPackage(distributionRequest, "VOID");
    SimpleDistributionPackage readPackage = SimpleDistributionPackage.fromStream(new ByteArrayInputStream(("DSTRPCK:TEST|").getBytes()), "VOID");
    assertNotNull(readPackage);
    assertEquals(createdPackage.getType(), readPackage.getType());
    assertEquals(createdPackage.getInfo().getRequestType(), readPackage.getInfo().getRequestType());
    assertEquals(Arrays.toString(createdPackage.getInfo().getPaths()), Arrays.toString(readPackage.getInfo().getPaths()));
    assertEquals(createdPackage.getId(), readPackage.getId());
    assertTrue(IOUtils.contentEquals(createdPackage.createInputStream(), readPackage.createInputStream()));
}
Also used : SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleDistributionPackage(org.apache.sling.distribution.packaging.impl.SimpleDistributionPackage) Test(org.junit.Test)

Example 22 with DistributionRequest

use of org.apache.sling.distribution.DistributionRequest in project sling by apache.

the class SimpleDistributionPackageTest method testCreatedAndReadPackagesEquality.

@Test
public void testCreatedAndReadPackagesEquality() throws Exception {
    DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.DELETE, "/abc");
    SimpleDistributionPackage createdPackage = new SimpleDistributionPackage(request, "VOID");
    SimpleDistributionPackage readPackage = SimpleDistributionPackage.fromStream(new ByteArrayInputStream(("DSTRPCK:DELETE|/abc").getBytes()), "VOID");
    assertNotNull(readPackage);
    assertEquals(createdPackage.getType(), readPackage.getType());
    assertEquals(createdPackage.getInfo().getRequestType(), readPackage.getInfo().getRequestType());
    assertEquals(Arrays.toString(createdPackage.getInfo().getPaths()), Arrays.toString(readPackage.getInfo().getPaths()));
    assertEquals(createdPackage.getId(), readPackage.getId());
    assertTrue(IOUtils.contentEquals(createdPackage.createInputStream(), readPackage.createInputStream()));
}
Also used : SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleDistributionPackage(org.apache.sling.distribution.packaging.impl.SimpleDistributionPackage) Test(org.junit.Test)

Example 23 with DistributionRequest

use of org.apache.sling.distribution.DistributionRequest in project sling by apache.

the class AgentDistributionPackageExporterTest method testTestExport.

@Test
public void testTestExport() throws Exception {
    AgentDistributionPackageExporter distributionPackageExporter = new AgentDistributionPackageExporter(null, mock(DistributionAgent.class), mock(DistributionPackageBuilderProvider.class), null);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    // vargarg doesn't match and causes compiler warning
    String[] args = new String[0];
    DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.TEST, args);
    final List<DistributionPackage> distributionPackages = new ArrayList<DistributionPackage>();
    distributionPackageExporter.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());
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) ArrayList(java.util.ArrayList) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionPackageProcessor(org.apache.sling.distribution.packaging.DistributionPackageProcessor) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ArrayList(java.util.ArrayList) List(java.util.List) DistributionPackageBuilderProvider(org.apache.sling.distribution.packaging.DistributionPackageBuilderProvider) Test(org.junit.Test)

Example 24 with DistributionRequest

use of org.apache.sling.distribution.DistributionRequest in project sling by apache.

the class PrivilegeDistributionRequestAuthorizationStrategyTest method testNoPermissionOnDelete.

@Test(expected = DistributionException.class)
public void testNoPermissionOnDelete() 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(session.nodeExists(path)).thenReturn(true);
    }
    when(distributionRequest.getPaths()).thenReturn(paths);
    when(distributionRequest.getRequestType()).thenReturn(DistributionRequestType.DELETE);
    strategy.checkPermission(resourceResolver, distributionRequest);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) DistributionRequest(org.apache.sling.distribution.DistributionRequest) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Privilege(javax.jcr.security.Privilege) Session(javax.jcr.Session) Test(org.junit.Test)

Example 25 with DistributionRequest

use of org.apache.sling.distribution.DistributionRequest in project sling by apache.

the class PrivilegeDistributionRequestAuthorizationStrategyTest method testCheckPermissionWithSession.

@Test
public void testCheckPermissionWithSession() throws Exception {
    String jcrPrivilege = "foo";
    PrivilegeDistributionRequestAuthorizationStrategy strategy = new PrivilegeDistributionRequestAuthorizationStrategy(jcrPrivilege);
    DistributionRequest distributionRequest = mock(DistributionRequest.class);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    Session session = mock(Session.class);
    when(resourceResolver.adaptTo(Session.class)).thenReturn(session);
    strategy.checkPermission(resourceResolver, distributionRequest);
}
Also used : DistributionRequest(org.apache.sling.distribution.DistributionRequest) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Session(javax.jcr.Session) Test(org.junit.Test)

Aggregations

DistributionRequest (org.apache.sling.distribution.DistributionRequest)52 Test (org.junit.Test)42 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)31 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)22 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)16 SlingRepository (org.apache.sling.jcr.api.SlingRepository)14 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)13 Session (javax.jcr.Session)11 List (java.util.List)10 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)10 DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)10 Event (javax.jcr.observation.Event)9 Scheduler (org.apache.sling.commons.scheduler.Scheduler)9 DistributionPackageProcessor (org.apache.sling.distribution.packaging.DistributionPackageProcessor)9 DistributionResponse (org.apache.sling.distribution.DistributionResponse)7 TreeMap (java.util.TreeMap)6 Resource (org.apache.sling.api.resource.Resource)6 DistributionPackageExporter (org.apache.sling.distribution.packaging.DistributionPackageExporter)6 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)6 FileDistributionPackageBuilder (org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder)6