com.kurento.kmf.media.PlayerEndpointTest.java Source code

Java tutorial

Introduction

Here is the source code for com.kurento.kmf.media.PlayerEndpointTest.java

Source

/*
 * (C) Copyright 2013 Kurento (http://kurento.org/)
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 */
package com.kurento.kmf.media;

import static com.kurento.kmf.media.SyncMediaServerTest.URL_SMALL;
import static java.util.concurrent.TimeUnit.SECONDS;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.kurento.kmf.common.exception.KurentoMediaFrameworkException;
import com.kurento.kmf.media.events.EndOfStreamEvent;
import com.kurento.kmf.media.events.MediaEventListener;

/**
 * {@link PlayerEndpoint} test suite.
 * 
 * <p>
 * Methods tested:
 * <ul>
 * <li>{@link PlayerEndpoint#getUri()}
 * <li>{@link PlayerEndpoint#play()}
 * <li>{@link PlayerEndpoint#pause()}
 * <li>{@link PlayerEndpoint#stop()}
 * </ul>
 * <p>
 * Events tested:
 * <ul>
 * <li>{@link PlayerEndpoint#addEndOfStreamListener(MediaEventListener)}
 * </ul>
 * 
 * 
 * @author Ivan Gracia (igracia@gsyc.es)
 * @version 1.0.0
 * 
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/kmf-api-test-context.xml")
public class PlayerEndpointTest {

    @Autowired
    private MediaPipelineFactory pipelineFactory;

    private MediaPipeline pipeline;

    private PlayerEndpoint player;

    @Before
    public void setup() throws KurentoMediaFrameworkException {
        pipeline = pipelineFactory.create();
        player = pipeline.newPlayerEndpoint(URL_SMALL).build();
    }

    @After
    public void teardown() {
        player.release();
        pipeline.release();
    }

    /**
     * start/pause/stop sequence test
     */
    @Test
    public void testPlayer() {
        player.play();
        player.pause();
        player.stop();
    }

    @Test
    public void testEventEndOfStream() throws InterruptedException {
        final BlockingQueue<EndOfStreamEvent> events = new ArrayBlockingQueue<EndOfStreamEvent>(1);
        player.addEndOfStreamListener(new MediaEventListener<EndOfStreamEvent>() {

            @Override
            public void onEvent(EndOfStreamEvent event) {
                events.add(event);
            }
        });

        player.play();

        Assert.assertNotNull(events.poll(7, SECONDS));
    }

    @Test
    public void testCommandGetUri() {
        Assert.assertTrue(URL_SMALL.equals(player.getUri()));
    }

}