CugImporter implements ProtectedPropertyImporter, CugConstants { @Override public boolean init(@NotNull Session session, @NotNull Root root, @NotNull NamePathMapper namePathMapper, boolean isWorkspaceImport, int uuidBehavior, @NotNull ReferenceChangeTracker referenceTracker, @NotNull SecurityProvider securityProvider) { if (initialized) { throw new IllegalStateException("Already initialized"); } try { ConfigurationParameters config = securityProvider.getConfiguration(AuthorizationConfiguration.class).getParameters(); supportedPaths = CugUtil.getSupportedPaths(config, mountInfoProvider); importBehavior = CugUtil.getImportBehavior(config); if (isWorkspaceImport) { PrincipalConfiguration pConfig = securityProvider.getConfiguration(PrincipalConfiguration.class); principalManager = pConfig.getPrincipalManager(root, namePathMapper); } else { principalManager = ((JackrabbitSession) session).getPrincipalManager(); } initialized = true; } catch (RepositoryException e) { log.warn("Error while initializing cug importer", e); } return initialized; } 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(expected = IllegalStateException.class) public void testInitTwice() { Session session = mock(Session.class); assertTrue(importer.init(session, root, getNamePathMapper(), true, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, new ReferenceChangeTracker(), getSecurityProvider())); importer.init(session, root, getNamePathMapper(), true, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, new ReferenceChangeTracker(), getSecurityProvider()); }
@Test public void testInitFailsToRetrievePrincipalManager() throws Exception { JackrabbitSession s = mock(JackrabbitSession.class); when(s.getPrincipalManager()).thenThrow(new RepositoryException()); assertFalse(importer.init(s, root, getNamePathMapper(), false, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING, new ReferenceChangeTracker(), getSecurityProvider())); }