Class MediaServiceDemoTest

    • Constructor Detail

      • MediaServiceDemoTest

        public MediaServiceDemoTest()
    • Method Detail

      • setUp

        public void setUp()
                   throws java.lang.Exception
        Prepares data for testing - sample media items, media folders, formats, containers, context and other data that will be used. Data is loaded from csv impex file.
        Throws:
        java.lang.Exception
      • testGetStreamFromMedia

        public void testGetStreamFromMedia()
        Demonstrates how to use media service to retrieve input stream that represents file that media item contains. Media with code "media1" contains sample text file that has specific length and this length is checked for retrieved file.
      • testGetDataFromMedia

        public void testGetDataFromMedia()
        Demonstrates how to use media service to retrieve byte array that contains data from file assigned to media item. Retrieved byte array is checked against number of bytes it contains.
      • testSetDataForMedia

        public void testSetDataForMedia()
        Demonstrates how to use media service to put byte array as data for underlying media file. New byte array is set for media item and then it is retrieved and its length is checked.
      • testSetStreamForMedia

        public void testSetStreamForMedia()
        Test demonstrates how to use media service to set input stream into underlying media file. New byte array input stream is created and put into media item with new name and mime type. Then input stream is retrieved from media and its length is checked. Also mime type and new name of the file is checked.
      • testSetFolderForMedia

        public void testSetFolderForMedia()
        In this test we set new media folder for selected media. Media folder is created in set up process from impex file and is here assigned to the media item. Then media model is saved and checked if media folder was changed to the new one.
      • testMoveData

        public void testMoveData()
        Test shows how to move data from one media object to another. New data (as byte array) is created and set for media object 2. Then we use media service to move this new data to the media object 1. Last step is to check if data was moved - model 2 should not contains this data anymore, and model 1 should contain this data.
      • testCopyData

        public void testCopyData()
        This test demonstrates how to copy data from one media item to other one. New data is created (as byte array) and then put into media model 2. Then it is copied from model 2 to model 1 and then both models are checked if contain new data.
      • testDuplicateData

        public void testDuplicateData()
        Here we demonstrate how to duplicate underlying media data. New data is created and put into model 2. Then this data is duplicated into model 1. The difference between copying and duplicating is that copying just make in the model new reference to existing file, and duplicating creates new file and assigns it to the target model.
      • testGetMediaByContext

        public void testGetMediaByContext()
        Here we show how to get corresponding media item byt its context. In the system there is created test context item that contains mappings between two media formats. Now, if we want to retrieve media object in the corresponding format we call this method and get proper media if the context contains mapping where current media format is denoted as source. Then corresponding media in target format will be returned from the media container.
      • testGetMediaByFormat

        public void testGetMediaByFormat()
        Here we have other situation with media container. We have media container obeject that contains medias in different formats. If we want to retrieve some media in the specified format we can call this method giving as arguments media container and required media format, and media model in specified format will be returned.
      • testGetFiles

        public void testGetFiles()
        Here we have a test that demostrates usage of the method getFiles. Using this method we retrieve all files from all replicated directories (if there is more than one). In the example we have one file in the media and we check if the file is our sample file.
      • testAddMediaToContainer

        public void testAddMediaToContainer()
        Here we show how to add new media model to the existing container. We just use proper method that takes container and list of elements to add as arguments and check container content before and after add operation. If the container already contains media with the format that is present in the list this media will be replaced with new one, so all medias in the container have different formats.
      • testRemoveMediaFromContainer

        public void testRemoveMediaFromContainer()
        Here we present very simple method that removes media from container. We remove existing media and check container for amount of medias before and after removal.
      • testGetMediaFormatForSourceFormat

        public void testGetMediaFormatForSourceFormat()
        This method demonstrates usage of the method that returns to us target media format for the given source format from the specified media context. Necessary mapping is placed in media context with impex file and we retrieve target format and check if we got expected one.