Search in sources :

Example 21 with SlingRepository

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

the class AbstractSlingRepositoryManager method stop.

/**
     * This method must be called if overwritten by implementations !!
     */
protected final void stop() {
    // ensure the repository is really disposed off
    if (repository != null || isRepositoryServiceRegistered()) {
        log.info("stop: Repository still running, forcing shutdown");
        // make sure we are not concurrently unregistering the repository
        synchronized (repoInitLock) {
            try {
                if (isRepositoryServiceRegistered()) {
                    try {
                        log.debug("stop: Unregistering SlingRepository service, registration=" + repositoryService);
                        unregisterService(repositoryService);
                    } catch (Throwable t) {
                        log.info("stop: Uncaught problem unregistering the repository service", t);
                    }
                    repositoryService = null;
                }
                if (repository != null) {
                    Repository oldRepo = repository;
                    repository = null;
                    // stop loader
                    if (this.loader != null) {
                        this.loader.dispose();
                        this.loader = null;
                    }
                    // destroy repository
                    this.destroy(this.masterSlingRepository);
                    try {
                        disposeRepository(oldRepo);
                    } catch (Throwable t) {
                        log.info("stop: Uncaught problem disposing the repository", t);
                    }
                }
            } catch (Throwable t) {
                log.warn("stop: Unexpected problem stopping repository", t);
            }
        }
    }
    if (repoInitializerTracker != null) {
        repoInitializerTracker.close();
        repoInitializerTracker = null;
    }
    if (whitelistTracker != null) {
        whitelistTracker.close();
        whitelistTracker = null;
    }
    this.repositoryService = null;
    this.repository = null;
    this.defaultWorkspace = null;
    this.bundleContext = null;
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) Repository(javax.jcr.Repository)

Example 22 with SlingRepository

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

the class DefaultContentCreatorTest method setup.

@Before
public void setup() throws Exception {
    final SlingRepository repo = RepositoryProvider.instance().getRepository();
    session = repo.loginAdministrative(null);
    contentCreator = new DefaultContentCreator(null);
    contentCreator.init(ImportOptionsFactory.createImportOptions(true, true, true, false, false), new HashMap<String, ContentReader>(), null, null);
    parentNode = session.getRootNode().addNode(getClass().getSimpleName()).addNode(uniqueId());
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) ContentReader(org.apache.sling.jcr.contentloader.ContentReader) Before(org.junit.Before)

Example 23 with SlingRepository

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

the class CreateNodeTest method setup.

@Before
public void setup() throws Exception {
    final SlingRepository repo = RepositoryProvider.instance().getRepository();
    session = repo.loginAdministrative(null);
    contentCreator = new DefaultContentCreator(null);
    contentCreator.init(ImportOptionsFactory.createImportOptions(true, true, true, false, false), new HashMap<String, ContentReader>(), null, null);
    testRoot = session.getRootNode().addNode(getClass().getSimpleName()).addNode(uniqueId());
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) ContentReader(org.apache.sling.jcr.contentloader.ContentReader) Before(org.junit.Before)

Example 24 with SlingRepository

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

the class PersistingJcrEventDistributionTriggerTest method testProcessEventWithPrivileges.

@Test
public void testProcessEventWithPrivileges() throws Exception {
    String nuggetsPath = "/var/nuggets";
    String serviceName = "serviceId";
    Session session = mock(Session.class);
    when(session.nodeExists("/var/nuggets")).thenReturn(true);
    Workspace workspace = mock(Workspace.class);
    ObservationManager observationManager = mock(ObservationManager.class);
    when(workspace.getObservationManager()).thenReturn(observationManager);
    when(session.getWorkspace()).thenReturn(workspace);
    when(session.hasPermission(nuggetsPath, Session.ACTION_ADD_NODE)).thenReturn(true);
    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";
    PersistedJcrEventDistributionTrigger persistingJcrEventdistributionTrigger = new PersistedJcrEventDistributionTrigger(repository, scheduler, resolverFactory, path, serviceName, nuggetsPath);
    DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
    persistingJcrEventdistributionTrigger.register(handler);
    Node nuggetsNode = mock(Node.class);
    Node eventNode = mock(Node.class);
    when(nuggetsNode.addNode(any(String.class), any(String.class))).thenReturn(eventNode);
    when(session.getNode(nuggetsPath)).thenReturn(nuggetsNode);
    Event event = mock(Event.class);
    when(event.getPath()).thenReturn("/some/path/generating/event");
    DistributionRequest distributionRequest = persistingJcrEventdistributionTrigger.processEvent(event);
    assertNotNull(distributionRequest);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionRequestHandler(org.apache.sling.distribution.trigger.DistributionRequestHandler) 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) ObservationManager(javax.jcr.observation.ObservationManager) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 25 with SlingRepository

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

the class JcrEventDistributionTriggerTest method testProcessEventOnIgnoredPattern.

@Test
public void testProcessEventOnIgnoredPattern() throws Exception {
    SlingRepository repository = mock(SlingRepository.class);
    Scheduler scheduler = mock(Scheduler.class);
    ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
    String path = "/home/users";
    String serviceName = "serviceId";
    String[] ignoredPaths = new String[] { "/home/users/\\w" };
    JcrEventDistributionTrigger jcrEventdistributionTrigger = new JcrEventDistributionTrigger(repository, scheduler, resolverFactory, path, false, serviceName, ignoredPaths);
    Event event = mock(Event.class);
    when(event.getPath()).thenReturn("/home/users/a");
    DistributionRequest distributionRequest = jcrEventdistributionTrigger.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) Event(javax.jcr.observation.Event) 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