package tech.greenfield.vertx.irked.base;

import java.util.Random;
import java.util.function.Function;

import org.junit.jupiter.api.extension.RegisterExtension;

import io.vertx.core.*;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.client.WebClientOptions;
import io.vertx.junit5.VertxExtension;
import io.vertx.junit5.VertxTestContext;
import tech.greenfield.vertx.irked.Controller;
import tech.greenfield.vertx.irked.server.Server;

public class TestBase {

	private static final int MAX_WEBSOCKET_MESSAGE_SIZE = 1024 * 1024 * 1024;

	@RegisterExtension
	static VertxExtension vertxExtension = new VertxExtension();
	protected final Integer port = new Random().nextInt(30000)+10000;

	protected static WebClientExt getClient(Vertx vertx) {
		return new WebClientExt(vertx, new WebClientOptions(new HttpClientOptions()
				.setIdleTimeout(0)
				.setMaxWebSocketMessageSize(MAX_WEBSOCKET_MESSAGE_SIZE)));
	}

	protected void deployController(Controller controller, Vertx vertx, Handler<AsyncResult<String>> handler) {
		Server server = new Server(controller);

		DeploymentOptions options = new DeploymentOptions().setConfig(new JsonObject().put("port", port));
		vertx.deployVerticle(server, options, handler);
	}

	protected static Function<Throwable, Void> failureHandler(VertxTestContext context) {
		return  t -> {
			context.failNow(t);
			return null;
		};
	}

}

@@ -36,16 +36,171 @@
 .base;%0A%0A
+import static org.hamcrest.MatcherAssert.assertThat;%0Aimport static org.hamcrest.Matchers.is;%0Aimport static tech.greenfield.vertx.irked.Matchers.notFound;%0A%0A
 import j
@@ -216,16 +216,16 @@
 Random;%0A
-
 import j
@@ -336,16 +336,52 @@
 core.*;%0A
+import io.vertx.core.buffer.Buffer;%0A
 import i
@@ -409,32 +409,32 @@
 pClientOptions;%0A
-
 import io.vertx.
@@ -455,16 +455,61 @@
 Object;%0A
+import io.vertx.ext.web.client.HttpResponse;%0A
 import i
@@ -1659,12 +1659,107 @@
 %0A%09%09%7D;%0A%09%7D
+%0A%09%0A%09protected void verifyNotFound(HttpResponse%3CBuffer%3E r) %7B%0A%09%09assertThat(r, is(notFound()));%0A%09%7D
 %0A%0A%7D%0A

add helper verify 404