Created
November 3, 2011 22:36
-
-
Save eugenp/1338125 to your computer and use it in GitHub Desktop.
RESTful Web Service Discoverability with Spring MVC 3.1, part 4 - the CREATION test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void whenResourceIsCreated_thenURIOfTheNewlyCreatedResourceIsDiscoverable(){ | |
// When | |
Foo unpersistedResource = new Foo( randomAlphabetic( 6 ) ); | |
Response createResponse = givenAuthenticated().contentType( MIME_JSON ) | |
.body( unpersistedResource ).post( paths.getFooURL() ); | |
final String uriOfNewlyCreatedResource = createResp | |
.getHeader( HttpHeaders.LOCATION ); | |
// Then | |
Response response = givenAuthenticated() | |
.header( HttpHeaders.ACCEPT, MIME_JSON ).get( uriOfNewlyCreatedResource ); | |
Foo resourceFromServer = response.body().as( Foo.class ); | |
assertThat( unpersistedResource, equalTo( resourceFromServer ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment