protected void _setReferenced(Node referent, String propertyName, Node referenced) throws RepositoryException { if (referenced != null) { String path = referenced.getPath(); ValueFactory valueFactory = session.getValueFactory(); Value value = valueFactory.createValue(path, PropertyType.PATH); referent.setProperty(propertyName, value); } else { referent.setProperty(propertyName, (String)null); } }
/** * Populates the workspace with child nodes under <code>testroot</code> with * each node has a value set in property with name * <code>propertyname1</code>. The actual value is created by using the * sessions value factory and the given <code>type</code>. * * @param values the String values. * @param type a JCR property type. */ protected void populate(String[] values, int type) throws RepositoryException { for (int i = 0; i < values.length; i++) { Node node = testRootNode.addNode(nodeNames[i], testNodeType); node.setProperty(propertyName1, vf.createValue(values[i], type)); } superuser.save(); }
/** * Tests if adding a property with <code>Node.setProperty(String, * Calendar)</code> works with <code>parentNode.save()</code> */ public void testNewCalendarPropertyParent() throws Exception { testNode.setProperty(propertyName1, c1); testRootNode.getSession().save(); assertEquals("Setting property with Node.setProperty(String, Calendar) and parentNode.save() not working", vf.createValue(c1), testNode.getProperty(propertyName1).getValue()); }
@Test public void addDecimalProperty() throws RepositoryException, IOException { Node parentNode = getNode(TEST_PATH); addProperty(parentNode, "decimal", getAdminSession().getValueFactory().createValue(BigDecimal.valueOf(21))); }
@Test public void literal() throws RepositoryException { Value v = vf.createValue(1); Literal l = f.literal(v); assertEquals(v, l.getLiteralValue()); assertEquals("1", l.toString()); assertEquals("'Joe''s'", f.literal(vf.createValue("Joe's")).toString()); assertEquals("' - \" - '", f.literal(vf.createValue(" - \" - ")).toString()); }
@Test public void setPropertyStringValueInt() throws RepositoryException { // GIVEN Node node = MgnlContext.getJCRSession("website").getRootNode().addNode("test", MgnlNodeType.NT_CONTENT); assertTrue(NodeUtil.isWrappedWith(node, MgnlAuditLoggingContentDecoratorNodeWrapper.class)); // WHEN node.setProperty("test", ValueFactoryImpl.getInstance().createValue("true"), PropertyType.BOOLEAN); // THEN assertEquals(PropertyType.BOOLEAN, node.getProperty("test").getType()); }
protected void setUp() throws Exception { super.setUp(); testNode = testRootNode.addNode(nodeName1, testNodeType); // abort test if the repository does not allow setting // decimal properties on this node ensureCanSetProperty(testNode, propertyName1, testNode.getSession().getValueFactory().createValue(new BigDecimal(0))); }
public void testReferenceLiteral() throws RepositoryException, NotExecutableException { ensureMixinType(node1, mixReferenceable); superuser.save(); Value literal = superuser.getValueFactory().createValue(node1); QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal); checkQOM(qom, new Node[]{}); }
protected void setUp() throws Exception { super.setUp(); // initialize some date value value = superuser.getValueFactory().createValue(GregorianCalendar.getInstance()); // create a new node under the testRootNode node = testRootNode.addNode(nodeName1, testNodeType); // create a new single-value property and save it Calendar initialValue = GregorianCalendar.getInstance(); initialValue.setTimeInMillis(0); property1 = node.setProperty(propertyName1, initialValue); superuser.save(); }
@Test public void addDateProperty() throws RepositoryException, IOException { Node parentNode = getNode(TEST_PATH); addProperty(parentNode, "date", getAdminSession().getValueFactory().createValue(Calendar.getInstance())); }
@Test public void testWriteRestrictions() throws Exception { NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); Set<Restriction> restrictions = ImmutableSet.of( provider.createRestriction("/test","boolean", vf.createValue(true)), provider.createRestriction("/test", "longs"), provider.createRestriction("/test", REP_GLOB, vf.createValue("*")), provider.createRestriction("/test", REP_NT_NAMES, vf.createValue("nt:base", PropertyType.NAME), vf.createValue("nt:version", PropertyType.NAME))); provider.writeRestrictions("/test", aceNode.getTree(), restrictions); }
@Test public void setPropertyStringValueArrayInt() throws RepositoryException { // GIVEN Node node = MgnlContext.getJCRSession("website").getRootNode().addNode("test", MgnlNodeType.NT_CONTENT); assertTrue(NodeUtil.isWrappedWith(node, MgnlAuditLoggingContentDecoratorNodeWrapper.class)); Value[] values = {ValueFactoryImpl.getInstance().createValue("true")}; // WHEN node.setProperty("test", values, PropertyType.BOOLEAN); // THEN assertEquals(PropertyType.BOOLEAN, node.getProperty("test").getType()); }
public void testNameLength() throws RepositoryException { node.setProperty(propertyName1, vf.createValue(node.getName(), PropertyType.NAME)); superuser.save(); checkOperators(propertyName1, node.getProperty(propertyName1).getLength()); }
public void testExtendedNameBasedPathValue() throws RepositoryException { ValueFactory vf = superuser.getValueFactory(); Value pathValue = vf.createValue(Workspace.PATH_VERSION_STORAGE_NODE, PropertyType.PATH); Property p = testRootNode.setProperty(propertyName1, pathValue); assertEquals("/jcr:system/jcr:versionStorage", p.getString()); String path = Workspace.PATH_VERSION_STORAGE_NODE + "/a/b/c/jcr:frozenNode"; pathValue = vf.createValue(path, PropertyType.PATH); p = testRootNode.setProperty(propertyName1, pathValue); assertEquals("/jcr:system/jcr:versionStorage/a/b/c/jcr:frozenNode", p.getString()); }
protected void setUp() throws Exception { super.setUp(); testNode = testRootNode.addNode(nodeName1, testNodeType); // abort test if the repository does not allow setting // double properties on this node ensureCanSetProperty(testNode, propertyName1, testNode.getSession().getValueFactory().createValue(0.0d)); }
public void testWeakReferenceLiteral() throws RepositoryException, NotExecutableException { ensureMixinType(node1, mixReferenceable); superuser.save(); Value literal = superuser.getValueFactory().createValue(node1, true); QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal); checkQOM(qom, new Node[]{}); }
protected void setUp() throws Exception { super.setUp(); // initialize some long value value = superuser.getValueFactory().createValue(73057230); // create a new node under the testRootNode node = testRootNode.addNode(nodeName1, testNodeType); // create a new single-value property and save it property1 = node.setProperty(propertyName1, 0L); superuser.save(); }
@Test public void addLongProperty() throws RepositoryException, IOException { Node parentNode = getNode(TEST_PATH); addProperty(parentNode, "long", getAdminSession().getValueFactory().createValue(42L)); }
@Test public void addProperty() throws Exception { final ValueFactory valueFactory = mock(ValueFactory.class); when(valueFactory.createValue(PROPERTY_VALUE)).thenReturn(new MockValue(PROPERTY_VALUE)); session.setValueFactory(valueFactory); final NodeOperation op = Ops.addProperty(PROPERTY_NAME, PROPERTY_VALUE); op.exec(rootNode, errorHandler); assertThat(rootNode, hasProperty(PROPERTY_NAME, PROPERTY_VALUE)); }
public void testLengthStringLiteral() throws RepositoryException { node.setProperty(propertyName1, "abc"); superuser.save(); String length = String.valueOf(node.getProperty(propertyName1).getLength()); executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length)); }