use of org.opennms.netmgt.model.OnmsUser in project opennms by OpenNMS.
the class GroupRestServiceIT method testUsers.
@Test
public void testUsers() throws Exception {
createGroup("deleteMe");
// test add user which does not exist to group
sendRequest(PUT, "/groups/deleteMe/users/totallyUniqueUser", 400);
// create user first
createUser("totallyUniqueUser");
LOG.debug("add totallyUniqueUser to deleteMe");
// add user to group
sendRequest(PUT, "/groups/deleteMe/users/totallyUniqueUser", 204);
String xml = sendRequest(GET, "/groups/deleteMe", 200);
assertTrue(xml.contains("totallyUniqueUser"));
LOG.debug("add totallyUniqueUser to deleteMe a second time");
// add user to group twice
// already added
sendRequest(PUT, "/groups/deleteMe/users/totallyUniqueUser", 400);
LOG.debug("get the list of users");
xml = sendRequest(GET, "/groups/deleteMe/users", 200);
assertEquals(1, StringUtils.countMatches(xml, "totallyUniqueUser"));
assertEquals(1, JaxbUtils.unmarshal(OnmsUserList.class, xml).size());
LOG.debug("get the totallyUniqueUser");
// get specific user
xml = sendRequest(GET, "/groups/deleteMe/users/totallyUniqueUser", 200);
assertNotNull(xml);
OnmsUser user = JaxbUtils.unmarshal(OnmsUser.class, xml);
assertNotNull(user);
assertEquals("totallyUniqueUser", user.getUsername());
LOG.debug("delete temporary users");
// clean up
sendRequest(DELETE, "/groups/deleteMe/users/totallyBogusUser", 400);
sendRequest(DELETE, "/groups/deleteMe/users/totallyUniqueUser", 204);
xml = sendRequest(GET, "/groups/deleteMe", 200);
assertFalse(xml.contains("totallyUniqueUser"));
LOG.debug("check that users were deleted");
// list all users of group
xml = sendRequest(GET, "/groups/deleteMe/users", 200);
assertNotNull(xml);
assertEquals(0, JaxbUtils.unmarshal(OnmsUserList.class, xml).size());
LOG.debug("check specific get when no users");
// get specific user
sendRequest(GET, "/groups/deleteMe/users/totallyUniqueUser", 404);
}
Aggregations