CacheValidatorProvider extends ValidatorProvider implements CacheConstants { static Map<String, Object> asCommitAttributes() { return Collections.singletonMap(CommitMarker.KEY, CommitMarker.INSTANCE); } CacheValidatorProvider(@NotNull Set<Principal> principals, @NotNull TreeProvider treeProvider);   }
@Test public void testCreateCacheWithCommitInfo() throws RepositoryException { for (Authorizable a : authorizables) { try { Tree node = getAuthorizableTree(a); Tree cache = TreeUtil.addChild(node, CacheConstants.REP_CACHE, CacheConstants.NT_REP_CACHE); cache.setProperty(CacheConstants.REP_EXPIRATION, 1L, Type.LONG); root.commit(CacheValidatorProvider.asCommitAttributes()); fail("Creating rep:cache node below a user or group must fail."); } catch (CommitFailedException e) { assertTrue(e.isConstraintViolation()); assertEquals(34, e.getCode()); } } }
@Test public void testCreateCacheBelowProfile() throws Exception { try { Tree node = getAuthorizableTree(getTestUser()); Tree child = TreeUtil.addChild(node, "profile", NodeTypeConstants.NT_OAK_UNSTRUCTURED); TreeUtil.addChild(child, CacheConstants.REP_CACHE, CacheConstants.NT_REP_CACHE).setProperty(CacheConstants.REP_EXPIRATION, 23L, Type.LONG); root.commit(CacheValidatorProvider.asCommitAttributes()); fail("Creating rep:cache node below a user or group must fail."); } catch (CommitFailedException e) { assertTrue(e.isConstraintViolation()); assertEquals(34, e.getCode()); } }
@Test public void testCreateCacheBelowPersistedProfile() throws Exception { try { Tree node = getAuthorizableTree(getTestUser()); Tree child = TreeUtil.addChild(node, "profile", NodeTypeConstants.NT_OAK_UNSTRUCTURED); root.commit(); TreeUtil.addChild(child, CacheConstants.REP_CACHE, CacheConstants.NT_REP_CACHE).setProperty(CacheConstants.REP_EXPIRATION, 23L, Type.LONG); root.commit(CacheValidatorProvider.asCommitAttributes()); fail("Creating rep:cache node below a user or group must fail."); } catch (CommitFailedException e) { assertTrue(e.isConstraintViolation()); assertEquals(34, e.getCode()); } }
@Test public void testModifyCache() throws Exception { List<PropertyState> props = new ArrayList<>(); props.add(PropertyStates.createProperty(CacheConstants.REP_EXPIRATION, 25)); props.add(PropertyStates.createProperty(CacheConstants.REP_GROUP_PRINCIPAL_NAMES, EveryonePrincipal.NAME)); props.add(PropertyStates.createProperty(JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED, Type.NAME)); props.add(PropertyStates.createProperty("residualProp", "anyvalue")); Tree cache = getCache(getTestUser()); for (PropertyState prop : props) { try { cache.setProperty(prop); root.commit(CacheValidatorProvider.asCommitAttributes()); fail("Modifying rep:cache node below a user or group must fail."); } catch (CommitFailedException e) { assertTrue(e.isConstraintViolation()); assertEquals(34, e.getCode()); } finally { root.refresh(); } } }
@Test public void testNestedCache() throws Exception { Tree cache = getCache(getTestUser()); try { Tree c = TreeUtil.getOrAddChild(cache, CacheConstants.REP_CACHE, CacheConstants.NT_REP_CACHE); c.setProperty(CacheConstants.REP_EXPIRATION, 223L, Type.LONG); root.commit(CacheValidatorProvider.asCommitAttributes()); fail("Creating nested cache must fail."); } catch (CommitFailedException e) { assertTrue(e.isConstraintViolation()); assertEquals(34, e.getCode()); } }