Here are the examples of the java api org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
155 Examples
19
View Complete Implementation : StatusResultMatchers.java
Copyright MIT License
Author : codeEngraver
Copyright MIT License
Author : codeEngraver
/**
* replacedert the response status code is {@code HttpStatus.INTERNAL_SERVER_ERROR} (500).
*/
public ResultMatcher isInternalServerError() {
return matcher(HttpStatus.INTERNAL_SERVER_ERROR);
}
19
View Complete Implementation : StatusAssertionTests.java
Copyright Apache License 2.0
Author : spring-projects
Copyright Apache License 2.0
Author : spring-projects
@Test
public void statusSerius5xx() {
Statusreplacedertions replacedertions = statusreplacedertions(HttpStatus.INTERNAL_SERVER_ERROR);
// Success
replacedertions.is5xxServerError();
// Wrong series
replacedertThatExceptionOfType(replacedertionError.clreplaced).isThrownBy(() -> replacedertions.is2xxSuccessful());
}
19
View Complete Implementation : StatusResultMatchers.java
Copyright Apache License 2.0
Author : spring-projects
Copyright Apache License 2.0
Author : spring-projects
/**
* replacedert the response status code is {@code HttpStatus.INTERNAL_SERVER_ERROR} (500).
*/
public ResultMatcher isInternalServerError() {
return matcher(HttpStatus.INTERNAL_SERVER_ERROR);
}
19
View Complete Implementation : StatusResultMatchers.java
Copyright MIT License
Author : Vip-Augus
Copyright MIT License
Author : Vip-Augus
/**
* replacedert the response status code is {@code HttpStatus.INTERNAL_SERVER_ERROR} (500).
*/
public ResultMatcher isInternalServerError() {
return matcher(HttpStatus.INTERNAL_SERVER_ERROR);
}
18
View Complete Implementation : ErrorTests.java
Copyright MIT License
Author : codeEngraver
Copyright MIT License
Author : codeEngraver
@Test
public void serverException() {
this.client.get().uri("/server-error").exchange().expectStatus().isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR).expectBody(Void.clreplaced);
}
18
View Complete Implementation : RouterFunctionsTests.java
Copyright Apache License 2.0
Author : spring-projects
Copyright Apache License 2.0
Author : spring-projects
@Test
public void toHttpHandlerHandlerThrowsException() {
HandlerFunction<ServerResponse> handlerFunction = request -> {
throw new IllegalStateException();
};
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
replacedertThat(result).isNotNull();
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
replacedertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
18
View Complete Implementation : ResponseEntityExceptionHandlerTests.java
Copyright Apache License 2.0
Author : spring-projects
Copyright Apache License 2.0
Author : spring-projects
private ResponseEnreplacedy<Object> testException(Exception ex) {
try {
ResponseEnreplacedy<Object> responseEnreplacedy = this.exceptionHandlerSupport.handleException(ex, this.request);
// SPR-9653
if (HttpStatus.INTERNAL_SERVER_ERROR.equals(responseEnreplacedy.getStatusCode())) {
replacedertThat(this.servletRequest.getAttribute("javax.servlet.error.exception")).isSameAs(ex);
}
this.defaultExceptionResolver.resolveException(this.servletRequest, this.servletResponse, null, ex);
replacedertThat(responseEnreplacedy.getStatusCode().value()).isEqualTo(this.servletResponse.getStatus());
return responseEnreplacedy;
} catch (Exception ex2) {
throw new IllegalStateException("handleException threw exception", ex2);
}
}
18
View Complete Implementation : ExceptionHandlingWebHandlerTests.java
Copyright MIT License
Author : Vip-Augus
Copyright MIT License
Author : Vip-Augus
@Test
public void unresolvedExceptionWithWebHttpHandlerAdapter() throws Exception {
// HttpWebHandlerAdapter handles unresolved errors
new HttpWebHandlerAdapter(createWebHandler(new UnresolvedExceptionHandler())).handle(this.exchange.getRequest(), this.exchange.getResponse()).block();
replacedertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.exchange.getResponse().getStatusCode());
}
18
View Complete Implementation : RouterFunctionBuilderTests.java
Copyright Apache License 2.0
Author : spring-projects
Copyright Apache License 2.0
Author : spring-projects
@Test
public void filters() {
AtomicInteger filterCount = new AtomicInteger();
RouterFunction<ServerResponse> route = RouterFunctions.route().GET("/foo", request -> ServerResponse.ok().build()).GET("/bar", request -> {
throw new IllegalStateException();
}).before(request -> {
int count = filterCount.getAndIncrement();
replacedertThat(count).isEqualTo(0);
return request;
}).after((request, response) -> {
int count = filterCount.getAndIncrement();
replacedertThat(count).isEqualTo(3);
return response;
}).filter((request, next) -> {
int count = filterCount.getAndIncrement();
replacedertThat(count).isEqualTo(1);
ServerResponse responseMono = next.handle(request);
count = filterCount.getAndIncrement();
replacedertThat(count).isEqualTo(2);
return responseMono;
}).onError(IllegalStateException.clreplaced, (e, request) -> ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).build()).build();
MockHttpServletRequest servletRequest = new MockHttpServletRequest("GET", "/foo");
ServerRequest fooRequest = new DefaultServerRequest(servletRequest, emptyList());
route.route(fooRequest).map(handlerFunction -> handle(handlerFunction, fooRequest));
replacedertThat(filterCount.get()).isEqualTo(4);
filterCount.set(0);
servletRequest = new MockHttpServletRequest("GET", "/bar");
ServerRequest barRequest = new DefaultServerRequest(servletRequest, emptyList());
Optional<Integer> responseStatus = route.route(barRequest).map(handlerFunction -> handle(handlerFunction, barRequest)).map(ServerResponse::statusCode).map(HttpStatus::value);
replacedertThat(responseStatus.get().intValue()).isEqualTo(500);
}
18
View Complete Implementation : ExtractingResponseErrorHandlerTests.java
Copyright Apache License 2.0
Author : spring-projects
Copyright Apache License 2.0
Author : spring-projects
@Test
public void handleErrorSeriesMatch() throws Exception {
given(this.response.getRawStatusCode()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR.value());
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
given(this.response.getHeaders()).willReturn(responseHeaders);
byte[] body = "{\"foo\":\"bar\"}".getBytes(StandardCharsets.UTF_8);
responseHeaders.setContentLength(body.length);
given(this.response.getBody()).willReturn(new ByteArrayInputStream(body));
replacedertThatExceptionOfType(MyRestClientException.clreplaced).isThrownBy(() -> this.errorHandler.handleError(this.response)).satisfies(ex -> replacedertThat(ex.getFoo()).isEqualTo("bar"));
}
18
View Complete Implementation : ResponseEntityExceptionHandlerTests.java
Copyright MIT License
Author : codeEngraver
Copyright MIT License
Author : codeEngraver
private ResponseEnreplacedy<Object> testException(Exception ex) {
try {
ResponseEnreplacedy<Object> responseEnreplacedy = this.exceptionHandlerSupport.handleException(ex, this.request);
// SPR-9653
if (HttpStatus.INTERNAL_SERVER_ERROR.equals(responseEnreplacedy.getStatusCode())) {
replacedertSame(ex, this.servletRequest.getAttribute("javax.servlet.error.exception"));
}
this.defaultExceptionResolver.resolveException(this.servletRequest, this.servletResponse, null, ex);
replacedertEquals(this.servletResponse.getStatus(), responseEnreplacedy.getStatusCode().value());
return responseEnreplacedy;
} catch (Exception ex2) {
throw new IllegalStateException("handleException threw exception", ex2);
}
}
18
View Complete Implementation : ExceptionHandlingWebHandlerTests.java
Copyright Apache License 2.0
Author : spring-projects
Copyright Apache License 2.0
Author : spring-projects
@Test
public void unresolvedExceptionWithWebHttpHandlerAdapter() throws Exception {
// HttpWebHandlerAdapter handles unresolved errors
new HttpWebHandlerAdapter(createWebHandler(new UnresolvedExceptionHandler())).handle(this.exchange.getRequest(), this.exchange.getResponse()).block();
replacedertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
18
View Complete Implementation : ResponseExceptionHandler.java
Copyright Apache License 2.0
Author : tmobile
Copyright Apache License 2.0
Author : tmobile
@ExceptionHandler(Exception.clreplaced)
protected ResponseEnreplacedy<Object> handleException(Exception ex, WebRequest request) {
log.debug(ex.getMessage());
return ResponseEnreplacedy.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"errors\":[\"Unexpected error :" + ex.getMessage() + "\"]}");
}
18
View Complete Implementation : RestTemplateTests.java
Copyright Apache License 2.0
Author : spring-projects
Copyright Apache License 2.0
Author : spring-projects
@Test
public void errorHandling() throws Exception {
String url = "https://example.com";
mockSentRequest(GET, url);
mockResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR);
willThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)).given(errorHandler).handleError(new URI(url), GET, response);
replacedertThatExceptionOfType(HttpServerErrorException.clreplaced).isThrownBy(() -> template.execute(url, GET, null, null));
verify(response).close();
}
18
View Complete Implementation : LocationByGatewayRestControllerTest.java
Copyright Apache License 2.0
Author : KonkerLabs
Copyright Apache License 2.0
Author : KonkerLabs
@Test
public void shouldTryListLocationsWithInternalError() throws Exception {
when(locationSearchService.findAll(tenant, application)).thenReturn(ServiceResponseBuilder.<List<Location>>error().build());
when(locationSearchService.findAll(gateway, tenant, application)).thenReturn(ServiceResponseBuilder.<List<Location>>error().build());
getMockMvc().perform(MockMvcRequestBuilders.get(MessageFormat.format("/{0}/{1}/", application.getName(), BASEPATH)).accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON)).andExpect(status().is5xxServerError()).andExpect(content().contentType("application/json;charset=UTF-8")).andExpect(jsonPath("$.code", is(HttpStatus.INTERNAL_SERVER_ERROR.value()))).andExpect(jsonPath("$.status", is("error"))).andExpect(jsonPath("$.timestamp", greaterThan(1400000000))).andExpect(jsonPath("$.messages").doesNotExist()).andExpect(jsonPath("$.result").doesNotExist());
}
18
View Complete Implementation : StatusAssertionTests.java
Copyright MIT License
Author : Vip-Augus
Copyright MIT License
Author : Vip-Augus
@Test
public void statusSerius5xx() {
Statusreplacedertions replacedertions = statusreplacedertions(HttpStatus.INTERNAL_SERVER_ERROR);
// Success
replacedertions.is5xxServerError();
try {
replacedertions.is2xxSuccessful();
fail("Wrong series expected");
} catch (replacedertionError error) {
// Expected
}
}
18
View Complete Implementation : ExceptionHandlingWebHandlerTests.java
Copyright MIT License
Author : codeEngraver
Copyright MIT License
Author : codeEngraver
@Test
public void unresolvedExceptionWithWebHttpHandlerAdapter() throws Exception {
// HttpWebHandlerAdapter handles unresolved errors
new HttpWebHandlerAdapter(createWebHandler(new UnresolvedExceptionHandler())).handle(this.exchange.getRequest(), this.exchange.getResponse()).block();
replacedertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.exchange.getResponse().getStatusCode());
}
18
View Complete Implementation : RestTemplateTests.java
Copyright MIT License
Author : codeEngraver
Copyright MIT License
Author : codeEngraver
@Test
public void errorHandling() throws Exception {
String url = "http://example.com";
mockSentRequest(GET, url);
mockResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR);
willThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)).given(errorHandler).handleError(new URI(url), GET, response);
try {
template.execute(url, GET, null, null);
fail("HttpServerErrorException expected");
} catch (HttpServerErrorException ex) {
// expected
}
verify(response).close();
}
18
View Complete Implementation : RestTemplateXhrTransportTests.java
Copyright MIT License
Author : Vip-Augus
Copyright MIT License
Author : Vip-Augus
@Test
public void errorResponseStatus() throws Exception {
connect(response(HttpStatus.OK, "o\n"), response(HttpStatus.INTERNAL_SERVER_ERROR, "Oops"));
verify(this.webSocketHandler).afterConnectionEstablished(any());
verify(this.webSocketHandler).handleTransportError(any(), any());
verify(this.webSocketHandler).afterConnectionClosed(any(), any());
verifyNoMoreInteractions(this.webSocketHandler);
}
18
View Complete Implementation : RestTemplateXhrTransportTests.java
Copyright MIT License
Author : codeEngraver
Copyright MIT License
Author : codeEngraver
@Test
public void errorResponseStatus() throws Exception {
connect(response(HttpStatus.OK, "o\n"), response(HttpStatus.INTERNAL_SERVER_ERROR, "Oops"));
verify(this.webSocketHandler).afterConnectionEstablished(any());
verify(this.webSocketHandler).handleTransportError(any(), any());
verify(this.webSocketHandler).afterConnectionClosed(any(), any());
verifyNoMoreInteractions(this.webSocketHandler);
}
18
View Complete Implementation : ExtractingResponseErrorHandlerTests.java
Copyright Apache License 2.0
Author : spring-projects
Copyright Apache License 2.0
Author : spring-projects
@Test
public void hasError() throws Exception {
given(this.response.getRawStatusCode()).willReturn(HttpStatus.I_AM_A_TEAPOT.value());
replacedertThat(this.errorHandler.hasError(this.response)).isTrue();
given(this.response.getRawStatusCode()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR.value());
replacedertThat(this.errorHandler.hasError(this.response)).isTrue();
given(this.response.getRawStatusCode()).willReturn(HttpStatus.OK.value());
replacedertThat(this.errorHandler.hasError(this.response)).isFalse();
}
18
View Complete Implementation : RouterFunctionsTests.java
Copyright MIT License
Author : Vip-Augus
Copyright MIT License
Author : Vip-Augus
@Test
public void toHttpHandlerHandlerThrowsException() {
HandlerFunction<ServerResponse> handlerFunction = request -> {
throw new IllegalStateException();
};
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
replacedertNotNull(result);
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
replacedertEquals(HttpStatus.INTERNAL_SERVER_ERROR, httpResponse.getStatusCode());
}
18
View Complete Implementation : RouterFunctionsTests.java
Copyright MIT License
Author : codeEngraver
Copyright MIT License
Author : codeEngraver
@Test
public void toHttpHandlerHandlerThrowsException() {
HandlerFunction<ServerResponse> handlerFunction = request -> {
throw new IllegalStateException();
};
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
replacedertNotNull(result);
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
replacedertEquals(HttpStatus.INTERNAL_SERVER_ERROR, httpResponse.getStatusCode());
}
18
View Complete Implementation : ErrorTests.java
Copyright Apache License 2.0
Author : spring-projects
Copyright Apache License 2.0
Author : spring-projects
@Test
public void serverException() {
this.client.get().uri("/server-error").exchange().expectStatus().isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR).expectBody(Void.clreplaced);
}
18
View Complete Implementation : RestTemplateXhrTransportTests.java
Copyright Apache License 2.0
Author : spring-projects
Copyright Apache License 2.0
Author : spring-projects
@Test
public void errorResponseStatus() throws Exception {
connect(response(HttpStatus.OK, "o\n"), response(HttpStatus.INTERNAL_SERVER_ERROR, "Oops"));
verify(this.webSocketHandler).afterConnectionEstablished(any());
verify(this.webSocketHandler).handleTransportError(any(), any());
verify(this.webSocketHandler).afterConnectionClosed(any(), any());
verifyNoMoreInteractions(this.webSocketHandler);
}
18
View Complete Implementation : RouterFunctionBuilderTests.java
Copyright MIT License
Author : Vip-Augus
Copyright MIT License
Author : Vip-Augus
@Test
public void filters() {
AtomicInteger filterCount = new AtomicInteger();
RouterFunction<ServerResponse> route = RouterFunctions.route().GET("/foo", request -> ServerResponse.ok().build()).GET("/bar", request -> {
throw new IllegalStateException();
}).before(request -> {
int count = filterCount.getAndIncrement();
replacedertEquals(0, count);
return request;
}).after((request, response) -> {
int count = filterCount.getAndIncrement();
replacedertEquals(3, count);
return response;
}).filter((request, next) -> {
int count = filterCount.getAndIncrement();
replacedertEquals(1, count);
ServerResponse responseMono = next.handle(request);
count = filterCount.getAndIncrement();
replacedertEquals(2, count);
return responseMono;
}).onError(IllegalStateException.clreplaced, (e, request) -> ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).build()).build();
MockHttpServletRequest servletRequest = new MockHttpServletRequest("GET", "/foo");
ServerRequest fooRequest = new DefaultServerRequest(servletRequest, emptyList());
Optional<ServerResponse> fooResponse = route.route(fooRequest).map(handlerFunction -> handle(handlerFunction, fooRequest));
replacedertEquals(4, filterCount.get());
filterCount.set(0);
servletRequest = new MockHttpServletRequest("GET", "/bar");
ServerRequest barRequest = new DefaultServerRequest(servletRequest, emptyList());
Optional<Integer> responseStatus = route.route(barRequest).map(handlerFunction -> handle(handlerFunction, barRequest)).map(ServerResponse::statusCode).map(HttpStatus::value);
replacedertEquals(500, responseStatus.get().intValue());
}
18
View Complete Implementation : ResponseEntityExceptionHandlerTests.java
Copyright MIT License
Author : Vip-Augus
Copyright MIT License
Author : Vip-Augus
private ResponseEnreplacedy<Object> testException(Exception ex) {
try {
ResponseEnreplacedy<Object> responseEnreplacedy = this.exceptionHandlerSupport.handleException(ex, this.request);
// SPR-9653
if (HttpStatus.INTERNAL_SERVER_ERROR.equals(responseEnreplacedy.getStatusCode())) {
replacedertSame(ex, this.servletRequest.getAttribute("javax.servlet.error.exception"));
}
this.defaultExceptionResolver.resolveException(this.servletRequest, this.servletResponse, null, ex);
replacedertEquals(this.servletResponse.getStatus(), responseEnreplacedy.getStatusCode().value());
return responseEnreplacedy;
} catch (Exception ex2) {
throw new IllegalStateException("handleException threw exception", ex2);
}
}
18
View Complete Implementation : ErrorTests.java
Copyright MIT License
Author : Vip-Augus
Copyright MIT License
Author : Vip-Augus
@Test
public void serverException() {
this.client.get().uri("/server-error").exchange().expectStatus().isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR).expectBody(Void.clreplaced);
}
18
View Complete Implementation : StatusAssertionTests.java
Copyright MIT License
Author : codeEngraver
Copyright MIT License
Author : codeEngraver
@Test
public void statusSerius5xx() {
Statusreplacedertions replacedertions = statusreplacedertions(HttpStatus.INTERNAL_SERVER_ERROR);
// Success
replacedertions.is5xxServerError();
try {
replacedertions.is2xxSuccessful();
fail("Wrong series expected");
} catch (replacedertionError error) {
// Expected
}
}
18
View Complete Implementation : DeviceFirmwareUpdateRestControllerTest.java
Copyright Apache License 2.0
Author : KonkerLabs
Copyright Apache License 2.0
Author : KonkerLabs
@Test
public void shouldReturnInternalErrorWhenListDeviceFirmwaresVersionUpdates() throws Exception {
List<DeviceFirmware> firmwares = new ArrayList<>();
firmwares.add(deviceFirmwareNew);
firmwares.add(deviceFirmwareNew);
List<DeviceFwUpdate> firmwaresUpdates = new ArrayList<>();
firmwaresUpdates.add(deviceFwUpdatePendingRequest);
firmwaresUpdates.add(deviceFwUpdatePendingRequest);
when(deviceRegisterService.getByDeviceGuid(tenant, application, device.getGuid())).thenReturn(ServiceResponseBuilder.<Device>ok().withResult(device).build());
when(deviceFirmwareService.findByVersion(tenant, application, device.getDeviceModel(), deviceFwUpdatePendingUpdate.getVersion())).thenReturn(ServiceResponseBuilder.<DeviceFirmware>ok().withResult(deviceFirmwareNew).build());
when(deviceFirmwareUpdateService.findByDeviceFirmware(tenant, application, deviceFirmwareNew)).thenReturn(ServiceResponseBuilder.<List<DeviceFwUpdate>>error().withMessage(DeviceFirmwareUpdateService.Validations.FIRMWARE_UPDATE_NOT_FOUND.getCode()).build());
getMockMvc().perform(MockMvcRequestBuilders.get(MessageFormat.format("/{0}/{1}/", application.getName(), BASEPATH_UPDATE)).param("deviceGuid", device.getGuid()).param("version", deviceFwUpdatePendingUpdate.getVersion()).contentType(MediaType.MULTIPART_FORM_DATA).accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().is5xxServerError()).andExpect(content().contentType("application/json;charset=UTF-8")).andExpect(jsonPath("$.code", is(HttpStatus.INTERNAL_SERVER_ERROR.value()))).andExpect(jsonPath("$.status", is("error"))).andExpect(jsonPath("$.timestamp", greaterThan(1400000000))).andExpect(jsonPath("$.messages[0]", is("Firmware update process not found"))).andExpect(jsonPath("$.result").doesNotExist());
}
18
View Complete Implementation : RestTemplateTests.java
Copyright MIT License
Author : Vip-Augus
Copyright MIT License
Author : Vip-Augus
@Test
public void errorHandling() throws Exception {
String url = "https://example.com";
mockSentRequest(GET, url);
mockResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR);
willThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)).given(errorHandler).handleError(new URI(url), GET, response);
try {
template.execute(url, GET, null, null);
fail("HttpServerErrorException expected");
} catch (HttpServerErrorException ex) {
// expected
}
verify(response).close();
}
17
View Complete Implementation : RestTemplateIntegrationTests.java
Copyright MIT License
Author : Vip-Augus
Copyright MIT License
Author : Vip-Augus
@Test
public void serverError() {
try {
template.execute(baseUrl + "/status/server", HttpMethod.GET, null, null);
fail("HttpServerErrorException expected");
} catch (HttpServerErrorException ex) {
replacedertEquals(HttpStatus.INTERNAL_SERVER_ERROR, ex.getStatusCode());
replacedertNotNull(ex.getStatusText());
replacedertNotNull(ex.getResponseBodyreplacedtring());
}
}
17
View Complete Implementation : ExtractingResponseErrorHandlerTests.java
Copyright MIT License
Author : Vip-Augus
Copyright MIT License
Author : Vip-Augus
@Test
public void hasError() throws Exception {
given(this.response.getRawStatusCode()).willReturn(HttpStatus.I_AM_A_TEAPOT.value());
replacedertTrue(this.errorHandler.hasError(this.response));
given(this.response.getRawStatusCode()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR.value());
replacedertTrue(this.errorHandler.hasError(this.response));
given(this.response.getRawStatusCode()).willReturn(HttpStatus.OK.value());
replacedertFalse(this.errorHandler.hasError(this.response));
}
17
View Complete Implementation : ExtractingResponseErrorHandlerTests.java
Copyright MIT License
Author : codeEngraver
Copyright MIT License
Author : codeEngraver
@Test
public void handleErrorSeriesMatch() throws Exception {
given(this.response.getRawStatusCode()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR.value());
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
given(this.response.getHeaders()).willReturn(responseHeaders);
byte[] body = "{\"foo\":\"bar\"}".getBytes(StandardCharsets.UTF_8);
responseHeaders.setContentLength(body.length);
given(this.response.getBody()).willReturn(new ByteArrayInputStream(body));
try {
this.errorHandler.handleError(this.response);
fail("MyRestClientException expected");
} catch (MyRestClientException ex) {
replacedertEquals("bar", ex.getFoo());
}
}
17
View Complete Implementation : AbstractHttpReceivingTransportHandler.java
Copyright MIT License
Author : codeEngraver
Copyright MIT License
Author : codeEngraver
private void handleReadError(ServerHttpResponse response, String error, String sessionId) {
try {
response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
response.getBody().write(error.getBytes(StandardCharsets.UTF_8));
} catch (IOException ex) {
throw new SockJsException("Failed to send error: " + error, sessionId, ex);
}
}
17
View Complete Implementation : RestTemplateIntegrationTests.java
Copyright MIT License
Author : codeEngraver
Copyright MIT License
Author : codeEngraver
@Test
public void serverError() {
try {
template.execute(baseUrl + "/status/server", HttpMethod.GET, null, null);
fail("HttpServerErrorException expected");
} catch (HttpServerErrorException ex) {
replacedertEquals(HttpStatus.INTERNAL_SERVER_ERROR, ex.getStatusCode());
replacedertNotNull(ex.getStatusText());
replacedertNotNull(ex.getResponseBodyreplacedtring());
}
}
17
View Complete Implementation : AbstractHttpReceivingTransportHandler.java
Copyright MIT License
Author : Vip-Augus
Copyright MIT License
Author : Vip-Augus
private void handleReadError(ServerHttpResponse response, String error, String sessionId) {
try {
response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
response.getBody().write(error.getBytes(StandardCharsets.UTF_8));
} catch (IOException ex) {
throw new SockJsException("Failed to send error: " + error, sessionId, ex);
}
}
17
View Complete Implementation : GatewayRestControllerTest.java
Copyright Apache License 2.0
Author : KonkerLabs
Copyright Apache License 2.0
Author : KonkerLabs
@Test
public void shouldReturnInternalErrorWhenDeleteGateway() throws Exception {
when(gatewayService.remove(tenant, application, gateway.getGuid())).thenReturn(ServiceResponseBuilder.<Gateway>error().build());
getMockMvc().perform(MockMvcRequestBuilders.delete(MessageFormat.format("/{0}/{1}/{2}", application.getName(), BASEPATH, gateway.getGuid())).contentType("application/json").accept(MediaType.APPLICATION_JSON)).andExpect(status().is5xxServerError()).andExpect(content().contentType("application/json;charset=UTF-8")).andExpect(jsonPath("$.code", is(HttpStatus.INTERNAL_SERVER_ERROR.value()))).andExpect(jsonPath("$.status", is("error"))).andExpect(jsonPath("$.timestamp", greaterThan(1400000000))).andExpect(jsonPath("$.result").doesNotExist());
}
17
View Complete Implementation : AbstractHttpReceivingTransportHandler.java
Copyright Apache License 2.0
Author : spring-projects
Copyright Apache License 2.0
Author : spring-projects
private void handleReadError(ServerHttpResponse response, String error, String sessionId) {
try {
response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
response.getBody().write(error.getBytes(StandardCharsets.UTF_8));
} catch (IOException ex) {
throw new SockJsException("Failed to send error: " + error, sessionId, ex);
}
}
17
View Complete Implementation : ExtractingResponseErrorHandlerTests.java
Copyright MIT License
Author : codeEngraver
Copyright MIT License
Author : codeEngraver
@Test
public void hasError() throws Exception {
given(this.response.getRawStatusCode()).willReturn(HttpStatus.I_AM_A_TEAPOT.value());
replacedertTrue(this.errorHandler.hasError(this.response));
given(this.response.getRawStatusCode()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR.value());
replacedertTrue(this.errorHandler.hasError(this.response));
given(this.response.getRawStatusCode()).willReturn(HttpStatus.OK.value());
replacedertFalse(this.errorHandler.hasError(this.response));
}
17
View Complete Implementation : LocationByGatewayRestControllerTest.java
Copyright Apache License 2.0
Author : KonkerLabs
Copyright Apache License 2.0
Author : KonkerLabs
@Test
public void shouldTryUpdateLocationWithInternalError() throws Exception {
when(locationService.update(tenant, application, location1.getGuid(), location1)).thenReturn(ServiceResponseBuilder.<Location>error().withMessage(LocationService.Messages.LOCATION_NOT_FOUND.getCode()).build());
getMockMvc().perform(MockMvcRequestBuilders.put(MessageFormat.format("/{0}/{1}/{2}", application.getName(), BASEPATH, location1.getName())).content(getJson(new LocationVO().apply(location1))).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andExpect(status().is5xxServerError()).andExpect(content().contentType("application/json;charset=UTF-8")).andExpect(jsonPath("$.code", is(HttpStatus.INTERNAL_SERVER_ERROR.value()))).andExpect(jsonPath("$.status", is("error"))).andExpect(jsonPath("$.timestamp", greaterThan(1400000000))).andExpect(jsonPath("$.messages.[0]", is("Location not found: {0}"))).andExpect(jsonPath("$.result").doesNotExist());
}
17
View Complete Implementation : GatewayRestControllerTest.java
Copyright Apache License 2.0
Author : KonkerLabs
Copyright Apache License 2.0
Author : KonkerLabs
@Test
public void shouldReturnInternalErrorWhenUpdateGateway() throws Exception {
when(gatewayService.update(tenant, application, gateway.getGuid(), gateway)).thenReturn(ServiceResponseBuilder.<Gateway>error().build());
getMockMvc().perform(MockMvcRequestBuilders.put(MessageFormat.format("/{0}/{1}/{2}", application.getName(), BASEPATH, gateway.getGuid())).content(getJson(new GatewayVO().apply(gateway))).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andExpect(status().is5xxServerError()).andExpect(content().contentType("application/json;charset=UTF-8")).andExpect(jsonPath("$.code", is(HttpStatus.INTERNAL_SERVER_ERROR.value()))).andExpect(jsonPath("$.status", is("error"))).andExpect(jsonPath("$.timestamp", greaterThan(1400000000))).andExpect(jsonPath("$.messages").doesNotExist()).andExpect(jsonPath("$.result").doesNotExist());
}
17
View Complete Implementation : ExtractingResponseErrorHandlerTests.java
Copyright MIT License
Author : Vip-Augus
Copyright MIT License
Author : Vip-Augus
@Test
public void handleErrorSeriesMatch() throws Exception {
given(this.response.getRawStatusCode()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR.value());
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
given(this.response.getHeaders()).willReturn(responseHeaders);
byte[] body = "{\"foo\":\"bar\"}".getBytes(StandardCharsets.UTF_8);
responseHeaders.setContentLength(body.length);
given(this.response.getBody()).willReturn(new ByteArrayInputStream(body));
try {
this.errorHandler.handleError(this.response);
fail("MyRestClientException expected");
} catch (MyRestClientException ex) {
replacedertEquals("bar", ex.getFoo());
}
}
17
View Complete Implementation : RoleController.java
Copyright MIT License
Author : danielliao11
Copyright MIT License
Author : danielliao11
@GetMapping
@ApiOperation(value = "List", httpMethod = "GET", response = RoleVO.clreplaced)
@ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "token", paramType = "header", dataType = "string", required = true) })
public ResponseEnreplacedy all() {
try {
return new ResponseEnreplacedy<>(roleDomain.all(), HttpStatus.OK);
} catch (Exception e) {
// Return unknown error and log the exception.
return resultHelper.errorResp(logger, e, ErrorType.UNKNOWN, e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
17
View Complete Implementation : UserController.java
Copyright MIT License
Author : danielliao11
Copyright MIT License
Author : danielliao11
@RequestMapping(method = RequestMethod.GET)
@ApiOperation(value = "List", httpMethod = "GET", response = UserVO.clreplaced)
@ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "token", paramType = "header", dataType = "string", required = true), @ApiImplicitParam(name = "name", value = "user's name", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "usr", value = "user's username", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "createdAtAfter", value = "unix milli timestamp", paramType = "query", dataType = "long"), @ApiImplicitParam(name = "createdAtBefore", value = "unix milli timestamp", paramType = "query", dataType = "long"), @ApiImplicitParam(name = "pageNo", paramType = "query", dataType = "int"), @ApiImplicitParam(name = "pageSize", paramType = "query", dataType = "int"), @ApiImplicitParam(name = "sortBy", paramType = "query", dataType = "string", example = "id:desc,usr:desc") })
public ResponseEnreplacedy all(@And({ @Spec(path = "usr", spec = Like.clreplaced), @Spec(path = "name", spec = Like.clreplaced), @Spec(path = "validFlag", constVal = "VALID", spec = In.clreplaced), @Spec(path = "createdAt", params = "createdAtAfter", spec = GreaterThanOrEqual.clreplaced), @Spec(path = "createdAt", params = "createdAtBefore", spec = LessThanOrEqual.clreplaced) }) @ApiIgnore Specification<User> userSpecification, @ApiIgnore UserParam param) {
try {
if (param.getPageNo() == null) {
return new ResponseEnreplacedy<>(userDomain.getAll(userSpecification, QueryHelper.getSort(param.getSortBy())), HttpStatus.OK);
}
} catch (Exception e) {
// Return unknown error and log the exception.
return resultHelper.errorResp(logger, e, ErrorType.UNKNOWN, e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
try {
return new ResponseEnreplacedy<>(userDomain.getPage(userSpecification, QueryHelper.getPageRequest(param)), HttpStatus.OK);
} catch (Exception e) {
// Return unknown error and log the exception.
return resultHelper.errorResp(logger, e, ErrorType.UNKNOWN, e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
17
View Complete Implementation : ResponseCreatorsTests.java
Copyright Apache License 2.0
Author : spring-projects
Copyright Apache License 2.0
Author : spring-projects
@Test
void serverError() throws Exception {
DefaultResponseCreator responseCreator = MockRestResponseCreators.withServerError();
MockClientHttpResponse response = (MockClientHttpResponse) responseCreator.createResponse(null);
replacedertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
replacedertThat(response.getHeaders().isEmpty()).isTrue();
replacedertThat(StreamUtils.copyToByteArray(response.getBody()).length).isEqualTo(0);
}
17
View Complete Implementation : RouterFunctionsTests.java
Copyright MIT License
Author : codeEngraver
Copyright MIT License
Author : codeEngraver
@Test
public void toHttpHandlerHandlerReturnsException() {
HandlerFunction<ServerResponse> handlerFunction = request -> Mono.error(new IllegalStateException());
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
replacedertNotNull(result);
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
replacedertEquals(HttpStatus.INTERNAL_SERVER_ERROR, httpResponse.getStatusCode());
}
17
View Complete Implementation : LocationByGatewayRestControllerTest.java
Copyright Apache License 2.0
Author : KonkerLabs
Copyright Apache License 2.0
Author : KonkerLabs
@Test
public void shouldTryDeleteLocationWithInternalError() throws Exception {
when(locationSearchService.findByName(tenant, application, location1.getName(), false)).thenReturn(ServiceResponseBuilder.<Location>ok().withResult(location1).build());
when(locationService.remove(tenant, application, location1.getGuid())).thenReturn(ServiceResponseBuilder.<Location>error().build());
getMockMvc().perform(MockMvcRequestBuilders.delete(MessageFormat.format("/{0}/{1}/{2}", application.getName(), BASEPATH, location1.getName())).contentType("application/json").accept(MediaType.APPLICATION_JSON)).andExpect(status().is5xxServerError()).andExpect(content().contentType("application/json;charset=UTF-8")).andExpect(jsonPath("$.code", is(HttpStatus.INTERNAL_SERVER_ERROR.value()))).andExpect(jsonPath("$.status", is("error"))).andExpect(jsonPath("$.timestamp", greaterThan(1400000000))).andExpect(jsonPath("$.messages").doesNotExist()).andExpect(jsonPath("$.result").doesNotExist());
}
17
View Complete Implementation : RouterFunctionsTests.java
Copyright Apache License 2.0
Author : spring-projects
Copyright Apache License 2.0
Author : spring-projects
@Test
public void toHttpHandlerHandlerReturnsException() {
HandlerFunction<ServerResponse> handlerFunction = request -> Mono.error(new IllegalStateException());
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
replacedertThat(result).isNotNull();
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
replacedertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
17
View Complete Implementation : RouterFunctionsTests.java
Copyright MIT License
Author : Vip-Augus
Copyright MIT License
Author : Vip-Augus
@Test
public void toHttpHandlerHandlerReturnsException() {
HandlerFunction<ServerResponse> handlerFunction = request -> Mono.error(new IllegalStateException());
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
replacedertNotNull(result);
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
replacedertEquals(HttpStatus.INTERNAL_SERVER_ERROR, httpResponse.getStatusCode());
}