/*
 * Created on Nov 18, 2004
 * Copyright (C) Andrea Schweer, 2004
 *
 * This file is part of the Greenstone Alerting Service.
 * Refer to the COPYING file in the base directory of this package
 * for licensing information.
 */
package org.greenstone.gsdlas;

import java.net.URL;
import java.util.*;

import junit.framework.TestCase;

/**
 * @author schweer
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ProfileStoreTest extends TestCase {

    public static void main(String[] args) {
        junit.textui.TestRunner.run(ProfileStoreTest.class);
    }

    public final void testAddSubscription() {
        try {
            addSubscriptions();
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }

    public final void testFilter() {
        try {
            addSubscriptions();
            
            URL url = new URL("http://localhost:8080/soap/servlet/rpcrouter");
            GreenstoneCommunicator gsComm = new GreenstoneCommunicator(url);
            
            Map event = new TreeMap();
            
            event.put(Constants.DOCUMENT_ID_FIELD, "20041118:5");
            event.put(Constants.COLLECTION_ID_FIELD, "gs3mgdemo");
            event.put(Constants.HOST_ID_FIELD, "http://localhost:8080/soap/servlet/rpcrouter");
            
            Set result = ProfileStore.getInstance().filter(event, gsComm);
            
            System.out.println(result.size());
            
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }

    private void addSubscriptions() throws Exception {
        Map valueMap = new TreeMap();
        
        valueMap.put(Constants.COLLECTION_ID_FIELD, "gs3mgdemo");
        valueMap.put(Constants.DOCUMENT_CONTENT_FIELD, "Tomatensalat");
        
        addSubscription(valueMap);
        
        valueMap.clear();
        
        valueMap.put(Constants.COLLECTION_ID_FIELD, "gs3mgdemo");
        valueMap.put(Constants.DOCUMENT_CONTENT_FIELD, "Water+Buffalo");
        
        addSubscription(valueMap);
        
        valueMap.clear();
        
        valueMap.put(Constants.COLLECTION_ID_FIELD, "gs3mgdemo");
        valueMap.put(Constants.DOCUMENT_CONTENT_FIELD, "gender+equality");
        
        addSubscription(valueMap);
    }
    
    private void addSubscription(Map valueMap) throws Exception {  
        ProfileStore.getInstance().createSubscription(valueMap);    
    }
    
}
