@NotNull private static Tree createTree(@Nullable String ntName) { return createTree(ntName, null, null); }
@NotNull private static Tree createTree(@Nullable String ntName, @Nullable String id) { return createTree(ntName, id, null); }
@Test public void testGetAuthorizableIdWithTypeFallback() { Map<AuthorizableType, String[]> test = ImmutableMap.<AuthorizableType,String[]>builder(). put(AuthorizableType.USER, new String[]{UserConstants.NT_REP_USER, UserConstants.NT_REP_SYSTEM_USER}). put(AuthorizableType.AUTHORIZABLE, new String[]{UserConstants.NT_REP_USER, UserConstants.NT_REP_SYSTEM_USER, UserConstants.NT_REP_GROUP}). put(AuthorizableType.GROUP, new String[]{UserConstants.NT_REP_GROUP}).build(); for (AuthorizableType type : test.keySet()) { for (String ntName : test.get(type)) { assertEquals("nodeName", UserUtil.getAuthorizableId(createTree(ntName, null, "nodeName"), type)); } } }
@Test public void testGetAuthorizableIdWithType() { Map<AuthorizableType, String[]> test = ImmutableMap.<AuthorizableType,String[]>builder(). put(AuthorizableType.USER, new String[] {UserConstants.NT_REP_USER, UserConstants.NT_REP_SYSTEM_USER}). put(AuthorizableType.AUTHORIZABLE, new String[] {UserConstants.NT_REP_USER, UserConstants.NT_REP_SYSTEM_USER, UserConstants.NT_REP_GROUP}). put(AuthorizableType.GROUP, new String[] {UserConstants.NT_REP_GROUP}).build(); for (AuthorizableType type : test.keySet()) { for (String ntName : test.get(type)) { assertEquals("id", UserUtil.getAuthorizableId(createTree(ntName, "id"), type)); } } }
@Test public void testGetTypeFromTree() { Map<String, AuthorizableType> test = ImmutableMap.of( UserConstants.NT_REP_GROUP, AuthorizableType.GROUP, UserConstants.NT_REP_USER, AuthorizableType.USER, UserConstants.NT_REP_SYSTEM_USER, AuthorizableType.USER ); for (String ntName : test.keySet()) { AuthorizableType expected = test.get(ntName); assertEquals(ntName, expected, UserUtil.getType(createTree(ntName))); } }
@Test public void testIsTypeGroupFromTree() { Map<String, Boolean> test = ImmutableMap.of( UserConstants.NT_REP_GROUP, true, UserConstants.NT_REP_USER, false, UserConstants.NT_REP_SYSTEM_USER, false, UserConstants.NT_REP_AUTHORIZABLE, false, JcrConstants.NT_FILE, false ); for (String key : test.keySet()) { assertEquals(test.get(key), UserUtil.isType(createTree(key), AuthorizableType.GROUP)); } }
@Test public void testIsTypeUserFromTree() { Map<String, Boolean> test = ImmutableMap.of( UserConstants.NT_REP_GROUP, false, UserConstants.NT_REP_USER, true, UserConstants.NT_REP_SYSTEM_USER, true, UserConstants.NT_REP_AUTHORIZABLE, false, JcrConstants.NT_FILE, false ); for (String ntName : test.keySet()) { boolean expected = test.get(ntName); assertEquals(ntName, expected, UserUtil.isType(createTree(ntName), AuthorizableType.USER)); } }
@Test public void testIsTypeAuthorizableFromTree() { Map<String, Boolean> test = ImmutableMap.of( UserConstants.NT_REP_GROUP, true, UserConstants.NT_REP_USER, true, UserConstants.NT_REP_SYSTEM_USER, true, UserConstants.NT_REP_AUTHORIZABLE, false, JcrConstants.NT_FILE, false ); for (String ntName : test.keySet()) { boolean expected = test.get(ntName); assertEquals(ntName, expected, UserUtil.isType(createTree(ntName), AuthorizableType.AUTHORIZABLE)); } }
@Test public void testIsSystemUser() { Map<String, Boolean> test = ImmutableMap.of( UserConstants.NT_REP_GROUP, false, UserConstants.NT_REP_USER, false, UserConstants.NT_REP_SYSTEM_USER, true, UserConstants.NT_REP_AUTHORIZABLE, false, JcrConstants.NT_FILE, false ); for (String ntName : test.keySet()) { boolean expected = test.get(ntName); assertEquals(ntName, expected, UserUtil.isSystemUser(createTree(ntName))); } }
@Test(expected=IllegalArgumentException.class) public void testGetAuthorizableIdTypeNotGroup() { UserUtil.getAuthorizableId(createTree(UserConstants.NT_REP_USER, "id"), AuthorizableType.GROUP); }
@Test(expected=IllegalArgumentException.class) public void testGetAuthorizableIdWithTypeNotGrou() { UserUtil.getAuthorizableId(createTree(UserConstants.NT_REP_SYSTEM_USER, "id"), AuthorizableType.GROUP); }
@Test(expected=IllegalArgumentException.class) public void testGetAuthorizableIdWithTypeNotUser() { UserUtil.getAuthorizableId(createTree(UserConstants.NT_REP_GROUP, "id"), AuthorizableType.USER); }
@Test public void testGetAuthorizableId() { List<String> test = ImmutableList.of(UserConstants.NT_REP_GROUP, UserConstants.NT_REP_SYSTEM_USER, UserConstants.NT_REP_USER); for (String ntName : test) { assertEquals("id", UserUtil.getAuthorizableId(createTree(ntName, "id"))); } }
@Test(expected=IllegalArgumentException.class) public void testGetAuthorizableIdTypeNotUser() { UserUtil.getAuthorizableId(createTree(JcrConstants.NT_UNSTRUCTURED, "id"), AuthorizableType.USER); }
@Test public void testGetTypeFromTree2() { List<String> test = ImmutableList.of( UserConstants.NT_REP_AUTHORIZABLE, JcrConstants.NT_FILE ); for (String ntName : test) { assertNull(UserUtil.getType(createTree(ntName))); } }
@Test public void testGetAuthorizableIdNoAuthorizableType() { List<String> test = ImmutableList.of(UserConstants.NT_REP_AUTHORIZABLE, JcrConstants.NT_UNSTRUCTURED); for (String ntName : test) { assertNull(UserUtil.getAuthorizableId(createTree(ntName, "id"))); } }
@Test public void testGetAuthorizableIdFallback() { List<String> test = ImmutableList.of(UserConstants.NT_REP_GROUP, UserConstants.NT_REP_SYSTEM_USER, UserConstants.NT_REP_USER); for (String ntName : test) { assertEquals("nName", UserUtil.getAuthorizableId(createTree(ntName, null, "nName"))); } }