UniquenessConstraintValidator { public void setSecondStore(PropertyQuery secondStore) { this.secondStore = checkNotNull(secondStore); } UniquenessConstraintValidator(String indexPath, NodeBuilder builder, NodeState rootState); void add(String propertyRelativePath, Set<String> afterKeys); void validate(); void setSecondStore(PropertyQuery secondStore);  }
@Test public void secondStore_SamePath() throws Exception{ defnb.indexRule("nt:base").property("foo").unique(); PropertyIndexUpdateCallback callback = newCallback(); propertyUpdated(callback, "/a", "foo", "bar"); callback.getUniquenessConstraintValidator() .setSecondStore((propertyRelativePath, value) -> singletonList("/a")); callback.done(); }
@Test(expected = CommitFailedException.class) public void secondStore_DiffPath() throws Exception{ defnb.indexRule("nt:base").property("foo").unique(); updateRootState("/b", "foo", "bar"); updateRootState("/a", "foo", "bar"); PropertyIndexUpdateCallback callback = newCallback(); propertyUpdated(callback, "/a", "foo", "bar"); callback.getUniquenessConstraintValidator() .setSecondStore((propertyRelativePath, value) -> singletonList("/b")); callback.done(); }
@Test public void secondStore_NodeNotExist() throws Exception{ defnb.indexRule("nt:base").property("foo").unique(); PropertyIndexUpdateCallback callback = newCallback(); propertyUpdated(callback, "/a", "foo", "bar"); callback.getUniquenessConstraintValidator() .setSecondStore((propertyRelativePath, value) -> singletonList("/b")); callback.done(); }
@Test public void secondStore_NodeExist_PropertyNotExist() throws Exception{ defnb.indexRule("nt:base").property("foo").unique(); NodeBuilder rootBuilder = root.builder(); rootBuilder.child("b"); root = rootBuilder.getNodeState(); PropertyIndexUpdateCallback callback = newCallback(); propertyUpdated(callback, "/a", "foo", "bar"); callback.getUniquenessConstraintValidator() .setSecondStore((propertyRelativePath, value) -> singletonList("/b")); callback.done(); }
@Test public void secondStore_NodeExist_PropertyExist_DifferentValue() throws Exception{ defnb.indexRule("nt:base").property("foo").unique(); NodeBuilder rootBuilder = root.builder(); rootBuilder.child("b").setProperty("foo", "bar2"); root = rootBuilder.getNodeState(); PropertyIndexUpdateCallback callback = newCallback(); propertyUpdated(callback, "/a", "foo", "bar"); callback.getUniquenessConstraintValidator() .setSecondStore((propertyRelativePath, value) -> singletonList("/b")); callback.done(); }
@Test(expected = CommitFailedException.class) public void secondStore_RelativeProperty() throws Exception{ defnb.indexRule("nt:base").property("jcr:content/foo").unique(); updateRootState("/b/jcr:content", "foo", "bar"); updateRootState("/a/jcr:content", "foo", "bar"); PropertyIndexUpdateCallback callback = newCallback(); propertyUpdated(callback, "/a", "jcr:content/foo", "bar"); callback.getUniquenessConstraintValidator() .setSecondStore((propertyRelativePath, value) -> singletonList("/b")); callback.done(); }