use of org.opennms.netmgt.model.OnmsFilterFavorite in project opennms by OpenNMS.
the class FilterFavoriteServiceIT method setUp.
@Before
public void setUp() {
populator.addExtension(new DatabasePopulator.Extension<FilterFavoriteDao>() {
@Override
public DaoSupport<FilterFavoriteDao> getDaoSupport() {
return new DaoSupport<FilterFavoriteDao>(FilterFavoriteDao.class, service.getFilterFavoriteDao());
}
@Override
public void onPopulate(DatabasePopulator populator, FilterFavoriteDao dao) {
dao.save(createFavorite("mvr", "First Favorite 1", "filter=severity%3D6&filter=node%3D2", OnmsFilterFavorite.Page.EVENT));
dao.save(createFavorite("mvr", "First Favorite 2", "filter=severity%3D6&filter=node%3D2", OnmsFilterFavorite.Page.EVENT));
dao.save(createFavorite("mvr", "First Favorite 3", "filter=severity%3D6&filter=node%3D2", OnmsFilterFavorite.Page.EVENT));
dao.save(createFavorite("mvr", "First Favorite 1", "filter=severity%3D6&filter=node%3D2", OnmsFilterFavorite.Page.ALARM));
dao.save(createFavorite("mvr", "First Favorite 2", "filter=severity%3D6&filter=node%3D2", OnmsFilterFavorite.Page.ALARM));
dao.save(createFavorite("mvr", "First Favorite 3", "filter=severity%3D6&filter=node%3D2", OnmsFilterFavorite.Page.ALARM));
}
@Override
public void onShutdown(DatabasePopulator populator, FilterFavoriteDao dao) {
for (OnmsFilterFavorite eachFavorite : dao.findAll()) {
dao.delete(eachFavorite);
}
}
private OnmsFilterFavorite createFavorite(String user, String filterName, String filterCriteria, Page page) {
OnmsFilterFavorite favorite = new OnmsFilterFavorite();
favorite.setName(filterName);
favorite.setFilter(filterCriteria);
favorite.setPage(page);
favorite.setUsername(user);
return favorite;
}
});
populator.populateDatabase();
}
use of org.opennms.netmgt.model.OnmsFilterFavorite in project opennms by OpenNMS.
the class FilterFavoriteServiceIT method createFavorite.
private static OnmsFilterFavorite createFavorite(FilterFavoriteService service, String username, String filterName, String filterCriteria, OnmsFilterFavorite.Page page) throws FilterFavoriteService.FilterFavoriteException {
final OnmsFilterFavorite filterToCreate = new OnmsFilterFavorite();
filterToCreate.setUsername(username);
filterToCreate.setName(filterName);
filterToCreate.setFilter(filterCriteria);
filterToCreate.setPage(page);
return createFavorite(service, filterToCreate, new AssertionCallback() {
@Override
public void validate(OnmsFilterFavorite favoriteToCreate, OnmsFilterFavorite createdFavorite) {
Assert.assertNotNull(favoriteToCreate);
Assert.assertNotNull(createdFavorite);
Assert.assertEquals(favoriteToCreate.getUsername(), createdFavorite.getUsername());
Assert.assertEquals(favoriteToCreate.getName(), createdFavorite.getName());
Assert.assertEquals(favoriteToCreate.getFilter(), createdFavorite.getFilter());
Assert.assertEquals(favoriteToCreate.getPage(), createdFavorite.getPage());
}
});
}
use of org.opennms.netmgt.model.OnmsFilterFavorite in project opennms by OpenNMS.
the class FilterFavoriteServiceIT method createFavorite.
private static OnmsFilterFavorite createFavorite(FilterFavoriteService service, OnmsFilterFavorite createFavorite, AssertionCallback callback) throws FilterFavoriteService.FilterFavoriteException {
final OnmsFilterFavorite favorite = service.createFavorite(createFavorite.getUsername(), createFavorite.getName(), createFavorite.getFilter(), createFavorite.getPage());
callback.validate(createFavorite, favorite);
return favorite;
}
use of org.opennms.netmgt.model.OnmsFilterFavorite in project opennms by OpenNMS.
the class FilterFavoriteServiceIT method testCreateAndDeleteFavorites.
@Test
public void testCreateAndDeleteFavorites() throws FilterFavoriteService.FilterFavoriteException {
List<OnmsFilterFavorite> alarmFavorites = service.getFavorites("mvr", OnmsFilterFavorite.Page.ALARM);
List<OnmsFilterFavorite> eventFavorites = service.getFavorites("mvr", OnmsFilterFavorite.Page.EVENT);
// CREATE OK
OnmsFilterFavorite favorite = createFavorite(service, "mvr", "First Favorite", "filter=severity%3D6&filter=node%3D2", OnmsFilterFavorite.Page.EVENT);
Assert.assertEquals(favorite, service.getFavorite(favorite.getId(), "mvr"));
// check that the created favorite is not in both lists, but in event list
List<OnmsFilterFavorite> newAlarmFavorites = service.getFavorites("mvr", OnmsFilterFavorite.Page.ALARM);
List<OnmsFilterFavorite> newEventFavorites = service.getFavorites("mvr", OnmsFilterFavorite.Page.EVENT);
Assert.assertEquals(alarmFavorites, newAlarmFavorites);
Assert.assertEquals(eventFavorites.size() + 1, newEventFavorites.size());
Assert.assertTrue(newEventFavorites.contains(favorite));
// CREATE NOK
try {
createFavorite(service, favorite.getUsername(), favorite.getName(), favorite.getFilter(), favorite.getPage());
Assert.fail("Creation should have been failed");
} catch (FilterFavoriteService.FilterFavoriteException ex) {
// Don't panic, this is expected ;)
;
}
// READ OK
Assert.assertEquals(favorite, service.getFavorite(favorite.getId(), "mvr"));
// READ NOK
// does not have this favorite
Assert.assertNull(service.getFavorite(favorite.getId(), "admin"));
// DELETE NOK
// does not belong to this user
Assert.assertEquals(false, service.deleteFavorite(favorite.getId(), "admin"));
// check original user, should still be there
Assert.assertNotNull(service.getFavorite(favorite.getId(), "mvr"));
// DELETE OK
// does belong to this user
Assert.assertEquals(true, service.deleteFavorite(favorite.getId(), "mvr"));
// check original user, should be deleted
Assert.assertNull(service.getFavorite(favorite.getId(), "mvr"));
}
use of org.opennms.netmgt.model.OnmsFilterFavorite in project opennms by OpenNMS.
the class EventController method index.
// index view
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws Exception {
List<OnmsFilterFavorite> userFilterList = favoriteService.getFavorites(request.getRemoteUser(), OnmsFilterFavorite.Page.EVENT);
ModelAndView modelAndView = new ModelAndView("event/index");
modelAndView.addObject("favorites", userFilterList.toArray());
modelAndView.addObject("callback", getFilterCallback());
return modelAndView;
}
Aggregations