Search in sources :

Example 1 with DatabasePopulator

use of org.opennms.netmgt.dao.DatabasePopulator 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&amp;filter=node%3D2", OnmsFilterFavorite.Page.EVENT));
            dao.save(createFavorite("mvr", "First Favorite 2", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.EVENT));
            dao.save(createFavorite("mvr", "First Favorite 3", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.EVENT));
            dao.save(createFavorite("mvr", "First Favorite 1", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.ALARM));
            dao.save(createFavorite("mvr", "First Favorite 2", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.ALARM));
            dao.save(createFavorite("mvr", "First Favorite 3", "filter=severity%3D6&amp;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();
}
Also used : DaoSupport(org.opennms.netmgt.dao.DatabasePopulator.DaoSupport) OnmsFilterFavorite(org.opennms.netmgt.model.OnmsFilterFavorite) Page(org.opennms.netmgt.model.OnmsFilterFavorite.Page) FilterFavoriteDao(org.opennms.netmgt.dao.api.FilterFavoriteDao) DatabasePopulator(org.opennms.netmgt.dao.DatabasePopulator) Before(org.junit.Before)

Example 2 with DatabasePopulator

use of org.opennms.netmgt.dao.DatabasePopulator in project opennms by OpenNMS.

the class OutageRestServiceIT method setUp.

@Before
@Override
public void setUp() throws Throwable {
    super.setUp();
    Assert.assertNotNull(populator);
    Assert.assertNotNull(applicationDao);
    populator.addExtension(new DatabasePopulator.Extension<ApplicationDao>() {

        private OnmsOutage unresolvedOutage;

        private OnmsEvent outageEvent;

        private OnmsApplication application;

        @Override
        public DatabasePopulator.DaoSupport<ApplicationDao> getDaoSupport() {
            return new DatabasePopulator.DaoSupport<>(ApplicationDao.class, applicationDao);
        }

        @Override
        public void onPopulate(DatabasePopulator populator, ApplicationDao dao) {
            OnmsDistPoller distPoller = populator.getDistPollerDao().whoami();
            outageEvent = populator.buildEvent(distPoller);
            outageEvent.setEventSeverity(OnmsSeverity.MINOR.getId());
            outageEvent.setEventCreateTime(new Date(1436881548292L));
            outageEvent.setEventTime(new Date(1436881548292L));
            populator.getEventDao().save(outageEvent);
            populator.getEventDao().flush();
            // create the application
            application = new OnmsApplication();
            application.setName("Awesome Application");
            dao.save(application);
            // get the SNMP service from node 1 and assign the application to it
            final OnmsMonitoredService svc = populator.getMonitoredServiceDao().get(populator.getNode1().getId(), InetAddressUtils.addr("192.168.1.2"), "HTTP");
            svc.addApplication(application);
            application.addMonitoredService(svc);
            populator.getMonitoredServiceDao().saveOrUpdate(svc);
            populator.getMonitoredServiceDao().flush();
            // create a unresolved outage
            unresolvedOutage = new OnmsOutage(new Date(1436881548292L), outageEvent, svc);
            populator.getOutageDao().save(unresolvedOutage);
            populator.getOutageDao().flush();
        }

        @Override
        public void onShutdown(DatabasePopulator populator, ApplicationDao dao) {
            // Delete OnmsApplications
            for (OnmsApplication application : dao.findAll()) {
                dao.delete(application);
            }
        }
    });
    populator.populateDatabase();
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) ApplicationDao(org.opennms.netmgt.dao.api.ApplicationDao) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) DatabasePopulator(org.opennms.netmgt.dao.DatabasePopulator) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Before(org.junit.Before)

Aggregations

Before (org.junit.Before)2 DatabasePopulator (org.opennms.netmgt.dao.DatabasePopulator)2 Date (java.util.Date)1 DaoSupport (org.opennms.netmgt.dao.DatabasePopulator.DaoSupport)1 ApplicationDao (org.opennms.netmgt.dao.api.ApplicationDao)1 FilterFavoriteDao (org.opennms.netmgt.dao.api.FilterFavoriteDao)1 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)1 OnmsDistPoller (org.opennms.netmgt.model.OnmsDistPoller)1 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)1 OnmsFilterFavorite (org.opennms.netmgt.model.OnmsFilterFavorite)1 Page (org.opennms.netmgt.model.OnmsFilterFavorite.Page)1 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)1 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)1