private User createUser(String name, String food, double weight, boolean cute) throws RepositoryException { User user = userMgr.createUser(name, ""); user.setProperty("profile/food", vf.createValue(food)); user.setProperty("profile/weight", vf.createValue(weight)); user.setProperty("profile/cute", vf.createValue(cute)); users.add(user); return user; }
private User createUser(String name, String food, double weight, boolean cute) throws RepositoryException { User user = userMgr.createUser(name, ""); user.setProperty("profile/food", vf.createValue(food)); user.setProperty("profile/weight", vf.createValue(weight)); user.setProperty("profile/cute", vf.createValue(cute)); users.add(user); return user; }
@Test public void testFilterDuplicateResults() throws Exception { user.setProperty(propertyName, v); user.setProperty("rel/path/to/" + propertyName, v); root.commit(); Iterator<Authorizable> result = queryMgr.findAuthorizables(propertyName, v.getString(), AuthorizableType.AUTHORIZABLE, false); assertResultContainsAuthorizables(result, user); }
@Test public void testFindWithCurrentRelPathTypeMismatch() throws Exception { user.setProperty(propertyName, v); root.commit(); Iterator<Authorizable> result = queryMgr.findAuthorizables("./" + propertyName, v.getString(), AuthorizableType.GROUP, false); assertResultContainsAuthorizables(result); }
@Test public void testFindWithCurrentRelPath() throws Exception { user.setProperty(propertyName, v); root.commit(); Iterator<Authorizable> result = queryMgr.findAuthorizables("./" + propertyName, v.getString(), AuthorizableType.USER, false); assertResultContainsAuthorizables(result, user); }
@Test public void testFindWithRelPath() throws Exception { user.setProperty(propertyName, v); root.commit(); Iterator<Authorizable> result = queryMgr.findAuthorizables("rel/path/to/" + propertyName, v.getString(), AuthorizableType.USER, false); assertResultContainsAuthorizables(result); }
@Test public void testFindAuthorizable() throws Exception { user.setProperty("prop", superuser.getValueFactory().createValue(true)); superuser.save(); session.refresh(false); Map<String, String> m = ImmutableMap.of("prop", "true", "my:property", "value", "my:node/my:property2", "value"); for (String relPath : m.keySet()) { String value = m.get(relPath); Iterator<Authorizable> result = getUserManager(session).findAuthorizables(relPath, value); assertTrue(result.hasNext()); assertEquals(user.getID(), result.next().getID()); } }
@Test public void testMultiValueToSingleValue() throws RepositoryException, NotExecutableException { Value v = superuser.getValueFactory().createValue("testValue"); try { user.setProperty("testProperty", new Value[] {v}); superuser.save(); } catch (RepositoryException e) { throw new NotExecutableException("Cannot test 'Authorizable.setProperty'."); } user.setProperty("testProperty", v); Property p = superuser.getProperty(user.getPath() + "/testProperty"); assertFalse(p.isMultiple()); }
@Test public void testSingleValueToMultiValue() throws RepositoryException, NotExecutableException { Value v = superuser.getValueFactory().createValue("testValue"); try { user.setProperty("testProperty", v); superuser.save(); } catch (RepositoryException e) { throw new NotExecutableException("Cannot test 'Authorizable.setProperty'."); } user.setProperty("testProperty", new Value[] {v}); Property p = superuser.getProperty(user.getPath() + "/testProperty"); assertTrue(p.isMultiple()); }
@Test public void testFindWithRelPathMultipleSelectorNames() throws Exception { user.setProperty(propertyName, v); Group g = createGroup("g", null); g.setProperty("rel/path/to/" + propertyName, v); root.commit(); for (AuthorizableType type : new AuthorizableType[] {AuthorizableType.AUTHORIZABLE, AuthorizableType.GROUP}) { Iterator<Authorizable> result = queryMgr.findAuthorizables("rel/path/to/" + propertyName, v.getString(), AuthorizableType.AUTHORIZABLE, false); assertResultContainsAuthorizables(result, g); } }
@Test public void testFindWithRelPathTypeMismatch() throws Exception { user.setProperty(propertyName, v); Group g = createGroup("g", null); g.setProperty("rel/path/to/" + propertyName, v); root.commit(); Iterator<Authorizable> result = queryMgr.findAuthorizables("rel/path/to/" + propertyName, v.getString(), AuthorizableType.USER, false); assertResultContainsAuthorizables(result); }
/** * @since OAK 1.0 */ @Test public void testFindNodesExact() throws Exception { Value vs = valueFactory.createValue("value \\, containing backslash"); user.setProperty(propertyName, vs); root.commit(); Iterator<Authorizable> result = queryMgr.findAuthorizables(propertyName, "value \\, containing backslash", AuthorizableType.USER, true); assertResultContainsAuthorizables(result, user); }
@Test public void testFindNodesNonExact() throws Exception { Value vs = valueFactory.createValue("value \\, containing backslash"); user.setProperty(propertyName, vs); root.commit(); Iterator<Authorizable> result = queryMgr.findAuthorizables(propertyName, "value \\, containing backslash", AuthorizableType.USER, false); assertResultContainsAuthorizables(result, user); }
@Test public void testFindNodesNonExactWithApostrophe() throws Exception { Value vs = valueFactory.createValue("value ' with apostrophe"); user.setProperty(propertyName, vs); root.commit(); Iterator<Authorizable> result = queryMgr.findAuthorizables(propertyName, "value ' with apostrophe", AuthorizableType.USER, false); assertResultContainsAuthorizables(result, user); }
@Test public void testFindNodesExactWithApostrophe() throws Exception { Value vs = valueFactory.createValue("value ' with apostrophe"); user.setProperty(propertyName, vs); root.commit(); Iterator<Authorizable> result = queryMgr.findAuthorizables(propertyName, "value ' with apostrophe", AuthorizableType.USER, true); assertResultContainsAuthorizables(result, user); }
@Test public void testAuthorizable() throws Exception { User u = mgr.createUser("u", "u"); u.setProperty("prop", getValueFactory().createValue("value")); assertFalse(root.hasPendingChanges()); u.setProperty("prop", new Value[] {getValueFactory().createValue(true)}); assertFalse(root.hasPendingChanges()); u.removeProperty("prop"); assertFalse(root.hasPendingChanges()); }
@Test public void testListOrphanedUsersException () throws Exception { User u = getUserManager().createUser(TestIdentityProvider.ID_EXCEPTION, null); u.setProperty(DefaultSyncContext.REP_EXTERNAL_ID, getValueFactory().createValue(new ExternalIdentityRef(TestIdentityProvider.ID_EXCEPTION, idp.getName()).getString())); root.commit(); String[] result = syncMBean.listOrphanedUsers(); assertEquals(0, result.length); }
/** * @see <a href="https://issues.apache.org/jira/browse/OAK-4360">OAK-4360</a> */ @Test public void testSyncUserException() throws Exception { User u = getUserManager().createUser(TestIdentityProvider.ID_EXCEPTION, null); u.setProperty(DefaultSyncContext.REP_EXTERNAL_ID, getValueFactory().createValue(new ExternalIdentityRef(TestIdentityProvider.ID_EXCEPTION, idp.getName()).getString())); root.commit(); String[] result = syncMBean.syncUsers(new String[]{TestIdentityProvider.ID_EXCEPTION}, false); assertResultMessages(result, TestIdentityProvider.ID_EXCEPTION, "ERR"); }
@Test public void testPurgeOrphanedUsersException() throws Exception { User u = getUserManager().createUser(TestIdentityProvider.ID_EXCEPTION, null); u.setProperty(DefaultSyncContext.REP_EXTERNAL_ID, getValueFactory().createValue(new ExternalIdentityRef(TestIdentityProvider.ID_EXCEPTION, idp.getName()).getString())); root.commit(); String[] result = syncMBean.purgeOrphanedUsers(); assertEquals(0, result.length); }
@Test public void testSyncAllUsersException() throws Exception { User u = getUserManager().createUser(TestIdentityProvider.ID_EXCEPTION, null); u.setProperty(DefaultSyncContext.REP_EXTERNAL_ID, getValueFactory().createValue(new ExternalIdentityRef(TestIdentityProvider.ID_EXCEPTION, idp.getName()).getString())); root.commit(); String[] result = syncMBean.syncAllUsers(false); assertResultMessages(result, TestIdentityProvider.ID_EXCEPTION, "ERR"); result = syncMBean.syncAllUsers(true); assertResultMessages(result, TestIdentityProvider.ID_EXCEPTION, "ERR"); }