package au.com.dius.pact.consumer.resultstests;

import au.com.dius.pact.consumer.ConsumerClient;
import au.com.dius.pact.consumer.ConsumerPactBuilder;
import au.com.dius.pact.model.PactFragment;
import org.apache.commons.lang3.SystemUtils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

public class PactVerifiedConsumerFailsTest extends ExpectedToFailBase {

    public PactVerifiedConsumerFailsTest() {
        super(RuntimeException.class);
    }

    @Override
    protected PactFragment createFragment(ConsumerPactBuilder.PactDslWithProvider builder) {
        return builder
            .uponReceiving("PactVerifiedConsumerPassesTest test interaction")
                .path("/")
                .method("GET")
                .willRespondWith()
                .status(200)
                .body("{\"responsetest\": true, \"name\": \"harry\"}")
            .toFragment();
    }


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

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

    @Override
    protected void runTest(String url) throws IOException {
        Map<String, Object> expectedResponse = new HashMap<String, Object>();
        expectedResponse.put("responsetest", true);
        expectedResponse.put("name", "fred");
        assertEquals(new ConsumerClient(url).getAsMap("/"), expectedResponse);
    }

    @Override
    protected void assertException(RuntimeException e) {
        if (SystemUtils.IS_JAVA_1_8) {
            assertThat(e.getMessage(),
                containsString("expected:<{responsetest=true, name=harry}> but was:<{responsetest=true, name=fred}>"));
        } else {
            assertThat(e.getMessage(),
                containsString("expected:<{name=harry, responsetest=true}> but was:<{name=fred, responsetest=true}>"));
        }
    }
}

@@ -1662,51 +1662,8 @@
 ) %7B%0A
-        if (SystemUtils.IS_JAVA_1_8) %7B%0A    
     
@@ -1685,36 +1685,32 @@
 e.getMessage(),%0A
-    
             cont
@@ -1813,194 +1813,8 @@
 ));%0A
-        %7D else %7B%0A            assertThat(e.getMessage(),%0A                containsString(%22expected:%3C%7Bname=harry, responsetest=true%7D%3E but was:%3C%7Bname=fred, responsetest=true%7D%3E%22));%0A        %7D%0A
     

drop unnessessary Java 8 check