package com.ibm.emb.test;

import javax.emb.MediaConverterSpec;
import javax.emb.MediaException;

import junit.framework.Test;
import junit.framework.TestSuite;

import com.ibm.emb.junit.EMBStaticHelper;
import com.ibm.emb.junit.EMBTestCaseBase;

/**
 * <pre>
 * 
 *  Line Item: MFB API 
 *  Subcategory 1: javax.emb
 *  Subcategory 2: MediaConverterSpec
 *  
 *  This abstract class provides test methods for all Methods described in the interface 
 *  MediaConverterSpec. 
 *  For testing implementations of this interface one needs to create a Tester
 *  class which extends this abstract class.
 *  
 * </pre>
 */
public abstract class MediaConverterSpecTest extends EMBTestCaseBase {

    public MediaConverterSpecTest(String name) throws MediaException {
        super(name);
    }

    /**
     * stdSuite method of this test class instantiates all tests necesssary to
     * for the standard compliance tests
     * @param String complete class Name of the implementor of the abstract test
     */
    public static Test stdSuite(String TestCaseImplementor) {
        TestSuite suite = new TestSuite(TestCaseImplementor);
        try {
            Class implementorClass = Class.forName(TestCaseImplementor);
            java.lang.reflect.Constructor implementorConstructor = implementorClass
                    .getDeclaredConstructor(new Class[] {String.class});
            suite.addTest((Test) implementorConstructor.newInstance(new String[] {"testEMB041"}));
            suite.addTest((Test) implementorConstructor.newInstance(new String[] {"testEMB042"}));
            suite.addTest((Test) implementorConstructor.newInstance(new String[] {"testEMB043"}));
        } catch (java.lang.reflect.InvocationTargetException ex) {
            String msg = "error dynamically creating " + TestCaseImplementor + " " + ex.toString();
            EMBStaticHelper.testTrace(msg);
            throw new RuntimeException(msg);
        } catch (ClassNotFoundException ex) {
            String msg = "Class not found " + TestCaseImplementor + " " + ex.toString();
            EMBStaticHelper.testTrace(msg);
            throw new RuntimeException(msg);
        } catch (NoSuchMethodException ex) {
            String msg = "No such method in " + TestCaseImplementor + " " + ex.toString();
            EMBStaticHelper.testTrace(msg);
            throw new RuntimeException(msg);
        } catch (InstantiationException ex) {
            String msg = TestCaseImplementor + " " + ex.toString();
            EMBStaticHelper.testTrace(msg);
            throw new RuntimeException(msg);
        } catch (IllegalAccessException ex) {
            String msg = TestCaseImplementor + " " + ex.toString();
            EMBStaticHelper.testTrace(msg);
            throw new RuntimeException(msg);
        }
        return suite;
    }

    /**
     * abstract method to create an instance of MediaConverterSpec this method
     * needs to be implemented in the test subclass and will create an Instance
     * of the concrete implementation of the class under test
     */
    public abstract MediaConverterSpec createMediaConverterSpec();

    /**
     * <pre>
     * 
     *  Testcase Name: getConverter()
     *  Testcase Number: EMB041
     *  
     *  setup:
     *  
     *  test procedure:  
     *  1.call getConverter()
     *    expected result: not null and instance of MediaConverter
     *  
     * </pre>
     */
    public void testEMB041() {
        //
        // test 1
        //
        MediaConverterSpec testInstance = createMediaConverterSpec();
        assertNotNull("test1 : ", testInstance);
        testTrace("test 1 passed");

        succeed();
    }

    /**
     * <pre>
     * 
     *  Testcase Name: getTargetFileExtension() {
     *  Testcase Number: EMB042
     *  
     *  setup:
     *  
     *  test procedure:
     *  1.call getTargetFileExtension
     *    expected result: return string without separator characters
     *  
     * </pre>
     */
    public void testEMB042() {
        //
        // test 1
        // 
        MediaConverterSpec testInstance = createMediaConverterSpec();
        String fileExt = testInstance.getTargetFileExtension();
        if (fileExt != null) {
            assertEquals("test 1: ", -1, fileExt.indexOf('\\'));
            assertEquals("test 1: ", -1, fileExt.indexOf('/'));
            assertEquals("test 1: ", -1, fileExt.indexOf(':'));
            assertEquals("test 1: ", -1, fileExt.indexOf(';'));
            assertEquals("test 1: ", -1, fileExt.indexOf('.'));
        }

        testTrace("test 1 passed");
        succeed();
    }

    /**
     * <pre>
     * 
     *  Testcase Name: getTargetMimeType()
     *  Testcase Number: EMB043
     *  
     *  setup:
     *  
     *  test procedure:
     *  1.create MediaConverterSpec testInstance and call getTargetMimeType
     *    expected result: string or null
     *  
     * </pre>
     */
    public void testEMB043() {
        //
        // test 1
        //
        MediaConverterSpec testInstance = createMediaConverterSpec();
        assertTrue("test 1: ", testInstance.getTargetMimeType() != "");
        testTrace("test 1 passed");
        succeed();
    }

}