package pact;

import java.util.logging.Level;
import java.util.logging.Logger;
import au.com.dius.pact.consumer.dsl.DslPart;
import au.com.dius.pact.consumer.dsl.PactDslJsonBody;
import au.com.dius.pact.consumer.dsl.PactDslWithProvider;
import au.com.dius.pact.model.PactFragment;
import au.com.dius.pact.consumer.ConsumerPactTest;
import java.util.Map;
import java.util.HashMap;
import au.com.dius.pact.consumer.PactProviderRule;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import org.junit.Rule;
import au.com.dius.pact.consumer.dsl.PactDslJsonArray;
import org.junit.Assert;


public class PactDslNestedJsonTest extends ConsumerPactTest {

    Logger logger = Logger.getLogger(PactDslJsonTest.class.getName());

    @Rule
    public PactProviderRule mockProvider = new PactProviderRule("test_provider", "localhost", 1234, this);

    private DslPart body = new PactDslJsonBody()
            .id()
            .object("2")
            .id()
            .stringValue("test", null)
            .closeObject()
            .array("numbers")
            .id()
            .number(100)
            .numberValue(101)
            .hexValue()
            .object()
            .id()
            .stringValue("name", "Rogger the Dogger")
            .timestamp()
            .date("dob", "MM/dd/yyyy")
            .closeObject()
            .closeArray();
    protected PactFragment createFragment(PactDslWithProvider builder) {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Content-Type", "application/json");

        PactFragment fragment = builder
                .uponReceiving("API nested json response")
                .path("/")
                .method("GET")
                .willRespondWith()
                .status(200)
                .headers(headers)
                .body(body)
                .toFragment();
        return fragment;
    }

    @Override
    protected String providerName() {
        return "test_provider";
    }

    @Override
    protected String consumerName() {
        return "test_consumer";
    }

    @Override
    protected void runTest(String url) {
        Map actualResponse;
        try {
            actualResponse = new ConsumerClient(url).getAsMap("/", "");
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

@@ -1063,38 +1063,46 @@
 2%22)%0A            
+    
 .id()%0A
+    
             .str
@@ -1185,32 +1185,36 @@
 s%22)%0A            
+    
 .id()%0A          
@@ -1211,24 +1211,28 @@
             
+   
+ 
 .number(100)
@@ -1228,24 +1228,28 @@
 number(100)%0A
+    
             
@@ -1278,16 +1278,20 @@
         
+  
+  
 .hexValu
@@ -1298,32 +1298,36 @@
 e()%0A            
+    
 .object()%0A      
@@ -1312,32 +1312,40 @@
       .object()%0A
+        
             .id(
@@ -1350,32 +1350,40 @@
 d()%0A            
+        
 .stringValue(%22na
@@ -1420,16 +1420,24 @@
         
+      
+  
 .timesta
@@ -1441,16 +1441,24 @@
 stamp()%0A
+        
         
@@ -1488,16 +1488,20 @@
 /yyyy%22)%0A
+    
         

fix syntax