UserContext implements Context, UserConstants { @Override public boolean definesProperty(@NotNull Tree parent, @NotNull PropertyState property) { String propName = property.getName(); String ntName = TreeUtil.getPrimaryTypeName(parent); if (NT_REP_USER.equals(ntName) || NT_REP_SYSTEM_USER.equals(ntName)) { return USER_PROPERTY_NAMES.contains(propName); } else if (NT_REP_GROUP.equals(ntName)) { return GROUP_PROPERTY_NAMES.contains(propName); } else if (NT_REP_PASSWORD.equals(ntName)) { return PWD_PROPERTY_NAMES.contains(propName); } else if (NT_REP_MEMBER_REFERENCES.equals(ntName)) { return REP_MEMBERS.equals(propName); } else return NT_REP_MEMBERS.equals(ntName); } private  UserContext(); @Override boolean definesProperty(@NotNull Tree parent, @NotNull PropertyState property); @Override boolean definesContextRoot(@NotNull Tree tree); @Override boolean definesTree(@NotNull Tree tree); @Override boolean definesLocation(@NotNull TreeLocation location); @Override boolean definesInternal(@NotNull Tree tree);  }
@Test public void testDefinesUserProperty() { Set<String> propNames = Sets.newHashSet(USER_PROPERTY_NAMES); propNames.removeAll(GROUP_PROPERTY_NAMES); for (String propName : propNames) { PropertyState property = PropertyStates.createProperty(propName, "value"); assertTrue(ctx.definesProperty(mockTree("nodeName", NT_REP_USER), property)); assertTrue(ctx.definesProperty(mockTree("nodeName", NT_REP_SYSTEM_USER), property)); assertFalse(ctx.definesProperty(mockTree("nodeName", NT_REP_GROUP), property)); } }
@Test public void testDefinesGroupProperty() { Set<String> propNames = Sets.newHashSet(GROUP_PROPERTY_NAMES); propNames.removeAll(USER_PROPERTY_NAMES); for (String propName : propNames) { PropertyState property = PropertyStates.createProperty(propName, "value"); assertFalse(ctx.definesProperty(mockTree("nodeName", NT_REP_USER), property)); assertFalse(ctx.definesProperty(mockTree("nodeName", NT_REP_SYSTEM_USER), property)); assertTrue(ctx.definesProperty(mockTree("nodeName", NT_REP_GROUP), property)); } }
@Test public void testDefinesAuthorizableProperty() { for (String propName : new String[] {REP_AUTHORIZABLE_ID, REP_PRINCIPAL_NAME}) { PropertyState property = PropertyStates.createProperty(propName, "value"); assertTrue(ctx.definesProperty(mockTree("nodeName", NT_REP_USER), property)); assertTrue(ctx.definesProperty(mockTree("nodeName", NT_REP_SYSTEM_USER), property)); assertTrue(ctx.definesProperty(mockTree("nodeName", NT_REP_GROUP), property)); } }
@Test public void testDefinesPasswordNodeProperty() { for (String propName : PWD_PROPERTY_NAMES) { PropertyState property = PropertyStates.createProperty(propName, "value"); assertTrue(ctx.definesProperty(mockTree("nodeName", NT_REP_PASSWORD), property)); assertFalse(ctx.definesProperty(mockTree("nodeName", NT_REP_USER), property)); assertFalse(ctx.definesProperty(mockTree("nodeName", NT_REP_SYSTEM_USER), property)); assertFalse(ctx.definesProperty(mockTree("nodeName", NT_REP_GROUP), property)); } }
@Test public void testDefinesMemberRefProperty() { PropertyState property = PropertyStates.createProperty(REP_MEMBERS, "value"); assertTrue(ctx.definesProperty(mockTree("nodeName", NT_REP_MEMBER_REFERENCES), property)); assertTrue(ctx.definesProperty(mockTree("nodeName", NT_REP_GROUP), property)); assertFalse(ctx.definesProperty(mockTree("nodeName", NT_REP_USER), property)); assertFalse(ctx.definesProperty(mockTree("nodeName", NT_REP_SYSTEM_USER), property)); }
@Test public void testDefinesMemberProperty() { for (String propName : new String[] {"any", "prop"}) { PropertyState property = PropertyStates.createProperty(propName, "value"); assertTrue(ctx.definesProperty(mockTree("nodeName", NT_REP_MEMBERS), property)); assertFalse(ctx.definesProperty(mockTree("nodeName", NT_REP_GROUP), property)); assertFalse(ctx.definesProperty(mockTree("nodeName", NT_REP_USER), property)); assertFalse(ctx.definesProperty(mockTree("nodeName", NT_REP_SYSTEM_USER), property)); } }
@Test public void testNameNotDefinesProperty() { for (String propName : new String[] {"anyName", JcrConstants.JCR_PRIMARYTYPE}) { PropertyState property = PropertyStates.createProperty(propName, "value"); for (String ntName : NT_NAMES) { boolean defines = NT_REP_MEMBERS.equals(ntName); assertEquals(defines, ctx.definesProperty(mockTree("anyName", ntName), property)); } } }
@Test public void testParentNotDefinesProperty() { for (String propName : Iterables.concat(USER_PROPERTY_NAMES, GROUP_PROPERTY_NAMES)) { PropertyState property = PropertyStates.createProperty(propName, "value"); for (String ntName : new String[] {NodeTypeConstants.NT_OAK_UNSTRUCTURED, NT_REP_AUTHORIZABLE_FOLDER}) { assertFalse(ctx.definesProperty(mockTree("anyName", ntName), property)); } } }