Search in sources :

Example 1 with IpLikeHopCriteria

use of org.opennms.features.topology.app.internal.support.IpLikeHopCriteria in project opennms by OpenNMS.

the class BundleContextHistoryManagerTest method verifySearchCriteriaPersistence.

/**
 * <p>This method tests the correctness of {@link org.opennms.features.topology.api.support.HistoryAwareSearchProvider#buildCriteriaFromQuery(SearchResult, GraphContainer)} method.
 * The {@link SearchCriteria} objects, generated by this method, are compared to those created directly, with the use of a corresponding constructor</p>
 * <p>
 * Additionally, it checks whether the {@link SavedHistory} objects are saved / loaded correctly and whether there is any data loss / distortion
 * </p>
 */
@Test
public void verifySearchCriteriaPersistence() {
    // Test 1 - checking whether method buildCriteriaFromQuery is working correctly
    // Testing for CategoryHopCriteria & CategorySearchProvider
    Criteria criterionNew = ((HistoryAwareSearchProvider) this.startingProviders.get(CriteriaTypes.category)).buildCriteriaFromQuery(this.startingSearchResults.get(CriteriaTypes.category), graphContainerMock);
    Assert.assertEquals(this.startingCriteria.get(CriteriaTypes.category), criterionNew);
    // Testing for IpLikeHopCriteria & IpLikeSearchProvider
    criterionNew = ((HistoryAwareSearchProvider) this.startingProviders.get(CriteriaTypes.ipLike)).buildCriteriaFromQuery(this.startingSearchResults.get(CriteriaTypes.ipLike), graphContainerMock);
    Assert.assertEquals(this.startingCriteria.get(CriteriaTypes.ipLike), criterionNew);
    // Testing for AlarmHopCriteria & AlarmSearchProvider
    criterionNew = ((HistoryAwareSearchProvider) this.startingProviders.get(CriteriaTypes.alarm)).buildCriteriaFromQuery(this.startingSearchResults.get(CriteriaTypes.alarm), graphContainerMock);
    Assert.assertEquals(this.startingCriteria.get(CriteriaTypes.alarm), criterionNew);
    // Step 1 - providing GraphContainer with a starting Criteria set
    for (Criteria criteria : this.startingCriteria.values()) {
        graphContainerMock.addCriteria(criteria);
    }
    // Saving and then loading history
    String fragment = historyManager.saveOrUpdateHistory("admin", graphContainerMock);
    historyManager.applyHistory(fragment, graphContainerMock);
    Assert.assertNotNull(capturedCriteria);
    Assert.assertThat(startingCriteria.values(), containsInAnyOrder(capturedCriteria.toArray()));
}
Also used : CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) SearchCriteria(org.opennms.features.topology.api.topo.SearchCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) IpLikeHopCriteria(org.opennms.features.topology.app.internal.support.IpLikeHopCriteria) AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) HistoryAwareSearchProvider(org.opennms.features.topology.api.support.HistoryAwareSearchProvider) Test(org.junit.Test)

Example 2 with IpLikeHopCriteria

use of org.opennms.features.topology.app.internal.support.IpLikeHopCriteria in project opennms by OpenNMS.

the class BundleContextHistoryManagerTest method initProvidersAndCriteria.

/**
 * In this method all starting {@link SearchCriteria} and {@link SearchProvider} objects are initialized
 */
private void initProvidersAndCriteria() {
    // Preparing SearchProviders
    CategoryProvider vertexProvider = new CategoryProvider() {

        @Override
        public Collection<OnmsCategory> getAllCategories() {
            return Lists.newArrayList(findCategoryByName("somename"));
        }

        @Override
        public OnmsCategory findCategoryByName(String m_categoryName) {
            OnmsCategory cat = new OnmsCategory("test", "test");
            cat.setId(Integer.valueOf(idCategory));
            return cat;
        }

        @Override
        public List<OnmsNode> findNodesForCategory(OnmsCategory category) {
            return new ArrayList<>();
        }
    };
    IpInterfaceProvider ipInterfaceProvider = new IpInterfaceProvider() {

        @Override
        public List<OnmsIpInterface> findMatching(org.opennms.core.criteria.Criteria criteria) {
            OnmsNode node = new OnmsNode();
            node.setId(Integer.valueOf(idIpLike));
            String ipAddr = "127.0.0.1";
            OnmsIpInterface ipInterface = new OnmsIpInterface(ipAddr, node);
            return Lists.newArrayList(ipInterface);
        }
    };
    AlarmProvider alarmProvider = new AlarmProvider() {

        @Override
        public List<OnmsAlarm> findMatchingAlarms(org.opennms.core.criteria.Criteria criteria) {
            Date eventTime = new Date();
            OnmsDistPoller distPoller = new OnmsDistPoller("pollerID");
            OnmsEvent event = new OnmsEvent();
            OnmsAlarm alarm = new OnmsAlarm(Integer.valueOf(idAlarm), "eventUI", distPoller, 2, 3, eventTime, event);
            return Lists.newArrayList(alarm);
        }
    };
    // Creating SearchResults to be used in testing
    SearchResult sResultCategory = new SearchResult(CategoryHopCriteria.NAMESPACE, idCategory, labelCategory, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
    SearchResult sResultAlarm = new SearchResult(AlarmHopCriteria.NAMESPACE, idAlarm, labelAlarm, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
    SearchResult sResultIpLike = new SearchResult(IpLikeHopCriteria.NAMESPACE, idIpLike, labelIpLike, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
    this.startingSearchResults.put(CriteriaTypes.alarm, sResultAlarm);
    this.startingSearchResults.put(CriteriaTypes.ipLike, sResultIpLike);
    this.startingSearchResults.put(CriteriaTypes.category, sResultCategory);
    // Initializing available (initial) SearchProviders
    final DefaultTopologyService topologyService = new DefaultTopologyService();
    topologyService.setServiceLocator(serviceLocatorMock);
    this.startingProviders.put(CriteriaTypes.category, new CategorySearchProvider(topologyService, vertexProvider));
    this.startingProviders.put(CriteriaTypes.ipLike, new IpLikeSearchProvider(ipInterfaceProvider));
    this.startingProviders.put(CriteriaTypes.alarm, new AlarmSearchProvider(alarmProvider));
    // Initializing available (initial) Criteria
    this.startingCriteria.put(CriteriaTypes.category, new CategoryHopCriteria(sResultCategory, vertexProvider, graphContainerMock));
    this.startingCriteria.put(CriteriaTypes.ipLike, new IpLikeHopCriteria(sResultIpLike, ipInterfaceProvider));
    this.startingCriteria.put(CriteriaTypes.alarm, new AlarmHopCriteria(new AlarmSearchProvider(alarmProvider).new AlarmSearchResult(sResultAlarm), alarmProvider));
}
Also used : CategoryProvider(org.opennms.features.topology.app.internal.CategoryProvider) OnmsNode(org.opennms.netmgt.model.OnmsNode) IpInterfaceProvider(org.opennms.features.topology.app.internal.IpInterfaceProvider) DefaultTopologyService(org.opennms.features.topology.app.internal.service.DefaultTopologyService) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ArrayList(java.util.ArrayList) OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) SearchResult(org.opennms.features.topology.api.topo.SearchResult) CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) SearchCriteria(org.opennms.features.topology.api.topo.SearchCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) IpLikeHopCriteria(org.opennms.features.topology.app.internal.support.IpLikeHopCriteria) AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) Date(java.util.Date) CategorySearchProvider(org.opennms.features.topology.app.internal.CategorySearchProvider) IpLikeHopCriteria(org.opennms.features.topology.app.internal.support.IpLikeHopCriteria) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) AlarmSearchProvider(org.opennms.features.topology.app.internal.AlarmSearchProvider) AlarmProvider(org.opennms.features.topology.app.internal.AlarmProvider) AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) IpLikeSearchProvider(org.opennms.features.topology.app.internal.IpLikeSearchProvider)

Example 3 with IpLikeHopCriteria

use of org.opennms.features.topology.app.internal.support.IpLikeHopCriteria in project opennms by OpenNMS.

the class IpLikeSearchProvider method addVertexHopCriteria.

/**
 * Creates a criteria that provides <VertexRefs> matching the IPLIKE query from the users query
 * stored in the <SearchResult> that was created by this class during the query method.  The SearchResult
 * and the Criterion use the OnmsIpinterfaceId as the ID for dereferencing in the container.
 */
@Override
public void addVertexHopCriteria(SearchResult searchResult, GraphContainer container) {
    LOG.debug("SearchProvider->addVertexHopCriteria: called with search result: '{}'", searchResult);
    IpLikeHopCriteria criterion = createCriteria(searchResult);
    container.addCriteria(criterion);
    LOG.debug("SearchProvider->addVertexHop: adding hop criteria {}.", criterion);
    logCriteriaInContainer(container);
}
Also used : IpLikeHopCriteria(org.opennms.features.topology.app.internal.support.IpLikeHopCriteria)

Aggregations

IpLikeHopCriteria (org.opennms.features.topology.app.internal.support.IpLikeHopCriteria)3 Criteria (org.opennms.features.topology.api.topo.Criteria)2 SearchCriteria (org.opennms.features.topology.api.topo.SearchCriteria)2 AlarmHopCriteria (org.opennms.features.topology.app.internal.support.AlarmHopCriteria)2 CategoryHopCriteria (org.opennms.features.topology.app.internal.support.CategoryHopCriteria)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Test (org.junit.Test)1 HistoryAwareSearchProvider (org.opennms.features.topology.api.support.HistoryAwareSearchProvider)1 SearchResult (org.opennms.features.topology.api.topo.SearchResult)1 AlarmProvider (org.opennms.features.topology.app.internal.AlarmProvider)1 AlarmSearchProvider (org.opennms.features.topology.app.internal.AlarmSearchProvider)1 CategoryProvider (org.opennms.features.topology.app.internal.CategoryProvider)1 CategorySearchProvider (org.opennms.features.topology.app.internal.CategorySearchProvider)1 IpInterfaceProvider (org.opennms.features.topology.app.internal.IpInterfaceProvider)1 IpLikeSearchProvider (org.opennms.features.topology.app.internal.IpLikeSearchProvider)1 DefaultTopologyService (org.opennms.features.topology.app.internal.service.DefaultTopologyService)1 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)1 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)1 OnmsDistPoller (org.opennms.netmgt.model.OnmsDistPoller)1