blob: f5c430152f3c504e76c55990c53ff777da80634e (
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
|
// Copyright Yahoo. 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.hamcrest.MatcherAssert.assertThat;
import static com.yahoo.jdisc.http.HttpResponse.Status.*;
/**
* @author Ulf Lilleengen
*/
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.ErrorCode.BAD_REQUEST, "Error doing something");
}
@Test
public void testThatHttpErrorResponseHasJsonContentType() {
HttpErrorResponse response = HttpErrorResponse.badRequest("Error doing something");
assertThat(response.getContentType(), is("application/json"));
}
}
|