package com.ibm.emb.test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Arrays;
import java.util.Date;

import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.ejb.RemoveException;
import javax.emb.GenericMediaFormat;
import javax.emb.ListenerVetoException;
import javax.emb.Media;
import javax.emb.MediaBean;
import javax.emb.MediaConverterSpec;
import javax.emb.MediaException;
import javax.emb.MediaHeader;
import javax.emb.MediaListener;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

import mfb.converters.BmpToJpegConverterSpec;
import mfb.converters.JpegToBmpConverterSpec;

import org.objectweb.jonas.emb.mfb.formats.image.BmpFormat;
import org.objectweb.jonas.emb.mfb.formats.image.JpegFormat;
import org.objectweb.jonas.emb.mfb.formats.playlist.GenericPlaylistFormat;

import com.ibm.emb.junit.ComplexMediaLocationInfo;
import com.ibm.emb.junit.EMBStaticHelper;
import com.ibm.emb.junit.EMBTestCaseBase;
import com.ibm.emb.junit.EmbeddedMediaLocationInfo;
import com.ibm.emb.meb.listener.GenericMediaListener;
import com.ibm.emb.meb.test.ejb.MediaEntityLocalTestDriver;
import com.ibm.emb.meb.test.ejb.MediaEntityLocalTestDriverHome;

/**
 * <pre>
 *
 *  Line Item: MEB API
 *  Subcategory 1: javax.emb
 *  Subcategory 2: MediaEntityLocal
 *
 * </pre>
 */
public class MediaEntityLocalTest extends EMBTestCaseBase {

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

    private static String MEBTESTER_JNDI = "java:comp/env/ejb/MediaEntityLocalTestDriverHome";

    private InitialContext ic;

    private MediaEntityLocalTestDriverHome mebHome = null;

    private MediaEntityLocalTestDriver mebTester = null;

    /**
     * initialization of test case (called before each test method)
     */
    protected void setUp() throws RemoteException, CreateException {
        if (mebHome == null) {
            try {
                ic = new InitialContext();
                Object ojb = ic.lookup(MEBTESTER_JNDI);
                mebHome = (MediaEntityLocalTestDriverHome) PortableRemoteObject.narrow(ojb,
                        MediaEntityLocalTestDriverHome.class);
            } catch (NamingException ne) {
                System.out.println("NamingException thrown during setup. Msg: " + ne.getMessage());
            }
        }
        // create new instance of MediaEntityLocalTestDriver
        mebTester = mebHome.create();
        return;
    }

    /**
     * <pre>
     *
     *  Testcase Name: addListener(MediaListener)
     *  Testcase Number: EMB100
     *
     *  setup:
     *
     *  test procedure:
     *  1.create new media entity me1, call addListener(null)
     *    expected result: NullPointerException
     *
     *  2.create new MediaListener listener1, call addListener(listener1)
     *    expected result: no exception, call getListeners and check if there is only one element
     *
     *  3.create MediaListener listener2, call addListener(listener2)
     *    expected result: no exception, call getListeners and check for two elements
     *
     *  4.call addListener(listener1)
     *    expected result: no exception, call getListeners and check there is still two elements
     *
     * </pre>
     */
    public void testEMB100() throws MediaException, IOException, InterruptedException, Throwable {

        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());

        GenericMediaListener listener1 = new GenericMediaListener("listener1");
        GenericMediaListener listener2 = new GenericMediaListener("listener2");
        MediaListener[] listeners = null;

        int exception = -1;
        //
        // test 1
        //
        try {
            exception = mebTester.addListenerExceptions(me1, null);
        } catch (Throwable e) {
            fail("test 2 threw " + e.toString());
        }
        assertEquals("test 1: Should throw a NullPointerException: " + exception,
                MediaEntityLocalTestDriver.NULLPOINTER, exception);
        testTrace("test 1 passed");
        //
        // test 2
        //
        try {
            mebTester.addMediaEntityListener(me1, listener1);
        } catch (Throwable e) {
            fail("test 2 threw " + e.toString());
        }
        listeners = mebTester.getMediaEntityListeners(me1);
        assertEquals("test 2: listener not added", 1, listeners.length);
        assertTrue("test 2: ", listener1.equals(listeners[0]));
        testTrace("test 2 passed");
        //
        // test 3
        //

        try {
            mebTester.addMediaEntityListener(me1, listener2);
        } catch (Throwable e) {
            fail("test 3 threw " + e.toString());
        }
        listeners = mebTester.getMediaEntityListeners(me1);
        assertEquals("test 3: ", 2, listeners.length);
        assertTrue("test 3: ", listener2.equals(listeners[1]));
        testTrace("test 3 passed");
        //
        // test 4
        //
        try {
            mebTester.addMediaEntityListener(me1, listener1);
        } catch (Throwable e) {
            fail("test 4 threw " + e.toString());
        }
        listeners = mebTester.getMediaEntityListeners(me1);
        assertEquals("test 4: ", 2, listeners.length);
        testTrace("test 4 passed");

        // remove test MEBs
        mebTester.removeMEBByPK(me1);

        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: addMetaData(MetaDataEntityLocal)
     *  Testcase Number: EMB101
     *
     *  setup: create Media entities me1 and me2
     *         create meta data entities md1 and md2
     *
     *  test procedure:
     *  1.call me1.addMetaData(null)
     *    expected result: NullPointerException
     *
     *  2.call me1.addMetaData(md1)
     *    expected result: no exception, call me1.getMetaData and check for one element
     *
     *  3.call me1.addMetaData(md2)
     *    expected result: no exception, call me1.getMetaData and check for two elements
     *
     *  4.call me2.addMetaData(md1)
     *    expected result: no exception, call me1.getMetaData and verify there are two elements
     *  	 call me2.getMetaData and verify there is one element
     *
     * </pre>
     */
    public void testEMB101() throws MediaException, CreateException, NamingException, IOException, FinderException,
            Throwable {

        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName2());

        String me1 = mebTester.createMediaEntityBean();
        String me2 = mebTester.createMediaEntityBean();

        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());

        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());

        String md1 = mebTester.createMetaDataEntityBean();
        String md2 = mebTester.createMetaDataEntityBean();
        String[] metaDataPKs = null;

        int exception = -1;
        //
        // test 1
        //
        try {
            exception = mebTester.addMetaDataExceptions(me1, null);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertEquals("test 1: Should throw a NullPointerException: " + exception,
                MediaEntityLocalTestDriver.NULLPOINTER, exception);
        testTrace("test 1 passed");
        //
        // test 2
        //
        mebTester.addMediaEntityMetaData(me1, md1);
        metaDataPKs = mebTester.getMediaEntityMetaData(me1);
        assertEquals("test 2: meta data not added", 1, metaDataPKs.length);
        assertEquals("test 2: meta data does not match", md1, metaDataPKs[0]);
        testTrace("test 2 passed");
        //
        // test 3
        //
        mebTester.addMediaEntityMetaData(me1, md2);
        metaDataPKs = mebTester.getMediaEntityMetaData(me1);
        assertEquals("test 3: meta data not added", 2, metaDataPKs.length);
        boolean match = false;
        if ((md1.equals(metaDataPKs[0]) && md2.equals(metaDataPKs[1]))
                || (md1.equals(metaDataPKs[1]) && md2.equals(metaDataPKs[0]))) {
            match = true;
        }
        assertTrue("test 3: meta data does not match", match);
        testTrace("test 3 passed");
        //
        // test 4
        //
        mebTester.addMediaEntityMetaData(me2, md1);
        metaDataPKs = mebTester.getMediaEntityMetaData(me2);
        assertEquals("test 4: meta data not added", 1, metaDataPKs.length);
        assertEquals("test 4: meta data does not match", md1, metaDataPKs[0]);
        assertEquals("test 4: meta data removed", 2, mebTester.getMediaEntityMetaData(me1).length);
        testTrace("test 4 passed");

        // remove test MEBs and MDEBs
        mebTester.removeMEBByPK(me1);
        mebTester.removeMEBByPK(me2);
        mebTester.removeMDEBByPK(md1);
        mebTester.removeMDEBByPK(md2);

        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: convert(MediaConverterSpec[])
     *  Testcase Number: EMB102
     *
     *  setup:
     *
     *  test procedure:
     *  1.call convert(null)
     *    expected result: NullPointerException
     *
     *  2.call convert(new MediaConverterSpec[0])
     *    expected result: content unchanged
     *
     *  3.create Media entity from bmp image file and store getLastModified()
     *    create 2 element array of converter specs:
     *  		(1) BmpToJpegConverterSpec
     *  		(2) JpegToBmpConverterSpec
     *    call convert
     *    expected result: media entity is a bmp image that is roughly the same size as original
     *  					  getLastModified() should have changed
     *
     *  4.create Media entity from bmp image file
     *    create 2 element array of converter specs with both being BmpToJpegConverterSpec
     *    call convert
     *    expected result: FormatSyntaxException
     *
     *  5.create Media entity from random content
     *    create 1 element array of converter specs with element being BmpToJpegConverterSpec
     *   call convert
     *    expected result:FormatSyntaxException
     *
     *  6.create Media entity from nonexistent file and create 1 element array of
     *    converter specs with BmpToJpegConverterSpec, call convert
     *    expected result: ContentAccessException
     *
     *  7.create Media entity from jpeg file and create 1 element array of converter specs
     *    with nonexistent converter (i.e. JpegToMpegConverterSpec)
     *    expected result: ConversionException
     *
     *  8.create Media entity from jpeg file
     *    call convert(new MediaConverterSpec[]{null, null})
     *    expected result: ConversionException
     *
     *  9.create Media entity from jpeg file
     *    call convert(new MediaConverterSpec[]{JpegToBmpConverterSpec})
     *    expected result: entity is converted to bmp, check format and file extension changed
     *  					  getLastModified updated
     *
     *  10.create Media entity from bmp file and create instance of Media listener
     *     call me1.addListener(listener)
     *     call convert(new MediaConverterSpec[]{BmpToJpegConverterSPec})
     *     expected result: ListenerVetoException
     *
     *  11.create Media entity and setLocation
     *     call me.convert(new MediaConverterSpec[]{JpegToBmpConverterSpec})
     *     expected result: ContentUnmutableException
     *
     * </pre>
     */
    public void testEMB102() throws MediaException, NamingException, IOException, InterruptedException, Throwable {

        mebTester.bindMediaFormat("jpg", new JpegFormat());
        mebTester.bindMediaFormat("bmp", new BmpFormat());
        mebTester.bindMediaFormat("test", new GenericMediaFormat());

        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getBmpPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        String me2 = mebTester.createMediaEntityBean();

        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());

        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());

        MediaConverterSpec[] mediaConverterSpecArray = null;

        int exception = -1;
        //
        // test 1
        //
        String me8 = mebTester.createMediaEntityBean();
        EmbeddedMediaLocationInfo me8LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        mebTester.setMediaEntityName(me8, me8LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me8, me8LocInfo.getMediaFile());
        try {
            exception = mebTester.convertExceptions(me8, null);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertEquals("test 1: Should throw a NullPointerException: " + exception,
                MediaEntityLocalTestDriver.NULLPOINTER, exception);
        testTrace("test 1 passed");
        //
        // test 2
        //
        // FIX : EMB 102 : no format, no content for me1 ?
        mebTester.convertMediaEntity(me1, new MediaConverterSpec[0]);
        assertTrue("test 2: not instance of JpegFormat", mebTester.getMediaEntityFormat(me1) instanceof JpegFormat);
        assertTrue("test 2: content modified", java.util.Arrays.equals(mebTester.getMediaEntityContent(me1), getByteArrayFromFile(me1LocInfo.getMediaFile())));
        testTrace("test 2 passed");
        //
        // test 3
        //
        Date beforeStamp = new Date(mebTester.getMediaEntityLastModified(me2));
        mediaConverterSpecArray = new MediaConverterSpec[] {new BmpToJpegConverterSpec(), new JpegToBmpConverterSpec()};
        int oldSize = (int) mebTester.getMediaEntitySize(me2);
        mebTester.convertMediaEntity(me2, mediaConverterSpecArray);
        Thread.sleep( 1000);
        Date afterStamp = new Date(mebTester.getMediaEntityLastModified(me2));
        assertTrue("test 3: Modification date", afterStamp.after(beforeStamp));
        assertTrue("test 3: Media entity is not in bmp format",
                mebTester.getMediaEntityFormat(me2) instanceof BmpFormat);
        assertEquals("test 3: wrong file extension", mebTester.getMediaEntityName(me2).substring(
                mebTester.getMediaEntityName(me2).indexOf('.') + 1), "bmp");
        // TODO: EMB 102 : Bmp to JPG then JPG to BMP no size change is not mandatory
        //assertEquals("test 3: new media is not same size as original", oldSize, mebTester.getMediaEntitySize(me2));
        testTrace("test 3 passed");
        //
        // test 4
        //
        mediaConverterSpecArray = new MediaConverterSpec[] {new BmpToJpegConverterSpec(), new BmpToJpegConverterSpec()};
        try {
            exception = mebTester.convertExceptions(me2, mediaConverterSpecArray);
        } catch (Throwable e) {
            fail("test 4 threw " + e.toString());
        }
        assertEquals("test 4: Should throw a MediaFormatException: " + exception,
                MediaEntityLocalTestDriver.MEDIAFORMAT, exception);
        testTrace("test 4 passed");
        //
        // test 5
        //
        String mediaBmpFullPath = embTestConfig.getMediaDir() + File.separatorChar + "Generated" + File.separatorChar + "test.bmp";
        FileOutputStream mediaBmpOutputStream = new FileOutputStream(mediaBmpFullPath);
        mediaBmpOutputStream.write(EMBStaticHelper.createRandomByteArray(1024));
        mediaBmpOutputStream.close();
        String me3 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me3, "test.test");
        mebTester.setMediaEntityContent(me3, new File(mediaBmpFullPath));
        mebTester.setMediaEntityName(me3, "test.bmp");
        mediaConverterSpecArray = new MediaConverterSpec[] {new BmpToJpegConverterSpec()};
        try {
            exception = mebTester.convertExceptions(me3, mediaConverterSpecArray);
        } catch (Throwable e) {
            fail("test 5 threw " + e.toString());
        }
        assertEquals("test 5: Should throw a MediaFormatException: " + exception,
                MediaEntityLocalTestDriver.MEDIAFORMAT, exception);
        testTrace("test 5 passed");
        //
        // test 6
        //
        String me4 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me4, "nonexistentBean.test");
        try {
            exception = mebTester.convertExceptions(me4, mediaConverterSpecArray);
        } catch (Throwable e) {
            fail("test 6 threw " + e.toString());
        }
        assertEquals("test 6: Should throw a ContentAccessException: " + exception,
                MediaEntityLocalTestDriver.CONTENTACCESS, exception);
        testTrace("test 6 passed");
        //
        // test 7
        //
        String me7 = mebTester.createMediaEntityBean();
        //TODO : EMB 102 : JpegToMpegConverterSpec does not exist any more
//        EmbeddedMediaLocationInfo me7LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
//        mebTester.setMediaEntityName(me7, me7LocInfo.getMediaName());
//        mebTester.setMediaEntityContent(me7, me7LocInfo.getMediaFile());
//
//        mediaConverterSpecArray = new MediaConverterSpec[] {new JpegToMpegConverterSpec()};
//        try {
//            exception = mebTester.convertExceptions(me7, mediaConverterSpecArray);
//        } catch (Throwable e) {
//            fail("test 7 threw " + e.toString());
//        }
//        assertEquals("test 7: Should throw a ConversionException: " + exception, MediaEntityLocalTestDriver.CONVERSION,
//                exception);
//        testTrace("test 7 passed");

        //
        // test 8
        //
        mediaConverterSpecArray = new MediaConverterSpec[] {null, null};
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        try {
            exception = mebTester.convertExceptions(me1, mediaConverterSpecArray);
        } catch (Throwable e) {
            fail("test 8 threw " + e.toString());
        }
        assertEquals("test 8: Should throw a ConversionException: " + exception, MediaEntityLocalTestDriver.CONVERSION,
                exception);
        testTrace("test 8 passed");
        //
        // test 9
        //
        mediaConverterSpecArray = new MediaConverterSpec[] {new JpegToBmpConverterSpec()};
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        beforeStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        mebTester.convertMediaEntity(me1, mediaConverterSpecArray);
        Thread.sleep( 1000);
        afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        assertTrue("test 9: Modification date", afterStamp.after(beforeStamp));
        assertTrue("test 9: media format did not change", mebTester.getMediaEntityFormat(me1) instanceof BmpFormat);
        assertEquals("test 9: wrong file extension", mebTester.getMediaEntityName(me1).substring(
                mebTester.getMediaEntityName(me1).indexOf('.') + 1), "bmp");
        testTrace("test 9 passed");
        //
        // test 10
        //
        mediaConverterSpecArray = new MediaConverterSpec[] {new JpegToBmpConverterSpec()};
        EmbeddedMediaLocationInfo me5LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName2());
        String me5 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me5, me5LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me5, me5LocInfo.getMediaFile());
        // add new listener to me5
        GenericMediaListener testListener = new GenericMediaListener();
        mebTester.addMediaEntityListener(me5, testListener);
        try {
            exception = mebTester.convertExceptions(me5, mediaConverterSpecArray);
        } catch (Throwable e) {
            fail("test 10 threw " + e.toString());
        }
        assertEquals("test 10: Should throw a ListenerVetoException", MediaEntityLocalTestDriver.LISTENERVETO,
                exception);
        testTrace("test 10 passed");
        //
        // test 11
        //
        String me6 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me6, me5LocInfo.getMediaName());
        mebTester.setMediaEntityLocation(me6, me5LocInfo.getMediaURL());
        try {
            exception = mebTester.convertExceptions(me6, mediaConverterSpecArray);
        } catch (Throwable e) {
            fail("test 11 threw " + e.toString());
        }
        assertEquals("test 11: Should throw a ContentUnmutableException", MediaEntityLocalTestDriver.CONTENTUNMUTABLE,
                exception);
        testTrace("test 11 passed");

        // remove test MEBs
        mebTester.removeMEBByPK(me1);
        mebTester.removeMEBByPK(me2);
        mebTester.removeMEBByPK(me3);
        mebTester.removeMEBByPK(me4);
        mebTester.removeMEBByPK(me5);
        mebTester.removeMEBByPK(me7);
        mebTester.removeMEBByPK(me8);

        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: exportMedia(URL)
     *  Testcase Number: EMB103
     *
     *  setup:
     *
     *  test procedure:
     *  1.call exportMedia(null)
     *    expected result: media exported to default location which is not null
     *
     *  2.create Media entity from nonexistent file and call exportMedia to valid location
     *    expected result: ContentAccessException
     *
     *  3.call rebind(&quot;jpg&quot;, new JpegFormat())
     *    create Media entity from jpeg file and call exportMedia with valid location
     *    expected result: no exception, access file at new location and verify instance of JpegFormat
     *
     *  4.call rebind(&quot;gpl&quot;, new GenericPlaylistFormat())
     *    create Media entity from playlist and call exportMedia with valid location
     *    expected result: no exception, access file at new location and verify instance of GenericPlaylistFormat
     *
     * </pre>
     */
    public void testEMB103() throws MediaException, IOException, CreateException, RemoteException, NamingException,
            FinderException, RemoveException {

        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());

        mebTester.bindMediaFormat("jpg", new JpegFormat());
        mebTester.bindMediaFormat("gpl", new GenericPlaylistFormat());
        mebTester.bindMediaFormat("tmp", new GenericMediaFormat());
        int exception = -1;
        URL returnedLoc = null;
        //
        // test 1
        //
        returnedLoc = mebTester.exportMediaEntity(me1, null);
        assertNotNull("test 1: location is null", returnedLoc);
        testTrace("test 1 passed");
        //
        // test 2
        //
        String me2 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me2, "nonexistentBean.tmp");
        String targetDirectory = embTestConfig.getMediaDir() + File.separatorChar + "export";

        // remove C:
        //URL targetLocation = new URL("file", embTestConfig.getTestClientIPAddress(), "/C:" + targetDirectory);
        URL targetLocation = new URL("file", embTestConfig.getTestClientIPAddress(), targetDirectory);
        try {
            exception = mebTester.exportMediaExceptions(me2, targetLocation);
        } catch (Throwable e) {
            testTrace("test 2 threw " + e.toString());
        }
        assertEquals("test 2: Should throw a ContentAccessException", MediaEntityLocalTestDriver.CONTENTACCESS,
                exception);
        testTrace("test 2 passed");
        //
        // test 3
        //
        returnedLoc = mebTester.exportMediaEntity(me1, targetLocation);
        String exportedMedia = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(exportedMedia, "exportedJpgPicture.jpg");
        mebTester.importMediaEntityContent(exportedMedia, returnedLoc, "testPicture.jpg");
        assertTrue("test 3: format of exported media is incorrect",
                mebTester.getMediaEntityFormat(exportedMedia) instanceof JpegFormat);
        assertTrue("test 3: content does not match", java.util.Arrays.equals(mebTester.getMediaEntityContent(me1),
                mebTester.getMediaEntityContent(exportedMedia)));
        testTrace("test 3 passed");
        mebTester.removeMEBByPK(exportedMedia);
        //
        // test 4
        //
        ComplexMediaLocationInfo me1NELocInfo = new ComplexMediaLocationInfo(ComplexMediaLocationInfo.MEDIAGPL1);
        String me1NE = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1NE, me1NELocInfo.getRootFile().getName());
        mebTester.importMediaEntityContent(me1NE, me1NELocInfo.getRootURL(), me1NELocInfo.getRootFile().getName());

        returnedLoc = mebTester.exportMediaEntity(me1NE, targetLocation);

        exportedMedia = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(exportedMedia, "exportedPlaylist.gpl");
        mebTester.importMediaEntityContent(exportedMedia, returnedLoc, "testPlaylist.gpl");
        String[] children = mebTester.getMediaEntityChildren(exportedMedia);
        assertTrue("test 4: format of exported media is incorrect",
                mebTester.getMediaEntityFormat(exportedMedia) instanceof GenericPlaylistFormat);
        assertTrue("test 4: nonembedded media has no children", children.length > 0);
        testTrace("test 4 passed");

        // remove test MEBs
        mebTester.removeMEBByPK(me1);
        mebTester.removeMEBByPK(me2);
        children = mebTester.getMediaEntityChildren(me1NE);
        mebTester.removeMEBByPK(me1NE);
        for (int i = 0; i < children.length; i++) {
            mebTester.removeMEBByPK(children[i]);
        }
        children = mebTester.getMediaEntityChildren(exportedMedia);
        mebTester.removeMEBByPK(exportedMedia);
        for (int i = 0; i < children.length; i++) {
            mebTester.removeMEBByPK(children[i]);
        }

        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: getChildren()
     *  Testcase Number: EMB104
     *
     *  setup: create Media entity from embedded media file, call me1
     *    	  create Media entity from nonembedded media file, call me2
     *
     *  test procedure:
     *  1.call me1.getChildren()
     *  	 expected result: empty array
     *
     *  2.call me2.getChildren()
     *    expected result: array containing all the MediaEntities which are referenced within me2
     *
     * </pre>
     */
    public void testEMB104() throws MediaException, MalformedURLException, IOException, CreateException,
            NamingException, FinderException, Throwable {

        mebTester.bindMediaFormat("jpg", new JpegFormat());
        mebTester.bindMediaFormat("gpl", new GenericPlaylistFormat());
        //
        // test 1
        //
        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        String[] meChildren = mebTester.getMediaEntityChildren(me1);
        assertTrue("test 1: Children array is not empty", meChildren.length == 0);
        testTrace("test 1 passed");
        //
        // test 2
        //
        ComplexMediaLocationInfo me2NELocInfo = new ComplexMediaLocationInfo(ComplexMediaLocationInfo.MEDIAGPL1);
        ComplexMediaLocationInfo me1NELocInfo = new ComplexMediaLocationInfo(ComplexMediaLocationInfo.MEDIAGPL1);
        String me2NE = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me2NE, me2NELocInfo.getRootFile().getName());
        mebTester.setMediaEntityContent(me2NE, me1NELocInfo.getRootFile());
        meChildren = mebTester.getMediaEntityChildren(me2NE);
        URL[] childURLs = new URL[meChildren.length];
        for (int i = 0; i < meChildren.length; i++) {
            childURLs[i] = mebTester.getMediaEntityLocation(meChildren[i]);
        }
        URL[] me2NEChildURLs = me2NELocInfo.getChildURLs();
        boolean childURLExists = false;
        for (int j = 0; j < me2NEChildURLs.length; j++) {
            for (int k = 0; k < childURLs.length; k++) {
                if (me2NEChildURLs[j].equals(childURLs[k])) {
                    childURLExists = true;
                    break;
                }
                if (!childURLExists) fail("test 2: child location is missing");
            }
        }
        testTrace("test 2 passed");

        // remove test MEBs
        mebTester.removeMEBByPK(me1);
        mebTester.removeMEBByPK(me2NE);
        for (int i = 0; i < meChildren.length; i++) {
            mebTester.removeMEBByPK(meChildren[i]);
        }

        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: getContent()
     *  Testcase Number: EMB105
     *
     *  setup:
     *
     *  test procedure:
     *  1.rebind(&quot;test&quot;, new GenericMediaFormat), create media entity and set content to random content with size of maxMediaSize
     *    call getContent()
     *    expected result: ContentTooLargeException
     *
     *  2.create small media entity, call getContent(), compare content with file content
     *    expected result: content and file content are equal
     *
     *  3.create testInstance from nonexistent file and call getContent()
     *    expected result: ContentAccessException
     *
     * </pre>
     */
    public void testEMB105() throws IOException, MediaException, Exception {

        String testInstance = mebTester.createMediaEntityBean();
        mebTester.bindMediaFormat("test", new GenericMediaFormat());
        int exception = -1;
        // check if longRunningTest
        if (embTestConfig.getIncludeLongRunningTest()) {
            int maxSize = Integer.parseInt(embTestConfig.getMaxMediaSize());
            if ((maxSize == -1) || (maxSize > Integer.MAX_VALUE)) {
                String largeFilePath = embTestConfig.getMediaDir() + File.separatorChar + "Generated" + File.separatorChar
                        + "largeFileMediaBean.test";
                File largeFile = new File(largeFilePath);
                largeFile.createNewFile();
                FileOutputStream largeFileOutputStream = new FileOutputStream(largeFile);

                // create byte array 1 byte larger than maxMediaSize
                byte[] testArray = EMBStaticHelper.createRandomByteArray(Integer.parseInt(embTestConfig
                        .getMaxMediaSize()) + 1);
                largeFileOutputStream.write(testArray);
                largeFileOutputStream.close();
                System.out.println("finished creating byte array");
                //
                // test 1
                //
                mebTester.setMediaEntityName(testInstance, "mediaBean.test");
                mebTester.importMediaEntityContent(testInstance, new URL("file",
                        embTestConfig.getTestClientIPAddress(), "/" + largeFilePath), null);
                System.out.println("imported content");
                try {
                    exception = mebTester.getContentExceptions(testInstance);
                } catch (Throwable e) {
                    fail("test 1 threw " + e.toString());
                }
                assertEquals("test 1: Should throw a ContentTooLargeException", exception,
                        MediaEntityLocalTestDriver.CONTENTTOOLARGE);
                testTrace("test 1 passed");
                largeFile.delete();
                mebTester.removeMEBByPK(testInstance);
            }
        }
        //
        // test2
        //
        // random test file
        File file1024Byte = new File(embTestConfig.getMediaDir() + File.separatorChar + "Generated" + File.separatorChar + "testMediaBeanFile.test");
        file1024Byte.createNewFile();
        FileOutputStream file1024ByteOutputStream = new FileOutputStream(file1024Byte);
        byte[] testArray = EMBStaticHelper.createRandomByteArray(1024);
        file1024ByteOutputStream.write(testArray);
        file1024ByteOutputStream.close();
        testInstance = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(testInstance, "testMediaBean.test");
        mebTester.setMediaEntityContent(testInstance, file1024Byte);
        byte[] contentArray = mebTester.getMediaEntityContent(testInstance);
        assertTrue("test 2: ", java.util.Arrays.equals(testArray, contentArray));
        testTrace("test 2 passed");
        mebTester.removeMEBByPK(testInstance);

        //
        // test 3
        //
        testInstance = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(testInstance, "mediaBean.test");
        try {
            exception = mebTester.getContentExceptions(testInstance);
        } catch (Throwable e) {
            fail("test 3 threw " + e.toString());
        }
        assertEquals("test 3: Should throw a ContentAccessException", exception,
                MediaEntityLocalTestDriver.CONTENTACCESS);
        testTrace("test 3 passed");
        mebTester.removeMEBByPK(testInstance);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: getDescription()
     *  Testcase Number: EMB106
     *
     *  setup: create Media entity from media file
     *
     *  test procedure:
     *  1.call setDescription with random string
     *    call getDescription
     *    expected result: returned string matches original
     *
     * </pre>
     */
    public void testEMB106() throws IOException, MediaException, CreateException, NamingException, FinderException,
            RemoveException {
        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        //
        // test 1
        //
        String desc = EMBStaticHelper.createRandomString(EMBStaticHelper.randomInt(0, 10));
        mebTester.setMediaEntityDescription(me1, desc);
        assertEquals("test 1: description does not match", mebTester.getMediaEntityDescription(me1), desc);
        testTrace("test 1 passed");
        mebTester.removeMEBByPK(me1);
        succeed();
    }

    /**
     * <pre>
     *
     *      Testcase Name: getFormat()
     *      Testcase Number: EMB107
     *
     *      setup:
     *
     *      test procedure:
     *      1.rebind(&quot;jpg&quot;, new JpegFormat()), create random content file with name test.jpg
     *      create MediaBean from file, run getFormat()
     *      expected result: not null and instance of JpegFormat
     *
     *      2.unbind(&quot;xxx&quot;) catch FormatNotFoundException
     *      create random content file with name test.xxx, create MediaBean from file, run getFormat()
     *      expected result: FormatNotFoundException
     *
     * </pre>
     */
    public void testEMB107() throws IOException, MediaException, Exception {

        String testInstance = mebTester.createMediaEntityBean();
        // register media format
        mebTester.bindMediaFormat("jpg", new JpegFormat());
        mebTester.bindMediaFormat("test", new GenericMediaFormat());
        mebTester.bindMediaFormat("xxx", new GenericMediaFormat());
        //
        // test1
        //
        EmbeddedMediaLocationInfo mediaLocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        mebTester.setMediaEntityName(testInstance, mediaLocInfo.getMediaName());
        mebTester.setMediaEntityContent(testInstance, mediaLocInfo.getMediaFile());
        assertNotNull("test 1", mebTester.getMediaEntityFormat(testInstance));
        assertTrue("test 1", mebTester.getMediaEntityFormat(testInstance) instanceof JpegFormat);
        testTrace("test 1 passed");
        mebTester.removeMEBByPK(testInstance);
        //
        // test2
        //
        File file1024Byte = new File(embTestConfig.getMediaDir() + File.separatorChar + "Generated" + File.separatorChar + "test.test");
        file1024Byte.createNewFile();
        FileOutputStream file1024ByteOutputStream = new FileOutputStream(file1024Byte);
        byte[] testArray = EMBStaticHelper.createRandomByteArray(1024);
        file1024ByteOutputStream.write(testArray);
        file1024ByteOutputStream.close();
        testInstance = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(testInstance, "test.test");
        mebTester.setMediaEntityContent(testInstance, file1024Byte);
        mebTester.setMediaEntityName(testInstance, "test.xxx");
        mebTester.unbindMediaFormat("xxx");
        int exception = -1;
        try {
            exception = mebTester.getFormatExceptions(testInstance);
        } catch (Throwable e) {
            fail("test 2 threw " + e.toString());
        }
        assertEquals("test 2 : Should throw a FormatNotFoundException", exception,
                MediaEntityLocalTestDriver.FORMATNOTFOUND);
        testTrace("test 2 passed");
        mebTester.removeMEBByPK(testInstance);

        succeed();
    }

    /**
     * <pre>
     *
     *      Testcase Name: getHeader()
     *      Testcase Number: EMB108
     *
     *      setup:
     *
     *      test procedure:
     *      1.rebind(&quot;jpg&quot;,new JpegFormat()), create media entity with name test.jpg
     *      set content with jpg file and call getHeader
     *      expected result: return value not null and equals getFormat().extractHeader()
     *
     *      2.unbind(&quot;xxx&quot;) catch FormatNotFoundException
     *      create media entity, set name to &quot;test.xxx&quot; and set content to random content, run getHeader()
     *      expected result: FormatNotFoundException is thrown
     *
     *      3.create file from random content, run getHeader()
     *      expected result: FormatSyntaxException
     *
     *      4.use static byte array to create BMP file (contains unsupported version) and run getHeader()
     *      expected result: FormatFeatureException
     *
     * </pre>
     */
    public void testEMB108() throws IOException, MediaException, Exception {
        // register media format
        mebTester.bindMediaFormat("jpg", new JpegFormat());
        mebTester.bindMediaFormat("bmp", new BmpFormat());
        mebTester.bindMediaFormat("test", new GenericMediaFormat());
        mebTester.bindMediaFormat("xxx", new GenericMediaFormat());

        File file1024Byte = new File(embTestConfig.getMediaDir() + File.separatorChar + "Generated" + File.separatorChar + "test.xxx");
        file1024Byte.createNewFile();
        FileOutputStream file1024ByteOutputStream = new FileOutputStream(file1024Byte);
        byte[] testArray = EMBStaticHelper.createRandomByteArray(1024);
        file1024ByteOutputStream.write(testArray);
        file1024ByteOutputStream.close();
        int exception = -1;
        //
        // test1
        //
        EmbeddedMediaLocationInfo mediaLocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName2());
        String testInstance = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(testInstance, mediaLocInfo.getMediaName());
        mebTester.setMediaEntityContent(testInstance, mediaLocInfo.getMediaFile());
        InputStream in = new FileInputStream(mediaLocInfo.getMediaFile());
        MediaHeader testHeader = mebTester.getMediaEntityHeader(testInstance);
        assertTrue("test 1: ", testHeader.equals(mebTester.getMediaEntityFormat(testInstance).extractHeader(in)));
        testTrace("test 1 passed");
        in.close();
        mebTester.removeMEBByPK(testInstance);
        //
        // test2
        //
        testInstance = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(testInstance, "test.test");
        mebTester.setMediaEntityContent(testInstance, file1024Byte);
        mebTester.setMediaEntityName(testInstance, "test.xxx");
        mebTester.unbindMediaFormat("xxx");
        try {
            exception = mebTester.getHeaderExceptions(testInstance);
        } catch (Throwable e) {
            fail("test 2 threw " + e.toString());
        }
        assertEquals("test 2: Should throw a FormatNotFoundException", exception,
                MediaEntityLocalTestDriver.FORMATNOTFOUND);
        testTrace("test 2 passed");
        mebTester.removeMEBByPK(testInstance);
        //
        // test 3
        //
        File file512Byte = new File(embTestConfig.getMediaDir() + File.separatorChar + "Generated" + File.separatorChar + "test.jpg");
        file512Byte.createNewFile();
        FileOutputStream file512ByteOutputStream = new FileOutputStream(file512Byte);
        byte[] randomArray = EMBStaticHelper.createRandomByteArray(512);
        file512ByteOutputStream.write(randomArray);
        file512ByteOutputStream.close();
        testInstance = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(testInstance, "test.test");
        mebTester.setMediaEntityContent(testInstance, file512Byte);
        mebTester.setMediaEntityName(testInstance, "test.jpg");
        try {
            exception = mebTester.getHeaderExceptions(testInstance);
        } catch (Throwable e) {
            fail("test 3 threw " + e.toString());
        }
        assertEquals("test 3: Should throw a FormatSyntaxException", MediaEntityLocalTestDriver.FORMATSYNTAX, exception );
        testTrace("test 3 passed");
        mebTester.removeMEBByPK(testInstance);
        //
        // test 4
        //
        byte[] corruptedBmpByteArray = {76, 86, 70, 43, 0, 0, 0, 0, 0, 0, 54, 4, 0, 0, 40, 0, 0, 0, 100, 0, 0, 0, 100,
                0, 0, 0, 1, 0, 8, 0, 0, 0, 0, 0, 16, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 1, 1, 1, 0, 2, 2, 2, 0, 3, 3, 3, 0, 4, 4, 4, 0, 5, 5, 5, 0, 6, 6, 6, 7, 7, 7, 0, 8, 8, 8, 0, 9,
                9, 9, 0, 1, 10, 10, 0, 11, 11};
        mebTester.bindMediaFormat("bmp", new BmpFormat());
        testInstance = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(testInstance, "test.test");
        mebTester.setMediaEntityContent(testInstance, corruptedBmpByteArray);
        mebTester.setMediaEntityName(testInstance, "test.bmp");
        try {
            exception = mebTester.getHeaderExceptions(testInstance);
        } catch (Throwable e) {
            fail("test 4 threw " + e.toString());
        }
        assertEquals("test 4: Should throw a FormatSyntaxException", exception,
                MediaEntityLocalTestDriver.FORMATSYNTAX);
        testTrace("test 4 passed");
        mebTester.removeMEBByPK(testInstance);

        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: getLastModified()
     *  Testcase Number: EMB109
     *
     *  setup: create Media entity from media file
     *
     *  test procedure:
     *  1.call getLastModified()
     *    expected result: no exception
     *
     *  2.call getLastModified and remember timestamp
     *    call setDescription(&quot;abc&quot;) and wait 2 seconds
     *    call getLastModified and verify it changed
     *    expected result: timestamp updated
     *
     * </pre>
     */
    public void testEMB109() throws IOException, MediaException, InterruptedException, CreateException,
            RemoteException, NamingException, FinderException, RemoveException {

        mebTester.bindMediaFormat("jpg", new JpegFormat());
        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        //
        // test 1
        //
        try {
            mebTester.getMediaEntityLastModified(me1);
            testTrace("test 1 passed");
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        } //
        // test 2
        //
        Date beforeStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        mebTester.setMediaEntityDescription(me1, "abc");
        Thread.sleep( 1000);
        Date afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        assertTrue("test 2: Modification date", afterStamp.after(beforeStamp));
        testTrace("test 2 passed");
        mebTester.removeMEBByPK(me1);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: getListeners()
     *  Testcase Number: EMB110
     *
     *  setup: create Media entity from media file
     *  		  create Media listeners listener1, listener2, and listener3
     *
     *  test procedure:
     *  1.call addListener(listener1), call addListener(listener2), call addListener(listener3)
     *    call getListeners()
     *    expected result: verify that listener1, listener2, and listener 3 are in array
     *
     * </pre>
     */
    public void testEMB110() throws IOException, MediaException, CreateException, RemoteException, NamingException,
            FinderException, RemoveException {
        mebTester.bindMediaFormat("jpg", new JpegFormat());

        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());

        GenericMediaListener listener1 = new GenericMediaListener();
        GenericMediaListener listener2 = new GenericMediaListener();
        GenericMediaListener listener3 = new GenericMediaListener();
        MediaListener[] mediaListenerArray = null;
        //
        // test 1
        //
        mebTester.addMediaEntityListener(me1, listener1);

        try {
            mebTester.setMediaEntityName(me1, "newName1.jpg");
        } catch (ListenerVetoException e) {
        }
        mebTester.addMediaEntityListener(me1, listener2);

        try {
            mebTester.setMediaEntityName(me1, "newName2.jpg");
        } catch (ListenerVetoException e) {
        }
        mebTester.addMediaEntityListener(me1, listener3);
        try {
            mediaListenerArray = mebTester.getMediaEntityListeners(me1);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        boolean ml1 = false;
        boolean ml2 = false;
        boolean ml3 = false;
        assertEquals("test 1: does not contain 3 elements", 3, mediaListenerArray.length);
        testTrace("test 1 passed");

        mebTester.removeMEBByPK(me1);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: getLocation()
     *  Testcase Number: EMB111
     *
     *  setup: create Media entity
     *
     *  test procedure:
     *  1.call getLocation()
     *    expected result: null
     *
     *  2.call setLocation()
     *    call getLocation()
     *    expected result: URL matches original random URL
     *
     * </pre>
     */
    public void testEMB111() throws IOException, MediaException, CreateException, RemoteException, NamingException,
            FinderException, RemoveException {
        mebTester.bindMediaFormat("jpg", new JpegFormat());
        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        //
        // test 1
        //
        assertNull("test 1: location not null", mebTester.getMediaEntityLocation(me1));
        testTrace("test 1 passed");
        //
        // test 2
        //
        URL location = me1LocInfo.getMediaURL();
        try {
            mebTester.setMediaEntityLocation(me1, location);
        } catch (Throwable e) {
            fail("test 2 threw " + e.toString());
        }
        assertTrue("test 2: location URL does is incorrect", mebTester.getMediaEntityLocation(me1).equals(location));
        testTrace("test 2 passed");
        mebTester.removeMEBByPK(me1);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: getMetaData()
     *  Testcase Number: EMB112
     *
     *  setup: create Media entity me1 and meta data entities md1 and md2
     *
     *  test procedure:
     *  1.call me1.addMetaData(md1)
     *    call me1.getMetaData()
     *    expected result: 1 element array consisting of md1
     *
     *  2.call me1.addMetaData(md2)
     *    call me1.getMetaData()
     *    expected result: 2 element array consisting of md1 and md2
     *
     * </pre>
     */
    public void testEMB112() throws IOException, MediaException, CreateException, RemoteException, NamingException,
            FinderException, RemoveException {
        mebTester.bindMediaFormat("jpg", new JpegFormat());

        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        String md1 = mebTester.createMetaDataEntityBean();
        String md2 = mebTester.createMetaDataEntityBean();
        //
        // test 1
        //
        try {
            mebTester.addMediaEntityMetaData(me1, md1);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertEquals("test 1: md1 not added", 1, mebTester.getMediaEntityMetaData(me1).length);
        assertEquals("test 1: incorrect meta data", md1, mebTester.getMediaEntityMetaData(me1)[0]);
        testTrace("test 1 passed");
        //
        // test 2
        //
        try {
            mebTester.addMediaEntityMetaData(me1, md2);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertEquals("test 2: md2 not added", 2, mebTester.getMediaEntityMetaData(me1).length);
        boolean match = false;
        if (((md1.equals(mebTester.getMediaEntityMetaData(me1)[0])) && (md2.equals(mebTester
                .getMediaEntityMetaData(me1)[1])))
                || ((md1.equals(mebTester.getMediaEntityMetaData(me1)[1])) && (md2.equals(mebTester
                        .getMediaEntityMetaData(me1)[0])))) {
            match = true;
        }
        assertTrue("test 2: meta data does not match", match);
        testTrace("test 2 passed");

        mebTester.removeMEBByPK(me1);
        mebTester.removeMDEBByPK(md1);
        mebTester.removeMDEBByPK(md2);

        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: getMimeType()
     *  Testcase Number: EMB113
     *
     *  setup:
     *
     *  test procedure:
     *  1.rebind(&quot;jpg&quot;, new JpegFormat())
     *    create media entity from jpg file, run getMimeType()
     *    expected result: result equals getFormat().getDefaultMimeType()
     *
     *  2.create random content file with name test.test, create media entity from file with mimetype &quot;test&quot;, run getMimeType()
     *    expected result: result is &quot;test&quot;
     *
     *  3.create media entity from jpg file
     *    then call unbind(&quot;jpg&quot;)
     *    call getMimeType
     *    expected result: FormatNotFound
     *
     * </pre>
     */
    public void testEMB113() throws IOException, MediaException, Exception {
        mebTester.bindMediaFormat("jpg", new JpegFormat());
        mebTester.bindMediaFormat("test", new GenericMediaFormat());

        File file1024Byte = new File(embTestConfig.getMediaDir() + File.separatorChar + "Generated" + File.separatorChar + "test.test");
        file1024Byte.createNewFile();
        FileOutputStream file1024ByteOutputStream = new FileOutputStream(file1024Byte);
        byte[] testArray = EMBStaticHelper.createRandomByteArray(1024);
        file1024ByteOutputStream.write(testArray);
        file1024ByteOutputStream.close();

        EmbeddedMediaLocationInfo mediaLocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, mediaLocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, mediaLocInfo.getMediaFile());

        String me2 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me2, "test.test");
        mebTester.setMediaEntityContent(me2, file1024Byte);
        //
        // test1
        //
        assertEquals("test1: ", mebTester.getMediaEntityMimeType(me1), mebTester.getMediaEntityFormat(me1)
                .getDefaultMimeType());
        testTrace("test 1 passed");
        //
        // test2
        //
        mebTester.setMediaEntityMimeType(me2, "test");
        assertEquals("test 2: ", "test", mebTester.getMediaEntityMimeType(me2));
        testTrace("test 2 passed");
        //
        // test 3
        //
        mebTester.unbindMediaFormat("jpg");
        int exception = -1;
        try {
            exception = mebTester.getMimeTypeExceptions(me1);
        } catch (Throwable e) {
            fail("test 3 threw " + e.toString());
        }
        assertEquals("test 3: Should throw a FormatNotFoundException", MediaEntityLocalTestDriver.FORMATNOTFOUND,
                exception);
        testTrace("test 3 passed");

        mebTester.removeMEBByPK(me1);
        mebTester.removeMEBByPK(me2);

        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: getName()
     *  Testcase Number: EMB114
     *
     *  setup:
     *
     *  test procedure:
     *  1.rebind(&quot;jpg&quot;, new JpegFormat()), create random content file with name test.jpg, create MediaBean from file with mimetype null, run getName()
     *    expected result: result is not null and contains a '.'
     *
     * </pre>
     */
    public void testEMB114() throws IOException, RemoveException, CreateException, RemoteException, NamingException,
            FinderException, MediaException {
        // random file
        EmbeddedMediaLocationInfo mediaLocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        // register media format
        mebTester.bindMediaFormat("jpg", new JpegFormat());
        String testInstance = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(testInstance, mediaLocInfo.getMediaName());
        mebTester.setMediaEntityContent(testInstance, mediaLocInfo.getMediaFile());
        //
        // test1
        //
        assertNotNull(mebTester.getMediaEntityName(testInstance));
        assertTrue("test 1: ", mebTester.getMediaEntityName(testInstance).indexOf(".") != -1);
        testTrace("test 1 passed");
        mebTester.removeMEBByPK(testInstance);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: getNextVersion()
     *  Testcase Number: EMB115
     *
     *  setup: create Media entities me1 and me2
     *
     *  test procedure:
     *  1.call me2.setPreviousVersion(me1)
     *    call me1.getNextVersion()
     *    expected result: return me2
     *
     *  2.call me2.getNextVersion()
     *    expected result: null
     *
     * </pre>
     */
    public void testEMB115() throws IOException, MediaException, CreateException, RemoteException, NamingException,
            FinderException, RemoveException {
        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName2());
        String me2 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());
        //
        // test 1
        //
        try {
            mebTester.setMediaEntityPreviousVersion(me2, me1);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertEquals("test 1: next version is not me2", me2, mebTester.getMediaEntityNextVersion(me1));
        testTrace("test 1 passed");
        //
        // test 2
        //
        assertNull("test 2: next version is not null", mebTester.getMediaEntityNextVersion(me2));
        testTrace("test 2 passed");

        mebTester.removeMEBByPK(me1);
        mebTester.removeMEBByPK(me2);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: getParents()
     *  Testcase Number: EMB116()
     *
     *  setup: create Media entity from embedded media file, call me1
     *  		  create Media entity from nonembedded media file, call me2
     *
     *  test procedure:
     *  1.call me1.getParent()
     *  	 expected result: empty array
     *
     *  2.call me2.getChildren()
     *    for all children, call getParents()
     *    expected result: me2
     *
     * </pre>
     */
    public void testEMB116() throws MediaException, IOException, CreateException, RemoteException, NamingException,
            FinderException, RemoveException {
        //
        // test 1
        //
        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        String[] meParents = mebTester.getMediaEntityParents(me1);
        assertTrue("test 1: parent array is not empty", meParents.length == 0);
        testTrace("test 1 passed");
        //
        // test 2
        //
        ComplexMediaLocationInfo me2NELocInfo = new ComplexMediaLocationInfo(ComplexMediaLocationInfo.MEDIAGPL1);
        String me2NE = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me2NE, me2NELocInfo.getRootFile().getName());
        mebTester.setMediaEntityContent(me2NE, me2NELocInfo.getRootFile());
        String[] meChildren = mebTester.getMediaEntityChildren(me2NE);
        for (int i = 0; i < meChildren.length; i++) {
            meParents = mebTester.getMediaEntityParents(meChildren[i]);
            assertEquals("test 2: does not contain 1 element", meParents.length, 1);
            assertEquals("test 2: parent is not me2", meParents[0], me2NE);
        }
        testTrace("test 2 passed");

        mebTester.removeMEBByPK(me1);
        mebTester.removeMEBByPK(me2NE);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: getPreviousVersion()
     *  Testcase Number: EMB117
     *
     *  setup: create Media entities me1 and me2 from media files
     *
     *  test procedure:
     *  1.call me2.setPreviousVersion(me1)
     *    call me2.getPreviousVersion
     *    expected result: me1
     *
     *  2.call me1.getPreviousVersion()
     *    expected result: null
     *
     * </pre>
     */
    public void testEMB117() throws IOException, MediaException, CreateException, RemoteException, NamingException,
            FinderException, RemoveException {
        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName2());
        String me2 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());
        //
        // test 1
        //
        mebTester.setMediaEntityPreviousVersion(me2, me1);
        assertEquals("test 1: previous version is not me1", mebTester.getMediaEntityPreviousVersion(me2), me1);
        testTrace("test 1 passed");
        //
        // test 2
        //
        assertNull("test 2: previous version is not null", mebTester.getMediaEntityPreviousVersion(me1));
        testTrace("test 2 passed");

        mebTester.removeMEBByPK(me1);
        mebTester.removeMEBByPK(me2);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: getProxy()
     *  Testcase Number: EMB118
     *
     *  setup: create Media entities me1 and me2 from media jpeg files
     *
     *  test procedure:
     *  1.call me1.getProxy()
     *    expected result: not null
     *
     *  2.call me1.setProxy(me2)
     *    call me1.getProxy()
     *    expected result: me2
     *
     * </pre>
     */
    public void testEMB118() throws IOException, MediaException, CreateException, RemoteException, NamingException,
            FinderException, RemoveException {
        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName2());
        String me2 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());
        MediaBean jpgMediaBean = new MediaBean(me2LocInfo.getMediaFile(), "image/jpeg");
        //
        // test 1
        //
        Media testMedia = mebTester.getMediaEntityProxy(me1);
        assertNotNull("test 1: proxy is null", testMedia);
        testTrace("test 1 passed");
        //
        // test 2
        //
        mebTester.setMediaEntityProxy(me1, me2);
        Media proxy = mebTester.getMediaEntityProxy(me1);
        assertNotNull("test 2: proxy is null", proxy);
        assertTrue("test 2: proxy is not me2", java.util.Arrays.equals(proxy.getContent(), jpgMediaBean.getContent()));
        testTrace("test 2 passed");

        mebTester.removeMEBByPK(me1);
        mebTester.removeMEBByPK(me2);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: getSize()
     *  Testcase Number: EMB119
     *
     *  setup:
     *
     *  test procedure:
     *  1.create random content file with name test.jpg and content size 1024, create MediaBean from file, run getSize()
     *    expected result: result is 1024
     *
     * </pre>
     */
    public void testEMB119() throws IOException, MediaException, Exception {
        // random file
        File file1024Byte = new File(embTestConfig.getMediaDir() + File.separatorChar + "Generated" + File.separatorChar + "test.jpg");
        file1024Byte.createNewFile();
        FileOutputStream file1024ByteOutputStream = new FileOutputStream(file1024Byte);
        byte[] testArray = EMBStaticHelper.createRandomByteArray(1024);
        file1024ByteOutputStream.write(testArray);
        file1024ByteOutputStream.close();
        // register media format
        mebTester.bindMediaFormat("test", new GenericMediaFormat());
        String testInstance = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(testInstance, "test.test");
        int exception = -1;
        //
        // test1
        //
        try {
            exception = mebTester.getSizeExceptions(testInstance);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertEquals("test 1: Should throw a ContentAccessException", exception,
                MediaEntityLocalTestDriver.CONTENTACCESS);
        testTrace("test 1 passed");
        //
        // test 2
        //
        mebTester.setMediaEntityContent(testInstance, file1024Byte);
        assertEquals("test 1: ", 1024, mebTester.getMediaEntitySize(testInstance));
        testTrace("test 2 passed");

        mebTester.removeMEBByPK(testInstance);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: importMedia(URL, String)
     *  Testcase Number: EMB120
     *
     *  setup: create Media entity me1 from jpeg media file
     *  		  rebind &quot;jpg&quot; and &quot;bmp&quot; file extensions to media format registry
     *
     *  test procedure:
     *  1.call me1.importMedia(null, null)
     *    expected result: NullPointerException
     *
     *  2.a.create media entity and call setName
     *      call me1.importMedia(validLocation, null)
     *      expected result: no exception, call me1.getContent and verify media content and format
     *  					    verify name remained the same
     *    b.create media entity and call importMedia(validLocation, null)
     *      expected result: no exception, call getContent and verify content and format
     *  						check that getName is not null
     *
     *  3.create URL from valid jpeg file location
     *    call me1.importMedia(location, randomName) where randomName has the &quot;jpg&quot; file extension
     *    expected result: no exception
     *  					  call me1.getContent and me1.getName to verify new content and name
     *
     *  4.create URL from valid bmp file location
     *    call me1.importMedia(location, randomName) where randomName has the &quot;bmp&quot; file extension
     *    expected result: no exception
     *  					  call me1.getFormat() and verify instance of BmpFormat
     *
     *  5.create URL from nonexistent file location
     *    call me1.importMedia(location, null)
     *    expected result: ContentAccessException
     *
     *  6.create URL pointing to valid playlist location
     *    call me1.importMedia(location, randomName) where randomName has the &quot;gpl&quot; file extension
     *    expected result: no exception
     *  					  verify getChildren is not null
     *
     *  7.create media entity, call setName and setContent
     *    call addListener
     *    call importMedia(validLocation, name)
     *    expected result: ListenerVetoException
     *
     *  8.create media entity and setName
     *    call importMedia with URL pointing to file larger than maxMediaSize
     *    expected result: ContentTooLargeException
     *
     * </pre>
     */
    public void testEMB120() throws IOException, MediaException, InterruptedException, CreateException,
            RemoteException, NamingException, FinderException, RemoveException {

        mebTester.bindMediaFormat("jpg", new JpegFormat());
        mebTester.bindMediaFormat("bmp", new BmpFormat());
        mebTester.bindMediaFormat("test", new GenericMediaFormat());

        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());

        EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName2());
        EmbeddedMediaLocationInfo me3LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getBmpPictureName1());

        int exception = -1;
        //
        // test 1
        //
        try {
            exception = mebTester.importMediaExceptions(me1, null, null);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertEquals("test 1: Should throw a NullPointerException", MediaEntityLocalTestDriver.NULLPOINTER, exception);
        testTrace("test 1 passed");
        //
        // test 2a
        //
        Date beforeStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        mebTester.importMediaEntityContent(me1, me2LocInfo.getMediaURL(), null);
        Thread.sleep( 1000);
        Date afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        assertTrue("test 2a: Modification date", afterStamp.after(beforeStamp));
        assertTrue("test 2a: media is not in Jpeg format", mebTester.getMediaEntityFormat(me1) instanceof JpegFormat);
        assertTrue("test 2a: new content does not match", Arrays.equals(mebTester.getMediaEntityContent(me1),
                getByteArrayFromFile(me2LocInfo.getMediaFile())));
        //TODO : EMB 120 : not compliant, import change name only if name is not already set
        //assertEquals("test 2a: name changed", me2LocInfo.getMediaName(), mebTester.getMediaEntityName(me1));
        testTrace("test 2a passed");
        //
        // test 2b
        //
        String me2 = mebTester.createMediaEntityBean();
        mebTester.importMediaEntityContent(me2, me2LocInfo.getMediaURL(), null);
        assertTrue("test 2b: media is not in Jpeg format", mebTester.getMediaEntityFormat(me2) instanceof JpegFormat);
        assertTrue("test 2b: new content does not match", Arrays.equals(mebTester.getMediaEntityContent(me2),
                getByteArrayFromFile(me2LocInfo.getMediaFile())));
        assertNotNull("test 2b: name is null", mebTester.getMediaEntityName(me2));
        testTrace("test 2b passed");
        //
        // test 3
        //
        beforeStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        mebTester.importMediaEntityContent(me1, me2LocInfo.getMediaURL(), me2LocInfo.getMediaName());
        Thread.sleep( 1000);
        afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        assertTrue("test 3: Modification date", afterStamp.after(beforeStamp));
        assertTrue("test 3: media is not in Jpeg format", mebTester.getMediaEntityFormat(me1) instanceof JpegFormat);
        assertTrue("test 3: new content does not match", java.util.Arrays.equals(mebTester.getMediaEntityContent(me1),
                getByteArrayFromFile(me2LocInfo.getMediaFile())));
        assertEquals("test 3: name not changed", mebTester.getMediaEntityName(me1), me2LocInfo.getMediaName());
        testTrace("test 3 passed");
        //
        // test 4
        //
        beforeStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        mebTester.importMediaEntityContent(me1, me3LocInfo.getMediaURL(), me3LocInfo.getMediaName());
        Thread.sleep( 1000);
        afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        assertTrue("test 4: Modification date", afterStamp.after(beforeStamp));
        assertTrue("test 4: media is not in Bmp format", mebTester.getMediaEntityFormat(me1) instanceof BmpFormat);
        assertTrue("test 4: new content does not match", Arrays.equals(mebTester.getMediaEntityContent(me1),
                getByteArrayFromFile(me3LocInfo.getMediaFile())));
        assertEquals("test 4: name not changed", mebTester.getMediaEntityName(me1), me3LocInfo.getMediaName());
        testTrace("test 4 passed");
        //
        // test 5
        //
        String nonexistentFilePath = embTestConfig.getMediaDir() + File.separatorChar + "nonexistentFile.bmp";
        URL srcLocation = new URL("file", embTestConfig.getTestClientIPAddress(), nonexistentFilePath);
        try {
            exception = mebTester.importMediaExceptions(me1, srcLocation, null);
        } catch (Throwable e) {
            fail("test 5 threw " + e.toString());
        }
        assertEquals("test 5: Should throw a ContentAccessException", exception,
                MediaEntityLocalTestDriver.CONTENTACCESS);
        testTrace("test 5 passed");
        //
        // test 6
        //
        ComplexMediaLocationInfo me1NELocInfo = new ComplexMediaLocationInfo(ComplexMediaLocationInfo.MEDIAGPL1);
        String me1NE = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1NE, me1NELocInfo.getRootFile().getName());
        mebTester.setMediaEntityContent(me1NE, me1NELocInfo.getRootFile());
        beforeStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        mebTester.importMediaEntityContent(me1, me1NELocInfo.getRootURL(), me1NELocInfo.getRootFile().getName());
        Thread.sleep( 1000);
        afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        assertTrue("test 6: Modification date", afterStamp.after(beforeStamp));
        assertTrue("test 6: media is not in playlist format",
                mebTester.getMediaEntityFormat(me1) instanceof GenericPlaylistFormat);
        assertEquals("test 6: name not changed", mebTester.getMediaEntityName(me1), me1NELocInfo.getRootFile()
                .getName());
        assertTrue("test 6: nonembedded media has no children", mebTester.getMediaEntityChildren(me1).length > 0);
        testTrace("test 6 passed");
        //
        // test 7
        //
        String me3 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me3, me3LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me3, me3LocInfo.getMediaFile());
        mebTester.addMediaEntityListener(me3, new GenericMediaListener());
        try {
            exception = mebTester.importMediaExceptions(me3, me2LocInfo.getMediaURL(), me2LocInfo.getMediaName());
        } catch (Throwable e) {
            fail("test 7 threw " + e.toString());
        }
        assertEquals("test 7: Should throw a ListenerVetoException", MediaEntityLocalTestDriver.LISTENERVETO, exception);
        testTrace("test 7 passed");
        //
        // test 8
        //
        if (embTestConfig.getIncludeLongRunningTest()) {
            String largeFilePath = embTestConfig.getMediaDir() + File.separatorChar + "Generated" + File.separatorChar + "largeFile.test";
            File largeFile = new File(largeFilePath);
            largeFile.createNewFile();
            FileOutputStream largeFileOutputStream = new FileOutputStream(largeFile);
            // create byte array 1 byte larger than maxMediaSize
            byte[] testArray = EMBStaticHelper
                    .createRandomByteArray(Integer.parseInt(embTestConfig.getMaxMediaSize()) + 1);
            largeFileOutputStream.write(testArray);
            largeFileOutputStream.close();

            String testInstance = mebTester.createMediaEntityBean();
            mebTester.setMediaEntityName(testInstance, "largeMedia.test");
            try {
                exception = mebTester.importMediaExceptions(testInstance, new URL("file", embTestConfig
                        .getTestClientIPAddress(), largeFilePath), null);
            } catch (Throwable e) {
                fail("test 8 threw " + e.toString());
            }
            assertEquals("test 8: Should throw a ContentTooLargeException", MediaEntityLocalTestDriver.CONTENTTOOLARGE,
                    exception);
            testTrace("test 8 passed");
            largeFile.delete();
            mebTester.removeMEBByPK(testInstance);
        }

        mebTester.removeMEBByPK(me1);
        mebTester.removeMEBByPK(me2);
        mebTester.removeMEBByPK(me3);
        mebTester.removeMEBByPK(me1NE);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: readContent(long position, byte[] buffer)
     *  Testcase Number: EMB121
     *
     *  setup: create file (1024 byte), rebind(&quot;test&quot;, new GenericMediaFormat()), create MediaBean
     *  	   	  create byte array buffer of size 1024 bytes
     *
     *  test procedure:
     *  1.call readContent(-1,testBuffer)
     *    expected result: IndexOutOfBoundsException
     *
     *  2.call readContent(1025,testBuffer)
     *    expected result: IndexOutOfBoundsException
     *
     *  3.call readContent(0,null)
     *    expected result: NullPointerException
     *
     *  4.call readContent(10,testBuffer) with buffer size 100 bytes
     *    compare to media content offset 10, length of return value
     *    expected result: same content
     *
     *  5.call readContent(1024,testBuffer)
     *    expected result: -1 returned with empty buffer
     *
     *  6.create testInstance from nonexistent file and call readContent(0,buffer)
     *    expected result: ContentAccessException
     *
     *  7.create testInstance of size 100 bytes and buffer of size 1024 bytes
     *    call readContent(0,testBuffer) and compare content of media and buffer
     *    expected result: buffer partially filled (return value is the length)
     *
     * </pre>
     */
    public void testEMB121() throws IOException, MediaException, Exception {
        //
        // Initialize the testcase
        //
        File file1024Byte = new File(embTestConfig.getMediaDir() + File.separatorChar + "Generated" + File.separatorChar + "testFile1024Byte.test");
        if(file1024Byte.exists()) file1024Byte.delete();
        file1024Byte.createNewFile();
        file1024Byte.deleteOnExit();
        FileOutputStream file1024ByteOutputStream = new FileOutputStream(file1024Byte);
        byte[] testArray = EMBStaticHelper.createRandomByteArray(1024);
        file1024ByteOutputStream.write(testArray);
        file1024ByteOutputStream.close();

        // register media format
        mebTester.bindMediaFormat("test", new GenericMediaFormat());
        String testInstance = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(testInstance, "testFile1024Byte.test");
        mebTester.setMediaEntityContent(testInstance, file1024Byte);


        byte[] testBuffer = new byte[1024];
        int exception = -1;

        //FIXME : EMB 121 : test 1 -> 3 crash the next one(content null)

        //
        // test 1
        //
//        try {
//            exception = mebTester.readContentExceptions(testInstance, -1, testBuffer);
//        } catch (Throwable e) {
//            fail("test 1 threw " + e.toString());
//        }
//        assertEquals("test 1: Should throw an IndexOutOfBoundsException", MediaEntityLocalTestDriver.INDEXOUTOFBOUNDS,
//                exception);
//        testTrace("test 1 passed");
        //
        // test 2
        //
//        try {
//            exception = mebTester.readContentExceptions(testInstance, 1025, testBuffer);
//        } catch (Throwable e) {
//            fail("test 2 threw " + e.toString());
//        }
//        assertEquals("test 2: Should throw an IndexOutOfBoundsException", MediaEntityLocalTestDriver.INDEXOUTOFBOUNDS,
//                exception);
//        testTrace("test 2 passed");
        //
        // test 3
        //
//        try {
//            exception = mebTester.readContentExceptions(testInstance, 0, null);
//        } catch (Throwable e) {
//            fail("test 3 threw " + e.toString());
//        }
//        assertEquals("test 3: Should throw an NullPointerException", MediaEntityLocalTestDriver.NULLPOINTER, exception);
//        testTrace("test 3 passed");

        //
        // test 4
        //
        byte[] buffer100Byte = new byte[100];
        boolean contentMatch = mebTester.readCompareContent(testInstance, 10, buffer100Byte, file1024Byte);
        assertTrue("test 4: content does not match", contentMatch);
        testTrace("test 4 passed");
        //
        // test 5
        //
        int amountCopied = mebTester.readMediaEntityContent(testInstance, 1024, testBuffer);
        assertEquals("test 5: ", -1, amountCopied);
        testTrace("test 5 passed");
        mebTester.removeMEBByPK(testInstance);
        //
        // test 6
        //
        testInstance = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(testInstance, "testMedia.test");
        try {
            exception = mebTester.readContentExceptions(testInstance, 0, testBuffer);
        } catch (Throwable e) {
            fail("test 6 threw " + e.toString());
        }
        assertEquals("test 6: Should throw a ContentAccessException", MediaEntityLocalTestDriver.CONTENTACCESS,
                exception);
        testTrace("test 6 passed");
        mebTester.removeMEBByPK(testInstance);
        //
        // test 7
        //
        File file100Byte = new File(embTestConfig.getMediaDir() + File.separatorChar + "Generated" + File.separatorChar + "testFile100Byte.test");
        file100Byte.createNewFile();
        FileOutputStream file100ByteOutputStream = new FileOutputStream(file100Byte);
        byte[] randomTestArray = EMBStaticHelper.createRandomByteArray(100);
        file100ByteOutputStream.write(randomTestArray);
        file100ByteOutputStream.close();

        testInstance = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(testInstance, "testFile100Byte.test");
        mebTester.setMediaEntityContent(testInstance, file100Byte);
        contentMatch = mebTester.readCompareContent(testInstance, 0, testBuffer, file100Byte);
        assertTrue("test 7: ", contentMatch);
        testTrace("test 7 passed");
        mebTester.removeMEBByPK(testInstance);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: readContent(long position, byte[] buffer, int offset, int length)
     *  Testcase Number: EMB122
     *
     *  setup: create file (1024 byte), rebind(&quot;test&quot;, new GenericMediaFormat()), create MediaBean
     *  	      create byte array buffer of size 1024 bytes
     *
     *  test procedure:
     *  1.call readContent(-1,testBuffer,0,1024)
     *    expected result: IndexOutOfBoundsException
     *
     *  2.call readContent(1025,testBuffer,0,1024)
     *    expected result: IndexOutOfBoundsException
     *
     *  3.call readContent(0,testBuffer,-1,1024)
     *    expected result: IndexOutOfBoundsException
     *
     *  4.call readContent(0,testBuffer,1025,1024)
     *    expected result: IndexOutOfBoundsException
     *
     *  5.call readContent(0,testBuffer,0,-1)
     *    expected result: NegativeIndexArrayException
     *
     *  6.call readContent(0,null,0,1024)
     *    expected result: NullPointerException
     *
     *  7.create testInstance from nonexistent file and call readContent(0,testBuffer,0,1024)
     *    expected result: ContentAccessException
     *
     *  8.call readContent(0,testBuffer,0,1024) (loop to fill buffer)
     *    compare with file content
     *    expected result: same content
     *
     *  9.call readContent(512,testBuffer,0,1024)
     *    expected result: buffer partially filled with 512 bytes matching last 512 bytes
     *    of media content (could be less if nonblocking)
     *
     *  10.call readContent(1024,testBuffer,0,1024)
     *     expected result: return -1 with empty buffer
     *
     *  11.call readContent(0,testBuffer,100,924), compare buffer offset 100 with media content
     *     (use return value as length)
     *     expected result: same content
     *
     *  12.call readContent(200,testBuffer,100,100), compare buffer offset 100 with file offset 200
     *     (use return value as length)
     *     expected result: same content
     *
     *  13.call readContent(0,testBuffer,0,1048), compare buffer with file content
     *     expected result: same content and no exceptions
     *
     * </pre>
     */
    public void testEMB122() throws IOException, MediaException, Throwable {

        //
        // Initialize the testcase
        //
        File file1024Byte = new File(embTestConfig.getMediaDir() + File.separatorChar + "Generated" + File.separatorChar + "testFile1024Byte.test");
        file1024Byte.createNewFile();
        FileOutputStream file1024ByteOutputStream = new FileOutputStream(file1024Byte);
        byte[] testArray = EMBStaticHelper.createRandomByteArray(1024);
        file1024ByteOutputStream.write(testArray);
        file1024ByteOutputStream.close();
        // register media format
        mebTester.bindMediaFormat("test", new GenericMediaFormat());
        String testInstance = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(testInstance, "testFile1024Byte.test");
        mebTester.setMediaEntityContent(testInstance, file1024Byte);
        byte[] testBuffer = new byte[1024];
        int exception = -1;
        //
        // test 1
        //
        try {
            exception = mebTester.readContentExceptions(testInstance, -1, testBuffer, 0, 1024);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertEquals("test 1: Should throw an IndexOutOfBoundsException", MediaEntityLocalTestDriver.INDEXOUTOFBOUNDS,
                exception);
        testTrace("test 1 passed");

        //
        // test 2
        //
        try {
            exception = mebTester.readContentExceptions(testInstance, 1025, testBuffer, 0, 1024);
        } catch (Throwable e) {
            fail("test 2 threw " + e.toString());
        }
        assertEquals("test 2: Should throw an IndexOutOfBoundsException", MediaEntityLocalTestDriver.INDEXOUTOFBOUNDS,
                exception);
        testTrace("test 2 passed");

        //
        // test 3
        //
        try {
            exception = mebTester.readContentExceptions(testInstance, 0, testBuffer, -1, 1024);
        } catch (Throwable e) {
            fail("test 3 threw " + e.toString());
        }
        assertEquals("test 3: Should throw an IndexOutOfBoundsException", MediaEntityLocalTestDriver.INDEXOUTOFBOUNDS,
                exception);
        testTrace("test 3 passed");
        //
        // test 4
        //
        /*
        try {
            exception = mebTester.readContentExceptions(testInstance, 0, testBuffer, 1025, 1024);
        } catch (Throwable e) {
            fail("test 4 threw " + e.toString());
        }
        assertEquals("test 4: Should throw an IndexOutOfBoundsException", MediaEntityLocalTestDriver.INDEXOUTOFBOUNDS,
                exception);
        testTrace("test 4 passed");
        //
        // test 5
        //
        try {
            exception = mebTester.readContentExceptions(testInstance, 0, testBuffer, 0, -1);
        } catch (Throwable e) {
            fail("test 5 threw " + e.toString());
        }
        assertEquals("test 5: Should throw a NegativeArraySizeExcepton", MediaEntityLocalTestDriver.NEGATIVEARRAYSIZE,
                exception);
        testTrace("test 5 passed");*/
        //
        // test 6
        //
        try {
            exception = mebTester.readContentExceptions(testInstance, 0, null, 0, 1024);
        } catch (Throwable e) {
            fail("test 6 threw " + e.toString());
        }
        assertEquals("test 6: Should throw a NullPointerExcepton", MediaEntityLocalTestDriver.NULLPOINTER, exception);
        testTrace("test 6 passed");
        //
        // test 7
        //
        String noContentMedia = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(noContentMedia, "testFile.test");
        try {
            exception = mebTester.readContentExceptions(noContentMedia, 0, testBuffer, 0, 1024);
        } catch (Throwable e) {
            fail("test 7 threw " + e.toString());
        }
        assertEquals("test 7: Should throw a ContentAccessException", MediaEntityLocalTestDriver.CONTENTACCESS,
                exception);
        testTrace("test 7 passed");
        mebTester.removeMEBByPK(noContentMedia);
        //
        // test 8
        //
        /*
        boolean contentValid = mebTester.readCompareContent(testInstance, 0, testBuffer, 0, 1024, testArray, true);
        assertTrue("test 8: content does not match ", contentValid);
        testTrace("test 8 passed");
        //
        // test 9
        //
        contentValid = mebTester.readCompareContent(testInstance, 512, testBuffer, 0, 1024, testArray, false);
        assertTrue("test 9: ", contentValid);
        testTrace("test 9 passed");
        //
        // test 10
        //
        int amountCopied = mebTester.readMediaEntityContent(testInstance, 1024, testBuffer, 0, 1024);
        assertEquals("test 10: ", -1, amountCopied);
        testTrace("test 10 passed");
        //
        // test 11
        //
        contentValid = mebTester.readCompareContent(testInstance, 0, testBuffer, 100, 924, testArray, false);
        assertTrue("test 11: ", contentValid);
        testTrace("test 11 passed");
        //
        // test 12
        //
        contentValid = mebTester.readCompareContent(testInstance, 200, testBuffer, 100, 100, testArray, false);
        assertTrue("test 12: ", contentValid);
        testTrace("test 12 passed");
        //
        // test 13
        //
        contentValid = mebTester.readCompareContent(testInstance, 0, testBuffer, 0, 1048, testArray, false);
        assertTrue("test 13: ", contentValid);
        testTrace("test 13 passed");
        mebTester.removeMEBByPK(testInstance);
        */

        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: removeListener(MediaListener)
     *  Testcase Number: EMB123
     *
     *  setup: create Media entity me1 and media listener listener1
     *
     *  test procedure:
     *  1.call removeListener(null)
     *    expected result: NullPointerException
     *
     *  2.call me1.addListener(listener1), call me1.getListeners() and verify listener is added
     *    call me1.removeListener(listener1), call me1.getListeners() and verify listener is removed
     *    expected result: listener1 is removed
     *
     *  3.create media listener listener 2
     *    call me1.removeListener(listener2)
     *    expected result: no action and no exception
     *
     * </pre>
     */
    public void testEMB123() throws IOException, MediaException, CreateException, RemoteException, NamingException,
            FinderException, RemoveException {
        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        GenericMediaListener listener1 = new GenericMediaListener();
        GenericMediaListener listener2 = new GenericMediaListener();
        int exception = -1;
        //
        // test 1
        //
        try {
            exception = mebTester.removeListenerExceptions(me1, null);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertEquals("test 1: Should throw a NullPointerException", exception, MediaEntityLocalTestDriver.NULLPOINTER);
        testTrace("test 1 passed");
        //
        // test 2
        //
        mebTester.addMediaEntityListener(me1, listener1);
        assertEquals("test 2: listener not added", 1, mebTester.getMediaEntityListeners(me1).length);
        mebTester.removeMediaEntityListener(me1, listener1);
        assertEquals("test 2: listener not removed", 0, mebTester.getMediaEntityListeners(me1).length);
        testTrace("test 2 passed");
        //
        // test 3
        //
        try {
            mebTester.removeMediaEntityListener(me1, listener2);
            testTrace("test 3 passed");
        } catch (Throwable e) {
            fail("test 3 threw " + e.toString());
        }
        mebTester.removeMEBByPK(me1);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: removeMetaData(MetaDataEntityLocal)
     *  Testcase Number: EMB124
     *
     *  setup: create Media entity me1 and meta data entity md1
     *
     *  test procedure:
     *  1.call removeMetaData(null)
     *    expected result: NullPointerException
     *
     *  2.call me1.addMetaData(md1), call me1.getMetaData() and verify meta data is added
     *    call me1.removeMetaData(md1), call me1.getMetaData() and verify md1 is removed
     *    expected result: md1 is removed
     *
     *  3.create meta data entity md2
     *    call me1.removeMetaData(md2)
     *    expected result: no exception
     *
     * </pre>
     */
    public void testEMB124() throws CreateException, IOException, MediaException, RemoteException, NamingException,
            FinderException, RemoveException {
        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        // use local home interface to create new meta data entity
        String md1 = mebTester.createMetaDataEntityBean();
        String md2 = mebTester.createMetaDataEntityBean();
        int exception = -1;
        //
        // test 1
        //
        try {
            exception = mebTester.removeMetaDataExceptions(me1, null);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertEquals("test 1: Should throw a NullPointerException", exception, MediaEntityLocalTestDriver.NULLPOINTER);
        testTrace("test 1 passed");
        //
        // test
        //
        mebTester.addMediaEntityMetaData(me1, md1);
        assertEquals("test 2; meta data not added", 1, mebTester.getMediaEntityMetaData(me1).length);
        mebTester.removeMediaEntityMetaData(me1, md1);
        assertEquals("test 2: meta data not removed", 0, mebTester.getMediaEntityMetaData(me1).length);
        testTrace("test 2 passed");
        //
        // test 3
        //
        try {
            mebTester.removeMediaEntityMetaData(me1, md2);
            testTrace("test 3 passed");
        } catch (Throwable e) {
            fail("test 3 threw " + e.toString());
        }

        mebTester.removeMEBByPK(me1);
        mebTester.removeMDEBByPK(md1);
        mebTester.removeMDEBByPK(md2);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: setChildren(MediaEntityLocal[] children)
     *  Testcase Number: EMB125
     *
     *  setup:
     *
     *  test procedure:
     *  1.call setChildren(null)
     *    expected result: NullPointerException
     *
     *  2.call setChildren(new MediaEntityLocal[] {null})
     *    expected result: NullPointerException
     *
     *  3.create nonembedded media with 1 child
     *    call setChildren with only 2 children passed in
     *    expected result: IllegalArgumentException
     *
     *  4.create nonembedded media with 1 child
     *    call setChildren(new MediaEntityLocal[0])
     *    expected result: IllegalArgumentException
     *
     *  5.create nonembedded media and set location
     *    call setChildren
     *    expected result: ContentUnmutableException
     *
     *  6.create embedded media and call setChildren(new MediaEntityLocal[0])
     *    expected result: no exception
     *
     *  7.create nonembedded media with 1 child
     *    call setChildren(new MediaEntityLocal[] {child})
     *    expected result: no exception and child content is updated
     *
     *  8.create nonembedded media with no content
     *    create child and call setChildren
     *    expected result: ContentAccessException
     *
     * </pre>
     */
    public void testEMB125() throws MalformedURLException, IOException, MediaException, CreateException,
            RemoteException, NamingException, FinderException, RemoveException {

        mebTester.bindMediaFormat("gpl", new GenericPlaylistFormat());
        mebTester.bindMediaFormat("bmp", new BmpFormat());

        // playlist with 3 children
        ComplexMediaLocationInfo me1NELocInfo = new ComplexMediaLocationInfo(ComplexMediaLocationInfo.MEDIAGPL1);
        String me1NE = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1NE, "testPlaylist1.gpl");
        mebTester.importMediaEntityContent(me1NE, me1NELocInfo.getRootURL(), null);

        // playlist with 1 child
        ComplexMediaLocationInfo me2NELocInfo = new ComplexMediaLocationInfo(ComplexMediaLocationInfo.MEDIAGPL2);
        String me2NE = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me2NE, "testPlaylist2.gpl");
        mebTester.importMediaEntityContent(me2NE, me2NELocInfo.getRootURL(), null);

        int exception = -1;
        //
        // test 1
        //
        try {
            exception = mebTester.setChildrenExceptions(me1NE, null);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertEquals("test 1: Should throw a NullPointerException", MediaEntityLocalTestDriver.NULLPOINTER, exception);
        testTrace("test 1 passed");
        //
        // test 2
        //
        try {
            exception = mebTester.setChildrenExceptions(me2NE, new String[] {null});
        } catch (Throwable e) {
            fail("test 2 threw " + e.toString());
        }
        assertEquals("test 2: Should throw a NullPointerException", MediaEntityLocalTestDriver.NULLPOINTER, exception);
        testTrace("test 2 passed");
        //
        // test 3
        //
        String mebChild1 = mebTester.createMediaEntityBean();
        String mebChild2 = mebTester.createMediaEntityBean();

        try {
            exception = mebTester.setChildrenExceptions(me2NE, new String[] {mebChild1, mebChild2});
        } catch (Throwable e) {
            fail("test 3 threw " + e.toString());
        }
        assertEquals("test 3: Should throw an IllegalArgumentException", MediaEntityLocalTestDriver.ILLEGALARGUMENT,
                exception);
        testTrace("test 3 passed");

        //
        // test 4
        //
        try {
            exception = mebTester.setChildrenExceptions(me2NE, new String[0]);
        } catch (Throwable e) {
            fail("test 4 threw " + e.toString());
        }
        assertEquals("test 4: Should throw an IllegalArgumentException", MediaEntityLocalTestDriver.ILLEGALARGUMENT,
                exception);
        testTrace("test 4 passed");

        //
        // test 5
        //
        String me3NE = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me3NE, "test.gpl");
        mebTester.setMediaEntityLocation(me3NE, me2NELocInfo.getRootURL());
        try {
            exception = mebTester.setChildrenExceptions(me3NE, new String[] {mebChild1});
        } catch (Throwable e) {
            fail("test 5 threw " + e.toString());
        }
        assertEquals("test 5: Should throw an ContentUnmutableException", MediaEntityLocalTestDriver.CONTENTUNMUTABLE,
                exception);
        testTrace("test 5 passed");
        //
        // test 6
        //
        EmbeddedMediaLocationInfo me4LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getBmpPictureName1());
        String me4 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me4, me4LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me4, me4LocInfo.getMediaFile());

        mebTester.setMediaEntityChildren(me4, new String[0]);
        testTrace("test 6 passed");

        //
        // test 7
        //
        mebTester.setMediaEntityChildren(me2NE, new String[] {me4});
        String[] children = mebTester.getMediaEntityChildren(me2NE);
        assertEquals("test 7: media entity does not have 1 child", 1, children.length);
        assertTrue("test 7: child content does not match", java.util.Arrays.equals(
                mebTester.getMediaEntityContent(me4), mebTester.getMediaEntityContent(children[0])));
        testTrace("test 7 passed");
        //
        // test 8
        //
        String noContentMedia = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(noContentMedia, "test.gpl");
        String child3 = mebTester.createMediaEntityBean();
        try {
            exception = mebTester.setChildrenExceptions(noContentMedia, new String[] {child3});
        } catch (Throwable e) {
            fail("test 8 threw " + e.toString());
        }
        assertEquals("test 8: Should throw a ContentAccessException", MediaEntityLocalTestDriver.CONTENTACCESS,
                exception);
        testTrace("test 8 passed");

        mebTester.removeMEBByPK(me1NE);
        mebTester.removeMEBByPK(me2NE);
        mebTester.removeMEBByPK(me3NE);
        mebTester.removeMEBByPK(me4);
        mebTester.removeMEBByPK(mebChild1);
        mebTester.removeMEBByPK(mebChild2);
        mebTester.removeMEBByPK(child3);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: setContent(byte[])
     *  Testcase Number: EMB126
     *
     *  setup: create Media entity me1 from bmp media file
     *
     *  test procedure:
     *  1.call setContent(null)
     *    expected result: no exception
     *
     *  2.call getLastModified() and remember timestamp
     *    call setContent() with testPicture2.bmp
     *    call getContent()
     *  	 wait 2 seconds
     *  	 expected result: content of new file
     *  					  call getLastModified() and check if timestamp changed
     *  					  call getFormat and check it has not changed
     *
     *  3.call setContent with testPicture1.jpg
     *    expected result: FormatSyntaxException (format change)
     *
     *  4.create Media entity from nonembedded media
     *    call getLastModified and remember timestamp
     *    call setContent with testPlaylist1.gpl
     *    wait 2 seconds
     *    call getContent
     *    expected result: content matches testPlaylist1
     *  					  call getChildren and check empty array is returned
     *  					  call getLastModified and check timestamp has changed
     *
     *  5.call setName(&quot;testPicture1.jpg&quot;)
     *    call setContent with testPicture1.jpg
     *    expected result: no exception
     *                     call getContent and verify new content and format change
     *
     *  6.create media listener and call me1.addListener(listener)
     *    call setContent with testPicture1.bmp
     *    expected result: ListenerVetoException
     *
     *  7.create media entity and call setName
     *    call setContent with byte array larger than maxMediaSize
     *    expected result: ContentTooLargeException
     *
     * </pre>
     */
    public void testEMB126() throws MalformedURLException, MediaException, IOException, InterruptedException,
            CreateException, RemoteException, NamingException, FinderException, RemoveException {

        mebTester.bindMediaFormat("jpg", new JpegFormat());
        mebTester.bindMediaFormat("bmp", new BmpFormat());
        mebTester.bindMediaFormat("test", new GenericMediaFormat());
        mebTester.bindMediaFormat("gpl", new GenericPlaylistFormat());
        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getBmpPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());

        EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getBmpPictureName2());
        EmbeddedMediaLocationInfo me3LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());

        ComplexMediaLocationInfo me4NELocInfo = new ComplexMediaLocationInfo(ComplexMediaLocationInfo.MEDIAGPL1);
        String me4NE = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me4NE, me4NELocInfo.getRootFile().getName());
        mebTester.setMediaEntityContent(me4NE, me4NELocInfo.getRootFile());
        int exception = -1;
        //
        // test 1
        //
        byte[] nullByteArray = null;
        try {
            mebTester.setMediaEntityContent(me1, nullByteArray);
        } catch (Exception e) {
            fail("test 1 threw " + e.toString());
        }
        testTrace("test 1 passed");
        //
        // test 2
        //
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        Date beforeStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        mebTester.setMediaEntityContent(me1, me2LocInfo.getMediaFile());
        Thread.sleep( 1000);
        Date afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        assertTrue("test 2: Modification date", afterStamp.after(beforeStamp));
        assertTrue("test 2: content does not match", java.util.Arrays.equals(mebTester.getMediaEntityContent(me1),
                getByteArrayFromFile(me2LocInfo.getMediaFile())));
        assertTrue("test 2: format changed", mebTester.getMediaEntityFormat(me1) instanceof BmpFormat);
        testTrace("test 2 passed");
        //
        // test 3
        //
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        try {
            exception = mebTester.setContentExceptions(me1, getByteArrayFromFile(me3LocInfo.getMediaFile()));
        } catch (Throwable e) {
            fail("test 3 threw " + e.toString());
        }
        assertEquals("test 3: Should throw a FormatSyntaxException", MediaEntityLocalTestDriver.FORMATSYNTAX,exception);
        testTrace("test 3 passed");
        //
        // test 4
        //
        beforeStamp = new Date(mebTester.getMediaEntityLastModified(me4NE));
        mebTester.setMediaEntityContent(me4NE, me4NELocInfo.getRootFile());
        Thread.sleep( 1000);
        afterStamp = new Date(mebTester.getMediaEntityLastModified(me4NE));
        assertTrue("test 4: Modification date", afterStamp.after(beforeStamp));
        assertTrue("test 4: content did not change", java.util.Arrays.equals(mebTester.getMediaEntityContent(me4NE),
                getByteArrayFromFile(me4NELocInfo.getRootFile())));
        assertTrue("test 4: format changed", mebTester.getMediaEntityFormat(me4NE) instanceof GenericPlaylistFormat);
        assertEquals("test 4: children stored", 0, mebTester.getMediaEntityChildren(me4NE).length);
        testTrace("test 4 passed");
        //
        // test 5
        //
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());

        mebTester.setMediaEntityName(me1, "testPicture1.jpg");
        beforeStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        mebTester.setMediaEntityContent(me1, getByteArrayFromFile(me3LocInfo.getMediaFile()));
        Thread.sleep( 1000);
        afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        assertTrue("test 5: Modification date", afterStamp.after(beforeStamp));
        assertTrue("test 5: content did not change", java.util.Arrays.equals(mebTester.getMediaEntityContent(me1),
                getByteArrayFromFile(me3LocInfo.getMediaFile())));
        assertTrue("test 5: format did not change", mebTester.getMediaEntityFormat(me1) instanceof JpegFormat);
        testTrace("test 5 passed");
        //
        // test 6
        //
        String me5 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me5, "test.bmp");
        // set content to testPicture1.bmp
        mebTester.setMediaEntityContent(me5, me1LocInfo.getMediaFile());
        GenericMediaListener testListener = new GenericMediaListener();
        mebTester.addMediaEntityListener(me5, testListener);
        try {
            // try to set content to testPicture2.bmp
            exception = mebTester.setContentExceptions(me5, getByteArrayFromFile(me2LocInfo.getMediaFile()));
        } catch (Throwable e) {
            fail("test 6 threw " + e.toString());
        }
        assertEquals("test 6: Should throw a ListenerVetoException", MediaEntityLocalTestDriver.LISTENERVETO, exception);
        assertTrue("test 6: content should not change", Arrays.equals(getByteArrayFromFile(me1LocInfo.getMediaFile()),
                mebTester.getMediaEntityContent(me5)));
        testTrace("test 6 passed");
        //
        // test 7
        //
        if (embTestConfig.getIncludeLongRunningTest()) {
            String largeFilePath = embTestConfig.getMediaDir() + File.separatorChar + "Generated" + File.separatorChar + "largeFile.test";
            File largeFile = new File(largeFilePath);
            largeFile.createNewFile();
            FileOutputStream largeFileOutputStream = new FileOutputStream(largeFile);
            // create byte array 1 byte larger than maxMediaSize
            byte[] testArray = EMBStaticHelper
                    .createRandomByteArray(Integer.parseInt(embTestConfig.getMaxMediaSize()) + 1);
            largeFileOutputStream.write(testArray);
            largeFileOutputStream.close();

            String testInstance = mebTester.createMediaEntityBean();
            mebTester.setMediaEntityName(testInstance, "largeMedia.test");
            try {
                exception = mebTester.setContentExceptions(testInstance, getByteArrayFromFile(largeFile));
            } catch (Throwable e) {
                fail("test 7 threw " + e.toString());
            }
            assertEquals("test 7: Should throw a ContentTooLargeException", MediaEntityLocalTestDriver.CONTENTTOOLARGE,
                    exception);
            testTrace("test 7 passed");
            largeFile.delete();
            mebTester.removeMEBByPK(testInstance);
        }

        mebTester.removeMEBByPK(me1);
        mebTester.removeMEBByPK(me4NE);
        mebTester.removeMEBByPK(me5);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: setContent(InputStream)
     *  Testcase Number: EMB127
     *
     *  setup: create Media entity me1 from bmp media file
     *
     *  test procedure:
     *  1.call setContent(null)
     *    expected result: NullPointerException
     *
     *  2.call getLastModified() and remember timestamp
     *    call setContent() with testPicture2.bmp
     *    call getContent()
     *  	 wait 2 seconds
     *  	 expected result: content of new file
     *  					  call getLastModified() and check if timestamp changed
     * 					  call getFormat and check it has not changed
     *
     *  3.call setContent with testPicture1.jpg
     *    expected result: FormatSyntaxException (format change)
     *
     *  4.create Media entity from nonembedded media
     *    call getLastModified and remember timestamp
     *    call setName(&quot;testPlaylist1.gpl&quot;)
     *    call setContent with testPlaylist1.gpl
     *    wait 2 seconds
     *    call getContent
     *    expected result: content matches testPlaylist1
     * 					  call getChildren and check empty array is returned
     * 					  call getLastModified and check timestamp has changed
     *
     *  5.call setName(&quot;testPicture1.jpg&quot;)
     *    call setContent with testPicture1.jpg
     *    expected result: no exception
     *                     call getContent and verify new content and format change
     *
     *  6.create media listener and call me1.addListener(listener)
     *    call setContent with testPicture1.bmp
     *    expected result: ListenerVetoException
     *
     *  7.create media entity and call setName
     *    call setContent with file larger than maxMediaSize
     *    expected result: ContentTooLargeException
     *
     * </pre>
     */
    public void testEMB127() throws IOException, MediaException, InterruptedException, CreateException,
            RemoteException, NamingException, FinderException, RemoveException {

        mebTester.bindMediaFormat("jpg", new JpegFormat());
        mebTester.bindMediaFormat("bmp", new BmpFormat());
        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getBmpPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getBmpPictureName2());
        EmbeddedMediaLocationInfo me3LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        ComplexMediaLocationInfo me4NELocInfo = new ComplexMediaLocationInfo(ComplexMediaLocationInfo.MEDIAGPL1);
        String me4NE = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me4NE, me4NELocInfo.getRootFile().getName());
        mebTester.setMediaEntityContent(me4NE, me4NELocInfo.getRootFile());
        int exception = -1;
        //
        // test 1
        //
        File nullFile = null;
        try {
            exception = mebTester.setContentExceptions(me1, nullFile);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertEquals("test 1: Should throw a NullPointerException", exception, MediaEntityLocalTestDriver.NULLPOINTER);
        testTrace("test 1 passed");
        //
        // test 2
        //
        Date beforeStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        mebTester.setMediaEntityContent(me1, me2LocInfo.getMediaFile());
        Thread.sleep( 1000);
        Date afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        assertTrue("test 2: Modification date", afterStamp.after(beforeStamp));
        assertTrue("test 2: content does not match", java.util.Arrays.equals(mebTester.getMediaEntityContent(me1),
                getByteArrayFromFile(me2LocInfo.getMediaFile())));
        assertTrue("test 2: format changed", mebTester.getMediaEntityFormat(me1) instanceof BmpFormat);
        testTrace("test 2 passed");
        //
        // test 3
        //

        try {
            exception = mebTester.setContentExceptions(me1, me3LocInfo.getMediaFile());
        } catch (Throwable e) {
            fail("test 3 threw " + e.toString());
        }
        assertEquals("test 3: Should throw a FormatSyntaxException", MediaEntityLocalTestDriver.FORMATSYNTAX, exception );
        testTrace("test 3 passed");
        //
        // test 4
        //
        mebTester.setMediaEntityName(me1, me4NELocInfo.getRootFile().getName());
        beforeStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        mebTester.setMediaEntityContent(me1, me4NELocInfo.getRootFile());
        Thread.sleep( 1000);
        afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        assertTrue("test 4: Modification date", afterStamp.after(beforeStamp));
        assertTrue("test 4: content does not match", java.util.Arrays.equals(mebTester.getMediaEntityContent(me1),
                getByteArrayFromFile(me4NELocInfo.getRootFile())));
        assertTrue("test 4: format changed", mebTester.getMediaEntityFormat(me1) instanceof GenericPlaylistFormat);
        assertEquals("test 4: children stored", 0, mebTester.getMediaEntityChildren(me1).length);
        testTrace("test 4 passed");
        //
        // test 5
        //
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());

        mebTester.setMediaEntityName(me1, "testPicture1.jpg");
        beforeStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        mebTester.setMediaEntityContent(me1, me3LocInfo.getMediaFile());
        Thread.sleep( 1000);
        afterStamp = new Date((mebTester.getMediaEntityLastModified(me1)));
        assertTrue("test 5: Modification date", afterStamp.after(beforeStamp));
        assertTrue("test 5: content did not change", java.util.Arrays.equals(mebTester.getMediaEntityContent(me1),
                getByteArrayFromFile(me3LocInfo.getMediaFile())));
        assertTrue("test 5: format did not change", mebTester.getMediaEntityFormat(me1) instanceof JpegFormat);
        testTrace("test 5 passed");
        //
        // test 6
        //
        String me5 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me5, "test.bmp");
        // set content to testPicture1.bmp
        mebTester.setMediaEntityContent(me5, me1LocInfo.getMediaFile());
        GenericMediaListener testListener = new GenericMediaListener();
        mebTester.addMediaEntityListener(me5, testListener);
        try {
            exception = mebTester.setContentExceptions(me5, getByteArrayFromFile(me2LocInfo.getMediaFile()));
        } catch (Throwable e) {
            fail("test 6 threw " + e.toString());
        }
        assertEquals("test 6: Should throw a ListenerVetoException", MediaEntityLocalTestDriver.LISTENERVETO, exception);
        assertTrue("test 6: content should not change", Arrays.equals(getByteArrayFromFile(me1LocInfo.getMediaFile()),
                mebTester.getMediaEntityContent(me5)));
        testTrace("test 6 passed");
        //
        // test 7
        //
        if (embTestConfig.getIncludeLongRunningTest()) {
            String largeFilePath = embTestConfig.getMediaDir() + File.separatorChar + "Generated" + File.separatorChar + "largeFile.test";
            File largeFile = new File(largeFilePath);
            largeFile.createNewFile();
            FileOutputStream largeFileOutputStream = new FileOutputStream(largeFile);
            // create byte array 1 byte larger than maxMediaSize
            byte[] testArray = EMBStaticHelper
                    .createRandomByteArray(Integer.parseInt(embTestConfig.getMaxMediaSize()) + 1);
            largeFileOutputStream.write(testArray);
            largeFileOutputStream.close();

            String testInstance = mebTester.createMediaEntityBean();
            mebTester.setMediaEntityName(testInstance, "largeMedia.test");
            try {
                exception = mebTester.setContentExceptions(testInstance, largeFile);
            } catch (Throwable e) {
                fail("test 7 threw " + e.toString());
            }
            assertEquals("test 7: Should throw a ContentTooLargeException", MediaEntityLocalTestDriver.CONTENTTOOLARGE,
                    exception);
            testTrace("test 7 passed");
            largeFile.delete();
            mebTester.removeMEBByPK(testInstance);
        }

        mebTester.removeMEBByPK(me1);
        mebTester.removeMEBByPK(me4NE);
        mebTester.removeMEBByPK(me5);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase name: setDescription(String)
     *  Testcase Number: EMB128
     *
     *  setup: create Media entity from embedded media file
     *
     *  test procedure:
     *  1.call setDescription(null)
     *    expected result: NullPointerException
     *
     *  2.call setDescription(&quot;&quot;)
     *    expected result : no exception
     *
     *  3.call getLastModified() and remember timestamp
     *    call setDescription(&quot;abc&quot;)
     *    wait 2 secs and call getDescription
     *    expected result: &quot;abc&quot; and verify timestamp has changed
     *
     *  4.create media listener and call addListener(listener)
     *    call setDescription(&quot;&quot;)
     *    expected result: ListenerVetoException
     *
     * </pre>
     */
    public void testEMB128() throws MediaException, IOException, InterruptedException, CreateException,
            RemoteException, NamingException, FinderException, RemoveException {

        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getBmpPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        int exception = -1;
        //
        // test 1
        //
        mebTester.setMediaEntityDescription(me1, null);
        assertNull("test 1: Description should be null", mebTester.getMediaEntityDescription(me1));
        testTrace("test 1 passed");
        //
        // test 2
        //
        try {
            mebTester.setMediaEntityDescription(me1, "");
            testTrace("test 2 passed");
        } catch (Throwable e) {
            fail("test 2 threw exception  " + e.toString());
        } //
        // test 3
        //
        Date beforeStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        String tstDesc = EMBStaticHelper.createRandomString(12);
        mebTester.setMediaEntityDescription(me1, tstDesc);
        Thread.sleep( 1000);
        assertEquals("test 3 description", mebTester.getMediaEntityDescription(me1), tstDesc);
        Date afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        assertTrue("test 3: Modification date", afterStamp.after(beforeStamp));
        testTrace("test 3 passed");
        //
        // test 4
        //
        GenericMediaListener testListener = new GenericMediaListener();
        mebTester.addMediaEntityListener(me1, testListener);
        try {
            exception = mebTester.setDescriptionExceptions(me1, "newDescription");
        } catch (Throwable e) {
            fail("test 4 threw " + e.toString());
        }
        assertEquals("test 4: Should throw a ListenerVetoException", MediaEntityLocalTestDriver.LISTENERVETO, exception);
        assertEquals("test 4: description should not change", tstDesc, mebTester.getMediaEntityDescription(me1));
        testTrace("test 4 passed");

        mebTester.removeMEBByPK(me1);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: setLocation(URL)
     *  Testcase Number: EMB129
     *
     *  setup: create Media entity using instance of MediaEntityLocalHome
     *
     *  test procedure:
     *  1.call setLocation(null)
     *    call getLocation
     *    expected result: null
     *
     *  2.call getLastModified() and remember timestamp
     *    call setLocation(valid local location URL)
     *    wait 2 seconds and call getLocation
     *    expected result: URL equal to new location and timestamp was updated
     *
     *  3.create media listener and call addListener(listener)
     *    call setLocation(valid URL)
     *    expected result: ListenerVetoException
     *
     *  4.call setContent with byte array from testPicture1.jpg
     *    call setLocation(valid URL)
     *    expected result: LocationUnmutableException
     *
     * </pre>
     */
    public void testEMB129() throws MediaException, IOException, InterruptedException, CreateException,
            RemoteException, NamingException, FinderException, RemoveException {

        mebTester.bindMediaFormat("jpg", new JpegFormat());
        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName2());

        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, "test.jpg");
        int exception = -1;
        //
        // test 1
        //
        mebTester.setMediaEntityLocation(me1, null);
        assertNull("test 1: location not null", mebTester.getMediaEntityLocation(me1));
        testTrace("test 1 passed");
        //
        // test 2
        //
        Date beforeStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        mebTester.setMediaEntityLocation(me1, me1LocInfo.getMediaURL());
        Thread.sleep( 1000);
        Date afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        assertTrue("test 2: Modification date", afterStamp.after(beforeStamp));
        assertTrue("test 2: URL did not change", mebTester.getMediaEntityLocation(me1).equals(me1LocInfo.getMediaURL()));
        testTrace("test 2 passed");
        //
        // test 3
        //
        GenericMediaListener testListener = new GenericMediaListener();
        mebTester.addMediaEntityListener(me1, testListener);
        try {
            exception = mebTester.setLocationExceptions(me1, me2LocInfo.getMediaURL());
        } catch (Throwable e) {
            fail("test 3 threw " + e.toString());
        }
        assertEquals("test 3: Should throw a ListenerVetoException", MediaEntityLocalTestDriver.LISTENERVETO, exception);
        assertTrue("test 3: URL should not change", me1LocInfo.getMediaURL().equals(
                mebTester.getMediaEntityLocation(me1)));
        testTrace("test 3 passed");
        //
        // test 4
        //
        String me2 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());
        try {
            exception = mebTester.setLocationExceptions(me2, me1LocInfo.getMediaURL());
        } catch (Throwable e) {
            fail("test 4 threw " + e.toString());
        }
        assertEquals("test 4: Should throw a LocationUnmutableException", MediaEntityLocalTestDriver.LOCATIONUNMUTABLE,
                exception);
        testTrace("test 4 passed");

        mebTester.removeMEBByPK(me1);
        mebTester.removeMEBByPK(me2);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: setMimeType(String)
     *  Testcase Number: EMB130
     *
     *  setup: create Media entity from embedded media file
     *
     *  test procedure:
     *  1.call setMimeType(null)
     *    expected result: NullPointerException
     *
     *  2.call getLastModified() and remember timestamp
     *    call setMimeType(&quot;www/unknown&quot;)
     *    wait 2 seconds and call check getMimeType()
     *    expected result: mime type equal to &quot;www/unknown&quot; and timestamp updated
     *
     *  3.create media listener and call addListener(listener)
     *    call setMimeType(&quot;image/bmp&quot;);
     *    expected result: ListenerVetoException
     *
     * </pre>
     */
    public void testEMB130() throws MalformedURLException, InterruptedException, MediaException, IOException,
            CreateException, RemoteException, NamingException, FinderException, RemoveException {

        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getBmpPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        int exception = -1;
        //
        // test 1
        //
        try {
            mebTester.setMediaEntityMimeType(me1, null);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertNotNull("test 1: mimeType is null", mebTester.getMediaEntityMimeType(me1));
        testTrace("test 1 passed");
        //
        // test 2
        //
        Date beforeStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        String tstMimeType = "www/unknown";
        mebTester.setMediaEntityMimeType(me1, tstMimeType);
        Thread.sleep(1000);
        Date afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        assertTrue("test 2: Modification date", afterStamp.after(beforeStamp));
        assertEquals("test 2 URL changed", mebTester.getMediaEntityMimeType(me1), tstMimeType);
        testTrace("test 2 passed");
        //
        // test 3
        //
        GenericMediaListener testListener = new GenericMediaListener();
        mebTester.addMediaEntityListener(me1, testListener);
        try {
            exception = mebTester.setMimeTypeExceptions(me1, "image/bmp");
        } catch (Throwable e) {
            fail("test 3 threw " + e.toString());
        }
        assertEquals("test 3: Should throw a ListenerVetoException", MediaEntityLocalTestDriver.LISTENERVETO, exception);

        assertEquals("test 3: mimeType should not change", tstMimeType, mebTester.getMediaEntityMimeType(me1));
        testTrace("test 3 passed");

        mebTester.removeMEBByPK(me1);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: setName()
     *  Testcase Number: EMB131
     *
     *  setup: create Media entity from jpg media file
     * 		  rebind jpg to format registry
     *  test procedure:
     *  1.call setName(null)
     *    expected result: NullPointerException
     *
     *  2.call setName with random string and file extension
     *    expected result: IllegalArgumentException
     *
     *  3.call setName with string and random file extension (no invalid characters)
     *    expected result: FormatNotFoundException
     *
     *  4.call setName with random string and jpeg file extension
     *    call getName
     *    expected result: name matches random string
     *
     *  5.create media listener and call addListener(listener)
     *    call setName(&quot;test.jpg&quot;)
     *    expected result: ListenerVetoException
     *
     * </pre>
     */
    public void testEMB131() throws IOException, MediaException, CreateException, RemoteException, NamingException,
            FinderException, RemoveException {

        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getBmpPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        int exception = -1;
        //
        // test 1
        //
        try {
            exception = mebTester.setNameExceptions(me1, null);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertEquals("test 1: Should throw a NullPointerException", MediaEntityLocalTestDriver.NULLPOINTER, exception);
        testTrace("test 1 passed");
        //
        // test 2
        //
        try {
            exception = mebTester.setNameExceptions(me1, EMBStaticHelper.createRandomString(EMBStaticHelper.randomInt(
                    0, 5))
                    + "&(*#?:;,$%" + '.' + EMBStaticHelper.createRandomString(EMBStaticHelper.randomInt(0, 3)));
        } catch (Throwable e) {
            fail("test 2 threw " + e.toString());
        }
        assertEquals("test 2: Should throw a IllegalArgumentException", MediaEntityLocalTestDriver.ILLEGALARGUMENT,
                exception);
        testTrace("test 2 passed");
        //
        // test 3
        //
        try {
            mebTester.unbindMediaFormat("lnv");
        } catch (Exception e) {
        }
        try {
            exception = mebTester.setNameExceptions(me1, "test.lnv");
        } catch (Throwable e) {
            fail("test 3 threw " + e.toString());
        }
        assertEquals("test 3: Should throw a FormatNotFoundException", MediaEntityLocalTestDriver.FORMATNOTFOUND,
                exception);
        testTrace("test 3 passed");
        //
        // test 4
        //
        String tempName = "tmp.jpg";
        Date beforeStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        mebTester.setMediaEntityName(me1, tempName);
        Date afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
        assertTrue("test 4: timestamp not updated", afterStamp.after(beforeStamp));
        assertEquals("test 4: name incorrect", tempName, mebTester.getMediaEntityName(me1));
        testTrace("test 4 passed");
        //
        // test 5
        //
        GenericMediaListener testListener = new GenericMediaListener();
        mebTester.addMediaEntityListener(me1, testListener);
        String oldName = mebTester.getMediaEntityName(me1);
        try {
            exception = mebTester.setNameExceptions(me1, "test.jpg");
        } catch (ListenerVetoException e) {
            fail("test 5 threw " + e.toString());
        }
        assertEquals("test 5: Should throw a ListenerVetoException", MediaEntityLocalTestDriver.LISTENERVETO, exception);
        assertEquals("test 5: name should not change", oldName, mebTester.getMediaEntityName(me1));
        testTrace("test 5 passed");

        mebTester.removeMEBByPK(me1);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: setPreviousVersion(MediaEntityLocal)
     *  Testcase Number: EMB132
     *
     *  setup: create Media entities me1, me2, and me3 from embedded media files
     *
     *  test procedure:
     *  1.call me1.setPreviousVersion(null)
     *    call me1.getPreviousVersion() and me1.getNextVersion()
     *    expected result: both are null
     *
     *  2.call me2.setPreviousVersion(me1)
     *   expected result: me1.getPreviousVersion() is null
     *   				  me1.getNextVersion() is me2
     *  			  		  me2.getPreviousVersion() is me1
     *  					  me2.getNextVersion() is null
     *
     *  3.call me2.setPreviousVersion(me1)
     *    expected result: no exception
     *
     *  4.call me3.setPreviousVersion(me1)
     *    expected result: VersionIntegrityException
     *
     *  5.call me2.setPreviousVersion(me3)
     *    expected result: VersionIntegrityException
     *
     *  6.call me1.setPreviousVersion(me3)
     *    expected result: VersionIntegrityException
     *
     *  7.call me3.setPreviousVersion(null)
     *    expected result: no exception
     *
     *  8.call me3.setPreviousVersion(me2)
     *    expected result: me1.getPreviousVersion() is null
     *  					  me1.getNextVersion() is me2
     *   				  me2.getPreviousVersion() is me1
     * 					  me2.getNextVersion() is me3
     *   				  me3.getPreviousVersion() is me2
     *  					  me3.getNextVersion() is null
     *
     *  9.call me2.setPreviousVersion(null)
     *    expected result: VersionIntegrityException
     *
     *  10.call me3.setPreviousVersion(null)
     *     expected result: me1.getPreviousVersion() is null
     *     				   me2.getPreviousVersion() is me1
     *  					   me2.getNextVersion() is null
     *  					   me3.getPreviousVersion() is null
     *  					   me3.getNextVersion() is null
     *
     *
     * </pre>
     */
    public void testEMB132() throws MalformedURLException, IOException, MediaException, CreateException,
            RemoteException, NamingException, FinderException, RemoveException {

        mebTester.bindMediaFormat("jpg", new JpegFormat());
        mebTester.bindMediaFormat("bmp", new BmpFormat());
        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
        EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName2());
        String me2 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());
        EmbeddedMediaLocationInfo me3LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getBmpPictureName1());
        String me3 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me3, me3LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me3, me3LocInfo.getMediaFile());
        int exception = -1;
        //
        // test 1
        //
        try {
            mebTester.setMediaEntityPreviousVersion(me1, null);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertNull("test 1: me1.getPreviousVersion is not null", mebTester.getMediaEntityPreviousVersion(me1));
        assertNull("test 1: me1.getNextVersion is not null", mebTester.getMediaEntityNextVersion(me1));
        testTrace("test 1 passed");
        //
        // test 2
        //
        mebTester.setMediaEntityPreviousVersion(me2, me1);
        assertNull("test 2: me1.getPreviousVersion is not null", mebTester.getMediaEntityPreviousVersion(me1));
        assertEquals("test 2: me1.getNextVersion is not me2", mebTester.getMediaEntityNextVersion(me1), me2);
        assertEquals("test 2: me2.getPreviousVersion is not me1", mebTester.getMediaEntityPreviousVersion(me2), me1);
        assertNull("test 2: me2.getNextVersion is not null", mebTester.getMediaEntityNextVersion(me2));
        testTrace("test 2 passed");
        //
        // test 3
        //
        try {
            mebTester.setMediaEntityPreviousVersion(me2, me1);
            testTrace("test 3 passed");
        } catch (Throwable e) {
            fail(" test 3 threw " + e.toString());
        } //
        // test 4
        //
        try {
            exception = mebTester.setPreviousVersionExceptions(me3, me1);
        } catch (Throwable e) {
            fail("test 4 threw " + e.toString());
        }
        assertEquals("test 4: Should throw a VersionChainIntegrityException",
                MediaEntityLocalTestDriver.VERSIONCHAININTEGRITY, exception);
        testTrace("test 4 passed");
        //
        // test 5
        //
        try {
            exception = mebTester.setPreviousVersionExceptions(me2, me3);
        } catch (Throwable e) {
            fail("test 5 threw " + e.toString());
        }
        assertEquals("test 5: Should throw a VersionChainIntegrityException",
                MediaEntityLocalTestDriver.VERSIONCHAININTEGRITY, exception);
        testTrace("test 5 passed");
        //
        // test 6
        //
        try {
            exception = mebTester.setPreviousVersionExceptions(me1, me3);
        } catch (Throwable e) {
            fail("test 6 threw " + e.toString());
        }
        assertEquals("test 6: Should throw a VersionChainIntegrityException",
                MediaEntityLocalTestDriver.VERSIONCHAININTEGRITY, exception);
        testTrace("test 6 passed");
        //
        // test 7
        //
        try {
            mebTester.setMediaEntityPreviousVersion(me3, null);
            testTrace("test 7 passed");
        } catch (Throwable e) {
            fail(" test 7 threw " + e.toString());
        } //
        // test 8
        //
        mebTester.setMediaEntityPreviousVersion(me3, me2);
        assertNull("test 8: me1.getPreviousVersion is not null", mebTester.getMediaEntityPreviousVersion(me1));
        assertEquals("test 8: me1.getNextVersion is not me2", mebTester.getMediaEntityNextVersion(me1), me2);
        assertEquals("test 8: me2.getPreviousVersion is not me1", mebTester.getMediaEntityPreviousVersion(me2), me1);
        assertEquals("test 8: me2.getNextVersion is not me3", mebTester.getMediaEntityNextVersion(me2), me3);
        assertEquals("test 8: me3.getPreviousVersion is not me2", mebTester.getMediaEntityPreviousVersion(me3), me2);
        assertNull("test 8: me3.getNextVersion is not null", mebTester.getMediaEntityNextVersion(me3));
        testTrace("test 8 passed");
        //
        // test 9
        //
        try {
            exception = mebTester.setPreviousVersionExceptions(me2, null);
        } catch (Throwable e) {
            fail("test 9 threw " + e.toString());
        }
        assertEquals("test 9: Should throw a VersionChainIntegrityException",
                MediaEntityLocalTestDriver.VERSIONCHAININTEGRITY, exception);
        testTrace("test 9 passed");
        //
        // test 10
        //
        mebTester.setMediaEntityPreviousVersion(me3, null);
        assertNull("test 10: me1.getPreviousVersion is not null", mebTester.getMediaEntityPreviousVersion(me1));
        assertEquals("test 10: me1.getNextVersion is not me2", mebTester.getMediaEntityNextVersion(me1), me2);
        assertEquals("test 10: me2.getPreviousVersion is not me1", mebTester.getMediaEntityPreviousVersion(me2), me1);
        assertNull("test 10: me2.getNextVersion is not null", mebTester.getMediaEntityNextVersion(me2));
        assertNull("test 10: me3.getPreviousVersion is not null", mebTester.getMediaEntityPreviousVersion(me3));
        assertNull("test 10: me3.getNextVersion is not null", mebTester.getMediaEntityNextVersion(me3));
        testTrace("test 10 passed");

        mebTester.removeMEBByPK(me1);
        mebTester.removeMEBByPK(me2);
        mebTester.removeMEBByPK(me3);
        succeed();
    }

    /**
     * <pre>
     *
     *  Testcase Name: setProxy(MediaEntityLocal)
     *  Testcase Number: EMB133
     *
     *  setup: create Media entites me1 and me2 from embedded media files
     *
     *  test procedure:
     *  1.call me1.setProxy(me2)
     *    call me1.getProxy()
     *    expected result: me2
     *
     *  2.call me2.setProxy(null)
     *    call me2.getProxy()
     *    expected result: not null and not me2
     *
     *  3.call me1.setProxy(me2)
     *    call me2.setProxy(me1)
     *    call me1.setProxy(me1)
     *    expected result: no exception
     *
     * </pre>
     */
    public void testEMB133() throws MalformedURLException, InterruptedException, IOException, MediaException,
            CreateException, RemoteException, NamingException, FinderException, RemoveException {

        mebTester.bindMediaFormat("jpg", new JpegFormat());
        mebTester.bindMediaFormat("bmp", new BmpFormat());

        EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getBmpPictureName1());
        String me1 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());

        EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
        String me2 = mebTester.createMediaEntityBean();
        mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());
        mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());

        MediaBean bmpMediaBean = new MediaBean(me1LocInfo.getMediaFile(), "image/bmp");
        MediaBean jpgMediaBean = new MediaBean(me2LocInfo.getMediaFile(), "image/jpeg");
        Media proxy = null;
        //
        // test 1
        //
        mebTester.setMediaEntityProxy(me1, me2);
        try {
            proxy = mebTester.getMediaEntityProxy(me1);
            assertNotNull("test 1: proxy is null", proxy);
        } catch (Throwable e) {
            fail("test 1 threw " + e.toString());
        }
        assertTrue("test 1: proxy does not match", Arrays.equals(proxy.getContent(), mebTester
                .getMediaEntityContent(me2)));
        testTrace("test 1 passed");
        //
        // test 2
        //
        mebTester.setMediaEntityProxy(me1, null);
        assertNotNull("test 2: proxy is null", mebTester.getMediaEntityProxy(me1));
        assertFalse("test 2: proxy not altered", Arrays.equals(mebTester.getMediaEntityProxy(me1).getContent(),
                mebTester.getMediaEntityContent(me2)));
        testTrace("test 2 passed");
        //
        // test 3
        //
        try {
            mebTester.setMediaEntityProxy(me1, me2);
            mebTester.setMediaEntityProxy(me2, me1);
            mebTester.setMediaEntityProxy(me1, me1);
            testTrace("test 3 passed");
        } catch (Throwable e) {
            fail("test 3  threw Exception " + e.toString());
        }

        mebTester.removeMEBByPK(me1);
        mebTester.removeMEBByPK(me2);
        succeed();
    }

}