Java Code Examples for org.springframework.web.bind.annotation.RequestMethod#name()

The following examples show how to use org.springframework.web.bind.annotation.RequestMethod#name() . 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: DataRestOperationBuilder.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Add operation description.
 *
 * @param operation the operation
 * @param requestMethod the request method
 * @param entity the entity
 */
private void addOperationDescription(Operation operation, RequestMethod requestMethod, String entity) {
	switch (requestMethod) {
		case GET:
			operation.setDescription("get-" + entity);
			break;
		case POST:
			operation.setDescription("create-" + entity);
			break;
		case DELETE:
			operation.setDescription("delete-" + entity);
			break;
		case PUT:
			operation.setDescription("update-" + entity);
			break;
		case PATCH:
			operation.setDescription("patch-" + entity);
			break;
		default:
			throw new IllegalArgumentException(requestMethod.name());
	}
}
 
Example 2
Source File: RequestMethodsRequestConditionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void getMatchingConditionWithEmptyConditions() {
	RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition();
	for (RequestMethod method : RequestMethod.values()) {
		if (method != OPTIONS) {
			HttpServletRequest request = new MockHttpServletRequest(method.name(), "");
			assertNotNull(condition.getMatchingCondition(request));
		}
	}
	testNoMatch(condition, OPTIONS);
}
 
Example 3
Source File: DataRestResponseBuilder.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
/**
 * Add response.
 *
 * @param requestMethod the request method
 * @param operationPath the operation path
 * @param apiResponses the api responses
 * @param apiResponse the api response
 */
private void addResponse(RequestMethod requestMethod, String operationPath, ApiResponses apiResponses, ApiResponse apiResponse) {
	switch (requestMethod) {
		case GET:
			addResponse200(apiResponses, apiResponse);
			if (operationPath.contains("/{id}"))
				addResponse404(apiResponses);
			break;
		case POST:
			apiResponses.put(String.valueOf(HttpStatus.CREATED.value()), apiResponse.description(HttpStatus.CREATED.getReasonPhrase()));
			break;
		case DELETE:
			addResponse204(apiResponses);
			addResponse404(apiResponses);
			break;
		case PUT:
			addResponse200(apiResponses, apiResponse);
			apiResponses.put(String.valueOf(HttpStatus.CREATED.value()), new ApiResponse().content(apiResponse.getContent()).description(HttpStatus.CREATED.getReasonPhrase()));
			addResponse204(apiResponses);
			break;
		case PATCH:
			addResponse200(apiResponses, apiResponse);
			addResponse204(apiResponses);
			break;
		default:
			throw new IllegalArgumentException(requestMethod.name());
	}
}
 
Example 4
Source File: RequestMethodsRequestConditionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void getMatchingConditionWithEmptyConditions() {
	RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition();
	for (RequestMethod method : RequestMethod.values()) {
		if (method != OPTIONS) {
			HttpServletRequest request = new MockHttpServletRequest(method.name(), "");
			assertNotNull(condition.getMatchingCondition(request));
		}
	}
	testNoMatch(condition, OPTIONS);
}
 
Example 5
Source File: RequestMethodsRequestConditionTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private void testMatch(RequestMethodsRequestCondition condition, RequestMethod method) {
	MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "");
	RequestMethodsRequestCondition actual = condition.getMatchingCondition(request);
	assertNotNull(actual);
	assertEquals(Collections.singleton(method), actual.getContent());
}
 
Example 6
Source File: RequestMethodsRequestConditionTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private void testNoMatch(RequestMethodsRequestCondition condition, RequestMethod method) {
	MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "");
	assertNull(condition.getMatchingCondition(request));
}
 
Example 7
Source File: RequestMethodsRequestConditionTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void testMatch(RequestMethodsRequestCondition condition, RequestMethod method) {
	MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "");
	RequestMethodsRequestCondition actual = condition.getMatchingCondition(request);
	assertNotNull(actual);
	assertEquals(Collections.singleton(method), actual.getContent());
}
 
Example 8
Source File: RequestMethodsRequestConditionTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void testNoMatch(RequestMethodsRequestCondition condition, RequestMethod method) {
	MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "");
	assertNull(condition.getMatchingCondition(request));
}