Package org.apache.directory.server.core.partition.ldif

Examples of org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition


    public void testKerberosServer() throws Exception
    {
        File configDir = new File( workDir, "kerberosServer" ); // could be any directory, cause the config is now in a single file
        String configFile = LdifConfigExtractor.extractSingleFileConfig( configDir, "kerberosServer.ldif", true );

        SingleFileLdifPartition configPartition = new SingleFileLdifPartition( schemaManager );
        configPartition.setId( "config" );
        configPartition.setPartitionPath( new File( configFile ).toURI() );
        configPartition.setSuffixDn( new Dn( "ou=config" ) );
        configPartition.setSchemaManager( schemaManager );

        configPartition.initialize();
        ConfigPartitionReader cpReader = new ConfigPartitionReader( configPartition );

        ConfigBean configBean = cpReader.readConfig( new Dn( schemaManager,
            "ou=servers,ads-directoryServiceId=default,ou=config" ), ConfigSchemaConstants.ADS_KERBEROS_SERVER_OC
            .getValue() );

        assertNotNull( configBean );
        KdcServerBean kdcServerBean = ( KdcServerBean ) configBean.getDirectoryServiceBeans().get( 0 );
        assertNotNull( kdcServerBean );

        configPartition.destroy();
    }
View Full Code Here


    public void testChangePasswordServer() throws Exception
    {
        File configDir = new File( workDir, "changePasswordServer" ); // could be any directory, cause the config is now in a single file
        String configFile = LdifConfigExtractor.extractSingleFileConfig( configDir, "changePasswordServer.ldif", true );

        SingleFileLdifPartition configPartition = new SingleFileLdifPartition( schemaManager );
        configPartition.setId( "config" );
        configPartition.setPartitionPath( new File( configFile ).toURI() );
        configPartition.setSuffixDn( new Dn( "ou=config" ) );
        configPartition.setSchemaManager( schemaManager );

        configPartition.initialize();
        ConfigPartitionReader cpReader = new ConfigPartitionReader( configPartition );

        ConfigBean configBean = cpReader.readConfig( new Dn( schemaManager,
            "ou=servers,ads-directoryServiceId=default,ou=config" ),
            ConfigSchemaConstants.ADS_CHANGE_PASSWORD_SERVER_OC.getValue() );

        assertNotNull( configBean );
        ChangePasswordServerBean changePasswordServerBean = ( ChangePasswordServerBean ) configBean
            .getDirectoryServiceBeans().get( 0 );
        assertNotNull( changePasswordServerBean );

        configPartition.destroy();
    }
View Full Code Here

    public void testLdapServer() throws Exception
    {
        File configDir = new File( workDir, "ldapServer" ); // could be any directory, cause the config is now in a single file
        String configFile = LdifConfigExtractor.extractSingleFileConfig( configDir, "ldapServer.ldif", true );

        SingleFileLdifPartition configPartition = new SingleFileLdifPartition( schemaManager );
        configPartition.setId( "config" );
        configPartition.setPartitionPath( new File( configFile ).toURI() );
        configPartition.setSuffixDn( new Dn( "ou=config" ) );
        configPartition.setSchemaManager( schemaManager );

        configPartition.initialize();
        ConfigPartitionReader cpReader = new ConfigPartitionReader( configPartition );

        ConfigBean configBean = cpReader.readConfig( new Dn( schemaManager,
            "ou=servers,ads-directoryServiceId=default,ou=config" ), ConfigSchemaConstants.ADS_LDAP_SERVER_OC
            .getValue() );

        assertNotNull( configBean );
        LdapServerBean ldapServerBean = ( LdapServerBean ) configBean.getDirectoryServiceBeans().get( 0 );
        assertNotNull( ldapServerBean );

        configPartition.destroy();
    }
View Full Code Here

    public void testChangePasswordServer() throws Exception
    {
        File configDir = new File( workDir, "changePasswordServer" ); // could be any directory, cause the config is now in a single file
        String configFile = LdifConfigExtractor.extractSingleFileConfig( configDir, "changePasswordServer.ldif", true );

        SingleFileLdifPartition configPartition = new SingleFileLdifPartition();
        configPartition.setId( "config" );
        configPartition.setPartitionPath( new File( configFile ).toURI() );
        configPartition.setSuffix( new Dn( "ou=config" ) );
        configPartition.setSchemaManager( schemaManager );
       
        configPartition.initialize();
        ConfigPartitionReader cpReader = new ConfigPartitionReader( configPartition );
       
        ConfigBean configBean = cpReader.readConfig( new Dn( "ou=servers,ads-directoryServiceId=default,ou=config" ), ConfigSchemaConstants.ADS_CHANGE_PASSWORD_SERVER_OC.getValue() );

        assertNotNull( configBean );
        ChangePasswordServerBean changePasswordServerBean = (ChangePasswordServerBean)configBean.getDirectoryServiceBeans().get( 0 );
        assertNotNull( changePasswordServerBean );

        configPartition.destroy();
    }
View Full Code Here

    public void testDhcpServer() throws Exception
    {
        File configDir = new File( workDir, "dhcpServer" ); // could be any directory, cause the config is now in a single file
        String configFile = LdifConfigExtractor.extractSingleFileConfig( configDir, "dhcpServer.ldif", true );

        SingleFileLdifPartition configPartition = new SingleFileLdifPartition();
        configPartition.setId( "config" );
        configPartition.setPartitionPath( new File( configFile ).toURI() );
        configPartition.setSuffix( new Dn( "ou=config" ) );
        configPartition.setSchemaManager( schemaManager );
       
        configPartition.initialize();
        ConfigPartitionReader cpReader = new ConfigPartitionReader( configPartition );
       
        ConfigBean configBean = cpReader.readConfig( new Dn( "ou=servers,ads-directoryServiceId=default,ou=config" ), ConfigSchemaConstants.ADS_DHCP_SERVER_OC.getValue() );

        assertNotNull( configBean );
        DhcpServerBean dhcpServerBean = (DhcpServerBean)configBean.getDirectoryServiceBeans().get( 0 );
        assertNotNull( dhcpServerBean );

        configPartition.destroy();
    }
View Full Code Here

    public void testLdapServer() throws Exception
    {
        File configDir = new File( workDir, "ldapServer" ); // could be any directory, cause the config is now in a single file
        String configFile = LdifConfigExtractor.extractSingleFileConfig( configDir, "ldapServer.ldif", true );

        SingleFileLdifPartition configPartition = new SingleFileLdifPartition();
        configPartition.setId( "config" );
        configPartition.setPartitionPath( new File( configFile ).toURI() );
        configPartition.setSuffix( new Dn( "ou=config" ) );
        configPartition.setSchemaManager( schemaManager );
       
        configPartition.initialize();
        ConfigPartitionReader cpReader = new ConfigPartitionReader( configPartition );
       
        ConfigBean configBean = cpReader.readConfig( new Dn( "ou=servers,ads-directoryServiceId=default,ou=config" ), ConfigSchemaConstants.ADS_LDAP_SERVER_OC.getValue() );

        assertNotNull( configBean );
        LdapServerBean ldapServerBean = (LdapServerBean)configBean.getDirectoryServiceBeans().get( 0 );
        assertNotNull( ldapServerBean );

        configPartition.destroy();
    }
View Full Code Here

    public void testNtpServer() throws Exception
    {
        File configDir = new File( workDir, "ntpServer" ); // could be any directory, cause the config is now in a single file
        String configFile = LdifConfigExtractor.extractSingleFileConfig( configDir, "ntpServer.ldif", true );

        SingleFileLdifPartition configPartition = new SingleFileLdifPartition();
        configPartition.setId( "config" );
        configPartition.setPartitionPath( new File( configFile ).toURI() );
        configPartition.setSuffix( new Dn( "ou=config" ) );
        configPartition.setSchemaManager( schemaManager );
       
        configPartition.initialize();
        ConfigPartitionReader cpReader = new ConfigPartitionReader( configPartition );
       
        ConfigBean configBean = cpReader.readConfig( new Dn( "ou=servers,ads-directoryServiceId=default,ou=config" ), ConfigSchemaConstants.ADS_NTP_SERVER_OC.getValue() );

        assertNotNull( configBean );
        NtpServerBean ntpServerBean = (NtpServerBean)configBean.getDirectoryServiceBeans().get( 0 );
        assertNotNull( ntpServerBean );

        configPartition.destroy();
    }
View Full Code Here

     */
    @Test
    @Ignore("Taking way too much time and very timing dependent")
    public void testConcurrentOperations() throws Exception
    {
        SingleFileLdifPartition partition = injectEntries();

        ThreadGroup tg = new ThreadGroup( "singlefileldifpartitionTG" );
       
        Thread modifyTask = new Thread( tg, getModifyTask( partition ), "modifyTaskThread" );
        Thread addAndDeleteTask = new Thread( tg, getAddAndDeleteTask( partition ), "addAndDeleteTaskThread" );
        Thread renameTask = new Thread( tg, getRenameTask( partition ), "renameTaskThread" );
        Thread moveTask = new Thread( tg, getMoveTask( partition ), "moveTaskThread" );
       
        modifyTask.start();
        addAndDeleteTask.start();
        renameTask.start();
        moveTask.start();
       
        while( tg.activeCount() > 0 )
        {
            Thread.sleep( 2000 );
        }
       
        // tests to be performed after the threads finish their work
        partition = reloadPartition();

        // test the work of modify thread
        LookupOperationContext lookupCtx = new LookupOperationContext( mockSession );
        lookupCtx.setDn( new Dn( "dc=threadDoModify,ou=test,ou=system" ) );

        Entry entry = partition.lookup( lookupCtx );
        assertNotNull( entry );
        assertEquals( "description no 999", entry.get( "description" ).getString() );
        assertExists( partition, contextEntry.getDn().getName() );
        assertExists( partition, "dc=child1,ou=test,ou=system" );
        assertExists( partition, "dc=child2,ou=test,ou=system" );
View Full Code Here

    }


    private SingleFileLdifPartition injectEntries() throws Exception
    {
        SingleFileLdifPartition partition = createPartition( null, true );
        AddOperationContext addCtx = new AddOperationContext( mockSession );
        addCtx.setEntry( contextEntry );

        partition.add( addCtx );

        ClonedServerEntry childEntry1 = createEntry( "dc=child1,ou=test,ou=system" );
        childEntry1.put( "ObjectClass", "top", "domain" );
        childEntry1.put( "dc", "child1" );
        addCtx.setEntry( childEntry1 );

        partition.add( addCtx );

        ClonedServerEntry childEntry2 = createEntry( "dc=child2,ou=test,ou=system" );
        childEntry2.put( "ObjectClass", "top", "domain" );
        childEntry2.put( "dc", "child2" );
        addCtx.setEntry( childEntry2 );

        partition.add( addCtx );

        ClonedServerEntry grandChild11 = createEntry( "dc=grandChild11,dc=child1,ou=test,ou=system" );
        grandChild11.put( "ObjectClass", "top", "domain" );
        grandChild11.put( "dc", "grandChild11" );
        addCtx.setEntry( grandChild11 );

        partition.add( addCtx );

        ClonedServerEntry grandChild12 = createEntry( "dc=grandChild12,dc=child1,ou=test,ou=system" );
        grandChild12.put( "ObjectClass", "top", "domain" );
        grandChild12.put( "dc", "grandChild12" );
        addCtx.setEntry( grandChild12 );

        partition.add( addCtx );

        ClonedServerEntry greatGrandChild111 = createEntry( "dc=greatGrandChild111,dc=grandChild11,dc=child1,ou=test,ou=system" );
        greatGrandChild111.put( "ObjectClass", "top", "domain" );
        greatGrandChild111.put( "dc", "greatGrandChild111" );
        addCtx.setEntry( greatGrandChild111 );

        partition.add( addCtx );

        return partition;
    }
View Full Code Here

        // Extracting of the config file
        File configDir = new File( workDir, "configWriter" ); // could be any directory, cause the config is now in a single file
        String configFile = LdifConfigExtractor.extractSingleFileConfig( configDir, "config.ldif", true );

        // Creating of the config partition
        SingleFileLdifPartition configPartition = new SingleFileLdifPartition();
        configPartition.setId( "config" );
        configPartition.setPartitionPath( new File( configFile ).toURI() );
        configPartition.setSuffix( new Dn( "ou=config" ) );
        configPartition.setSchemaManager( schemaManager );
        configPartition.initialize();

        // Reading the config partition
        ConfigPartitionReader cpReader = new ConfigPartitionReader( configPartition );
        ConfigBean configBean = cpReader.readConfig();
        assertNotNull( configBean );

        // Creating the config writer
        ConfigWriter configWriter = new ConfigWriter( schemaManager, configBean );

        // Reading the original config file
        LdifReader ldifReader = new LdifReader( configFile );
        List<LdifEntry> originalConfigEntries = new ArrayList<LdifEntry>();
        while ( ldifReader.hasNext() )
        {
            originalConfigEntries.add( ldifReader.next() );
        }
        ldifReader.close();

        // Getting the list of entries of generated config
        List<LdifEntry> generatedConfigEntries = configWriter.getConvertedLdifEntries();

        // Comparing the number of entries
        assertEquals( originalConfigEntries.size(), generatedConfigEntries.size() );

        // Comparing each entry in both lists (which have been sorted before)
        Comparator<LdifEntry> dnComparator = new Comparator<LdifEntry>()
        {
            public int compare( LdifEntry o1, LdifEntry o2 )
            {
                return o1.getDn().toString().compareToIgnoreCase( o2.getDn().toString() );
            }
        };
        Collections.sort( originalConfigEntries, dnComparator );
        Collections.sort( generatedConfigEntries, dnComparator );
        for ( int i = 0; i < originalConfigEntries.size(); i++ )
        {
            Entry originalConfigEntry = originalConfigEntries.get( i ).getEntry();
            Entry generatedConfigEntry = generatedConfigEntries.get( i ).getEntry();

            // Comparing DNs
            assertTrue( originalConfigEntry.getDn().getNormName().equals( generatedConfigEntry.getDn().getNormName() ) );
        }

        // Destroying the config partition
        configPartition.destroy();
    }
View Full Code Here

TOP

Related Classes of org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.