blob: cd18823ea1c7bbb6db0ef51c7879527d0a1f2d6c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.http;
import org.junit.Test;
import java.io.IOException;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static com.yahoo.jdisc.http.HttpResponse.Status.*;
/**
* @author lulf
* @since 5.1
*/
public class HttpErrorResponseTest {
@Test
public void testThatHttpErrorResponseIsRenderedAsJson() throws IOException {
HttpErrorResponse response = HttpErrorResponse.badRequest("Error doing something");
assertThat(response.getJdiscResponse().getStatus(), is(BAD_REQUEST));
assertThat(SessionHandlerTest.getRenderedString(response), is("{\"error-code\":\"BAD_REQUEST\",\"message\":\"Error doing something\"}"));
}
@Test
public void testThatHttpErrorResponseProvidesCorrectErrorMessage() throws IOException {
HttpErrorResponse response = HttpErrorResponse.badRequest("Error doing something");
HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(response, BAD_REQUEST, HttpErrorResponse.errorCodes.BAD_REQUEST, "Error doing something");
}
@Test
public void testThatHttpErrorResponseHasJsonContentType() throws IOException {
HttpErrorResponse response = HttpErrorResponse.badRequest("Error doing something");
assertThat(response.getContentType(), is("application/json"));
}
}
|