use of javax.jcr.nodetype.NodeTypeManager 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.NodeTypeManager 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"));
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit-oak by apache.
the class RepositoryTest method importNodeType.
// Regression test for OAK-299
@Test
public void importNodeType() throws RepositoryException, IOException, ParseException {
Session session = getAdminSession();
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
if (!manager.hasNodeType("myNodeType")) {
StringBuilder defs = new StringBuilder();
defs.append("[\"myNodeType\"]\n");
defs.append(" - prop1\n");
defs.append(" + * (nt:base) = nt:unstructured \n");
Reader cndReader = new InputStreamReader(new ByteArrayInputStream(defs.toString().getBytes()));
CndImporter.registerNodeTypes(cndReader, session);
}
NodeType myNodeType = manager.getNodeType("myNodeType");
assertTrue(myNodeType.isNodeType("nt:base"));
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit-oak by apache.
the class NodeTypeTest method removeMandatoryProperty.
@Test
public void removeMandatoryProperty() throws Exception {
Session session = getAdminSession();
Node root = session.getRootNode();
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
String cnd = "<'test'='http://www.apache.org/jackrabbit/test'>\n" + "[test:MyType] > nt:unstructured\n" + " - test:mandatory (string) mandatory";
CndImporter.registerNodeTypes(new StringReader(cnd), session);
Node n = root.addNode("test", "test:MyType");
n.setProperty("test:mandatory", "value");
session.save();
try {
n.getProperty("test:mandatory").remove();
session.save();
fail("Must fail with ConstraintViolationException");
} catch (ConstraintViolationException e) {
// expected
session.refresh(false);
}
// remove the mandatory property
cnd = "<'test'='http://www.apache.org/jackrabbit/test'>\n" + "[test:MyType] > nt:unstructured";
CndImporter.registerNodeTypes(new StringReader(cnd), session, true);
// check node type
NodeTypeDefinition ntd = manager.getNodeType("test:MyType");
assertEquals(0, ntd.getDeclaredPropertyDefinitions().length);
// now we should be able to remove the property
n.getProperty("test:mandatory").remove();
session.save();
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit-oak by apache.
the class ObservationTest 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);
n.setProperty("test_property1", 42);
n.setProperty("test_property2", "forty_two");
n.addMixin(TEST_TYPE);
Node refNode = n.addNode(REFERENCEABLE_NODE);
refNode.addMixin(JcrConstants.MIX_REFERENCEABLE);
test_uuid = refNode.getProperty(JcrConstants.JCR_UUID).getString();
session.save();
observingSession = createAdminSession();
observationManager = observingSession.getWorkspace().getObservationManager();
}
Aggregations