use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class CompatibilityIssuesTest method addNodeTest.
@Test
public void addNodeTest() throws RepositoryException {
Session session = getAdminSession();
// node type with default child-node type of to nt:base
String ntName = "test";
NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
ntt.setName(ntName);
NodeDefinitionTemplate child = ntm.createNodeDefinitionTemplate();
child.setName("*");
child.setDefaultPrimaryTypeName("nt:base");
child.setRequiredPrimaryTypeNames(new String[] { "nt:base" });
List<NodeDefinition> children = ntt.getNodeDefinitionTemplates();
children.add(child);
ntm.registerNodeType(ntt, true);
// try to create a node with the default nt:base
Node node = session.getRootNode().addNode("defaultNtBase", ntName);
// See OAK-1013
node.addNode("nothrow");
try {
node.addNode("throw", "nt:hierarchyNode");
fail("Abstract primary type should cause ConstraintViolationException");
} catch (ConstraintViolationException expected) {
}
session.save();
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class RepositoryTest method mixin.
@Test
public void mixin() throws RepositoryException {
NodeTypeManager ntMgr = getAdminSession().getWorkspace().getNodeTypeManager();
NodeTypeTemplate mixTest = ntMgr.createNodeTypeTemplate();
mixTest.setName("mix:test");
mixTest.setMixin(true);
ntMgr.registerNodeType(mixTest, false);
Node testNode = getNode(TEST_PATH);
NodeType[] mix = testNode.getMixinNodeTypes();
assertEquals(0, mix.length);
testNode.addMixin("mix:test");
testNode.getSession().save();
Session session2 = createAnonymousSession();
try {
mix = session2.getNode(TEST_PATH).getMixinNodeTypes();
assertEquals(1, mix.length);
assertEquals("mix:test", mix[0].getName());
} finally {
session2.logout();
}
testNode.removeMixin("mix:test");
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class NodeTypeTest method trivialUpdates.
@Test
public void trivialUpdates() throws Exception {
// test various trivial updates that should not trigger repository scans
// whether or not the repository scan happens can not be checked directly;
// it requires inspecting the INFO level log
String[] types = new String[] { "trivial1", "trivial2" };
ArrayList<NodeTypeTemplate> ntt = new ArrayList<NodeTypeTemplate>();
// adding node types
Session session = getAdminSession();
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
for (String t : types) {
NodeTypeTemplate nt = manager.createNodeTypeTemplate();
nt.setName(t);
ntt.add(nt);
}
manager.registerNodeTypes(ntt.toArray(new NodeTypeTemplate[0]), false);
// adding an optional property
ntt = new ArrayList<NodeTypeTemplate>();
for (String t : types) {
NodeTypeDefinition ntd = manager.getNodeType(t);
PropertyDefinitionTemplate opt = manager.createPropertyDefinitionTemplate();
opt.setMandatory(false);
opt.setName("optional");
opt.setRequiredType(PropertyType.STRING);
PropertyDefinitionTemplate opts = manager.createPropertyDefinitionTemplate();
opts.setMandatory(false);
opts.setMultiple(true);
opts.setName("optionals");
opts.setRequiredType(PropertyType.STRING);
NodeTypeTemplate nt = manager.createNodeTypeTemplate(ntd);
List pdt = nt.getPropertyDefinitionTemplates();
pdt.add(opt);
pdt.add(opts);
ntt.add(nt);
}
manager.registerNodeTypes(ntt.toArray(new NodeTypeTemplate[0]), true);
// make one optional property mandatory
ntt = new ArrayList<NodeTypeTemplate>();
for (String t : types) {
NodeTypeDefinition ntd = manager.getNodeType(t);
PropertyDefinitionTemplate opt = manager.createPropertyDefinitionTemplate();
opt.setMandatory("trivial2".equals(t));
opt.setName("optional");
opt.setRequiredType(PropertyType.STRING);
PropertyDefinitionTemplate opts = manager.createPropertyDefinitionTemplate();
opts.setMandatory("trivial2".equals(t));
opts.setMultiple(true);
opts.setName("optionals");
opts.setRequiredType(PropertyType.STRING);
NodeTypeTemplate nt = manager.createNodeTypeTemplate(ntd);
List pdt = nt.getPropertyDefinitionTemplates();
pdt.add(opt);
pdt.add(opts);
ntt.add(nt);
}
// but update both node types
manager.registerNodeTypes(ntt.toArray(new NodeTypeTemplate[0]), true);
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class ObservationRefreshTest method setup.
@Before
public void setup() throws RepositoryException {
Session session = getAdminSession();
NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
NodeTypeTemplate mixTest = ntMgr.createNodeTypeTemplate();
mixTest.setName(TEST_TYPE);
mixTest.setMixin(true);
ntMgr.registerNodeType(mixTest, false);
Node n = session.getRootNode().addNode(TEST_NODE, TEST_NODE_TYPE);
n.addMixin(TEST_TYPE);
Node refNode = n.addNode(REFERENCEABLE_NODE);
refNode.addMixin(JcrConstants.MIX_REFERENCEABLE);
session.save();
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(RepositoryImpl.REFRESH_INTERVAL, 0);
observingSession = ((JackrabbitRepository) getRepository()).login(new SimpleCredentials("admin", "admin".toCharArray()), null, attrs);
observationManager = observingSession.getWorkspace().getObservationManager();
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class RepositoryTest method nodeTypeRegistry.
@Test
public void nodeTypeRegistry() throws RepositoryException {
NodeTypeManager ntMgr = getAdminSession().getWorkspace().getNodeTypeManager();
assertFalse(ntMgr.hasNodeType("foo"));
NodeTypeTemplate ntd = ntMgr.createNodeTypeTemplate();
ntd.setName("foo");
ntMgr.registerNodeType(ntd, false);
assertTrue(ntMgr.hasNodeType("foo"));
ntMgr.unregisterNodeType("foo");
assertFalse(ntMgr.hasNodeType("foo"));
}
Aggregations