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