package integration;

import static org.junit.Assert.assertTrue;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import mock.fixtures.DogFixture;

import org.junit.After;
import org.junit.Before;

public class VertxMVCTestBase {
    protected Vertx vertx;

    @Before
    public void setUp(TestContext context) throws Exception {
    	vertx = Vertx.vertx();
    	Async async = context.async();
        vertx.deployVerticle("integration.TestVerticle", handler -> {
        	if (handler.cause() != null) {
        		handler.cause().printStackTrace();
        	}
        	assertTrue(handler.succeeded());
        	assertTrue(DogFixture.dogs.size() > 0);
        	async.complete();
        });
    }

    @After
    public void tearDown(TestContext context) throws Exception {
    	Async async = context.async();
        if (vertx != null) {
            vertx.close(handler -> {
            	if (handler.cause() != null) {
            		handler.cause().printStackTrace();
            	}
            	assertTrue(handler.succeeded());
            	assertTrue(DogFixture.dogs.isEmpty());
            	async.complete();
            });
        }
    }

    public HttpClientOptions options() {
        HttpClientOptions options = new HttpClientOptions();
        options.setDefaultHost(TestVerticle.HOST);
        options.setDefaultPort(TestVerticle.PORT);
        options.setKeepAlive(false);
        return options;
    }

    public HttpClient client() {
        return vertx.createHttpClient(options());
    }

}

@@ -173,40 +173,8 @@
 ns;%0A
-import io.vertx.ext.unit.Async;%0A
 impo
@@ -457,44 +457,8 @@
 ();%0A
-    %09Async async = context.async();%0A
     
@@ -514,158 +514,47 @@
 e%22, 
-handler -%3E %7B%0A        %09if (handler.cause() != null) %7B%0A        %09%09handler.cause().printStackTrace();%0A        %09%7D%0A        %09assertTrue(handler.succeeded());
+context.asyncAssertSuccess(handler -%3E %7B
 %0A   
@@ -611,36 +611,10 @@
     
-%09async.complete();%0A        
 %7D
+)
 );%0A 
@@ -699,44 +699,8 @@
 n %7B%0A
-    %09Async async = context.async();%0A
     
@@ -752,174 +752,47 @@
 ose(
-handler -%3E %7B%0A            %09if (handler.cause() != null) %7B%0A            %09%09handler.cause().printStackTrace();%0A            %09%7D%0A            %09assertTrue(handler.succeeded());
+context.asyncAssertSuccess(handler -%3E %7B
 %0A   
@@ -856,40 +856,10 @@
     
-%09async.complete();%0A            
 %7D
+)
 );%0A 

use latest vertx-unit feature