package tech.greenfield.vertx.irked.base;

import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.runner.RunWith;

import io.vertx.core.AsyncResult;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.junit.RunTestOnContext;
import io.vertx.ext.unit.junit.Timeout;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import tech.greenfield.vertx.irked.Controller;
import tech.greenfield.vertx.irked.server.Server;

@RunWith(VertxUnitRunner.class)
@Ignore public class TestBase {

	@ClassRule
	public static RunTestOnContext rule = new RunTestOnContext();
	@Rule
	public Timeout timeoutRule = Timeout.seconds(3600);
	protected final Integer port = 1234;

	protected HttpClient getClient() {
		return rule.vertx().createHttpClient(new HttpClientOptions().setIdleTimeout(0));
	}

	protected void deployController(Controller controller, Handler<AsyncResult<String>> handler) {
		Server server = new Server(controller);
	
		DeploymentOptions options = new DeploymentOptions().setConfig(new JsonObject().put("port", port));
		rule.vertx().deployVerticle(server, options, handler);
	}

}

@@ -36,16 +36,42 @@
 .base;%0A%0A
+import java.util.Random;%0A%0A
 import o
@@ -868,12 +868,41 @@
 t = 
-1234
+new Random().nextInt(30000)+10000
 ;%0A%0A%09

use random port for controller tests to prevent race conditions