package integration.filters;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import integration.TestVerticle;
import integration.VertxNubesTestBase;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;

import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(VertxUnitRunner.class)
public class FiltersTest extends VertxNubesTestBase {

    @Test
    public void testOrderFilters(TestContext context) {
        Async async = context.async();
        client().getNow("/filters/order", response -> {
            response.bodyHandler(buffer -> {
                assertEquals("before1;before2;before3;after1;after2;after3;", buffer.toString("UTF-8"));
                async.complete();
            });
        });
    }

    @Test
    public void testAOP(TestContext context) {
        Async async = context.async();
        client().getNow("/filters/aop", response -> {
            String before = response.getHeader(TestVerticle.HEADER_DATE_BEFORE);
            String after = response.getHeader(TestVerticle.HEADER_DATE_AFTER);
            assertNotNull("Header before should've been set", before);
            assertNotNull("Header after should've been set", after);
            long timeBefore = Long.parseLong(before);
            long timeAfter = Long.parseLong(after);
            System.out.println("before : " + before);
            System.out.println("after : " + after);
            assertTrue("@After should be executed after @Before", timeAfter >= timeBefore);
            async.complete();
        });
    }
}

@@ -492,30 +492,24 @@
 Base %7B%0A%0A
-    
+%09
 @Test%0A
-    
+%09
 public v
@@ -548,32 +548,26 @@
  context) %7B%0A
-        
+%09%09
 Async async 
@@ -581,32 +581,26 @@
 xt.async();%0A
-        
+%09%09
 client().get
@@ -635,28 +635,19 @@
 se -%3E %7B%0A
-            
+%09%09%09
 response
@@ -671,32 +671,20 @@
 er -%3E %7B%0A
-                
+%09%09%09%09
 assertEq
@@ -768,24 +768,12 @@
 ));%0A
-                
+%09%09%09%09
 asyn
@@ -790,57 +790,33 @@
 ();%0A
-            %7D);%0A        %7D);%0A    %7D%0A%0A    
+%09%09%09%7D);%0A%09%09%7D);%0A%09%7D%0A%0A%09
 @Test%0A
-    
+%09
 publ
@@ -854,24 +854,18 @@
 text) %7B%0A
-        
+%09%09
 Async as
@@ -887,24 +887,18 @@
 sync();%0A
-        
+%09%09
 client()
@@ -935,28 +935,19 @@
 se -%3E %7B%0A
-            
+%09%09%09
 String b
@@ -1007,28 +1007,19 @@
 EFORE);%0A
-            
+%09%09%09
 String a
@@ -1077,28 +1077,19 @@
 AFTER);%0A
-            
+%09%09%09
 assertNo
@@ -1139,28 +1139,19 @@
 efore);%0A
-            
+%09%09%09
 assertNo
@@ -1199,28 +1199,19 @@
 after);%0A
-            
+%09%09%09
 long tim
@@ -1244,28 +1244,19 @@
 efore);%0A
-            
+%09%09%09
 long tim
@@ -1291,126 +1291,11 @@
 r);%0A
-            System.out.println(%22before : %22 + before);%0A            System.out.println(%22after : %22 + after);%0A            
+%09%09%09
 asse
@@ -1374,20 +1374,11 @@
 e);%0A
-            
+%09%09%09
 asyn
@@ -1395,24 +1395,15 @@
 ();%0A
-        %7D);%0A    
+%09%09%7D);%0A%09
 %7D%0A%7D%0A

remove println