Search in sources :

Example 46 with Workspace

use of javax.jcr.Workspace in project sling by apache.

the class NodeTypeLoader method registerNodeType.

public static boolean registerNodeType(Session session, String systemId, Reader reader, boolean reregisterExisting) throws IOException, RepositoryException {
    try {
        Workspace wsp = session.getWorkspace();
        CndImporter.registerNodeTypes(reader, systemId, wsp.getNodeTypeManager(), wsp.getNamespaceRegistry(), session.getValueFactory(), reregisterExisting);
    } catch (RepositoryException re) {
        if (isReRegisterBuiltinNodeType(re)) {
            log.debug("Attempt to re-register built-in node type, RepositoryException ignored", re);
        } else {
            throw re;
        }
    } catch (ParseException e) {
        throw new IOException("Unable to parse CND Input: " + e.getMessage());
    }
    return true;
}
Also used : RepositoryException(javax.jcr.RepositoryException) ParseException(org.apache.jackrabbit.commons.cnd.ParseException) IOException(java.io.IOException) Workspace(javax.jcr.Workspace)

Example 47 with Workspace

use of javax.jcr.Workspace in project sling by apache.

the class DownloadDefaultBinaryValueTest method setUp.

@Before
public void setUp() throws RepositoryException, IOException {
    // create mocks
    request = mock(SlingHttpServletRequest.class);
    response = mock(SlingHttpServletResponse.class);
    resourceResolver = mock(ResourceResolver.class);
    resource = mock(Resource.class);
    rootNode = mock(Node.class);
    session = mock(Session.class);
    workspace = mock(Workspace.class);
    ntManager = mock(NodeTypeManager.class);
    outStream = new ByteArrayOutputStream();
    // stubbing
    when(request.getMethod()).thenReturn(HttpConstants.METHOD_GET);
    when(request.getResourceResolver()).thenReturn(resourceResolver);
    when(resourceResolver.getResource("/")).thenReturn(resource);
    when(resource.adaptTo(Node.class)).thenReturn(rootNode);
    when(rootNode.getSession()).thenReturn(session);
    when(session.getWorkspace()).thenReturn(workspace);
    when(workspace.getNodeTypeManager()).thenReturn(ntManager);
    when(response.getWriter()).thenReturn(new PrintWriter(outStream, true));
    propDefGenerator = new MockPropertyDefGenerator();
}
Also used : SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) MockPropertyDefGenerator(org.apache.sling.jcr.js.nodetypes.mock.MockPropertyDefGenerator) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) Node(javax.jcr.Node) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) PrintWriter(java.io.PrintWriter) Before(org.junit.Before)

Example 48 with Workspace

use of javax.jcr.Workspace in project sling by apache.

the class FileVaultContentSerializerTest method testImportFromStream.

@Test
public void testImportFromStream() throws Exception {
    Packaging packaging = mock(Packaging.class);
    ImportMode importMode = ImportMode.REPLACE;
    AccessControlHandling aclHandling = AccessControlHandling.IGNORE;
    String[] packageRoots = new String[] { "/" };
    String[] nodeFilters = new String[0];
    String[] propertyFilters = new String[0];
    boolean useReferences = false;
    int thershold = 1024;
    FileVaultContentSerializer fileVaultContentSerializer = new FileVaultContentSerializer("vlt", packaging, importMode, aclHandling, packageRoots, nodeFilters, propertyFilters, useReferences, thershold);
    ResourceResolver sessionResolver = mock(ResourceResolver.class);
    Session session = mock(Session.class);
    File file = new File(getClass().getResource("/vlt/dp.vlt").getFile());
    PackageManager pm = mock(PackageManager.class);
    VaultPackage vaultPackage = mock(VaultPackage.class);
    when(pm.open(any(File.class))).thenReturn(vaultPackage);
    when(packaging.getPackageManager()).thenReturn(pm);
    Workspace workspace = mock(Workspace.class);
    ObservationManager observationManager = mock(ObservationManager.class);
    when(workspace.getObservationManager()).thenReturn(observationManager);
    when(session.getWorkspace()).thenReturn(workspace);
    when(sessionResolver.adaptTo(Session.class)).thenReturn(session);
    fileVaultContentSerializer.importFromStream(sessionResolver, new FileInputStream(file));
}
Also used : AccessControlHandling(org.apache.jackrabbit.vault.fs.io.AccessControlHandling) ObservationManager(javax.jcr.observation.ObservationManager) FileInputStream(java.io.FileInputStream) ImportMode(org.apache.jackrabbit.vault.fs.api.ImportMode) PackageManager(org.apache.jackrabbit.vault.packaging.PackageManager) Packaging(org.apache.jackrabbit.vault.packaging.Packaging) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) File(java.io.File) VaultPackage(org.apache.jackrabbit.vault.packaging.VaultPackage) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 49 with Workspace

use of javax.jcr.Workspace in project sling by apache.

the class FileVaultContentSerializerTest method testExportToStream.

@Test
public void testExportToStream() throws Exception {
    Packaging packaging = mock(Packaging.class);
    ImportMode importMode = ImportMode.REPLACE;
    AccessControlHandling aclHandling = AccessControlHandling.IGNORE;
    String[] packageRoots = new String[] { "/etc/packages" };
    String[] nodeFilters = new String[0];
    String[] propertyFilters = new String[0];
    boolean useReferences = false;
    int threshold = 1024;
    FileVaultContentSerializer fileVaultContentSerializer = new FileVaultContentSerializer("vlt", packaging, importMode, aclHandling, packageRoots, nodeFilters, propertyFilters, useReferences, threshold);
    ResourceResolver sessionResolver = mock(ResourceResolver.class);
    Session session = mock(Session.class);
    PackageManager pm = mock(PackageManager.class);
    when(packaging.getPackageManager()).thenReturn(pm);
    OutputStream outputStream = new ByteArrayOutputStream();
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            return null;
        }
    }).when(pm).assemble(same(session), any(ExportOptions.class), same(outputStream));
    Workspace workspace = mock(Workspace.class);
    ObservationManager observationManager = mock(ObservationManager.class);
    when(workspace.getObservationManager()).thenReturn(observationManager);
    when(session.getWorkspace()).thenReturn(workspace);
    when(sessionResolver.adaptTo(Session.class)).thenReturn(session);
    DistributionExportFilter filter = mock(DistributionExportFilter.class);
    DistributionRequest request = mock(DistributionRequest.class);
    when(request.getPaths()).thenReturn(new String[] { "/libs" });
    when(request.getFilters("/libs")).thenReturn(new String[0]);
    DistributionExportOptions exportOptions = new DistributionExportOptions(request, filter);
    fileVaultContentSerializer.exportToStream(sessionResolver, exportOptions, outputStream);
}
Also used : AccessControlHandling(org.apache.jackrabbit.vault.fs.io.AccessControlHandling) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObservationManager(javax.jcr.observation.ObservationManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DistributionExportOptions(org.apache.sling.distribution.serialization.DistributionExportOptions) DistributionRequest(org.apache.sling.distribution.DistributionRequest) ImportMode(org.apache.jackrabbit.vault.fs.api.ImportMode) PackageManager(org.apache.jackrabbit.vault.packaging.PackageManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DistributionExportOptions(org.apache.sling.distribution.serialization.DistributionExportOptions) ExportOptions(org.apache.jackrabbit.vault.packaging.ExportOptions) Packaging(org.apache.jackrabbit.vault.packaging.Packaging) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DistributionExportFilter(org.apache.sling.distribution.serialization.DistributionExportFilter) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 50 with Workspace

use of javax.jcr.Workspace in project sling by apache.

the class PersistingJcrEventDistributionTriggerTest method testProcessEventWithPrivilegesAndNoNuggetsNode.

@Test
public void testProcessEventWithPrivilegesAndNoNuggetsNode() throws Exception {
    String nuggetsPath = "/var/nuggets";
    String serviceName = "serviceId";
    Session session = mock(Session.class);
    // 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);
    Workspace workspace = mock(Workspace.class);
    ObservationManager observationManager = mock(ObservationManager.class);
    when(workspace.getObservationManager()).thenReturn(observationManager);
    when(session.getWorkspace()).thenReturn(workspace);
    when(session.hasPermission(any(String.class), eq(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 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)

Aggregations

Workspace (javax.jcr.Workspace)105 Node (javax.jcr.Node)51 Session (javax.jcr.Session)25 AccessDeniedException (javax.jcr.AccessDeniedException)18 Test (org.junit.Test)18 RepositoryException (javax.jcr.RepositoryException)16 JackrabbitWorkspace (org.apache.jackrabbit.api.JackrabbitWorkspace)16 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)10 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)8 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)7 File (java.io.File)6 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 OutputStream (java.io.OutputStream)6 ObservationManager (javax.jcr.observation.ObservationManager)6 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)6 FileOutputStream (java.io.FileOutputStream)5 NodeIterator (javax.jcr.NodeIterator)4 Version (javax.jcr.version.Version)4