<commit_before>/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *  
 *    http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License. 
 *  
 */
package org.apache.directory.server.xdbm;


import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertFalse;

import java.io.File;

import org.junit.Before;
import org.junit.Test;


/**
 * Tests the {@link GenericIndex} class.
 *
 * @author <a href="mailto:<EMAIL>">Apache Directory Project</a>
 * @version $Rev$, $Date$
 */
public class GenericIndexTest
{

    GenericIndex<String, Long, Long> index;


    @Before
    public void setUp()
    {
        String tmpDir = System.getProperty( "java.io.tmpdir" );
        index = new GenericIndex<String, Long, Long>( "cn", 42, new File( tmpDir ) );
    }


    @Test
    public void testConstructor1()
    {
        index = new GenericIndex<String, Long, Long>( "cn" );
        assertEquals( "cn", index.getAttributeId() );
        assertEquals( GenericIndex.DEFAULT_INDEX_CACHE_SIZE, index.getCacheSize() );
        assertNull( index.getWkDirPath() );
    }


    @Test
    public void testConstructor2()
    {
        index = new GenericIndex<String, Long, Long>( "cn", 42 );
        assertEquals( "cn", index.getAttributeId() );
        assertEquals( 42, index.getCacheSize() );
        assertNull( index.getWkDirPath() );
    }


    @Test
    public void testConstructor3()
    {
        String tmpDir = System.getProperty( "java.io.tmpdir" );

        index = new GenericIndex<String, Long, Long>( "cn", 42, new File( tmpDir ) );
        assertEquals( "cn", index.getAttributeId() );
        assertEquals( 42, index.getCacheSize() );
        assertNotNull( index.getWkDirPath() );
        assertEquals( tmpDir, index.getWkDirPath().getPath() );
    }


    @Test
    public void testSetGetAttributeId()
    {
        index.setAttributeId( "sn" );
        assertEquals( "sn", index.getAttributeId() );
        index.setAttributeId( null );
        assertNull( index.getAttributeId() );
    }


    @Test
    public void testSetGetCacheSize()
    {
        index.setCacheSize( 0 );
        assertEquals( 0, index.getCacheSize() );
        index.setCacheSize( Integer.MAX_VALUE );
        assertEquals( Integer.MAX_VALUE, index.getCacheSize() );
        index.setCacheSize( Integer.MIN_VALUE );
        assertEquals( Integer.MIN_VALUE, index.getCacheSize() );
    }


    @Test
    public void testSetGetWkDirPath()
    {
        String tmpDir = System.getProperty( "java.io.tmpdir" );
        String zzzDir = tmpDir + File.separator + "zzz";

        index.setWkDirPath( new File( zzzDir ) );
        assertNotNull( index.getWkDirPath() );
        assertEquals( zzzDir, index.getWkDirPath().getPath() );
        index.setWkDirPath( null );
        assertNull( index.getWkDirPath() );
    }


    @Test(expected = UnsupportedOperationException.class)
    public void testAdd() throws Exception
    {
        index.add( "test", 5L );
    }


    @Test(expected = UnsupportedOperationException.class)
    public void testClose() throws Exception
    {
        index.close();
    }


    @Test(expected = UnsupportedOperationException.class)
    public void testCount() throws Exception
    {
        index.count();<commit_msg>Fixed tests on Windows.<commit_after>/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *  
 *    http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License. 
 *  
 */
package org.apache.directory.server.xdbm;


import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertFalse;

import java.io.File;

import org.junit.Before;
import org.junit.Test;


/**
 * Tests the {@link GenericIndex} class.
 *
 * @author <a href="mailto:<EMAIL>">Apache Directory Project</a>
 * @version $Rev$, $Date$
 */
public class GenericIndexTest
{

    GenericIndex<String, Long, Long> index;


    @Before
    public void setUp()
    {
        String tmpDir = System.getProperty( "java.io.tmpdir" );
        index = new GenericIndex<String, Long, Long>( "cn", 42, new File( tmpDir ) );
    }


    @Test
    public void testConstructor1()
    {
        index = new GenericIndex<String, Long, Long>( "cn" );
        assertEquals( "cn", index.getAttributeId() );
        assertEquals( GenericIndex.DEFAULT_INDEX_CACHE_SIZE, index.getCacheSize() );
        assertNull( index.getWkDirPath() );
    }


    @Test
    public void testConstructor2()
    {
        index = new GenericIndex<String, Long, Long>( "cn", 42 );
        assertEquals( "cn", index.getAttributeId() );
        assertEquals( 42, index.getCacheSize() );
        assertNull( index.getWkDirPath() );
    }


    @Test
    public void testConstructor3()
    {
        File tmpDir = new File(System.getProperty( "java.io.tmpdir" ));

        index = new GenericIndex<String, Long, Long>( "cn", 42, tmpDir );
        assertEquals( "cn", index.getAttributeId() );
        assertEquals( 42, index.getCacheSize() );
        assertNotNull( index.getWkDirPath() );
        assertEquals( tmpDir.getPath(), index.getWkDirPath().getPath() );
    }


    @Test
    public void testSetGetAttributeId()
    {
        index.setAttributeId( "sn" );
        assertEquals( "sn", index.getAttributeId() );
        index.setAttributeId( null );
        assertNull( index.getAttributeId() );
    }


    @Test
    public void testSetGetCacheSize()
    {
        index.setCacheSize( 0 );
        assertEquals( 0, index.getCacheSize() );
        index.setCacheSize( Integer.MAX_VALUE );
        assertEquals( Integer.MAX_VALUE, index.getCacheSize() );
        index.setCacheSize( Integer.MIN_VALUE );
        assertEquals( Integer.MIN_VALUE, index.getCacheSize() );
    }


    @Test
    public void testSetGetWkDirPath()
    {
        File tmpDir = new File( System.getProperty( "java.io.tmpdir" ));
        File zzzDir = new File( tmpDir, "zzz"  );

        index.setWkDirPath( zzzDir );
        assertNotNull( index.getWkDirPath() );
        assertEquals( zzzDir.getPath(), index.getWkDirPath().getPath() );
        index.setWkDirPath( null );
        assertNull( index.getWkDirPath() );
    }


    @Test(expected = UnsupportedOperationException.class)
    public void testAdd() throws Exception
    {
        index.add( "test", 5L );
    }


    @Test(expected = UnsupportedOperationException.class)
    public void testClose() throws Exception
    {
        index.close();
    }


    @Test(expected = UnsupportedOperationException.class)
    public void testCount() throws Exception
    {
        index.count();
{'fraction_non_alphanumeric': 0.11145320197044335, 'fraction_numerical': 0.0049261083743842365, 'mean_word_length': 2.934593023255814, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6443399', 'n_tokens_mistral': 2364, 'n_tokens_neox': 2306, 'n_words': 644}