package org.kurento.client.internal.test;

import java.util.Properties;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.kurento.client.internal.transport.jsonrpc.RomServerJsonRpcHandler;
import org.kurento.jsonrpc.client.JsonRpcClient;
import org.kurento.jsonrpc.client.JsonRpcClientWebSocket;
import org.kurento.jsonrpc.internal.server.config.JsonRpcConfiguration;
import org.kurento.jsonrpc.server.JsonRpcConfigurer;
import org.kurento.jsonrpc.server.JsonRpcHandlerRegistry;

public class WebSocketRomTest extends AbstractRomTest {

	private static RomServerJsonRpcHandler handler;

	@Configuration
	@ComponentScan(basePackageClasses = JsonRpcConfiguration.class)
	@EnableAutoConfiguration
	public static class BootTestApplication implements JsonRpcConfigurer {

		@Override
		public void registerJsonRpcHandlers(JsonRpcHandlerRegistry registry) {
			registry.addHandler(handler, "/handler");
		}
	}

	protected ConfigurableApplicationContext context;

	@Override
	protected JsonRpcClient createJsonRpcClient() {
		return new JsonRpcClientWebSocket("ws://localhost:" + getPort()
				+ "/handler");
	}

	@Override
	protected void startJsonRpcServer(RomServerJsonRpcHandler jsonRpcHandler) {

		handler = jsonRpcHandler;

		Properties properties = new Properties();
		properties.put("server.port", getPort());

		SpringApplication application = new SpringApplication(
				BootTestApplication.class);
		application.setDefaultProperties(properties);

		context = application.run();
	}

	protected static String getPort() {
		String port = System.getProperty("http.port");
		if (port == null) {
			port = "7788";
		}
		return port;
	}

	@Override
	protected void destroyJsonRpcServer() {
		context.close();
	}
}

@@ -70,319 +70,8 @@
 s;%0A%0A
-import org.springframework.boot.SpringApplication;%0Aimport org.springframework.boot.autoconfigure.EnableAutoConfiguration;%0Aimport org.springframework.context.ConfigurableApplicationContext;%0Aimport org.springframework.context.annotation.ComponentScan;%0Aimport org.springframework.context.annotation.Configuration;%0A
 impo
@@ -438,64 +438,511 @@
 ry;%0A
-%0Apublic class WebSocketRomTest extends AbstractRomTest %7B
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0Aimport org.springframework.boot.SpringApplication;%0Aimport org.springframework.boot.autoconfigure.EnableAutoConfiguration;%0Aimport org.springframework.context.ConfigurableApplicationContext;%0Aimport org.springframework.context.annotation.ComponentScan;%0Aimport org.springframework.context.annotation.Configuration;%0A%0Apublic class WebSocketRomTest extends AbstractRomTest %7B%0A%0A%09private static Logger log = LoggerFactory.getLogger(WebSocketRomTest.class);
 %0A%0A%09p
@@ -1423,44 +1423,24 @@
 ) %7B%0A
+%0A
 %09%09
-return new JsonRpcClientWebSocket(
+String uri = 
 %22ws:
@@ -1464,21 +1464,17 @@
 etPort()
-%0A%09%09%09%09
+ 
 + %22/hand
@@ -1473,24 +1473,111 @@
 + %22/handler%22
+;%0A%09%09log.info(%22Creating client in URI: %22 + uri);%0A%09%09return new JsonRpcClientWebSocket(uri
 );%0A%09%7D%0A%0A%09@Ove
@@ -1659,17 +1659,16 @@
 dler) %7B%0A
-%0A
 %09%09handle
@@ -1732,16 +1732,43 @@
 ties();%0A
+%09%09String port = getPort();%0A
 %09%09proper
@@ -1791,25 +1791,20 @@
 .port%22, 
-getP
+p
 ort
-()
 );%0A%0A%09%09Sp
@@ -1937,16 +1937,65 @@
 ties);%0A%0A
+%09%09log.info(%22Creating server in port: %22 + port);%0A%0A
 %09%09contex

Update WebSocketRom tests