@Test public void shouldHaveJcrSystemNodeUnderRoot() throws Exception { JcrRootNode node = session.getRootNode(); Node system = node.getNode("jcr:system"); assertThat(system, is(notNullValue())); assertThat(system.getPath(), is("/jcr:system")); }
@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")); }
private Node nodeFor( String path ) throws RepositoryException { if (path.equals("/")) { return session().getRootNode(); } return session().getRootNode().getNode(relativePath(path)); }
protected void addMixinRecursively( String path, String... nodeTypes ) throws RepositoryException { Node node = session().getRootNode().getNode(relativePath(path)); addMixin(node, true, nodeTypes); }
protected Node addMixin( String path, String... nodeTypes ) throws RepositoryException { Node node = session().getRootNode().getNode(relativePath(path)); return addMixin(node, false, nodeTypes); }
protected void navigate( String path ) throws RepositoryException { Node node = session().getRootNode().getNode(relativePath(path)); navigate(node, true); }
@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 shouldImportIntoSessionTheDocumentViewOfTheContentUsedInTckTests() throws Exception { Session session3 = repository.login(); session.nodeTypeManager().registerNodeTypes(resourceStream("tck/tck_test_types.cnd"), true); session.importXML("/", resourceStream("tck/documentViewForTckTests.xml"), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING); assertThat(session.getRootNode().hasNode("testroot/workarea"), is(true)); assertThat(session.getRootNode().getNode("testroot/workarea"), is(notNullValue())); assertThat(session.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 shouldImportIntoWorkspaceTheSystemViewOfTheContentUsedInTckTests() throws Exception { Session session3 = repository.login(); session.nodeTypeManager().registerNodeTypes(resourceStream("tck/tck_test_types.cnd"), true); session.getWorkspace().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(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 shouldMoveToNewName() throws Exception { initializeData(); session.move("/a/b/c", "/a/b/d"); session.getRootNode().getNode("a").getNode("b").getNode("d"); try { session.getRootNode().getNode("a").getNode("b").getNode("c"); fail("Node still exists at /a/b/c after move"); } catch (PathNotFoundException e) { // Expected } }
@Test public void shouldImportIntoWorkspaceTheDocumentViewOfTheContentUsedInTckTests() throws Exception { Session session3 = repository.login(); session.nodeTypeManager().registerNodeTypes(resourceStream("tck/tck_test_types.cnd"), true); session.getWorkspace().importXML("/", resourceStream("tck/documentViewForTckTests.xml"), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING); assertThat(session.getRootNode().hasNode("testroot/workarea"), is(true)); assertThat(session.getRootNode().getNode("testroot/workarea"), is(notNullValue())); assertThat(session.getNode("/testroot/workarea"), is(notNullValue())); assertNode("/testroot/workarea"); Session session1 = repository.login(); 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 shouldProvideIdentifierEvenIfNotReferenceable() throws Exception { initializeData(); // The b node was not set up to be referenceable in this test, but does have a mixin type Node node = session.getRootNode().getNode("a").getNode("b").getNode("c"); assertThat(node.getIdentifier(), is(notNullValue())); }
@Test public void shouldProvideIdentifierEvenIfNoMixinTypes() throws Exception { initializeData(); // The b node was not set up to be referenceable in this test, but does have a mixin type Node node = session.getRootNode().getNode("a").getNode("b").getNode("c"); assertThat(node.getIdentifier(), is(notNullValue())); }
@Test public void shouldNotAllowInvalidReferenceValue() throws Exception { NodeType constrainedType = validateTypeDefinition(); JcrPropertyDefinition prop = propertyDefinitionFor(constrainedType, TestLexicon.CONSTRAINED_REFERENCE); Value value = session.getValueFactory().createValue(session.getRootNode().getNode("a")); assertThat(prop.satisfiesConstraints(value, session), is(false)); }
@Test public void shouldNotAllowInvalidReferenceValues() throws Exception { NodeType constrainedType = validateTypeDefinition(); JcrPropertyDefinition prop = propertyDefinitionFor(constrainedType, TestLexicon.CONSTRAINED_REFERENCE); Value value = session.getValueFactory().createValue(session.getRootNode().getNode("a")); assertThat(satisfiesConstraints(prop, new Value[] {value}), is(false)); }
@SuppressWarnings( "deprecation" ) @Test( expected = UnsupportedRepositoryOperationException.class ) public void shouldNotProvideUuidIfNoMixinTypes() throws Exception { initializeData(); // The c node was not set up to be referenceable in this test and has no mixin types Node node = session.getRootNode().getNode("a").getNode("b").getNode("c"); node.getUUID(); }
@SuppressWarnings( "deprecation" ) @Test( expected = UnsupportedRepositoryOperationException.class ) public void shouldNotProvideUuidIfNotReferenceable() throws Exception { initializeData(); // The b node was not set up to be referenceable in this test, but does have a mixin type Node node = session.getRootNode().getNode("a").getNode("b").getNode("c"); node.getUUID(); }
@Test @FixFor("MODE-1573") public void shouldPerformRoundTripOnDocumentViewWithBinaryContent() throws Exception { JcrTools tools = new JcrTools(); File binaryFile = new File("src/test/resources/io/binary.pdf"); assert (binaryFile.exists() && binaryFile.isFile()); File outputFile = File.createTempFile("modeshape_import_export_" + System.currentTimeMillis(), "_test"); outputFile.deleteOnExit(); tools.uploadFile(session, "file", binaryFile); session.save(); session.exportDocumentView("/file", new FileOutputStream(outputFile), false, false); assertTrue(outputFile.length() > 0); session.getRootNode().getNode("file").remove(); session.save(); //sleep so that the binary can be properly cleaned up (this is done via a listener) Thread.sleep(200); session.getWorkspace().importXML("/", new FileInputStream(outputFile), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); assertNotNull(session.getNode("/file")); assertNotNull(session.getNode("/file/jcr:content")); Property data = session.getNode("/file/jcr:content").getProperty("jcr:data"); assertNotNull(data); Binary binary = (Binary)data.getBinary(); assertNotNull(binary); assertEquals(binaryFile.length(), binary.getSize()); }
node = session.getRootNode().getNode("Test3"); printMessage("Checking out " + node.getPath()); vm.checkout(node.getPath());
@Test public void shouldAllowCreatingManyUnstructuredNodesWithNoSameNameSiblings() throws Exception { Stopwatch sw = new Stopwatch(); for (int i = 0; i != 15; ++i) { // Each iteration adds another node under the root and creates the many nodes under that node ... Node node = session.getRootNode().addNode("testNode"); session.save(); int count = 100; if (i > 2) sw.start(); for (int j = 0; j != count; ++j) { node.addNode("childNode" + j); } session.save(); if (i > 2) sw.stop(); // Now add another node ... node.addNode("oneMore"); session.save(); session.getRootNode().getNode("testNode").remove(); session.save(); } printMessage(sw.getDetailedStatistics().toString()); }