Skip to content

Commit

Permalink
JCR-2652 Can no longer set a Date property using a Long value
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/branches/1.6@953623 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Claus Koell committed Jun 11, 2010
1 parent 10f75bf commit 995e128
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Expand Up @@ -19,18 +19,15 @@
import org.apache.commons.collections.map.ReferenceMap;
import org.apache.jackrabbit.core.nodetype.EffectiveNodeType;
import org.apache.jackrabbit.core.nodetype.NodeDef;
import org.apache.jackrabbit.core.nodetype.NodeDefId;
import org.apache.jackrabbit.core.nodetype.NodeDefinitionImpl;
import org.apache.jackrabbit.core.nodetype.NodeTypeConflictException;
import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
import org.apache.jackrabbit.core.nodetype.PropDef;
import org.apache.jackrabbit.core.nodetype.PropDefId;
import org.apache.jackrabbit.core.nodetype.PropertyDefinitionImpl;
import org.apache.jackrabbit.core.security.AccessManager;
import org.apache.jackrabbit.core.state.ItemState;
import org.apache.jackrabbit.core.state.ItemStateException;
import org.apache.jackrabbit.core.state.ItemStateListener;
import org.apache.jackrabbit.core.state.ItemStateManager;
import org.apache.jackrabbit.core.state.NoSuchItemStateException;
import org.apache.jackrabbit.core.state.NodeState;
import org.apache.jackrabbit.core.state.PropertyState;
Expand All @@ -53,8 +50,6 @@
import javax.jcr.PathNotFoundException;
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.PropertyDefinition;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -222,7 +217,7 @@ PropertyDefinitionImpl getDefinition(PropertyState state)
try {
NodeImpl parent = (NodeImpl) getItem(state.getParentId());
return parent.getApplicablePropertyDefinition(
state.getName(), state.getType(), state.isMultiValued(), true);
state.getName(), state.getType(), state.isMultiValued(), false);
} catch (ItemNotFoundException e) {
// parent probably removed, get it from attic
}
Expand Down
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.jackrabbit.core.data;

import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
import org.apache.jackrabbit.test.AbstractJCRTest;

Expand All @@ -26,6 +27,8 @@
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
import javax.jcr.nodetype.ConstraintViolationException;

public class NodeTypeTest extends AbstractJCRTest {

Expand Down Expand Up @@ -67,5 +70,26 @@ public void doTestNodeTypesWithBinaryDefaultValue(int len)
assertEquals(PropertyType.BINARY, value.getType());
assertEquals(def, value.getString());
}

/**
* Tests if it is possible to set a Long Value to a Date property
* @see JCR-2652
*/
public void testSetNonExactTypedPropertyValue() throws RepositoryException {
Node node = testRootNode.addNode("foo", JcrConstants.NT_RESOURCE);
ValueFactory vf = superuser.getValueFactory();
Value value = vf.createValue("1234", 3);
// Attempt to use the LongValue to set a Date property
try {
node.setProperty(JcrConstants.JCR_LASTMODIFIED, value);
// Mandatory Properties will be set for JcrConstants.NT_RESOURCE
node.setProperty(JcrConstants.JCR_DATA, "value");
node.setProperty(JcrConstants.JCR_MIMETYPE, "text/plain");
} catch (ConstraintViolationException e) {
fail("No ConstraintViolation should happen if a LongValue is set to a Date property");
}
superuser.save();
assertNotNull(node.getProperty(JcrConstants.JCR_LASTMODIFIED));
}

}

0 comments on commit 995e128

Please sign in to comment.