Can not get HAL format in Spring Boot MVC unit test

Viewed 1039

I am trying the Spring HATEOAS with Spring Boot. And I wrote a unit test with rest assured:

given().standaloneSetup(new GreetingApi())
        .accept("application/hal+json;charset=UTF-8")
        .when()
        .get("/greeting")
        .prettyPeek()
        .then().statusCode(200)
        .body("content", equalTo("Hello, World"))
        .body("_links.self.href", endsWith("/greeting?name=World"));

The test return response like this:

Content-Type: application/hal+json;charset=UTF-8

{
    "content": "Hello, World",
    "links": [
        {
            "rel": "self",
            "href": "http://localhost/greeting?name=World"
        }
    ]
}

But actually the response get like this when I run the whole Spring Boot Application:

HTTP/1.1 200 
Content-Type: application/hal+json;charset=UTF-8
Date: Wed, 24 May 2017 15:28:39 GMT
Transfer-Encoding: chunked

{
    "_links": {
        "self": {
            "href": "http://localhost:8080/greeting?name=World"
        }
    },
    "content": "Hello, World"
}

So there must be some method to configure the response for HATEOAS, but I didn't find it.

Hope someone who is familiar about this can help me.

The whole repository is here.

1 Answers
Related