Search in sources :

Example 16 with SlingRepository

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

the class ImportingDistributionPackageProcessorTest method testProcess.

@Test
public void testProcess() throws Exception {
    DistributionPackageImporter importer = mock(DistributionPackageImporter.class);
    SlingRepository repository = mock(SlingRepository.class);
    String agentService = "agentService";
    ResourceResolverFactory resourceResolverFactory = mock(ResourceResolverFactory.class);
    String subServiceName = "ssn";
    SimpleDistributionAgentAuthenticationInfo authInfo = new SimpleDistributionAgentAuthenticationInfo(repository, agentService, resourceResolverFactory, subServiceName);
    String callingUser = "foo";
    String requestId = "123";
    DefaultDistributionLog log = mock(DefaultDistributionLog.class);
    ImportingDistributionPackageProcessor processor = new ImportingDistributionPackageProcessor(importer, authInfo, callingUser, requestId, log);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, "/");
    map.put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, DistributionRequestType.TEST);
    DistributionPackageInfo info = new DistributionPackageInfo("foo", map);
    when(distributionPackage.getInfo()).thenReturn(info);
    processor.process(distributionPackage);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HashMap(java.util.HashMap) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) Test(org.junit.Test)

Example 17 with SlingRepository

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

the class RepositoryDistributionPackageImporterTest method testImportPackageWithRequiredPrivileges.

@Test
public void testImportPackageWithRequiredPrivileges() throws Exception {
    SlingRepository repository = mock(SlingRepository.class);
    String serviceName = "admin";
    Session session = mock(Session.class);
    ValueFactory vf = mock(ValueFactory.class);
    when(session.getValueFactory()).thenReturn(vf);
    AccessControlManager acm = mock(AccessControlManager.class);
    String privilegeName = "jcr:read";
    Privilege privilege = mock(Privilege.class);
    String path = "/var/something";
    Node rootNode = mock(Node.class);
    Node createdNode = mock(Node.class);
    Node jcrContentNode = mock(Node.class);
    when(createdNode.addNode(JcrConstants.JCR_CONTENT, NodeType.NT_RESOURCE)).thenReturn(jcrContentNode);
    when(rootNode.addNode(any(String.class), any(String.class))).thenReturn(createdNode);
    when(session.getNode(path)).thenReturn(rootNode);
    when(acm.hasPrivileges(path, new Privilege[] { privilege })).thenReturn(true);
    when(acm.privilegeFromName(privilegeName)).thenReturn(privilege);
    when(session.getAccessControlManager()).thenReturn(acm);
    when(repository.loginService(serviceName, null)).thenReturn(session);
    RepositoryDistributionPackageImporter repositoryDistributionPackageImporter = new RepositoryDistributionPackageImporter(repository, serviceName, path, privilegeName);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    when(distributionPackage.getId()).thenReturn("someid");
    InputStream stream = mock(InputStream.class);
    when(distributionPackage.createInputStream()).thenReturn(stream);
    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) InputStream(java.io.InputStream) Node(javax.jcr.Node) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ValueFactory(javax.jcr.ValueFactory) Privilege(javax.jcr.security.Privilege) Session(javax.jcr.Session) Test(org.junit.Test)

Example 18 with SlingRepository

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

the class SystemUsersTest method assertSystemUser.

private void assertSystemUser(String name) throws RepositoryException {
    final SlingRepository repo = teleporter.getService(SlingRepository.class);
    final Session s = repo.loginAdministrative(null);
    try {
        final Credentials creds = new SimpleCredentials(name, new char[] {});
        try {
            s.impersonate(creds);
        } catch (RepositoryException rex) {
            fail("Impersonation as " + name + " failed: " + rex.toString());
        }
    } finally {
        s.logout();
    }
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) SimpleCredentials(javax.jcr.SimpleCredentials) RepositoryException(javax.jcr.RepositoryException) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Session(javax.jcr.Session)

Example 19 with SlingRepository

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

the class JcrResourceListenerScalabilityTest method setUp.

@SuppressWarnings("deprecation")
@Before
public void setUp() throws RepositoryException, InvalidSyntaxException {
    ObservationManager observationManager = mock(ObservationManager.class);
    Workspace workspace = mock(Workspace.class);
    when(workspace.getObservationManager()).thenReturn(observationManager);
    Session session = mock(Session.class);
    when(session.getWorkspace()).thenReturn(workspace);
    SlingRepository repository = mock(SlingRepository.class);
    when(repository.loginAdministrative(null)).thenReturn(session);
    final ProviderContext ctx = new SimpleProviderContext();
    this.config = new JcrListenerBaseConfig(ctx.getObservationReporter(), RepositoryUtil.getRepository());
    jcrResourceListener = new JcrResourceListener(this.config, ctx.getObservationReporter().getObserverConfigurations().get(0));
    Event event = mock(MockEvent.class);
    events = mock(EventIterator.class);
    when(events.hasNext()).thenReturn(true);
    when(event.getPath()).thenCallRealMethod();
    when(event.getType()).thenReturn(Event.NODE_ADDED);
    when(events.nextEvent()).thenReturn(event);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) ProviderContext(org.apache.sling.spi.resource.provider.ProviderContext) Event(javax.jcr.observation.Event) ObservationManager(javax.jcr.observation.ObservationManager) EventIterator(javax.jcr.observation.EventIterator) Workspace(javax.jcr.Workspace) Session(javax.jcr.Session) Before(org.junit.Before)

Example 20 with SlingRepository

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

the class OakVirtualInstanceBuilder method useRepositoryOf.

@Override
public VirtualInstanceBuilder useRepositoryOf(VirtualInstanceBuilder other) throws Exception {
    if (!(other instanceof OakVirtualInstanceBuilder)) {
        throw new IllegalArgumentException("other must be of type OakVirtualInstanceBuilder but is: " + other);
    }
    OakVirtualInstanceBuilder otherOakbuilder = (OakVirtualInstanceBuilder) other;
    nodeStore = otherOakbuilder.nodeStore;
    SlingRepository repository = RepositoryTestHelper.newOakRepository(nodeStore);
    factory = MockFactory.mockResourceResolverFactory(repository);
    leaseCollection = otherOakbuilder.leaseCollection;
    hookedToBuilder = other;
    ownRepository = false;
    return this;
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository)

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