Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAK-11000: Test coverage for common JCR operations related to importing content #1622

Open
wants to merge 13 commits into
base: trunk
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
OAK-11000: use constants from java.jcr.Property
  • Loading branch information
reschke committed Aug 7, 2024
commit a4cf43e51df7f30e7289e9c693b5664a5c600dce
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public void setup() throws RepositoryException {
public void jcrMixinCreatedOnNtUnstructured() throws RepositoryException {
Node test = testNode.addNode(TEST_NODE_NAME, NodeType.NT_UNSTRUCTURED);
try {
test.setProperty("jcr:created", false);
test.setProperty(Property.JCR_CREATED, false);
session.save();
test.addMixin(NodeType.MIX_CREATED);
session.save();
assertEquals(false, test.getProperty("jcr:created").getBoolean());
assertEquals(false, test.getProperty(Property.JCR_CREATED).getBoolean());
// in Oak, existing properties are left as-is (even the property
// type), which means that after adding the mixin:created type, the
// state of the node might be inconsistent with the mixin:created
Expand All @@ -98,15 +98,15 @@ public void jcrMixinReferenceableOnNtUnstructuredBeforeSettingMixin() throws Rep
Node test = testNode.addNode(TEST_NODE_NAME, NodeType.NT_UNSTRUCTURED);
try {
String testUuid = UUID.randomUUID().toString();
test.setProperty("jcr:uuid", testUuid);
test.setProperty(Property.JCR_UUID, testUuid);
session.save();
test.addMixin(NodeType.MIX_REFERENCEABLE);
session.save();
// JCR spec
// (https://developer.adobe.com/experience-manager/reference-materials/spec/jcr/2.0/3_Repository_Model.html#3.8%20Referenceable%20Nodes)
// requests an "auto-created" property, so it might be a surprise
// that Oak actually keeps the application-assigned previous value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The algorithm used to create the property value is free to use the existing one and I think that is also the most sane approach, so is it really that surprising?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the spec says "autocreated" :-)

assertEquals(testUuid, test.getProperty("jcr:uuid").getString());
assertEquals(testUuid, test.getProperty(Property.JCR_UUID).getString());
} finally {
test.remove();
session.save();
Expand All @@ -121,8 +121,8 @@ public void jcrMixinReferenceableOnNtUnstructuredBeforeSettingMixinButWithConfli
session.save();

try {
String testUuid = ref.getProperty("jcr:uuid").getString();
test.setProperty("jcr:uuid", testUuid);
String testUuid = ref.getProperty(Property.JCR_UUID).getString();
test.setProperty(Property.JCR_UUID, testUuid);
// note this fails even though test hasn't be set to mix:referenceable
session.save();
fail("Attempt so set a UUID already in use should fail");
Expand All @@ -142,7 +142,7 @@ public void jcrMixinReferenceableOnNtUnstructuredAfterSettingMixin() throws Repo
session.save();
try {
String testUuid = UUID.randomUUID().toString();
test.setProperty("jcr:uuid", testUuid);
test.setProperty(Property.JCR_UUID, testUuid);
session.save();
fail("Setting jcr:uuid after adding mixin:referenceable should fail");
} catch (ConstraintViolationException ex) {
Expand All @@ -160,22 +160,22 @@ public void jcrMixinReferenceableOnNtUnstructuredAfterRemovingMixin() throws Rep
session.save();
try {
// check jcr:uuid is there
String prevUuid = test.getProperty("jcr:uuid").getString();
String prevUuid = test.getProperty(Property.JCR_UUID).getString();
test.removeMixin(NodeType.MIX_REFERENCEABLE);
session.save();
// ist jcr:uuid gone now?
try {
String newUuid = test.getProperty("jcr:uuid").getString();
String newUuid = test.getProperty(Property.JCR_UUID).getString();
fail("jcr:uuid should be gone after removing the mixin type, was " + prevUuid + ", now is " + newUuid);
} catch (PathNotFoundException ex) {
// expected
}
String testUuid = UUID.randomUUID().toString();
test.setProperty("jcr:uuid", testUuid);
test.setProperty(Property.JCR_UUID, testUuid);
session.save();
test.addMixin(NodeType.MIX_REFERENCEABLE);
session.save();
assertEquals(testUuid, test.getProperty("jcr:uuid").getString());
assertEquals(testUuid, test.getProperty(Property.JCR_UUID).getString());
Node check = session.getNodeByIdentifier(testUuid);
assertTrue(test.isSame(check));
} finally {
Expand All @@ -196,7 +196,7 @@ public void jcrMixinReferenceableOnNtUnstructuredAfterRemovingMixinButDanglingRe
try {
test.removeMixin(NodeType.MIX_REFERENCEABLE);
String testUuid = UUID.randomUUID().toString();
test.setProperty("jcr:uuid", testUuid);
test.setProperty(Property.JCR_UUID, testUuid);
session.save();
fail("Changing jcr:uuid causing a dangling refence should fail");
} catch (ReferentialIntegrityException ex) {
Expand All @@ -220,9 +220,9 @@ public void changeUuidOnReferencedNodeWithOnlyMixin() throws RepositoryException
try {
String newUuid = UUID.randomUUID().toString();
updateJcrUuidUsingRemoveMixin(test, newUuid);
assertEquals(newUuid, test.getProperty("jcr:uuid").getString());
assertEquals(newUuid, test.getProperty(Property.JCR_UUID).getString());
session.save();
assertEquals(newUuid, test.getProperty("jcr:uuid").getString());
assertEquals(newUuid, test.getProperty(Property.JCR_UUID).getString());
} finally {
ref.remove();
test.remove();
Expand All @@ -233,7 +233,7 @@ public void changeUuidOnReferencedNodeWithOnlyMixin() throws RepositoryException
@Test
public void changeUuidOnReferencedNodeWithInheritedMixin() throws RepositoryException {
Node test = testNode.addNode(TEST_NODE_NAME, NodeType.NT_RESOURCE);
test.setProperty("jcr:data", session.getValueFactory().createBinary(new ByteArrayInputStream(new byte[0])));
test.setProperty(Property.JCR_DATA, session.getValueFactory().createBinary(new ByteArrayInputStream(new byte[0])));
session.save();
Node ref = testNode.addNode(TEST_NODE_NAME_REF, NodeType.NT_UNSTRUCTURED);
ref.setProperty("reference", test.getIdentifier(), PropertyType.REFERENCE);
Expand All @@ -255,7 +255,7 @@ public void changeUuidOnReferencedNodeWithInheritedMixin() throws RepositoryExce
@Test
public void changeUuidOnReferencedNodeWithInheritedMixinByChangingNodeTypeTemporarily() throws RepositoryException {
Node test = testNode.addNode(TEST_NODE_NAME, NodeType.NT_RESOURCE);
test.setProperty("jcr:data", session.getValueFactory().createBinary(new ByteArrayInputStream(new byte[0])));
test.setProperty(Property.JCR_DATA, session.getValueFactory().createBinary(new ByteArrayInputStream(new byte[0])));
session.save();
Node ref = testNode.addNode(TEST_NODE_NAME_REF, NodeType.NT_UNSTRUCTURED);
ref.setProperty("reference", test.getIdentifier(), PropertyType.REFERENCE);
Expand All @@ -264,10 +264,10 @@ public void changeUuidOnReferencedNodeWithInheritedMixinByChangingNodeTypeTempor
try {
String newUuid = UUID.randomUUID().toString();
updateJcrUuidUsingNodeTypeManager(test, newUuid);
assertEquals(newUuid, test.getProperty("jcr:uuid").getString());
assertEquals(newUuid, test.getProperty(Property.JCR_UUID).getString());
session.save();
session.refresh(false);
assertEquals(newUuid, test.getProperty("jcr:uuid").getString());
assertEquals(newUuid, test.getProperty(Property.JCR_UUID).getString());
} finally {
ref.remove();
test.remove();
Expand All @@ -289,7 +289,7 @@ private static void updateJcrUuidUsingRemoveMixin(Node target, String newUUID) t

// rewrite jcr:uuid
target.removeMixin(NodeType.MIX_REFERENCEABLE);
target.setProperty("jcr:uuid", newUUID);
target.setProperty(Property.JCR_UUID, newUUID);
target.addMixin(NodeType.MIX_REFERENCEABLE);

// restore references
Expand All @@ -316,7 +316,7 @@ private static void updateJcrUuidUsingNodeTypeManager(Node target, String newUUI
// rewrite jcr:uuid
String temporaryType = registerPrimaryTypeExtendingAndUnprotectingJcrUUID(target);
target.setPrimaryType(temporaryType);
target.setProperty("jcr:uuid", newUUID);
target.setProperty(Property.JCR_UUID, newUUID);
target.setPrimaryType(previousType);
unregisterPrimaryTypeExtendingAndUnprotectingJcrUUID(target, temporaryType);

Expand Down Expand Up @@ -360,7 +360,7 @@ private static String registerPrimaryTypeExtendingAndUnprotectingJcrUUID(Node no
unprotectedNTT.setName(tmpNodeTypeName);
unprotectedNTT.setDeclaredSuperTypeNames(new String[] {node.getPrimaryNodeType().getName()});
PropertyDefinitionTemplate pdt = ntMgr.createPropertyDefinitionTemplate();
pdt.setName("jcr:uuid");
pdt.setName(Property.JCR_UUID);
pdt.setProtected(false);
unprotectedNTT.getPropertyDefinitionTemplates().add(pdt);
ntMgr.registerNodeType(unprotectedNTT, true);
Expand Down
Loading