/** * @throws RepositoryException */ public void testFrozenChildNodeNodeType() throws RepositoryException { versionableNode.addNode("child"); versionableNode.getSession().save(); VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); String path = versionableNode.getPath(); Version v = versionManager.checkin(path); Node n = v.getFrozenNode().getNode("child"); String puuid = n.getProperty(jcrPrimaryType).getValue().getString(); String nuuid = n.getPrimaryNodeType().getName(); assertEquals("jcr:primaryType needs to be equal to the getPrimaryNodeType() return value.", nuuid, puuid); }
public void testCreatePathValue() throws RepositoryException { ValueFactory vf = superuser.getValueFactory(); Value pathValue = vf.createValue("[" +identifier+ "]", PropertyType.PATH); assertEquals(PropertyType.PATH, pathValue.getType()); assertEquals("[" +identifier+ "]", pathValue.getString()); assertFalse(pathValue.equals(vf.createValue(testRootNode.getPath(), PropertyType.PATH))); }
private Object getValue(Value value) throws RepositoryException { switch (value.getType()) { case PropertyType.BOOLEAN: return Boolean.valueOf(value.getBoolean()); case PropertyType.LONG: return Long.valueOf(value.getLong()); case PropertyType.DOUBLE: return Double.valueOf(value.getDouble()); case PropertyType.STRING: default: return value.getString(); } }
/** Wrap JCR Values in a simple way */ private Scriptable wrap(Value value) throws ValueFormatException, IllegalStateException, RepositoryException { Object javaObject; if (value.getType() == PropertyType.REFERENCE) { String nodeUuid = value.getString(); javaObject = node.getSession().getNodeByUUID(nodeUuid); } else { javaObject = toJavaObject(value); } return ScriptRuntime.toObject(this, javaObject); }
/** * @throws RepositoryException */ public void testFrozenNodeNodeType() throws RepositoryException { VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); String path = versionableNode.getPath(); Version v = versionManager.checkin(path); Node n = v.getFrozenNode(); String puuid = n.getProperty(jcrPrimaryType).getValue().getString(); String nuuid = n.getPrimaryNodeType().getName(); assertEquals("jcr:primaryType needs to be equal to the getPrimaryNodeType() return value.", nuuid, puuid); }
/** * @throws RepositoryException */ public void testFrozenChildNodeUUUID() throws RepositoryException { versionableNode.addNode("child"); versionableNode.getSession().save(); VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); String path = versionableNode.getPath(); Version v = versionManager.checkin(path); Node n = v.getFrozenNode().getNode("child"); String puuid = n.getProperty(jcrUUID).getValue().getString(); String nuuid = n.getIdentifier(); assertEquals("jcr:uuid needs to be equal to the getIdentifier() return value.", nuuid, puuid); }
public void testMVReferences() throws RepositoryException { Node ref0 = testRootNode.addNode(nodeName2, testNodeType); ref0.addMixin(mixReferenceable); Node ref1 = testRootNode.addNode(nodeName3, testNodeType); ref1.addMixin(mixReferenceable); superuser.save(); Node n = testRootNode.addNode(nodeName1, testNodeType); Value[] vs = new Value[]{ superuser.getValueFactory().createValue(ref0), superuser.getValueFactory().createValue(ref1) }; n.setProperty("myref", vs); superuser.save(); assertEquals("ref0", ref0.getIdentifier(), n.getProperty("myref").getValues()[0].getString()); assertEquals("ref1", ref1.getIdentifier(), n.getProperty("myref").getValues()[1].getString()); checkReferences("refs", ref0.getReferences(), n.getPath() + "/myref"); checkReferences("refs", ref1.getReferences(), n.getPath() + "/myref"); }
/** * @throws RepositoryException */ public void testFrozenNodeUUUID() throws RepositoryException { VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); String path = versionableNode.getPath(); Version v = versionManager.checkin(path); Node n = v.getFrozenNode(); String puuid = n.getProperty(jcrUUID).getValue().getString(); String nuuid = n.getIdentifier(); assertEquals("jcr:uuid needs to be equal to the getIdentifier() return value.", nuuid, puuid); }
public void testNotNormalizedPathValue() throws RepositoryException { ValueFactory vf = superuser.getValueFactory(); Value pathValue = vf.createValue("/a/../b/./c/dd/..", PropertyType.PATH); Property p = testRootNode.setProperty(propertyName1, pathValue); assertEquals(PropertyType.PATH, p.getType()); assertEquals(pathValue.getString(), p.getValue().getString()); assertEquals(pathValue, p.getValue()); } }
private static boolean hasMixin(Node node, String type) throws RepositoryException { if (!node.hasProperty("jcr:mixinTypes")) { return false; } NodeTypeManager ntMgr = node.getSession().getWorkspace().getNodeTypeManager(); for (Value value : node.getProperty("jcr:mixinTypes").getValues()) { NodeType nt = ntMgr.getNodeType(value.getString()); if (nt.isNodeType(type)) { return true; } } return false; }
public void testMixTitleOnFolder() throws Exception { Node n = testRootNode.addNode("folder", JcrConstants.NT_FOLDER); n.addMixin("mix:title"); superuser.save(); // create jcr:title property with type STRING (converted) => declaring NT is mix:title (and Property title = n.setProperty("jcr:title", 12345); assertEquals(PropertyType.STRING, title.getType()); PropertyDefinition def = title.getDefinition(); assertEquals("mix:title", def.getDeclaringNodeType().getName()); assertEquals(PropertyType.STRING, def.getRequiredType()); // set value to BINARY -> changes value but not definition (binary gets converted) title.setValue(superuser.getValueFactory().createValue("abc", PropertyType.BINARY)); assertEquals(PropertyType.STRING, title.getType()); assertEquals(PropertyType.STRING, title.getValue().getType()); def = title.getDefinition(); assertEquals("mix:title", def.getDeclaringNodeType().getName()); assertEquals(PropertyType.STRING, def.getRequiredType()); superuser.save(); }
private Node getActualNode(Session session, Node node) throws RepositoryException { NodeType type = node.getPrimaryNodeType(); if (type.getName().equals("nt:versionedChild")) { String uuid = node.getProperty("jcr:childVersionHistory").getValue().getString(); Node actualNode = session.getNodeByIdentifier(uuid); String name = actualNode.getName(); actualNode = session.getNodeByIdentifier(name); return actualNode; } return node; }
private Node getActualNode(Session session, Node node) throws RepositoryException { NodeType type = node.getPrimaryNodeType(); if (type.getName().equals("nt:versionedChild")) { String uuid = node.getProperty("jcr:childVersionHistory").getValue().getString(); Node actualNode = session.getNodeByUUID(uuid); String name = actualNode.getName(); actualNode = session.getNodeByUUID(name); return actualNode; } return node; }
@Override public NodeType[] getMixinNodeTypes() throws RepositoryException { Value[] vals = this.node.getProperty("jcr:frozenMixinTypes").getValues(); NodeTypeManager typeMan = getJCRNode().getSession().getWorkspace().getNodeTypeManager(); NodeType[] types = new NodeType[vals.length]; int i = 0; for (Value val : vals) { types[i++] = typeMan.getNodeType(val.getString()); } return types; }
public void test() throws Exception { Node root = superuser.getRootNode(); ValueFactory vf = superuser.getValueFactory(); // store a binary in the data store root.setProperty("p1", vf.createBinary(new RandomInputStream(1, STREAM_LENGTH))); superuser.save(); // read from the binary, but don't close the file Value v1 = root.getProperty("p1").getValue(); InputStream in = v1.getBinary().getStream(); in.read(); // store the same content at a different place - // this will change the last modified date of the file root.setProperty("p2", vf.createBinary(new RandomInputStream(1, STREAM_LENGTH))); superuser.save(); in.close(); }
public void testStringRequiredTypeBoolean() throws Exception { Value stringValue = superuser.getValueFactory().createValue("true", PropertyType.STRING); Property p = node.setProperty(BOOLEAN_PROP_NAME, stringValue); assertEquals(PropertyType.BOOLEAN, p.getType()); assertEquals(PropertyType.BOOLEAN, p.getValue().getType()); assertTrue(p.getBoolean()); PropertyDefinition def = p.getDefinition(); assertEquals(PropertyType.BOOLEAN, def.getRequiredType()); assertEquals(NT_NAME, def.getDeclaringNodeType().getName()); }
public void testRequiredTypeLongChangeBoolean() throws Exception { Property p = node.setProperty(LONG_PROP_NAME, 12345); assertEquals(PropertyType.LONG, p.getType()); assertEquals(PropertyType.LONG, p.getValue().getType()); PropertyDefinition def = p.getDefinition(); assertEquals(PropertyType.LONG, def.getRequiredType()); assertEquals(NT_NAME, def.getDeclaringNodeType().getName()); superuser.save(); try { p.setValue(true); fail("Conversion from BOOLEAN to LONG must throw ValueFormatException"); } catch (ValueFormatException e) { // success } try { node.setProperty(LONG_PROP_NAME, true); fail("Conversion from BOOLEAN to LONG must throw ValueFormatException"); } catch (ValueFormatException e) { // success } }
@Test public void addAlienBinaryProperty() throws RepositoryException, IOException { Session session = getAdminSession(); QValue qValue = QValueFactoryImpl.getInstance().create("binaryValue".getBytes()); Value value = new QValueValue(qValue, new DefaultNamePathResolver(session)); getNode(TEST_PATH).setProperty("binary", value); session.save(); Value valueAgain = getNode(TEST_PATH).getProperty("binary").getValue(); assertEqualStream(value.getBinary().getStream(), valueAgain.getBinary().getStream()); }
protected long getLongProperty(String property) { try { Node theNode = getVersionContentNode(); if ( theNode.hasProperty( property ) ) { Property data = theNode.getProperty( property ); return data.getValue().getLong(); } else { return 0; } } catch ( RepositoryException e ) { throw new RulesRepositoryException( e ); } }