Created
February 18, 2012 03:49
-
-
Save brianm/1857271 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 testStartDeployedThing() throws Exception | |
{ | |
// find the deployment url | |
_Root root = http.prepareGet("http://localhost:25365/") | |
.setHeader("accept", MediaType.APPLICATION_JSON) | |
.execute(new JsonMappingAsyncHandler<_Root>(_Root.class)).get(); | |
_Action deploy = Iterables.find(root._actions, fieldEquals("rel", "deploy")); | |
// perform a deployment against it | |
_DeployedSlot c = http.preparePost(deploy.uri) | |
.setHeader("content-type", MediaType.APPLICATION_JSON) | |
.setBody(mapper.writeValueAsString(new _Deploy())) | |
.execute(new JsonMappingAsyncHandler<_DeployedSlot>(_DeployedSlot.class)) | |
.get(); | |
// start the deployed thing | |
_Action start = Iterables.find(c._actions, fieldEquals("rel", "start")); | |
assertThat(start.method, equalTo("POST")); | |
assertThat(start.params, equalTo(Collections.<String, String>emptyMap())); | |
Response start_response = http.preparePost(start.uri) | |
.execute() | |
.get(); | |
// http client does not follow redirects correctly, so we | |
// need to hardcode following the see other :-( | |
assertThat(start_response.getStatusCode(), isHttpRedirect()); | |
String slot_uri = start_response.getHeader("location"); | |
// check to make sure the deployed thing is now running | |
_DeployedSlot started = http.prepareGet(slot_uri) | |
.setHeader("accept", MediaType.APPLICATION_JSON) | |
.execute(new JsonMappingAsyncHandler<_DeployedSlot>(_DeployedSlot.class)) | |
.get(); | |
assertThat(started.slot.running, equalTo(true)); | |
} |
_Foo is a convention I use for throwaway classes, in this case for things which exist solely for jackson to map json into for this test. It largely prevents them showing up with IDEA's go to class behavior.
Nice, very readable. Have you thought of how to add abstractions for retries, or generalized error handling?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Part of integration/acceptance test suite for https://github.com/brianm/sculptor (which has no readme as it is not ready for general consumption :-)