protected JcrSession( JcrSession original, boolean readOnly ) { // Most of the components can be reused from the original session ... this.repository = original.repository; this.context = original.context; this.sessionRegistry = original.sessionRegistry; this.valueFactory = original.valueFactory; this.sessionAttributes = original.sessionAttributes; this.workspace = original.workspace; this.hasCustomAuthorizationProvider = original.hasCustomAuthorizationProvider; // Create a new session cache and root node ... this.cache = repository.repositoryCache().createSession(context, this.workspace.getName(), readOnly); this.rootNode = new JcrRootNode(this, this.cache.getRootKey()); this.jcrNodes.put(this.rootNode.key(), this.rootNode); // Increment the statistics ... this.nanosCreated = System.nanoTime(); repository.statistics().increment(ValueMetric.SESSION_COUNT); acm = new AccessControlManagerImpl(this); this.mimeTypeDetectionEnabled = original.mimeTypeDetectionEnabled; }
@Override protected void doRemove() throws ConstraintViolationException, RepositoryException { String msg = JcrI18n.unableToRemoveRootNode.text(workspaceName()); throw new ConstraintViolationException(msg); } }
@Test public void shouldLogInAsUserWithReadWriteRole() throws Exception { String repoName = REPO_NAME; String jaasPolicyName = "modeshape-jcr"; String[] anonRoleNames = {}; Document config = createRepositoryConfiguration(repoName, jaasPolicyName, anonRoleNames); startRepositoryWith(config, repoName); session = repository.login(new SimpleCredentials("readwrite", "readwrite".toCharArray())); session.getRootNode().getPath(); session.getRootNode().getDefinition(); session.getRootNode().addNode("someNewNode"); }
@Test public void shouldLogInAsAnonymousUsingNoCredentials() throws Exception { String repoName = REPO_NAME; String jaasPolicyName = "modeshape-jcr-non-existant"; String[] anonRoleNames = {ModeShapeRoles.READWRITE}; Document config = createRepositoryConfiguration(repoName, jaasPolicyName, anonRoleNames); startRepositoryWith(config, repoName); session = repository.login(); session.getRootNode().getPath(); session.getRootNode().addNode("someNewNode"); }
@Override public void createWorkspace( String name, String srcWorkspace ) throws AccessDeniedException, UnsupportedRepositoryOperationException, NoSuchWorkspaceException, RepositoryException { validateCrossWorkspaceAction(srcWorkspace); createWorkspace(name); JcrSession newWorkspaceSession = session.spawnSession(name, false); JcrSession srcWorkspaceSession = session.spawnSession(srcWorkspace, true); deepClone(srcWorkspaceSession, srcWorkspaceSession.getRootNode().key(), newWorkspaceSession, newWorkspaceSession.getRootNode().key()); }
@Test public void shouldAllowCreatingNodeUnderUnsavedNode() throws Exception { Node node = session.getRootNode().addNode("testNode"); node.addNode("childNode"); session.save(); }
@Test @FixFor( "MODE-2109 ") public void shouldNotSupportSNS() throws Exception { Node col = session.getRootNode().addNode("smallCol", "test:smallCollection"); col.addNode("child"); col = session.getRootNode().addNode("smallCol", "test:smallCollection"); col.addNode("child"); session.save(); col = session.getRootNode().getNode("smallCol");
@Test @SkipLongRunning public void shouldAllowCreatingManyUnstructuredNodesWithSameNameSiblings() throws Exception { JcrRootNode node = session.getRootNode(); int count = 10000; long start1 = System.nanoTime(); for (int i = 0; i != count; ++i) { node.addNode("childNode"); } long millis = TimeUnit.MILLISECONDS.convert(Math.abs(System.nanoTime() - start1), TimeUnit.NANOSECONDS); printMessage("Time to create " + count + " nodes under root: " + millis + " ms"); long start2 = System.nanoTime(); session.save(); millis = TimeUnit.MILLISECONDS.convert(Math.abs(System.nanoTime() - start2), TimeUnit.NANOSECONDS); printMessage("Time to save " + count + " new nodes: " + millis + " ms"); millis = TimeUnit.MILLISECONDS.convert(Math.abs(System.nanoTime() - start1), TimeUnit.NANOSECONDS); printMessage("Total time to create " + count + " new nodes and save: " + millis + " ms"); NodeIterator iter = node.getNodes("childNode"); assertThat(iter.getSize(), is((long)count)); while (iter.hasNext()) { Node child = iter.nextNode(); assertThat(child.getPrimaryNodeType().getName(), is("nt:unstructured")); } // Now add another node ... start1 = System.nanoTime(); node.addNode("oneMore"); session.save(); millis = TimeUnit.MILLISECONDS.convert(Math.abs(System.nanoTime() - start1), TimeUnit.NANOSECONDS); printMessage("Time to create " + (count + 1) + "th node and save: " + millis + " ms"); }
@Test public void shouldImportIntoSessionTheSystemViewOfTheContentUsedInTckTests() throws Exception { Session session3 = repository.login(); session.nodeTypeManager().registerNodeTypes(resourceStream("tck/tck_test_types.cnd"), true); session.importXML("/", resourceStream("tck/systemViewForTckTests.xml"), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING); assertThat(session.getRootNode().hasNode("testroot/workarea"), is(true)); assertThat(session.getRootNode().getNode("testroot/workarea"), is(notNullValue())); assertNode("/testroot/workarea"); Session session1 = repository.login(); assertThat(session1.getRootNode().hasNode("testroot/workarea"), is(false)); session.save(); assertThat(session1.getRootNode().hasNode("testroot/workarea"), is(true)); assertThat(session1.getRootNode().getNode("testroot/workarea"), is(notNullValue())); assertThat(session1.getNode("/testroot/workarea"), is(notNullValue())); session1.logout(); assertThat(session3.getRootNode().hasNode("testroot/workarea"), is(true)); assertThat(session3.getRootNode().getNode("testroot/workarea"), is(notNullValue())); assertThat(session3.getNode("/testroot/workarea"), is(notNullValue())); session3.logout(); }
@Test public void shouldHaveLoadedContent() throws RepositoryException { Node node = session.getRootNode().getNode("Cars"); assertThat(node, is(notNullValue())); assertThat(node.hasNode("Sports"), is(true)); assertThat(node.hasNode("Utility"), is(true)); assertThat(node.hasNode("Hybrid"), is(true)); // System.out.println(node.getNode("Hybrid").getNodes().nextNode().getPath()); assertThat(node.hasNode("Hybrid/Toyota Prius"), is(true)); assertThat(node.getPrimaryNodeType().getName(), is("nt:unstructured")); }
for (NodeIterator nodeIterator = rootNode.getNodesInternal(); nodeIterator.hasNext();) { AbstractJcrNode child = (AbstractJcrNode)nodeIterator.nextNode(); if (child.key().equals(systemKey)) {
@Test public void shouldNotWreakHavocIfSequencerFails() throws Exception { EditableDocument doc = Schematic.newDocument(); addSequencer(doc, "seq1", TestSequencersHolder.FaultyDuringExecute.class.getName(), "/foo[@bar] => /output"); startRepositoryWithConfiguration(doc); // Now use a session to add a '/foo' node with a 'bar' property ... Node foo = session.getRootNode().addNode("foo"); foo.setProperty("bar", "value of bar"); foo.setProperty("baz", "value of baz"); session.save(); expectSequencingFailure(foo); // Now verify that there is NO output node, since the sequencer should have failed ... assertThat(session.getRootNode().hasNode("output/foo"), is(false)); }
@Override public void afterEach() throws Exception { NodeIterator nodeIterator = session.getRootNode().getNodes(); while (nodeIterator.hasNext()) { Node node = nodeIterator.nextNode(); if (!JcrLexicon.SYSTEM.getString().equals(node.getName())) { node.remove(); } } session.save(); super.afterEach(); }
@Override public void createWorkspace( String name, String srcWorkspace ) throws AccessDeniedException, UnsupportedRepositoryOperationException, NoSuchWorkspaceException, RepositoryException { validateCrossWorkspaceAction(srcWorkspace); createWorkspace(name); JcrSession newWorkspaceSession = session.spawnSession(name, false); JcrSession srcWorkspaceSession = session.spawnSession(srcWorkspace, true); deepClone(srcWorkspaceSession, srcWorkspaceSession.getRootNode().key(), newWorkspaceSession, newWorkspaceSession.getRootNode().key()); }
@Test public void shouldAllowCreatingNodesTwoLevelsBelowRoot() throws Exception { Node node = session.getRootNode().addNode("testNode"); session.save(); node.addNode("childNode"); session.save(); }
@Test public void shouldLogInAsWritableAnonymousUserIfNoProviderAuthenticatesCredentials() throws Exception { String repoName = REPO_NAME; String jaasPolicyName = "modeshape-jcr"; String[] anonRoleNames = {ModeShapeRoles.READWRITE}; Document config = createRepositoryConfiguration(repoName, jaasPolicyName, anonRoleNames); startRepositoryWith(config, repoName); session = repository.login(new SimpleCredentials("readwrite", "wrongpassword".toCharArray())); assertThat(session.isAnonymous(), is(true)); session.getRootNode().getPath(); session.getRootNode().getDefinition(); session.getRootNode().addNode("someNewNode"); }
@Test @FixFor("MODE-2069") public void shouldOnlyTrimLeadingAndTrailingSpacesWhenSearchingViaRegex() throws Exception { JcrRootNode rootNode = session.getRootNode(); Node a = rootNode.addNode(" A "); Node b = rootNode.addNode("B "); Node c = rootNode.addNode(" C"); Node de = rootNode.addNode("D E"); session.save(); try { assertEquals(1, rootNode.getNodes(" A ").getSize()); assertEquals(1, rootNode.getNodes("B ").getSize()); assertEquals(1, rootNode.getNodes(" C").getSize()); assertEquals(2, rootNode.getNodes(" A |B ").getSize()); assertEquals(3, rootNode.getNodes(" A | B | C ").getSize()); assertEquals(1, rootNode.getNodes("D E").getSize()); assertEquals(1, rootNode.getNodes(" D E ").getSize()); assertEquals(2, rootNode.getNodes(" A |D E").getSize()); } finally { a.remove(); b.remove(); c.remove(); de.remove(); session.save(); } }