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