package com.kurento.kms.media;

import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import com.kurento.kms.media.Stream.Continuation;
import com.kurento.kms.media.internal.KmsConstants;

public class MediaServerTest {

	private static MediaFactory mediaFactory;

	@BeforeClass
	public static void setUpBeforeClass() throws MediaException {
		Properties properties = new Properties();
		properties.setProperty(KmsConstants.SERVER_ADDRESS, "localhost");
		properties.setProperty(KmsConstants.SERVER_PORT, ""
				+ KmsConstants.DEFAULT_SERVER_PORT);

		mediaFactory = new MediaFactory(properties);
	}

	@AfterClass
	public static void afterClass() {
	}

	@Test
	public void testStream() throws MediaException, IOException,
			InterruptedException {
		Stream stream = mediaFactory.getStream();
		final Semaphore sem = new Semaphore(0);
		stream.generateOffer(new Continuation() {
			@Override
			public void onSucess(String spec) {
				System.out.println("onSucess. spec: " + spec);
				sem.release();
			}

			@Override
			public void onError(Throwable cause) {
				System.out.println("onError");
			}
		});

		Assert.assertTrue(sem.tryAcquire(10, TimeUnit.SECONDS));
	}

	@Test
	public void testPlayer() throws MediaException, IOException {
		MediaPlayer player = mediaFactory.getMediaPlayer("");
		player.play();
	}
}

@@ -264,24 +264,62 @@
 unit.Test;%0A%0A
+import com.kurento.kms.api.MediaType;%0A
 import com.k
@@ -770,16 +770,49 @@
 PORT);%0A%0A
+%09%09MediaFactory.init(properties);%0A
 %09%09mediaF
@@ -819,20 +819,16 @@
 actory =
- new
  MediaFa
@@ -832,27 +832,33 @@
 aFactory
-(properties
+.getMediaFactory(
 );%0A%09%7D%0A%0A%09
@@ -902,17 +902,62 @@
 Class() 
-%7B
+throws IOException %7B%0A%09%09mediaFactory.release();
 %0A%09%7D%0A%0A%09@T
@@ -1467,16 +1467,36 @@
 ONDS));%0A
+%09%09stream.release();%0A
 %09%7D%0A%0A%09@Te
@@ -1635,12 +1635,1031 @@
 lay();%0A%09
-%7D
+%09player.pause();%0A%09%09player.stop();%0A%09%09player.release();%0A%09%7D%0A%0A%09@Test%0A%09public void testRecorder() throws MediaException, IOException %7B%0A%09%09MediaRecorder recorder = mediaFactory.getMediaRecorder(%22%22);%0A%09%09recorder.record();%0A%09%09recorder.pause();%0A%09%09recorder.stop();%0A%09%09recorder.release();%0A%09%7D%0A%0A%09@Test%0A%09public void testJoinable() throws MediaException, IOException %7B%0A%09%09Stream streamA = mediaFactory.getStream();%0A%09%09Stream streamB = mediaFactory.getStream();%0A%0A%09%09streamA.join(streamB);%0A%09%09streamA.unjoin(streamB);%0A%0A%09%09System.out.println(%22MediaSrcs: %22 + streamA.getMediaSrcs());%0A%09%09System.out.println(%22MediaSinks: %22 + streamA.getMediaSinks());%0A%0A%09%09System.out.println(%22MediaSrcs audio: %22%0A%09%09%09%09+ streamA.getMediaSrcs(MediaType.AUDIO));%0A%09%09System.out.println(%22MediaSrcs video: %22%0A%09%09%09%09+ streamA.getMediaSrcs(MediaType.VIDEO));%0A%0A%09%09System.out.println(%22MediaSinks audio: %22%0A%09%09%09%09+ streamA.getMediaSinks(MediaType.AUDIO));%0A%09%09System.out.println(%22MediaSinks video: %22%0A%09%09%09%09+ streamA.getMediaSinks(MediaType.VIDEO));%0A%0A%09%09streamA.release();%0A%09%09streamB.release();%0A%09%7D%0A
 %0A%7D%0A

Update tests.