package hu.supercluster.overpasser.library.query;

import org.junit.Before;
import org.junit.Test;

import hu.supercluster.overpasser.library.output.OutputModificator;
import hu.supercluster.overpasser.library.output.OutputOrder;
import hu.supercluster.overpasser.library.output.OutputVerbosity;

import static hu.supercluster.overpasser.library.output.OutputFormat.*;
import static org.hamcrest.CoreMatchers.isA;
import static org.junit.Assert.*;

public class OverpassQueryTest {

    private OverpassQuery query;

    @Before
    public void setUp() throws Exception {
        query = new OverpassQuery();
    }

    @Test
    public void testBuild() throws Exception {
        final String s = query.build();

        assertEquals(";", s);
    }

    @Test
    public void testFormat() throws Exception {
        query.format(JSON);

        assertEquals("[\"out\":\"json\"];", query.build());
    }

    @Test
    public void testTimeout() throws Exception {
        query.timeout(30);

        assertEquals("[\"timeout\":\"30\"];", query.build());
    }

    @Test
    public void testFilterQuery() throws Exception {
        OverpassFilterQuery filterQuery = query.filterQuery();

        assertThat(filterQuery, isA(OverpassFilterQuery.class));
    }

    @Test
    public void testOutputWithDefaultArgs() throws Exception {
        query.output(100);

        assertEquals("; out body center qt 100;", query.build());
    }

    @Test
    public void testOutputWithCustomArgs() throws Exception {
        query.output(OutputVerbosity.META, OutputModificator.GEOM, OutputOrder.ASC, 100);

        assertEquals("; out meta geom asc 100;", query.build());
    }

    @Test
    public void testExample1() throws Exception {
        String result = new OverpassQuery()
                .format(JSON)
                .timeout(30)
                .filterQuery()
                .node()
                .amenity("parking")
                .notEquals("access", "private")
                .boundingBox(
                        47.48047027491862, 19.039797484874725,
                        47.51331674014172, 19.07404761761427
                )
                .end()
                .output(OutputVerbosity.BODY, OutputModificator.CENTER, OutputOrder.QT, 100)
                .build()
        ;

        String expected = "[\"out\":\"json\"][\"timeout\":\"30\"]; (node[\"amenity\"=\"parking\"][\"access\"!=\"private\"](47.48047027491862,19.039797484874725,47.51331674014172,19.07404761761427);<;); out body center qt 100;";

        assertEquals(expected, result);
    }

    @Test
    public void testExample2() throws Exception {
        String result = new OverpassQuery()
                .format(JSON)
                .timeout(30)
                .filterQuery()
                  .way()
                  .amenity("parking")
                  .notEquals("access", "private")
                  .boundingBox(
                          47.48047027491862, 19.039797484874725,
                          47.51331674014172, 19.07404761761427
                  )
                .end()
                .output(OutputVerbosity.BODY, OutputModificator.CENTER, OutputOrder.QT, 100)
                .build()
                ;

        String expected = "[\"out\":\"json\"][\"timeout\":\"30\"]; (way[\"amenity\"=\"parking\"][\"access\"!=\"private\"](47.48047027491862,19.039797484874725,47.51331674014172,19.07404761761427);<;); out body center qt 100;";

        assertEquals(expected, result);
    }
}
@@ -1872,16 +1872,20 @@
         
+    
 .node()%0A
@@ -1892,32 +1892,36 @@
                 
+   
+ 
 .amenity(%22parkin
@@ -1916,32 +1916,36 @@
 nity(%22parking%22)%0A
+    
                 
@@ -1984,32 +1984,36 @@
                 
+  
+  
 .boundingBox(%0A  
@@ -2002,32 +2002,36 @@
   .boundingBox(%0A
+    
                 
@@ -2093,32 +2093,36 @@
                 
+    
 47.5133167401417
@@ -2134,32 +2134,36 @@
 .07404761761427%0A
+    
                 
@@ -2808,15 +2808,19 @@
     
+  
 .way()%0A
+  
     
@@ -2863,32 +2863,34 @@
                 
+  
 .notEquals(%22acce
@@ -2897,32 +2897,34 @@
 ss%22, %22private%22)%0A
+  
                 
@@ -3059,32 +3059,34 @@
 .07404761761427%0A
+  
                 
@@ -3081,32 +3081,32 @@
               )%0A
-
                 
@@ -3226,32 +3226,24 @@
    .build()%0A
-        
         ;%0A%0A 

Fix indentation