CugImporter implements ProtectedPropertyImporter, CugConstants { @Override public boolean handlePropInfo(@NotNull Tree parent, @NotNull PropInfo protectedPropInfo, @NotNull PropertyDefinition def) { if (CugUtil.definesCug(parent) && isValid(protectedPropInfo, def) && CugUtil.isSupportedPath(parent.getPath(), supportedPaths)) { Set<String> principalNames = new HashSet<>(); for (TextValue txtValue : protectedPropInfo.getTextValues()) { String principalName = txtValue.getString(); Principal principal = principalManager.getPrincipal(principalName); if (principal == null) { switch (importBehavior) { case ImportBehavior.IGNORE: log.debug("Ignoring unknown principal with name '{}'.", principalName); break; case ImportBehavior.BESTEFFORT: log.debug("Importing unknown principal '{}'", principalName); principalNames.add(principalName); break; default: throw new AccessControlException("Unknown principal '" + principalName + "'."); } } else { principalNames.add(principalName); } } parent.setProperty(REP_PRINCIPAL_NAMES, principalNames, Type.STRINGS); return true; } else { return false; } } CugImporter(@NotNull MountInfoProvider mountInfoProvider); @Override boolean init(@NotNull Session session, @NotNull Root root, @NotNull NamePathMapper namePathMapper, boolean isWorkspaceImport, int uuidBehavior, @NotNull ReferenceChangeTracker referenceTracker, @NotNull SecurityProvider securityProvider); @Override void processReferences(); @Override boolean handlePropInfo(@NotNull Tree parent, @NotNull PropInfo protectedPropInfo, @NotNull PropertyDefinition def); @Override void propertiesCompleted(@NotNull Tree protectedParent);  }
@Test public void testHandlePropertyNonCugParent() throws Exception { createCug(root, SUPPORTED_PATH, "principalName"); Tree nonCugParent = root.getTree(SUPPORTED_PATH); assertFalse(importer.handlePropInfo(nonCugParent, mock(PropInfo.class), mock(PropertyDefinition.class))); }
@Test public void testHandlePropertyUnsupportedNamePropInfo() throws Exception { createCug(root, SUPPORTED_PATH, "principalName"); Tree cugParent = root.getTree(SUPPORTED_PATH).getChild(REP_CUG_POLICY); PropInfo propInfo = when(mock(PropInfo.class).getName()).thenReturn("unsupportedPropName").getMock(); assertFalse(importer.handlePropInfo(cugParent, propInfo, mock(PropertyDefinition.class))); }
@Test public void testHandlePropertySingleValuePropDef() throws Exception { createCug(root, SUPPORTED_PATH, "principalName"); Tree cugParent = root.getTree(SUPPORTED_PATH).getChild(REP_CUG_POLICY); PropInfo propInfo = when(mock(PropInfo.class).getName()).thenReturn(REP_PRINCIPAL_NAMES).getMock(); PropertyDefinition propDef = when(mock(PropertyDefinition.class).isMultiple()).thenReturn(false).getMock(); assertFalse(importer.handlePropInfo(cugParent, propInfo, propDef)); }
@Test public void testHandlePropertyPropDefWithWrongDeclaringNt() throws Exception { createCug(root, SUPPORTED_PATH, "principalName"); Tree cugParent = root.getTree(SUPPORTED_PATH).getChild(REP_CUG_POLICY); PropInfo propInfo = when(mock(PropInfo.class).getName()).thenReturn(REP_PRINCIPAL_NAMES).getMock(); NodeType nt = when(mock(NodeType.class).getName()).thenReturn(NodeTypeConstants.NT_UNSTRUCTURED).getMock(); PropertyDefinition propDef = mock(PropertyDefinition.class); when(propDef.isMultiple()).thenReturn(true); when(propDef.getDeclaringNodeType()).thenReturn(nt); assertFalse(importer.handlePropInfo(cugParent, propInfo, propDef)); }