use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class OpvIgnoreTest method testWritePropertyWithIgnoreOPVAfterCheckIn.
//OAK-3328
public void testWritePropertyWithIgnoreOPVAfterCheckIn() throws RepositoryException {
Node ignoreTestNode = testRootNode.addNode("ignoreTestNode", JcrConstants.NT_UNSTRUCTURED);
String ignoredPropertyName = "ignoredProperty";
NodeTypeTemplate mixinWithIgnoreProperty = createNodeTypeWithIgnoreOPVProperty(ignoredPropertyName);
Node node = ignoreTestNode.addNode("testNode", testNodeType);
node.addMixin(mixinWithIgnoreProperty.getName());
node.setProperty(ignoredPropertyName, "initial value");
node.addMixin(mixVersionable);
superuser.save();
VersionManager vMgr = superuser.getWorkspace().getVersionManager();
if (!node.isCheckedOut()) {
vMgr.checkout(node.getPath());
}
vMgr.checkin(node.getPath());
node.setProperty(ignoredPropertyName, "next value");
superuser.save();
Property ignoreProperty = node.getProperty(ignoredPropertyName);
assertEquals("next value", ignoreProperty.getString());
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class OpvIgnoreTest method testRemovePropertyWithIgnoreOPVAfterCheckIn.
//OAK-3328
public void testRemovePropertyWithIgnoreOPVAfterCheckIn() throws RepositoryException {
Node ignoreTestNode = testRootNode.addNode("ignoreTestNode", JcrConstants.NT_UNSTRUCTURED);
String ignoredPropertyName = "test:ignoredProperty";
NodeTypeTemplate mixinWithIgnoreProperty = createNodeTypeWithIgnoreOPVProperty(ignoredPropertyName);
Node node = ignoreTestNode.addNode("testNode", testNodeType);
node.addMixin(mixinWithIgnoreProperty.getName());
node.setProperty(ignoredPropertyName, "initial value");
node.addMixin(mixVersionable);
superuser.save();
VersionManager vMgr = superuser.getWorkspace().getVersionManager();
if (!node.isCheckedOut()) {
vMgr.checkout(node.getPath());
}
vMgr.checkin(node.getPath());
node.getProperty(ignoredPropertyName).remove();
superuser.save();
assertFalse(node.hasProperty(ignoredPropertyName));
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class OpvAbortTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
vMgr = superuser.getWorkspace().getVersionManager();
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
NodeDefinitionTemplate def = ntMgr.createNodeDefinitionTemplate();
def.setOnParentVersion(OnParentVersionAction.ABORT);
def.setName("child");
def.setRequiredPrimaryTypeNames(new String[] { NT_BASE });
NodeTypeTemplate tmpl = ntMgr.createNodeTypeTemplate();
tmpl.setName("OpvAbortTest");
tmpl.setMixin(true);
tmpl.getNodeDefinitionTemplates().add(def);
ntMgr.registerNodeType(tmpl, true);
testRootNode.addMixin(MIX_VERSIONABLE);
superuser.save();
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class PropertyTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
NodeTypeTemplate template = ntMgr.createNodeTypeTemplate();
template.setName(NT_NAME);
template.setDeclaredSuperTypeNames(new String[] { JcrConstants.NT_BASE });
template.setMixin(false);
PropertyDefinitionTemplate pdt = ntMgr.createPropertyDefinitionTemplate();
pdt.setName(BOOLEAN_PROP_NAME);
pdt.setRequiredType(PropertyType.BOOLEAN);
template.getPropertyDefinitionTemplates().add(pdt);
pdt = ntMgr.createPropertyDefinitionTemplate();
pdt.setName(LONG_PROP_NAME);
pdt.setRequiredType(PropertyType.LONG);
template.getPropertyDefinitionTemplates().add(pdt);
ntMgr.registerNodeType(template, true);
node = testRootNode.addNode(nodeName2, NT_NAME);
assertEquals(NT_NAME, node.getPrimaryNodeType().getName());
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class NodeTypeTest method updateNodeType.
@Test
public void updateNodeType() throws Exception {
Session session = getAdminSession();
Node root = session.getRootNode();
ValueFactory vf = session.getValueFactory();
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
Node n = root.addNode("q1", "nt:query");
n.setProperty("jcr:statement", vf.createValue("statement"));
session.save();
NodeTypeDefinition ntd = manager.getNodeType("nt:query");
NodeTypeTemplate ntt = manager.createNodeTypeTemplate(ntd);
try {
manager.registerNodeType(ntt, true);
// no changes to the type, so the registration should be a no-op
} catch (ConstraintViolationException unexpected) {
fail();
}
// make the (still missing) jcr:language property mandatory
@SuppressWarnings("unchecked") List<PropertyDefinitionTemplate> pdts = ntt.getPropertyDefinitionTemplates();
for (PropertyDefinitionTemplate pdt : pdts) {
if ("jcr:language".equals(pdt.getName())) {
pdt.setMandatory(true);
}
}
try {
manager.registerNodeType(ntt, true);
fail();
} catch (ConstraintViolationException expected) {
// the registration fails because of the would-be invalid content
}
// add the jcr:language property so it can be made mandatory
n.setProperty("jcr:language", vf.createValue("language"));
session.save();
try {
manager.registerNodeType(ntt, true);
// now the mandatory property exists, so the type change is OK
} catch (ConstraintViolationException unexpected) {
fail();
}
}
Aggregations