Search in sources :

Example 1 with OnmsGroupList

use of org.opennms.netmgt.model.OnmsGroupList in project opennms by OpenNMS.

the class GroupRestServiceIT method testGroup.

@Test
public void testGroup() throws Exception {
    // Testing GET Collection
    String xml = sendRequest(GET, "/groups", 200);
    assertTrue(xml.contains("Admin"));
    LOG.debug("testGroup: XML = " + xml);
    OnmsGroupList list = JaxbUtils.unmarshal(OnmsGroupList.class, xml);
    assertEquals(1, list.getGroups().size());
    assertEquals(xml, "Admin", list.getGroups().get(0).getName());
    xml = sendRequest(GET, "/groups/Admin", 200);
    assertTrue(xml.contains(">Admin<"));
    sendRequest(GET, "/groups/idontexist", 404);
}
Also used : OnmsGroupList(org.opennms.netmgt.model.OnmsGroupList) Test(org.junit.Test)

Example 2 with OnmsGroupList

use of org.opennms.netmgt.model.OnmsGroupList in project opennms by OpenNMS.

the class GroupRestServiceIT method testAddGroup.

@Test
public void testAddGroup() throws Exception {
    OnmsGroupList groups = JaxbUtils.unmarshal(OnmsGroupList.class, sendRequest(GET, "/groups", 200));
    assertNotNull(groups);
    assertTrue(groups.size() > 0);
    int initialGroupSize = groups.size();
    // add group
    createGroup("My little Test group");
    String xml = sendRequest(GET, "/groups", 200);
    groups = JaxbUtils.unmarshal(OnmsGroupList.class, xml);
    assertEquals(initialGroupSize + 1, groups.size());
    assertTrue(xml.contains(">My little Test group<"));
}
Also used : OnmsGroupList(org.opennms.netmgt.model.OnmsGroupList) Test(org.junit.Test)

Example 3 with OnmsGroupList

use of org.opennms.netmgt.model.OnmsGroupList in project opennms by OpenNMS.

the class GroupRestService method getGroups.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public OnmsGroupList getGroups() {
    readLock();
    try {
        final OnmsGroupList list = m_groupService.getOnmsGroupList();
        final List<OnmsGroup> groups = new ArrayList<OnmsGroup>(list.getGroups());
        Collections.sort(groups, new Comparator<OnmsGroup>() {

            @Override
            public int compare(final OnmsGroup a, final OnmsGroup b) {
                return a.getName().compareTo(b.getName());
            }
        });
        list.setGroups(groups);
        return list;
    } finally {
        readUnlock();
    }
}
Also used : OnmsGroupList(org.opennms.netmgt.model.OnmsGroupList) ArrayList(java.util.ArrayList) OnmsGroup(org.opennms.netmgt.model.OnmsGroup) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

OnmsGroupList (org.opennms.netmgt.model.OnmsGroupList)3 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 OnmsGroup (org.opennms.netmgt.model.OnmsGroup)1