/* 
 * QoS Discovery Component
 * Copyright (C) 2006 Sebastian Gerlach
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

package ch.epfl.qosdisc.wsmx;

import org.wsmo.service.*;

import ie.deri.wsmx.discovery.lightweight.LightweightDiscovery;

import java.util.*;

import ch.epfl.qosdisc.operators.Manager;
import ch.epfl.qosdisc.operators.TestFrame;

/**
 * Standalone testing class.
 * 
 * @author Sebastian Gerlach
 */
public class TestStandalone {

    /**
     * A main function for standalone testing.
     * 
     * @param args The command line arguments.
     */
    public static void main(String[] args) {

        // Run the stand-alone test.
        TestFrame tf = new TestFrame(".");
        
        // Load a goal.
        Goal goal = Manager.getGoal(TestFrame.props.getProperty("goal"));

        // Add the services.
        Set<WebService> services = new HashSet<WebService>();
        for(int i = 1;;i++) {
            String sn = TestFrame.props.getProperty("service"+i);
            if(sn == null)
                break;
            services.add((WebService)Manager.getService(sn));
        }
        
        // Do we interface with functional discovery?
        String func = TestFrame.props.getProperty("functional");
        boolean functional = func!=null ? func.equals("true") : false;
        if(functional) {
            try {
                // Add the services to the functional discovery component.
                LightweightDiscovery lwd = new LightweightDiscovery();
                lwd.addWebService(services);
                
                // Perform the functional discovery.
                List<WebService> funcServices = lwd.discover(goal);
                
                // Copy only the remaining services.
                services.clear();
                services.addAll(funcServices);
            } catch(Exception ex) {
                ex.printStackTrace();
            }
        }
        
        // Add the services to the test frame.
        for(WebService s : services)
            tf.addService(s);
        
        // And find the matching services.
        tf.achieveGoal(goal);
    }


}

