// FromRDFTest.java
//
// Created: March 2008
//
// Copyright 2008 Martin Senger
//
// 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.biomoby.shared.extended;

import org.biomoby.shared.MobyException;
import org.biomoby.shared.MobyDataType;
import org.biomoby.shared.MobyServiceType;
import org.biomoby.shared.MobyNamespace;
import org.biomoby.shared.MobyService;

import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

public class FromRDFTest {

    private static final String INPUT_DTYPES     = "src/test/junit-resources/dtypes.rdf";
    private static final String INPUT_NAMESPACES = "src/test/junit-resources/namespaces.rdf";
    private static final String INPUT_SERVICES   = "src/test/junit-resources/services.rdf";
    private static final String INPUT_STYPES     = "src/test/junit-resources/stypes.rdf";
 
    /**************************************************************************
     *
     *                              Tests
     *
     **************************************************************************/

    @Test
    public void parseDataTypes()
	throws MobyException {

	DataTypeParser sip =
	    new DataTypeParser ("file:" + INPUT_DTYPES);
	MobyDataType[] result = sip.getMobyDataTypesFromRDF();
	assertEquals (400, result.length);
    }

    @Test
    public void parseServiceTypes()
	throws MobyException {

	ServiceTypeParser sip =
	    new ServiceTypeParser ("file:" + INPUT_STYPES);
	MobyServiceType[] result = sip.getMobyServiceTypesFromRDF();
	assertEquals (111, result.length);
    }

    @Test
    public void parseServices()
	throws MobyException {

	ServiceInstanceParser sip =
	    new ServiceInstanceParser ("file:" + INPUT_SERVICES);
	MobyService[] result = sip.getMobyServicesFromRDF();
	assertEquals (654, result.length);
    }

    @Test
    public void parseNamespaces()
	throws MobyException {

	NamespaceParser sip =
	    new NamespaceParser ("file:" + INPUT_NAMESPACES);
	MobyNamespace[] result = sip.getMobyNamespacesFromRDF();
	assertEquals (384, result.length);
    }


    /**************************************************************************
     *
     *                            Optional parts
     *
     **************************************************************************/

    /**************************************************************************
     * This is to be able to run this JUnit 4 tests with a JUnit 3.x runner.
     **************************************************************************/
    public static junit.framework.Test suite() {
        return new junit.framework.JUnit4TestAdapter (getThisClass());
    }

    /**************************************************************************
     * Run tests from the command line.
     **************************************************************************/
    public static void main (String args[]) {
	org.junit.runner.JUnitCore.main (getThisClassName());
    }

    /**************************************************************************
     * Get the class (name) of this class (note that this is a static
     * method). This madness is here just because I do not want to
     * change the class name in the optional methods above when I copy
     * and paste this into a new test file.
     **************************************************************************/
    private static String getThisClassName() {
	Exception e = new Exception();
	StackTraceElement[] sTrace = e.getStackTrace();
	// sTrace[0] will be always there
	return sTrace[0].getClassName();
    }

    private static Class getThisClass() {
	try {
	    return org.apache.commons.lang.ClassUtils.getClass (getThisClassName());
	} catch (ClassNotFoundException e) {
	    System.err.println ("Cannot get class name.");
	    return java.lang.Object.class;
	}
    }

}
