/** * {@inheritDoc} */ @Override protected void initNodeTypes(NodeTypeManager ntm) throws RepositoryException { JcrNodeTypeManager ntmi = (JcrNodeTypeManager) ntm; try { InputStream is = null; try { is = this.getClass().getResourceAsStream(DEFAULT_NODETYPE_FILE); ntmi.registerNodeTypes(is, true); } finally { if (is != null) { is.close(); } } } catch (IOException e) { throw new RepositoryException("Failed to init NodeTypes: " + e.getMessage(), e); } }
@Override public NodeTypeIterator registerNodeTypes( File file, boolean allowUpdate ) throws IOException, RepositoryException { String content = IoUtil.read(file); if (content.startsWith("<?xml")) { // This is Jackrabbit XML format ... return registerNodeTypes(importFromXml(new InputSource(new FileInputStream(file))), allowUpdate); } // Assume this is CND format ... CndImporter importer = new CndImporter(context()); Problems problems = new SimpleProblems(); importer.importFrom(content, problems, file.getAbsolutePath()); // Check for (and report) any problems ... if (problems.hasProblems()) { // There are errors and/or warnings, so report them ... String summary = messageFrom(problems); if (problems.hasErrors()) { String msg = JcrI18n.errorsParsingNodeTypeDefinitions.text(file.getAbsolutePath(), summary); throw new RepositoryException(msg); } // Otherwise, there are warnings, so log them ... I18n msg = JcrI18n.warningsParsingNodeTypeDefinitions; Logger.getLogger(getClass()).warn(msg, file.getAbsolutePath(), summary); } // Register the node types ... return registerNodeTypes(importer.getNodeTypeDefinitions(), allowUpdate); }
@Override public NodeTypeIterator registerNodeTypes( File file, boolean allowUpdate ) throws IOException, RepositoryException { String content = IoUtil.read(file); if (content.startsWith("<?xml")) { // This is Jackrabbit XML format ... return registerNodeTypes(importFromXml(new InputSource(new FileInputStream(file))), allowUpdate); } // Assume this is CND format ... CndImporter importer = new CndImporter(context()); Problems problems = new SimpleProblems(); importer.importFrom(content, problems, file.getAbsolutePath()); // Check for (and report) any problems ... if (problems.hasProblems()) { // There are errors and/or warnings, so report them ... String summary = messageFrom(problems); if (problems.hasErrors()) { String msg = JcrI18n.errorsParsingNodeTypeDefinitions.text(file.getAbsolutePath(), summary); throw new RepositoryException(msg); } // Otherwise, there are warnings, so log them ... I18n msg = JcrI18n.warningsParsingNodeTypeDefinitions; Logger.getLogger(getClass()).warn(msg, file.getAbsolutePath(), summary); } // Register the node types ... return registerNodeTypes(importer.getNodeTypeDefinitions(), allowUpdate); }
@Test @FixFor( "MODE-1807" ) public void shouldAllowOverridingChildDefinitionWithSubtypeOfOriginalDefinition() throws Exception { InputStream cndStream = getClass().getResourceAsStream("/cnd/orc.cnd"); assertThat(cndStream, is(notNullValue())); nodeTypeManager().registerNodeTypes(cndStream, true); }
protected static void registerNodeTypes( JcrSession session, String pathToClasspathResource ) throws RepositoryException, IOException { URL url = resourceUrl(pathToClasspathResource); session.getWorkspace().getNodeTypeManager().registerNodeTypes(url, true); }
@FixFor( "MODE-1828" ) @Test public void shouldAllowNodeTypeChangeAfterWrite() throws Exception { session = createSession(); session.workspace().getNodeTypeManager() .registerNodeTypes(getClass().getResourceAsStream("/cnd/nodeTypeChange-initial.cnd"), true); Node testRoot = session.getRootNode().addNode("/testRoot", "test:nodeTypeA"); testRoot.setProperty("fieldA", "foo"); session.save(); session.workspace().getNodeTypeManager() .registerNodeTypes(getClass().getResourceAsStream("/cnd/nodeTypeChange-next.cnd"), true); testRoot = session.getNode("/testRoot"); assertEquals("foo", testRoot.getProperty("fieldA").getString()); testRoot.setProperty("fieldB", "bar"); session.save(); testRoot = session.getNode("/testRoot"); assertEquals("foo", testRoot.getProperty("fieldA").getString()); assertEquals("bar", testRoot.getProperty("fieldB").getString()); }
@FixFor( "MODE-1783" ) @Test public void shouldValidateStringPropertyConstraints() throws Exception { JcrWorkspace workspace = session.getWorkspace(); workspace.getNodeTypeManager().registerNodeTypes(getClass().getClassLoader().getResourceAsStream( "cnd/propertyWithConstraint.cnd"), true); Node testNode = session.getRootNode().addNode("testNode", "test:nodeType"); try { testNode.setProperty("test:stringProp", "aa"); fail("Regexp constraint not validated on property"); } catch (ConstraintViolationException e) { //expected testNode.setProperty("test:stringProp", "a"); } session.save(); testNode = session.getNode("/testNode"); try { testNode.setProperty("test:stringProp", "bb"); fail("Regexp constraint not validated on property"); } catch (ConstraintViolationException e) { //expected } }
@Test @FixFor( "MODE-1857" ) public void shouldAllowOverridingOfPropertyDefinitions() throws Exception { InputStream cnd = getClass().getClassLoader().getResourceAsStream("cnd/overridingPropertyDefinition.cnd"); assertThat(cnd, is(notNullValue())); session.getWorkspace().getNodeTypeManager().registerNodeTypes(cnd, true); Node car = session.getRootNode().addNode("car", "car"); car.setProperty("engine", "4CYL"); Node cycle = session.getRootNode().addNode("cycle", "motorcycle"); cycle.setProperty("engine", "2CYL"); session.save(); try { car.setProperty("engine", "2CYL"); fail("Should not have allowed setting the 'engine' property on a node of type 'car' to \"2CYL\""); } catch (ConstraintViolationException e) { // expected ... } try { cycle.setProperty("engine", "4CYL"); fail("Should not have allowed setting the 'engine' property on a node of type 'car' to \"2CYL\""); } catch (ConstraintViolationException e) { // expected ... } }
@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 @FixFor( "MODE-1857" ) public void shouldAllowOverridingOfPropertyDefinitionsWithResidualDefinitions() throws Exception { InputStream cnd = getClass().getClassLoader().getResourceAsStream("cnd/overridingPropertyDefinitionWithResidual.cnd"); assertThat(cnd, is(notNullValue())); session.getWorkspace().getNodeTypeManager().registerNodeTypes(cnd, true); Node car = session.getRootNode().addNode("car", "car"); car.setProperty("engine", "4CYL"); Node cycle = session.getRootNode().addNode("cycle", "motorcycle"); cycle.setProperty("engine", "2CYL"); session.save(); try { car.setProperty("engine", "2CYL"); fail("Should not have allowed setting the 'engine' property on a node of type 'car' to \"2CYL\""); } catch (ConstraintViolationException e) { // expected ... } try { cycle.setProperty("engine", "4CYL"); fail("Should not have allowed setting the 'engine' property on a node of type 'car' to \"2CYL\""); } catch (ConstraintViolationException e) { // expected ... } }
@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 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(); }
@Override @Before public void beforeEach() throws Exception { super.beforeEach(); session.getWorkspace().getNodeTypeManager().registerNodeTypes(getTestTypes(), true); }
@Test @FixFor( "MODE-2511" ) public void shouldAllowReorderNodesWhenSameNameIsDisabled() throws Exception { try { session.getWorkspace().getNodeTypeManager().registerNodeTypes(resourceStream("cnd/magnolia.cnd"), true); // add 2 nodes under a parent that doesn't allow SNS and reorder them final Node root = session.getRootNode(); final Node parent = root.addNode("parent", "mgnl:content"); parent.addNode("name1", "nt:folder"); parent.addNode("name2", "nt:folder"); parent.orderBefore("name2", "name1"); session.save(); } finally { session.logout(); } }
@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 @FixFor( "MODE-1807" ) public void shouldRegisterCNDFileWithResidualChildDefinition() throws Exception { session = createSession(); InputStream cndStream = getClass().getResourceAsStream("/cnd/orc.cnd"); assertThat(cndStream, is(notNullValue())); session.getWorkspace().getNodeTypeManager().registerNodeTypes(cndStream, true); session.getRootNode().addNode("patient", "orc:patient").addNode("patientcase", "orc:patientcase"); session.save(); assertNotNull(session.getNode("/patient/patientcase")); }
@FixFor( " MODE-1315 " ) @Test public void shouldReceiveEventWhenPropertyDeletedOnCustomNode() throws Exception { session.getWorkspace() .getNodeTypeManager() .registerNodeTypes(getClass().getClassLoader().getResourceAsStream("cars.cnd"), true); Node car = getRoot().addNode("car", "car:Car"); car.setProperty("car:maker", "Audi"); session.save(); SimpleListener listener = addListener(1, Event.PROPERTY_REMOVED, null, true, null, new String[] {"car:Car"}, false); Property carMakerProperty = car.getProperty("car:maker"); String propertyPath = carMakerProperty.getPath(); carMakerProperty.remove(); session.save(); listener.waitForEvents(); checkResults(listener); Event receivedEvent = listener.getEvents().get(0); assertEquals(Event.PROPERTY_REMOVED, receivedEvent.getType()); assertEquals(propertyPath, receivedEvent.getPath()); }
@FixFor( "MODE-1821" ) @Test public void shouldFailIfSNSAreNotSupported() throws Exception { session.workspace().getNodeTypeManager().registerNodeTypes(resourceStream("cnd/no_sns.cnd"), true); Node testRoot = session.getRootNode().addNode("/testRoot", "test:nodeWithoutSNS"); testRoot.addNode("childA", "nt:unstructured"); session.save(); try { testRoot.addNode("childA", "nt:unstructured"); fail("Same name sibling are not supported, an exception should've been thrown"); } catch (ItemExistsException ex) { // this is expected since this is not allowed. } // Now run two threads that are timed very carefully ... int numThreads = 2; final CyclicBarrier barrier = new CyclicBarrier(numThreads); Operation operation = session1 -> { Node testRoot1 = session1.getNode("/testRoot"); testRoot1.addNode("childB", "nt:unstructured"); barrier.await(); // one of the saves should fail but it doesn't session1.save(); }; run(2, numThreads, 1, operation); verify(new NumberOfChildren(2, "testRoot")); }
@Override @Before public void beforeEach() throws Exception { super.beforeEach(); nameFactory = session.nameFactory(); repoTypeManager = session.repository().nodeTypeManager(); session.getWorkspace().getNodeTypeManager().registerNodeTypes(getTestTypes(), true); }
@Test @FixFor( "MODE-1916" ) public void shouldFindPublicChildNodeDefinitionsWhenBothPublicAndProtectedAreDefined() throws Exception { InputStream cndStream = getClass().getResourceAsStream("/cnd/protectedDefinitions.cnd"); assertThat(cndStream, is(notNullValue())); nodeTypeManager().registerNodeTypes(cndStream, true); Name parking = new BasicName(null, "parking"); Name level = new BasicName(null, "level"); Set<Name> garage = Collections.<Name>singleton(new BasicName(null, "garage")); JcrNodeDefinition def = repoTypeManager.getNodeTypes().findChildNodeDefinitions(parking, garage) .findBestDefinitionForChild(level, level, true, SiblingCounter.noSiblings()); assertNotNull(def); Name car = new BasicName(null, "car"); def = repoTypeManager.getNodeTypes().findChildNodeDefinitions(parking, garage) .findBestDefinitionForChild(car, car, true, SiblingCounter.noSiblings()); assertNotNull(def); }