/*
 * Copyright 2004-2009 the original author or authors.
 * 
 * Licensed 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.compass.core.test.engine;

import org.compass.core.Compass;
import org.compass.core.config.RuntimeCompassSettings;
import org.compass.core.converter.DefaultConverterLookup;
import org.compass.core.engine.SearchEngine;
import org.compass.core.engine.SearchEngineFactory;
import org.compass.core.engine.naming.StaticPropertyNamingStrategy;
import org.compass.core.executor.DefaultExecutorManager;
import org.compass.core.executor.ExecutorManager;
import org.compass.core.impl.DefaultCompass;
import org.compass.core.lucene.engine.LuceneSearchEngine;
import org.compass.core.lucene.engine.LuceneSearchEngineFactory;
import org.compass.core.metadata.impl.DefaultCompassMetaData;

/**
 * @author kimchy
 */
public abstract class AbstractSearchEngineTests extends AbstractEngineTests {

    private SearchEngine searchEngine;

    private SearchEngineFactory searchEngineFactory;

    // we have it here for transactional settings
    protected Compass compass;

    public SearchEngine getSearchEngine() {
        return this.searchEngine;
    }

    public SearchEngineFactory getSearchEngineFactory() {
        return searchEngineFactory;
    }

    public LuceneSearchEngine getLuceneSearchEngine() {
        return (LuceneSearchEngine) getSearchEngine();
    }

    protected void setUp() throws Exception {
        super.setUp();
        this.searchEngineFactory = createSearchEngineFactory();
        this.compass = new DefaultCompass(getMapping(), new DefaultConverterLookup(), new DefaultCompassMetaData(),
                new StaticPropertyNamingStrategy(), getSettings(), (LuceneSearchEngineFactory) searchEngineFactory);
        this.searchEngine = searchEngineFactory.openSearchEngine(new RuntimeCompassSettings(compass.getSettings()));
    }

    public SearchEngine createNewSearchEngine() {
        return searchEngineFactory.openSearchEngine(new RuntimeCompassSettings(compass.getSettings()));
    }

    protected void tearDown() throws Exception {
        searchEngine.close();
        compass.close();
        searchEngineFactory.getIndexManager().deleteIndex();
        super.tearDown();
    }

    protected abstract SearchEngineFactory createSearchEngineFactory();

    protected ExecutorManager createExecutorManager() {
        DefaultExecutorManager executorManager = new DefaultExecutorManager();
        executorManager.configure(getSettings());
        return executorManager;
    }
}

@@ -1304,16 +1304,65 @@
 etaData;
+%0Aimport org.compass.core.util.FileHandlerMonitor;
 %0A%0A/**%0A *
@@ -1554,16 +1554,68 @@
 ctory;%0A%0A
+    private FileHandlerMonitor fileHandlerMonitor;%0A%0A
     // w
@@ -2358,16 +2358,148 @@
 ctory);%0A
+        this.fileHandlerMonitor = FileHandlerMonitor.getFileHandlerMonitor(compass);%0A        fileHandlerMonitor.verifyNoHandlers();%0A
         
@@ -2871,32 +2871,32 @@
 ompass.close();%0A
-
         searchEn
@@ -2936,24 +2936,71 @@
 eteIndex();%0A
+        fileHandlerMonitor.verifyNoHandlers();%0A
         supe

verify file handlers in search engine tests as well