use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit-oak by apache.
the class QueryTest method testOak1354.
@Test
public void testOak1354() throws Exception {
Session session = createAdminSession();
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
if (!manager.hasNodeType("mymixinOak1354")) {
StringBuilder defs = new StringBuilder();
defs.append("[mymixinOak1354]\n");
defs.append(" mixin");
Reader cndReader = new InputStreamReader(new ByteArrayInputStream(defs.toString().getBytes()));
CndImporter.registerNodeTypes(cndReader, session);
}
Node p = session.getRootNode().addNode("one");
p.addMixin("mymixinOak1354");
session.save();
Query q = session.getWorkspace().getQueryManager().createQuery("SELECT * FROM [mymixinOak1354]", Query.JCR_SQL2);
QueryResult qr = q.execute();
NodeIterator ni = qr.getNodes();
assertTrue(ni.hasNext());
Node n = ni.nextNode();
assertEquals("/one", n.getPath());
assertFalse(ni.hasNext());
session.logout();
}
use of javax.jcr.nodetype.NodeTypeManager 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.NodeTypeManager in project jackrabbit-oak by apache.
the class UpgradeOldSegmentTest method upgradeFrom10.
@Test
public void upgradeFrom10() throws Exception {
File testFolder = new File(new File("target"), UpgradeOldSegmentTest.class.getSimpleName());
FileUtils.deleteDirectory(testFolder);
File oldRepo = new File(testFolder, "test-repo-1.0");
oldRepo.mkdirs();
try (InputStream in = UpgradeOldSegmentTest.class.getResourceAsStream("/test-repo-1.0.zip")) {
Util.unzip(in, oldRepo);
}
SegmentTarNodeStoreContainer newRepoContainer = new SegmentTarNodeStoreContainer();
OakUpgrade.main("segment-old:" + oldRepo.getPath(), newRepoContainer.getDescription());
Repository repo = new Jcr(newRepoContainer.open()).createRepository();
Session s = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
Node myType = s.getNode("/jcr:system/jcr:nodeTypes/test:MyType");
assertEquals(2, Iterators.size(myType.getNodes("jcr:propertyDefinition")));
NodeTypeManager ntMgr = s.getWorkspace().getNodeTypeManager();
assertTrue(ntMgr.hasNodeType("test:MyType"));
NodeType nt = ntMgr.getNodeType("test:MyType");
PropertyDefinition[] pDefs = nt.getDeclaredPropertyDefinitions();
assertEquals(2, pDefs.length);
for (PropertyDefinition pd : pDefs) {
String name = pd.getName();
if (name.equals("test:mandatory")) {
assertTrue(pd.isMandatory());
} else if (name.equals("test:optional")) {
assertFalse(pd.isMandatory());
} else {
fail("Unexpected property definition: " + name);
}
}
// flip mandatory flag for test:mandatory
String cnd = "<'test'='http://www.apache.org/jackrabbit/test'>\n" + "[test:MyType] > nt:unstructured\n" + " - test:mandatory (string)\n" + " - test:optional (string)";
CndImporter.registerNodeTypes(new StringReader(cnd), s, true);
myType = s.getNode("/jcr:system/jcr:nodeTypes/test:MyType");
assertEquals(2, Iterators.size(myType.getNodes("jcr:propertyDefinition")));
nt = ntMgr.getNodeType("test:MyType");
pDefs = nt.getDeclaredPropertyDefinitions();
assertEquals(2, pDefs.length);
for (PropertyDefinition pd : pDefs) {
String name = pd.getName();
if (name.equals("test:mandatory")) {
assertFalse(pd.isMandatory());
} else if (name.equals("test:optional")) {
assertFalse(pd.isMandatory());
} else {
fail("Unexpected property definition: " + name);
}
}
s.logout();
if (repo instanceof JackrabbitRepository) {
((JackrabbitRepository) repo).shutdown();
}
newRepoContainer.close();
newRepoContainer.clean();
deleteRecursive(testFolder);
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit-oak by apache.
the class RepositoryUpgradeTest method verifyCustomNodeTypes.
@Test
public void verifyCustomNodeTypes() throws Exception {
Session session = createAdminSession();
try {
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
assertTrue(manager.hasNodeType("test:unstructured"));
NodeType type = manager.getNodeType("test:unstructured");
assertFalse(type.isMixin());
assertTrue(type.isNodeType("nt:unstructured"));
boolean foundDefaultString = false;
boolean foundDefaultPath = false;
for (PropertyDefinition pDef : type.getPropertyDefinitions()) {
if ("defaultString".equals(pDef.getName())) {
assertEquals(PropertyType.STRING, pDef.getRequiredType());
assertNotNull(pDef.getDefaultValues());
assertEquals(1, pDef.getDefaultValues().length);
assertEquals("stringValue", pDef.getDefaultValues()[0].getString());
foundDefaultString = true;
} else if ("defaultPath".equals(pDef.getName())) {
assertEquals(PropertyType.PATH, pDef.getRequiredType());
assertNotNull(pDef.getDefaultValues());
assertEquals(1, pDef.getDefaultValues().length);
assertEquals("/jcr:path/nt:value", pDef.getDefaultValues()[0].getString());
foundDefaultPath = true;
}
}
assertTrue("Expected property definition with name \"defaultString\"", foundDefaultString);
assertTrue("Expected property definition with name \"defaultPath\"", foundDefaultPath);
} finally {
session.logout();
}
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit-oak by apache.
the class RepositoryUpgradeTest method createSourceContent.
@Override
@SuppressWarnings("unchecked")
protected void createSourceContent(Session session) throws Exception {
JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace();
NamespaceRegistry registry = workspace.getNamespaceRegistry();
registry.registerNamespace("test", "http://www.example.org/");
NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
NodeTypeTemplate template = nodeTypeManager.createNodeTypeTemplate();
template.setName("test:unstructured");
template.setDeclaredSuperTypeNames(new String[] { "nt:unstructured" });
PropertyDefinitionTemplate pDef1 = nodeTypeManager.createPropertyDefinitionTemplate();
pDef1.setName("defaultString");
pDef1.setRequiredType(PropertyType.STRING);
Value stringValue = session.getValueFactory().createValue("stringValue");
pDef1.setDefaultValues(new Value[] { stringValue });
template.getPropertyDefinitionTemplates().add(pDef1);
PropertyDefinitionTemplate pDef2 = nodeTypeManager.createPropertyDefinitionTemplate();
pDef2.setName("defaultPath");
pDef2.setRequiredType(PropertyType.PATH);
Value pathValue = session.getValueFactory().createValue("/jcr:path/nt:value", PropertyType.PATH);
pDef2.setDefaultValues(new Value[] { pathValue });
template.getPropertyDefinitionTemplates().add(pDef2);
nodeTypeManager.registerNodeType(template, false);
template = nodeTypeManager.createNodeTypeTemplate();
template.setName("test:referenceable");
template.setDeclaredSuperTypeNames(new String[] { "nt:unstructured", "mix:referenceable" });
nodeTypeManager.registerNodeType(template, false);
Node root = session.getRootNode();
Node referenceable = root.addNode("referenceable", "test:unstructured");
referenceable.addMixin(NodeType.MIX_REFERENCEABLE);
Node versionable = root.addNode("versionable", NT_UNSTRUCTURED);
versionable.addMixin(MIX_VERSIONABLE);
Node child = versionable.addNode("child", "test:referenceable");
child.addNode("child2", NT_UNSTRUCTURED);
session.save();
Node sns = root.addNode("sns");
sns.addNode("sibling");
sns.addNode("sibling");
sns.addNode("sibling");
session.getWorkspace().getVersionManager().checkin("/versionable");
Node properties = root.addNode("properties", "test:unstructured");
properties.setProperty("boolean", true);
Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream(BINARY));
try {
properties.setProperty("binary", binary);
} finally {
binary.dispose();
}
properties.setProperty("date", DATE);
properties.setProperty("decimal", new BigDecimal(123));
properties.setProperty("double", Math.PI);
properties.setProperty("long", 9876543210L);
properties.setProperty("reference", referenceable);
properties.setProperty("weak_reference", session.getValueFactory().createValue(referenceable, true));
properties.setProperty("mv_reference", new Value[] { session.getValueFactory().createValue(versionable, false) });
properties.setProperty("mv_weak_reference", new Value[] { session.getValueFactory().createValue(versionable, true) });
properties.setProperty("string", "test");
properties.setProperty("multiple", "a,b,c".split(","));
session.save();
binary = properties.getProperty("binary").getBinary();
try {
InputStream stream = binary.getStream();
try {
for (byte aBINARY : BINARY) {
assertEquals(aBINARY, (byte) stream.read());
}
assertEquals(-1, stream.read());
} finally {
stream.close();
}
} finally {
binary.dispose();
}
}
Aggregations