Skip to content

Instantly share code, notes, and snippets.

@jeffblack360
Created February 22, 2013 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffblack360/5010200 to your computer and use it in GitHub Desktop.
Save jeffblack360/5010200 to your computer and use it in GitHub Desktop.
How to set "roles" in the createUser_shouldCreateANewUserWithRoles() @test method.
/**
* @see UserController#createUser(SimpleObject,WebRequest)
* @throws Exception
* @verifies create a new user
*/
@Test
public void createUser_shouldCreateANewUserWithRoles() throws Exception {
long originalCount = getAllCount();
SimpleObject user = new SimpleObject();
user.add("username", "test user");
user.add("password", "Secret123");
user.add("person", "da7f524f-27ce-4bb2-86d6-6d1d05312bd5");
user.add("roles", new String[] {"3480cb6d-c291-46c8-8d3a-96dc33d199fb"});
String json = new ObjectMapper().writeValueAsString(user);
MockHttpServletRequest req = request(RequestMethod.POST, getURI());
req.setContent(json.getBytes());
SimpleObject newUser = deserialize(handle(req));
Util.log("Created User", newUser);
Assert.assertNotNull(PropertyUtils.getProperty(newUser, "uuid"));
Assert.assertEquals(originalCount + 1, getAllCount());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment