use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit-oak by apache.
the class NodeTypeDefinitionManagementTest method testUnRegisterNodeType.
@Test
public void testUnRegisterNodeType() throws Exception {
NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
ntd.setName("testUnregisterNodeType");
ntd.setMixin(true);
ntm.registerNodeType(ntd, true);
Workspace testWsp = testSession.getWorkspace();
try {
try {
NodeTypeManager testNtm = testWsp.getNodeTypeManager();
testNtm.unregisterNodeType(ntd.getName());
fail("Node type unregistration should be denied.");
} catch (AccessDeniedException e) {
// success
}
try {
NodeTypeManager testNtm = testWsp.getNodeTypeManager();
testNtm.unregisterNodeTypes(new String[] { ntd.getName() });
fail("Node type unregistration should be denied.");
} catch (AccessDeniedException e) {
// success
}
} finally {
// NOTE: diff to jr-core where unregisterNt was not supported
ntm.unregisterNodeType(ntd.getName());
}
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit-oak by apache.
the class OpvIgnoreTest method createNodeTypeWithIgnoreOPVProperty.
private NodeTypeTemplate createNodeTypeWithIgnoreOPVProperty(String propertyName) throws RepositoryException {
NodeTypeManager manager = superuser.getWorkspace().getNodeTypeManager();
NodeTypeTemplate nt = manager.createNodeTypeTemplate();
nt.setName("testType");
nt.setMixin(true);
PropertyDefinitionTemplate opt = manager.createPropertyDefinitionTemplate();
opt.setMandatory(false);
opt.setName(propertyName);
opt.setRequiredType(PropertyType.STRING);
opt.setOnParentVersion(OnParentVersionAction.IGNORE);
List pdt = nt.getPropertyDefinitionTemplates();
pdt.add(opt);
manager.registerNodeType(nt, true);
return nt;
}
use of javax.jcr.nodetype.NodeTypeManager 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.NodeTypeManager in project jackrabbit by apache.
the class RepositoryCopierTest method verifyTargetRepository.
private void verifyTargetRepository() throws Exception {
RepositoryImpl repository = RepositoryImpl.create(RepositoryConfig.create(TARGET));
try {
Session session = repository.login(CREDENTIALS);
try {
assertEquals("http://www.example.org/", session.getNamespaceURI("test"));
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
assertTrue(manager.hasNodeType("test:unstructured"));
NodeType type = manager.getNodeType("test:unstructured");
assertFalse(type.isMixin());
assertTrue(type.isNodeType("nt:unstructured"));
assertTrue(session.nodeExists("/properties"));
Node properties = session.getNode("/properties");
assertEquals(PropertyType.BOOLEAN, properties.getProperty("boolean").getType());
assertEquals(true, properties.getProperty("boolean").getBoolean());
assertEquals(PropertyType.BINARY, properties.getProperty("binary").getType());
Binary binary = properties.getProperty("binary").getBinary();
try {
InputStream stream = binary.getStream();
try {
for (int i = 0; i < BINARY.length; i++) {
assertEquals(BINARY[i], (byte) stream.read());
}
assertEquals(-1, stream.read());
} finally {
stream.close();
}
} finally {
binary.dispose();
}
assertEquals(PropertyType.DATE, properties.getProperty("date").getType());
assertEquals(DATE.getTimeInMillis(), properties.getProperty("date").getDate().getTimeInMillis());
assertEquals(PropertyType.DECIMAL, properties.getProperty("decimal").getType());
assertEquals(new BigDecimal(123), properties.getProperty("decimal").getDecimal());
assertEquals(PropertyType.DOUBLE, properties.getProperty("double").getType());
assertEquals(Math.PI, properties.getProperty("double").getDouble());
assertEquals(PropertyType.LONG, properties.getProperty("long").getType());
assertEquals(9876543210L, properties.getProperty("long").getLong());
assertEquals(PropertyType.REFERENCE, properties.getProperty("reference").getType());
assertEquals(identifier, properties.getProperty("reference").getString());
assertEquals("/referenceable", properties.getProperty("reference").getNode().getPath());
assertEquals(PropertyType.STRING, properties.getProperty("string").getType());
assertEquals("test", properties.getProperty("string").getString());
assertEquals(PropertyType.STRING, properties.getProperty("multiple").getType());
Value[] values = properties.getProperty("multiple").getValues();
assertEquals(3, values.length);
assertEquals("a", values[0].getString());
assertEquals("b", values[1].getString());
assertEquals("c", values[2].getString());
} finally {
session.logout();
}
} finally {
repository.shutdown();
}
}
use of javax.jcr.nodetype.NodeTypeManager 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