Java Code Examples for org.springframework.http.MediaType#APPLICATION_ATOM_XML

The following examples show how to use org.springframework.http.MediaType#APPLICATION_ATOM_XML . 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: HttpEntityMethodProcessorMockTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test(expected = HttpMediaTypeNotAcceptableException.class)
public void handleReturnValueNotAcceptable() throws Exception {
	String body = "Foo";
	ResponseEntity<String> returnValue = new ResponseEntity<String>(body, HttpStatus.OK);

	MediaType accepted = MediaType.APPLICATION_ATOM_XML;
	servletRequest.addHeader("Accept", accepted.toString());

	given(messageConverter.canWrite(String.class, null)).willReturn(true);
	given(messageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN));
	given(messageConverter.canWrite(String.class, accepted)).willReturn(false);

	processor.handleReturnValue(returnValue, returnTypeResponseEntity, mavContainer, webRequest);

	fail("Expected exception");
}
 
Example 2
Source File: RequestResponseBodyMethodProcessorMockTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test(expected = HttpMediaTypeNotAcceptableException.class)
public void handleReturnValueNotAcceptable() throws Exception {
	MediaType accepted = MediaType.APPLICATION_ATOM_XML;
	servletRequest.addHeader("Accept", accepted.toString());

	given(stringMessageConverter.canWrite(String.class, null)).willReturn(true);
	given(stringMessageConverter.getSupportedMediaTypes()).willReturn(Arrays.asList(MediaType.TEXT_PLAIN));
	given(stringMessageConverter.canWrite(String.class, accepted)).willReturn(false);

	processor.handleReturnValue("Foo", returnTypeString, mavContainer, webRequest);
}
 
Example 3
Source File: HttpEntityMethodProcessorMockTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void shouldFailHandlingWhenContentTypeNotSupported() throws Exception {
	String body = "Foo";
	ResponseEntity<String> returnValue = new ResponseEntity<>(body, HttpStatus.OK);
	MediaType accepted = MediaType.APPLICATION_ATOM_XML;
	servletRequest.addHeader("Accept", accepted.toString());

	given(stringHttpMessageConverter.canWrite(String.class, null)).willReturn(true);
	given(stringHttpMessageConverter.getSupportedMediaTypes())
			.willReturn(Collections.singletonList(TEXT_PLAIN));

	assertThatExceptionOfType(HttpMediaTypeNotAcceptableException.class).isThrownBy(() ->
			processor.handleReturnValue(returnValue, returnTypeResponseEntity, mavContainer, webRequest));
}
 
Example 4
Source File: RequestResponseBodyMethodProcessorMockTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test(expected = HttpMediaTypeNotAcceptableException.class)
public void handleReturnValueNotAcceptable() throws Exception {
	MediaType accepted = MediaType.APPLICATION_ATOM_XML;
	servletRequest.addHeader("Accept", accepted.toString());

	given(stringMessageConverter.canWrite(String.class, null)).willReturn(true);
	given(stringMessageConverter.getSupportedMediaTypes()).willReturn(Arrays.asList(MediaType.TEXT_PLAIN));
	given(stringMessageConverter.canWrite(String.class, accepted)).willReturn(false);

	processor.handleReturnValue("Foo", returnTypeString, mavContainer, webRequest);
}
 
Example 5
Source File: HttpEntityMethodProcessorMockTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void shouldFailHandlingWhenContentTypeNotSupported() throws Exception {
	String body = "Foo";
	ResponseEntity<String> returnValue = new ResponseEntity<>(body, HttpStatus.OK);
	MediaType accepted = MediaType.APPLICATION_ATOM_XML;
	servletRequest.addHeader("Accept", accepted.toString());

	given(stringHttpMessageConverter.canWrite(String.class, null)).willReturn(true);
	given(stringHttpMessageConverter.getSupportedMediaTypes())
			.willReturn(Collections.singletonList(TEXT_PLAIN));

	this.thrown.expect(HttpMediaTypeNotAcceptableException.class);
	processor.handleReturnValue(returnValue, returnTypeResponseEntity, mavContainer, webRequest);
}
 
Example 6
Source File: RequestResponseBodyMethodProcessorMockTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test(expected = HttpMediaTypeNotAcceptableException.class)
public void handleReturnValueNotAcceptable() throws Exception {
	MediaType accepted = MediaType.APPLICATION_ATOM_XML;
	servletRequest.addHeader("Accept", accepted.toString());

	given(messageConverter.canWrite(String.class, null)).willReturn(true);
	given(messageConverter.getSupportedMediaTypes()).willReturn(Arrays.asList(MediaType.TEXT_PLAIN));
	given(messageConverter.canWrite(String.class, accepted)).willReturn(false);

	processor.handleReturnValue("Foo", returnTypeString, mavContainer, webRequest);
}