use of org.opennms.netmgt.model.OnmsCategoryCollection in project opennms by OpenNMS.
the class GroupRestServiceIT method testCategories.
@Test
public void testCategories() throws Exception {
createGroup("testGroup");
String xml = sendRequest(GET, "/groups/testGroup/categories", 200);
assertNotNull(xml);
OnmsCategoryCollection categories = JAXB.unmarshal(new StringReader(xml), OnmsCategoryCollection.class);
assertNotNull(categories);
assertTrue(categories.getCategories().isEmpty());
// add category to group
// fails, because Category is not there
sendRequest(PUT, "/groups/testGroup/categories/testCategory", 400);
// create category
createCategory("testCategory");
// should not fail, because Category is now there
sendRequest(PUT, "/groups/testGroup/categories/testCategory", 204);
// get data
xml = sendRequest(GET, "/groups/testGroup/categories/testCategory", 200);
assertNotNull(xml);
OnmsCategory category = JAXB.unmarshal(new StringReader(xml), OnmsCategory.class);
assertNotNull(category);
assertEquals("testCategory", category.getName());
// add again (fails)
// should fail, because Category is already there
sendRequest(PUT, "/groups/testGroup/categories/testCategory", 400);
// remove category from group
// should not fail
sendRequest(DELETE, "/groups/testGroup/categories/testCategory", 204);
// should fail, because category is already removed
sendRequest(DELETE, "/groups/testGroup/categories/testCategory", 400);
// test that all categories for group "testGroup" have been removed
xml = sendRequest(GET, "/groups/testGroup/categories", 200);
assertNotNull(xml);
categories = JaxbUtils.unmarshal(OnmsCategoryCollection.class, xml);
assertNotNull(categories);
assertTrue(categories.getCategories().isEmpty());
}
use of org.opennms.netmgt.model.OnmsCategoryCollection in project opennms by OpenNMS.
the class CategoryRestServiceIT method testCategories.
@Test
@JUnitTemporaryDatabase
public void testCategories() throws Exception {
// get initial categories
String xml = sendRequest("GET", "/categories", 200);
assertNotNull(xml);
OnmsCategoryCollection categories = JAXB.unmarshal(new StringReader(xml), OnmsCategoryCollection.class);
int initialSize = categories.size();
assertNotNull(categories);
assertEquals(initialSize, categories.size());
// add category
createCategory("testCategory");
xml = sendRequest("GET", "/categories", 200);
categories = JAXB.unmarshal(new StringReader(xml), OnmsCategoryCollection.class);
assertEquals(initialSize + 1, categories.size());
assertTrue(xml.contains("name=\"testCategory\""));
// add again (should fail)
sendData("POST", MediaType.APPLICATION_XML, "/categories", JaxbUtils.marshal(new OnmsCategory("testCategory")), 400);
xml = sendRequest("GET", "/categories", 200);
categories = JAXB.unmarshal(new StringReader(xml), OnmsCategoryCollection.class);
assertEquals(initialSize + 1, categories.size());
assertTrue(xml.contains("name=\"testCategory\""));
// delete
sendRequest("DELETE", "/categories/testCategory", 204);
xml = sendRequest("GET", "/categories", 200);
categories = JAXB.unmarshal(new StringReader(xml), OnmsCategoryCollection.class);
assertEquals(initialSize, categories.size());
assertFalse(xml.contains("name=\"testCategory\""));
}
Aggregations