use of javax.jcr.nodetype.NodeTypeTemplate 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();
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class ObservationTest method deepNodeTypeMixinHierarchy.
@Test
public void deepNodeTypeMixinHierarchy() throws Exception {
NodeTypeManager ntm = getAdminSession().getWorkspace().getNodeTypeManager();
NodeTypeTemplate parentMixin = ntm.createNodeTypeTemplate();
parentMixin.setName("parentmixin");
parentMixin.setMixin(true);
ntm.registerNodeType(parentMixin, false);
NodeTypeTemplate childMixin = ntm.createNodeTypeTemplate();
childMixin.setName("childmixin");
childMixin.setMixin(true);
childMixin.setDeclaredSuperTypeNames(new String[] { "parentmixin" });
ntm.registerNodeType(childMixin, false);
NodeTypeTemplate mytype = ntm.createNodeTypeTemplate();
mytype.setName("mytype");
mytype.setMixin(false);
mytype.setDeclaredSuperTypeNames(new String[] { "childmixin" });
NodeDefinitionTemplate child = ntm.createNodeDefinitionTemplate();
child.setName("*");
child.setDefaultPrimaryTypeName("nt:base");
child.setRequiredPrimaryTypeNames(new String[] { "nt:base" });
List<NodeDefinition> children = mytype.getNodeDefinitionTemplates();
children.add(child);
ntm.registerNodeType(mytype, false);
getAdminSession().save();
// create a fresh session here to catch the above new node type definitions
observingSession = createAdminSession();
observationManager = observingSession.getWorkspace().getObservationManager();
JackrabbitObservationManager oManager = (JackrabbitObservationManager) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter().setAbsPath("/").setIsDeep(true).setNodeTypes(new String[] { "parentmixin" }).setEventTypes(ALL_EVENTS);
oManager.addEventListener(listener, filter);
Node n = getNode(TEST_PATH).addNode("n", "mytype");
listener.expect(n.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
Node m = n.addNode("m", "nt:unstructured");
listener.expect(m.getPath(), NODE_ADDED);
getAdminSession().save();
Thread.sleep(1000);
List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
assertTrue("Missing events: " + missing, missing.isEmpty());
List<Event> unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class OpvIgnoreTest method createNodeDefinitionWithIgnoreOPVNode.
private NodeDefinitionTemplate createNodeDefinitionWithIgnoreOPVNode(String nodeTypeName) throws RepositoryException {
NodeTypeManager manager = superuser.getWorkspace().getNodeTypeManager();
NodeDefinitionTemplate def = manager.createNodeDefinitionTemplate();
def.setOnParentVersion(OnParentVersionAction.IGNORE);
def.setName("child");
def.setRequiredPrimaryTypeNames(new String[] { JcrConstants.NT_BASE });
NodeTypeTemplate tmpl = manager.createNodeTypeTemplate();
tmpl.setName(nodeTypeName);
tmpl.setMixin(true);
tmpl.getNodeDefinitionTemplates().add(def);
manager.registerNodeType(tmpl, true);
return def;
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit by apache.
the class IndexingConfigurationImplTest method testAddNodeTypeToRegistry.
public void testAddNodeTypeToRegistry() throws Exception {
IndexingConfiguration config = createConfig("config4");
// add node type
NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
String baseName = "indexingTextNodeType";
int i = 0;
String nt;
do {
nt = baseName + "_" + i++;
} while (ntMgr.hasNodeType(nt));
// register node type
NodeTypeTemplate ntTemplate = ntMgr.createNodeTypeTemplate();
ntTemplate.setName(nt);
ntTemplate.setDeclaredSuperTypeNames(new String[] { ntUnstructured });
ntMgr.registerNodeType(ntTemplate, false);
// create node
Node n = testRootNode.addNode(nodeName2, nt);
session.save();
// get state
NodeState state = (NodeState) getSearchIndex().getContext().getItemStateManager().getItemState(new NodeId(n.getIdentifier()));
assertTrue(config.isIndexed(state, FOO));
assertFalse(config.isIncludedInNodeScopeIndex(state, FOO));
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit by apache.
the class NodeTypeCreationTest method testEmptyNodeTypeTemplate.
public void testEmptyNodeTypeTemplate() throws Exception {
NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
assertNull(ntt.getName());
assertFalse(ntt.isMixin());
assertFalse(ntt.isAbstract());
assertFalse(ntt.hasOrderableChildNodes());
// note: isQueryable cannot be tested as defautl value is defined
// by the implementation
assertNotNull(ntt.getDeclaredSupertypeNames());
assertEquals(0, ntt.getDeclaredSupertypeNames().length);
assertNull(ntt.getPrimaryItemName());
assertNull(ntt.getDeclaredChildNodeDefinitions());
assertNull(ntt.getDeclaredPropertyDefinitions());
assertNotNull(ntt.getNodeDefinitionTemplates());
assertTrue(ntt.getNodeDefinitionTemplates().isEmpty());
assertNotNull(ntt.getPropertyDefinitionTemplates());
assertTrue(ntt.getPropertyDefinitionTemplates().isEmpty());
}
Aggregations