@Deprecated @Override public void save() throws AccessDeniedException, ItemExistsException, ConstraintViolationException, InvalidItemStateException, ReferentialIntegrityException, VersionException, LockException, NoSuchNodeTypeException, RepositoryException { if (this.isRoot()) { // Just call save on the session (it's more efficient) ... session.save(); } else { session.save(this); } }
@Test( expected = RepositoryException.class ) public void shouldNotAllowWritesIfReadonly() throws Exception { federationManager.createProjection("/testRoot", "mock-source-readonly", MockConnector.DOC1_LOCATION, "federated1"); Node doc1Federated = session.getNode("/testRoot/federated1"); Node externalNode1 = doc1Federated.addNode("federated1_1", null); externalNode1.addNode("federated1_1_1", null); session.save(); }
@Test public void shouldReturnEmptyIterator() throws RepositoryException { Node jcrRootNode = session.getRootNode(); Node rootNode = jcrRootNode.addNode("mapSuperclassTest"); Node newNode = rootNode.addNode("newNode"); assertNotNull(newNode); NodeIterator nodeIterator = rootNode.getNodes("myMap"); assertFalse(nodeIterator.hasNext()); session.save(); nodeIterator = rootNode.getNodes("myMap"); assertFalse(nodeIterator.hasNext()); }
@Test( expected = ConstraintViolationException.class ) public void shouldNotAllowRemovalIfExistingPropertyWouldHaveNoDefinition() throws Exception { Node a = session.getRootNode().addNode("a", BASE_PRIMARY_TYPE); a.addMixin(MIXIN_TYPE_B); a.setProperty(PROPERTY_B, "true"); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); nodeA.removeMixin(MIXIN_TYPE_B); session.save(); }
@Test public void shouldAllowUpdatingNodesInWritableStoreBasedProjection() throws Exception { Node file = session.getNode("/testRoot/store/dir3/simple.json"); file.addMixin("flex:anyProperties"); file.setProperty("extraProp", "extraValue"); session.save(); assertNoSidecarFile(storeProjection, "dir3/simple.json.modeshape"); Node file2 = session.getNode("/testRoot/store/dir3/simple.json"); assertThat(file2.getProperty("extraProp").getString(), is("extraValue")); }
@Test public void shouldRemoveSequencerIfItCrashesDuringInitialize() throws Exception { EditableDocument doc = Schematic.newDocument(); addSequencer(doc, "seq1", TestSequencersHolder.FaultyDuringInitialize.class.getName(), "/foo[@bar] => /output"); startRepositoryWithConfiguration(doc); Node foo = session.getRootNode().addNode("foo"); foo.setProperty("bar", "value of bar"); session.save(); Thread.sleep(100L); assertEquals(0, TestSequencersHolder.FaultyDuringInitialize.EXECUTE_CALL_COUNTER.get()); }
@Test public void shouldNotAllowUpdatingNodesInReadOnlyProjection() throws Exception { Node file = session.getNode("/testRoot/readonly/dir3/simple.json"); try { file.addMixin("flex:anyProperties"); file.setProperty("extraProp", "extraValue"); session.save(); fail("failed to throw read-only exception"); } catch (RepositoryException e) { // expected } }
@Test( expected = ConstraintViolationException.class ) public void shouldNotAllowRemovalIfExistingChildNodeWouldHaveNoDefinition() throws Exception { Node a = session.getRootNode().addNode("a", BASE_PRIMARY_TYPE); a.addMixin(MIXIN_TYPE_B); a.addNode(CHILD_NODE_B); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); nodeA.removeMixin(MIXIN_TYPE_B); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowEmptyMixinTypeName() throws Exception { session.getRootNode().addNode("a", PRIMARY_TYPE_A); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); nodeA.canAddMixin(""); }
@Test public void shouldAutoCreateAutoCreatedPropertiesOnAddition() throws Exception { session.getRootNode().addNode("a"); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); assertThat(nodeA.canAddMixin(MIXIN_TYPE_WITH_AUTO_PROP), is(true)); nodeA.addMixin(MIXIN_TYPE_WITH_AUTO_PROP); Property prop = nodeA.getProperty(PROPERTY_B); assertThat(prop, is(notNullValue())); assertThat(prop.getLong(), is(10L)); }
@Test public void shouldAllowAddingMixinIfNoConflict() throws Exception { session.getRootNode().addNode("a", PRIMARY_TYPE_A).addMixin("mix:referenceable"); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); assertThat(nodeA.canAddMixin(MIXIN_TYPE_B), is(true)); }
@Test( expected = ConstraintViolationException.class ) public void shouldNotAllowAdditionIfResidualPropertyConflicts() throws Exception { session.getRootNode().addNode("a", "nt:unstructured"); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); Property b = nodeA.setProperty(PROPERTY_B, "Not a boolean"); assertThat(b.getType(), is(not(PropertyType.UNDEFINED))); // see JavaDoc on javax.jcr.PropertyType.UNDEFINED assertThat(nodeA.canAddMixin(MIXIN_TYPE_WITH_AUTO_PROP), is(false)); nodeA.addMixin(MIXIN_TYPE_WITH_AUTO_PROP); }
@Test public void shouldAllowDeletingTransientNodeWithNoChildren() throws Exception { Node node = session.getRootNode().addNode("testNode"); node.remove(); session.save(); }
@Test public void shouldAllowAddingMixinIfPrimaryTypeConflicts() throws Exception { session.getRootNode().addNode("a", PRIMARY_TYPE_A).addMixin("mix:referenceable"); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); assertThat(nodeA.canAddMixin(MIXIN_TYPE_C), is(true)); }
@Test public void shouldAllowAddingMixinIfMixinTypeConflicts() throws Exception { session.getRootNode().addNode("a", PRIMARY_TYPE_A).addMixin(MIXIN_TYPE_B); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); assertThat(nodeA.canAddMixin(MIXIN_TYPE_C), is(true)); }
@Test public void shouldAutoCreateAutoCreatedChildNodesOnAddition() throws Exception { session.getRootNode().addNode("a"); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); assertThat(nodeA.canAddMixin(MIXIN_TYPE_WITH_AUTO_CHILD), is(true)); nodeA.addMixin(MIXIN_TYPE_WITH_AUTO_CHILD); Node childNode = nodeA.getNode(CHILD_NODE_B); assertThat(childNode, is(notNullValue())); assertThat(childNode.getPrimaryNodeType().getName(), is("nt:unstructured")); }
@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")); }
@Test @FixFor( "MODE-2012" ) public void clonedUUIDsShouldBeTheSame() throws Exception { tools.registerNodeTypes(session, "cnd/references.cnd"); Node nodeA = session.getRootNode().addNode("A", "test:node"); Node nodeB = session.getRootNode().addNode("B", "test:node"); session.save(); otherWorkspace.clone("default", "/", "/", true); assertEquals(nodeA.getIdentifier(), otherSession.getNode("/A").getIdentifier()); assertEquals(nodeB.getIdentifier(), otherSession.getNode("/B").getIdentifier()); }