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.*;
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 org.junit.Assert;
import au.com.dius.pact.consumer.dsl.PactDslJsonArray;


public class PactDslArrayLikeTest extends ConsumerPactTest {

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

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

    String v3Path = "/v3";
            DslPart body = new PactDslJsonBody()
                    .object("meta")
                        .integerType("Count")
                        .eachLike("base")
                            .id()
                            .stringType("url")
                            .closeObject()
                        .closeArray()
                        .eachLike("stats")
                            .integerType("avg")
                            .integerType("Comments")
                            .integerType("daily")
                            .integerType("views")
                            .integerType("Dislikes")
                            .integerType("Likes")
                            .integerType("Views")
                            .integerType("totalC")
                            .integerType("totalV")
                            .closeObject()
                        .closeArray()
                    .closeObject()
                    .object("result")
                        .eachLike("packages")
                            .booleanType("instore")
                            .booleanType("custom")
                            .stringType("description")
                            .id()
                            .stringType("name")
                            .stringType("shortName")
                            .stringType("uri")
                            .eachLike("parents")
                                .id()
                                .stringType("uri")
                                .closeObject()
                            .closeArray()
                            .eachLike("stats")
                                .integerType("avg")
                                .integerType("comments")
                                .integerType("daily")
                                .integerType("views")
                                .integerType("Dislikes")
                                .integerType("Likes")
                                .integerType("Views")
                                .integerType("totalC")
                                .integerType("totalV")
                                .closeObject()
                            .closeArray()
                            .eachLike("omissions")
                                .closeObject()
                            .closeArray()
                            .eachLike("children")
                            .closeObject()
                            .closeArray()
                            .closeObject()
                        .closeArray()
                    .closeObject();
    protected PactFragment createFragment(PactDslWithProvider builder) {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Content-Type", "application/json");

        PactFragment fragment = builder
                .uponReceiving("API v3 endpoint 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);
        }

        /*try {
            actualResponse = new ConsumerClient(url).getAsMap(v3Path, "");
            Map expectedResponse = new HashMap();
            expectedResponse.put("dbQueryTime", 0.003489971160888672);
            expectedResponse.put("redisQueryTime", 0.0006480216979980469);
            expectedResponse.put("status", "api is up.");
            expectedResponse.put("totalTime", 0.005939006805419922);
            logger.info(expectedResponse.toString());
            logger.info(actualResponse.toString());
            Assert.assertEquals(expectedResponse.toString(), actualResponse.toString());

        } catch (Exception e) {
            throw new RuntimeException(e);
        }*/
    }
}

@@ -4584,706 +4584,8 @@
    %7D
-%0A%0A        /*try %7B%0A            actualResponse = new ConsumerClient(url).getAsMap(v3Path, %22%22);%0A            Map expectedResponse = new HashMap();%0A            expectedResponse.put(%22dbQueryTime%22, 0.003489971160888672);%0A            expectedResponse.put(%22redisQueryTime%22, 0.0006480216979980469);%0A            expectedResponse.put(%22status%22, %22api is up.%22);%0A            expectedResponse.put(%22totalTime%22, 0.005939006805419922);%0A            logger.info(expectedResponse.toString());%0A            logger.info(actualResponse.toString());%0A            Assert.assertEquals(expectedResponse.toString(), actualResponse.toString());%0A%0A        %7D catch (Exception e) %7B%0A            throw new RuntimeException(e);%0A        %7D*/
 %0A   

remove commented code