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