Java Code Examples for org.springframework.http.HttpStatus#values()

The following examples show how to use org.springframework.http.HttpStatus#values() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatusResultMatchersTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testHttpStatusCodeResultMatchers() throws Exception {

	List<AssertionError> failures = new ArrayList<>();

	for (HttpStatus status : HttpStatus.values()) {
		MockHttpServletResponse response = new MockHttpServletResponse();
		response.setStatus(status.value());
		MvcResult mvcResult = new StubMvcResult(request, null, null, null, null, null, response);
		try {
			Method method = getMethodForHttpStatus(status);
			ResultMatcher matcher = (ResultMatcher) ReflectionUtils.invokeMethod(method, this.matchers);
			try {
				matcher.match(mvcResult);
			}
			catch (AssertionError error) {
				failures.add(error);
			}
		}
		catch (Exception ex) {
			throw new Exception("Failed to obtain ResultMatcher for status " + status, ex);
		}
	}

	if (!failures.isEmpty()) {
		fail("Failed status codes: " + failures);
	}
}
 
Example 2
Source File: StatusResultMatchersTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void statusRanges() throws Exception {
	for (HttpStatus status : HttpStatus.values()) {
		MockHttpServletResponse response = new MockHttpServletResponse();
		response.setStatus(status.value());
		MvcResult mvcResult = new StubMvcResult(request, null, null, null, null, null, response);
		switch (status.series().value()) {
			case 1:
				this.matchers.is1xxInformational().match(mvcResult);
				break;
			case 2:
				this.matchers.is2xxSuccessful().match(mvcResult);
				break;
			case 3:
				this.matchers.is3xxRedirection().match(mvcResult);
				break;
			case 4:
				this.matchers.is4xxClientError().match(mvcResult);
				break;
			case 5:
				this.matchers.is5xxServerError().match(mvcResult);
				break;
			default:
				fail("Unexpected range for status code value " + status);
		}
	}
}
 
Example 3
Source File: StatusResultMatchersTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testHttpStatusCodeResultMatchers() throws Exception {

	List<AssertionError> failures = new ArrayList<>();

	for (HttpStatus status : HttpStatus.values()) {
		MockHttpServletResponse response = new MockHttpServletResponse();
		response.setStatus(status.value());
		MvcResult mvcResult = new StubMvcResult(request, null, null, null, null, null, response);
		try {
			Method method = getMethodForHttpStatus(status);
			ResultMatcher matcher = (ResultMatcher) ReflectionUtils.invokeMethod(method, this.matchers);
			try {
				matcher.match(mvcResult);
			}
			catch (AssertionError error) {
				failures.add(error);
			}
		}
		catch (Exception ex) {
			throw new Exception("Failed to obtain ResultMatcher for status " + status, ex);
		}
	}

	if (!failures.isEmpty()) {
		fail("Failed status codes: " + failures);
	}
}
 
Example 4
Source File: StatusResultMatchersTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void statusRanges() throws Exception {
	for (HttpStatus status : HttpStatus.values()) {
		MockHttpServletResponse response = new MockHttpServletResponse();
		response.setStatus(status.value());
		MvcResult mvcResult = new StubMvcResult(request, null, null, null, null, null, response);
		switch (status.series().value()) {
			case 1:
				this.matchers.is1xxInformational().match(mvcResult);
				break;
			case 2:
				this.matchers.is2xxSuccessful().match(mvcResult);
				break;
			case 3:
				this.matchers.is3xxRedirection().match(mvcResult);
				break;
			case 4:
				this.matchers.is4xxClientError().match(mvcResult);
				break;
			case 5:
				this.matchers.is5xxServerError().match(mvcResult);
				break;
			default:
				fail("Unexpected range for status code value " + status);
		}
	}
}
 
Example 5
Source File: HeimdallResponseErrorHandler.java    From heimdall with Apache License 2.0 5 votes vote down vote up
/**
 * Delegates to {@link #hasError(HttpStatus)} with the response status code.
 */
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
	int rawStatusCode = response.getRawStatusCode();
	for (HttpStatus statusCode : HttpStatus.values()) {
		if (statusCode.value() == rawStatusCode) {
			return hasError(statusCode);
		}
	}
	return false;
}
 
Example 6
Source File: StatusResultMatchersTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testHttpStatusCodeResultMatchers() throws Exception {

	List<AssertionError> failures = new ArrayList<AssertionError>();

	for(HttpStatus status : HttpStatus.values()) {
		MockHttpServletResponse response = new MockHttpServletResponse();
		response.setStatus(status.value());
		MvcResult mvcResult = new StubMvcResult(request, null, null, null, null, null, response);
		try {
			Method method = getMethodForHttpStatus(status);
			ResultMatcher matcher = (ResultMatcher) ReflectionUtils.invokeMethod(method, this.matchers);
			try {
				matcher.match(mvcResult);
			}
			catch (AssertionError error) {
				failures.add(error);
			}
		}
		catch (Exception ex) {
			throw new Exception("Failed to obtain ResultMatcher for status " + status, ex);
		}
	}

	if (!failures.isEmpty()) {
		fail("Failed status codes: " + failures);
	}
}
 
Example 7
Source File: StatusResultMatchersTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void statusRanges() throws Exception {

	for(HttpStatus status : HttpStatus.values()) {

		MockHttpServletResponse response = new MockHttpServletResponse();
		response.setStatus(status.value());
		MvcResult mvcResult = new StubMvcResult(request, null, null, null, null, null, response);
		switch (status.series().value()) {
			case 1:
				this.matchers.is1xxInformational().match(mvcResult);
				break;
			case 2:
				this.matchers.is2xxSuccessful().match(mvcResult);
				break;
			case 3:
				this.matchers.is3xxRedirection().match(mvcResult);
				break;
			case 4:
				this.matchers.is4xxClientError().match(mvcResult);
				break;
			case 5:
				this.matchers.is5xxServerError().match(mvcResult);
				break;
			default:
				fail("Unexpected range for status code value " + status);
		}
	}
}
 
Example 8
Source File: AdviceTraitsTest.java    From problem-spring-web with MIT License 4 votes vote down vote up
@SuppressWarnings("unused")
private static HttpStatus[] data() {
    return HttpStatus.values();
}