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;
}
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());
}
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());
}
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);
}
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);
}
Aggregations