package fi.hsl.parkandride.itest;

import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.RestAssured.when;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;

import java.io.Serializable;

import org.junit.Ignore;
import org.junit.Test;
import org.springframework.http.HttpStatus;

import com.jayway.restassured.http.ContentType;

import fi.hsl.parkandride.core.domain.Facility;

public class ErrorHandlingITest extends AbstractIntegrationTest {
    @Test
    public void notFound() {
        when()
            .get("api/v1/facilities/42")
        .then()
            .statusCode(HttpStatus.NOT_FOUND.value())
            .body(is(""))
        ;
    }

    @Test
    public void validationException() {
        given()
            .header("Content-Type", "application/json;charset=UTF-8")
            .body(new Facility())
        .when()
            .post("/api/v1/facilities")
        .then()
            .statusCode(HttpStatus.BAD_REQUEST.value())
            .body("status", is(HttpStatus.BAD_REQUEST.value()))
            .body("message", is("Invalid data. See violations for details."))
        ;
    }

    // bindException
    // jsonException
    // methodNotSupportedException
    // exception
}

@@ -179,113 +179,12 @@
 ers.
-hasItems;%0Aimport static org.hamcrest.Matchers.is;%0A%0Aimport java.io.Serializable;%0A%0Aimport org.junit.Ignore;
+is;%0A
 %0Aimp
@@ -251,55 +251,81 @@
 us;%0A
-%0A
 import 
-com.jayway.restassured
+org.springframework
 .http.
-ContentType
+converter.HttpMessageNotReadableException
 ;%0A%0Ai
@@ -1111,32 +1111,446 @@
     
-// bindException
+@Test%0A    public void jsonException() %7B%0A        given()%0A            .header(%22Content-Type%22, %22application/json;charset=UTF-8%22)%0A            .body(%22%7B %5C%22name%5C%22: %5C%22foo%5C%22, %5C%22location%5C%22: %5C%22bar%5C%22  %7D%22)%0A        .when()%0A            .post(%22/api/v1/facilities%22)%0A        .then()%0A            .statusCode(HttpStatus.BAD_REQUEST.value())%0A            .body(%22exception%22, is(HttpMessageNotReadableException.class.getCanonicalName()))%0A        ;%0A    %7D%0A
 %0A    // 
 json
@@ -1545,20 +1545,20 @@
 %0A    // 
-json
+bind
 Exceptio

test error handling, json exception