UserUtil implements UserConstants { @Nullable public static String getAuthorizableId(@NotNull Tree authorizableTree) { checkNotNull(authorizableTree); if (UserUtil.isType(authorizableTree, AuthorizableType.AUTHORIZABLE)) { PropertyState idProp = authorizableTree.getProperty(UserConstants.REP_AUTHORIZABLE_ID); if (idProp != null) { return idProp.getValue(STRING); } else { return Text.unescapeIllegalJcrChars(authorizableTree.getName()); } } return null; } private  UserUtil(); static boolean isAdmin(@NotNull ConfigurationParameters parameters, @NotNull String userId); @NotNull static String getAdminId(@NotNull ConfigurationParameters parameters); @NotNull static String getAnonymousId(@NotNull ConfigurationParameters parameters); static boolean isType(@Nullable Tree authorizableTree, @NotNull AuthorizableType type); @Nullable static AuthorizableType getType(@NotNull Tree authorizableNode); @Nullable static AuthorizableType getType(@Nullable String primaryTypeName); static boolean isSystemUser(@Nullable Tree authorizableTree); @Nullable static String getAuthorizableRootPath(@NotNull ConfigurationParameters parameters,
                                                 @Nullable AuthorizableType type); @Nullable static String getAuthorizableId(@NotNull Tree authorizableTree); @NotNull static String getAuthorizableId(@NotNull Tree authorizableTree, @NotNull AuthorizableType type); @Nullable static T castAuthorizable(@Nullable Authorizable authorizable, Class<T> authorizableClass); static int getImportBehavior(@NotNull ConfigurationParameters config);  }
@Test(expected = NullPointerException.class) public void testGetAuthorizableIdNullTree() { UserUtil.getAuthorizableId(null); }
@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 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"))); } }
@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 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 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(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(expected=IllegalArgumentException.class) public void testGetAuthorizableIdTypeNotUser() { UserUtil.getAuthorizableId(createTree(JcrConstants.NT_UNSTRUCTURED, "id"), AuthorizableType.USER); }