Search in sources :

Example 21 with OnmsUser

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);
}
Also used : OnmsUser(org.opennms.netmgt.model.OnmsUser) Test(org.junit.Test)

Aggregations

OnmsUser (org.opennms.netmgt.model.OnmsUser)21 Test (org.junit.Test)8 Path (javax.ws.rs.Path)5 User (org.opennms.netmgt.config.users.User)5 ArrayList (java.util.ArrayList)2 DELETE (javax.ws.rs.DELETE)2 PUT (javax.ws.rs.PUT)2 OnmsUserList (org.opennms.netmgt.model.OnmsUserList)2 DirtiesContext (org.springframework.test.annotation.DirtiesContext)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Properties (java.util.Properties)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 Matcher (java.util.regex.Matcher)1