Search in sources :

Example 26 with SlingRepository

use of org.apache.sling.jcr.api.SlingRepository in project sling by apache.

the class PersistingJcrEventDistributionTriggerTest method testProcessEventWithoutPrivilegesAndNuggetsPath.

@Test
public void testProcessEventWithoutPrivilegesAndNuggetsPath() throws Exception {
    String serviceName = "serviceId";
    Session session = mock(Session.class);
    when(session.hasPermission(eq("var"), eq(Session.ACTION_ADD_NODE))).thenReturn(true);
    when(session.hasPermission(eq("nuggets"), eq(Session.ACTION_ADD_NODE))).thenReturn(true);
    // first time it doesn't exist and should be created
    when(session.nodeExists("/var/nuggets")).thenReturn(false);
    // second time it should exist
    when(session.nodeExists("/var/nuggets")).thenReturn(true);
    Node rootNode = mock(Node.class);
    Node varNode = mock(Node.class);
    Node nuggetsNode = mock(Node.class);
    when(varNode.addNode("nuggets", "sling:Folder")).thenReturn(nuggetsNode);
    when(rootNode.addNode("var", "sling:Folder")).thenReturn(varNode);
    when(session.getRootNode()).thenReturn(rootNode);
    SlingRepository repository = mock(SlingRepository.class);
    Scheduler scheduler = mock(Scheduler.class);
    ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
    when(repository.loginService(serviceName, null)).thenReturn(session);
    String path = "/some/path";
    String nuggetsPath = "/var/nuggets";
    PersistedJcrEventDistributionTrigger persistingJcrEventdistributionTrigger = new PersistedJcrEventDistributionTrigger(repository, scheduler, resolverFactory, path, serviceName, nuggetsPath);
    Event event = mock(Event.class);
    DistributionRequest distributionRequest = persistingJcrEventdistributionTrigger.processEvent(event);
    assertNull(distributionRequest);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionRequest(org.apache.sling.distribution.DistributionRequest) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) Scheduler(org.apache.sling.commons.scheduler.Scheduler) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) Session(javax.jcr.Session) Test(org.junit.Test)

Example 27 with SlingRepository

use of org.apache.sling.jcr.api.SlingRepository in project sling by apache.

the class SimpleDistributionAgentAuthenticationInfoTest method testInfoNotNull.

@Test
public void testInfoNotNull() throws Exception {
    SlingRepository slingRepository = mock(SlingRepository.class);
    String agentService = "dumb";
    ResourceResolverFactory resourceResolverFactory = mock(ResourceResolverFactory.class);
    String subServiceName = "ssn";
    SimpleDistributionAgentAuthenticationInfo authenticationInfo = new SimpleDistributionAgentAuthenticationInfo(slingRepository, agentService, resourceResolverFactory, subServiceName);
    assertNotNull(authenticationInfo.getAgentService());
    assertNotNull(authenticationInfo.getResourceResolverFactory());
    assertNotNull(authenticationInfo.getSlingRepository());
    assertNotNull(authenticationInfo.getSubServiceName());
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) Test(org.junit.Test)

Example 28 with SlingRepository

use of org.apache.sling.jcr.api.SlingRepository in project sling by apache.

the class RepoinitPathTest method pathExists.

@Test
public void pathExists() throws RepositoryException {
    final SlingRepository repo = teleporter.getService(SlingRepository.class);
    final Session s = repo.loginAdministrative(null);
    try {
        assertTrue(s.nodeExists("/repoinit/provisioningModelTest"));
    } finally {
        s.logout();
    }
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) Session(javax.jcr.Session) Test(org.junit.Test)

Example 29 with SlingRepository

use of org.apache.sling.jcr.api.SlingRepository in project sling by apache.

the class RepositoryDistributionPackageImporterTest method testImportPackageWithoutRequiredPrivileges.

@Test(expected = DistributionException.class)
public void testImportPackageWithoutRequiredPrivileges() throws Exception {
    SlingRepository repository = mock(SlingRepository.class);
    String serviceName = "admin";
    Session session = mock(Session.class);
    AccessControlManager acm = mock(AccessControlManager.class);
    String privilegeName = "jcr:read";
    Privilege privilege = mock(Privilege.class);
    when(acm.privilegeFromName(privilegeName)).thenReturn(privilege);
    when(session.getAccessControlManager()).thenReturn(acm);
    when(repository.loginService(serviceName, null)).thenReturn(session);
    String path = "/var/something";
    RepositoryDistributionPackageImporter repositoryDistributionPackageImporter = new RepositoryDistributionPackageImporter(repository, serviceName, path, privilegeName);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    when(distributionPackage.getId()).thenReturn("someid");
    repositoryDistributionPackageImporter.importPackage(resourceResolver, distributionPackage);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) AccessControlManager(javax.jcr.security.AccessControlManager) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Privilege(javax.jcr.security.Privilege) Session(javax.jcr.Session) Test(org.junit.Test)

Example 30 with SlingRepository

use of org.apache.sling.jcr.api.SlingRepository in project sling by apache.

the class RepositoryDistributionPackageImporterTest method testImportPackageWithUnauthorizedServiceUser.

@Test(expected = DistributionException.class)
public void testImportPackageWithUnauthorizedServiceUser() throws Exception {
    SlingRepository repository = mock(SlingRepository.class);
    String serviceName = "admin";
    String path = "/var/something";
    String privilegeName = "jcr:read";
    RepositoryDistributionPackageImporter repositoryDistributionPackageImporter = new RepositoryDistributionPackageImporter(repository, serviceName, path, privilegeName);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    when(distributionPackage.getId()).thenReturn("someid");
    repositoryDistributionPackageImporter.importPackage(resourceResolver, distributionPackage);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Aggregations

SlingRepository (org.apache.sling.jcr.api.SlingRepository)33 Test (org.junit.Test)18 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)14 Session (javax.jcr.Session)12 Event (javax.jcr.observation.Event)10 Scheduler (org.apache.sling.commons.scheduler.Scheduler)9 DistributionRequest (org.apache.sling.distribution.DistributionRequest)9 Credentials (javax.jcr.Credentials)4 Node (javax.jcr.Node)4 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)4 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)4 DistributionPackageImporter (org.apache.sling.distribution.packaging.DistributionPackageImporter)4 Before (org.junit.Before)4 SimpleCredentials (javax.jcr.SimpleCredentials)3 Workspace (javax.jcr.Workspace)3 ObservationManager (javax.jcr.observation.ObservationManager)3 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)3 Repository (javax.jcr.Repository)2 RepositoryException (javax.jcr.RepositoryException)2 AccessControlManager (javax.jcr.security.AccessControlManager)2